diff --git a/config/fxdata/lua/triggers/Builtins.lua b/config/fxdata/lua/triggers/Builtins.lua index 14614b61e9..d3c6c550a1 100644 --- a/config/fxdata/lua/triggers/Builtins.lua +++ b/config/fxdata/lua/triggers/Builtins.lua @@ -90,7 +90,6 @@ function OnApplyDamage(thing, damage, dealing_player) ProcessEvent("ApplyDamage",eventData) end - --- Called when a creature levels up ---@param creature Creature function OnLevelUp(creature) @@ -99,6 +98,22 @@ function OnLevelUp(creature) ProcessEvent("LevelUp",eventData) end +--- Called when a thing is picked up. Can be Creatures, Chickens, Specials, Gold, etc. +---@param thing Thing +function OnPickUp(thing) + local eventData = {} + eventData.thing = thing + ProcessEvent("PickUp",eventData) +end + +--- Called when a thing is slapped. Can be Creatures, Traps, Shots, Objects, etc. +---@param thing Thing +function OnSlap(thing) + local eventData = {} + eventData.thing = thing + ProcessEvent("Slap",eventData) +end + --- Called when a unit resurrects from his rebirth ability (like a vampire) --- @param unit Creature The unit that rises from the death with 1xp level less function OnCreatureRebirth(unit) diff --git a/src/lua_triggers.c b/src/lua_triggers.c index 1a88507af6..2605e427e4 100644 --- a/src/lua_triggers.c +++ b/src/lua_triggers.c @@ -279,6 +279,38 @@ void lua_on_level_up(struct Thing *thing) } } +void lua_on_pick_up(struct Thing* thing, PlayerNumber plyr_idx) +{ + SYNCDBG(6, "Starting"); + lua_getglobal(Lvl_script, "OnPickUp"); + if (lua_isfunction(Lvl_script, -1)) + { + lua_pushThing(Lvl_script, thing); + lua_pushPlayer(Lvl_script, plyr_idx); + CheckLua(Lvl_script, lua_pcall(Lvl_script, 1, 0, 0), "OnPickUp"); + } + else + { + lua_pop(Lvl_script, 1); + } +} + +void lua_on_slap(struct Thing* thing,PlayerNumber plyr_idx) +{ + SYNCDBG(6, "Starting"); + lua_getglobal(Lvl_script, "OnSlap"); + if (lua_isfunction(Lvl_script, -1)) + { + lua_pushThing(Lvl_script, thing); + lua_pushPlayer(Lvl_script, plyr_idx); + CheckLua(Lvl_script, lua_pcall(Lvl_script, 1, 0, 0), "OnSlap"); + } + else + { + lua_pop(Lvl_script, 1); + } +} + // Called when a slab type changes (e.g. pretty_path -> hatchery_area, path -> pretty_path) void lua_on_slab_kind_change(MapSlabCoord slb_x, MapSlabCoord slb_y, SlabKind old_slab) { diff --git a/src/lua_triggers.h b/src/lua_triggers.h index acb5376daf..c3ee6b98b8 100644 --- a/src/lua_triggers.h +++ b/src/lua_triggers.h @@ -39,6 +39,8 @@ void lua_on_trap_placed(struct Thing *traptng); void lua_on_object_destroyed(struct Thing* objtng); void lua_on_apply_damage_to_thing(struct Thing *thing, HitPoints dmg, PlayerNumber dealing_plyr_idx); void lua_on_level_up(struct Thing *thing); +void lua_on_pick_up(struct Thing* thing, PlayerNumber plyr_idx); +void lua_on_slap(struct Thing* thing, PlayerNumber plyr_idx); void lua_on_slab_kind_change(MapSlabCoord slb_x, MapSlabCoord slb_y, SlabKind old_slab); void lua_on_slab_owner_change(MapSlabCoord slb_x, MapSlabCoord slb_y, PlayerNumber old_owner); void lua_on_room_owner_change(struct Room *room, PlayerNumber old_owner); diff --git a/src/magic_powers.c b/src/magic_powers.c index 757014263d..565ce25a77 100644 --- a/src/magic_powers.c +++ b/src/magic_powers.c @@ -1159,9 +1159,11 @@ static TbResult magic_use_power_hand(PowerKind power_kind, PlayerNumber plyr_idx { if (power_hand_is_full(get_player(plyr_idx))) return Lb_FAIL; - else - if (place_thing_in_power_hand(thing, plyr_idx)) + else if (place_thing_in_power_hand(thing, plyr_idx)) + { + lua_on_pick_up(thing, plyr_idx); return Lb_SUCCESS; + } else return Lb_FAIL; } @@ -1751,6 +1753,7 @@ static TbResult magic_use_power_slap_thing(PowerKind power_kind, PlayerNumber pl { struct PlayerInfo *player; struct Dungeon *dungeon; + lua_on_slap(thing, plyr_idx); if (!thing_exists(thing)) { return Lb_FAIL; }