Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion config/fxdata/lua/triggers/Builtins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Comment on lines +103 to +113
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)
Expand Down
32 changes: 32 additions & 0 deletions src/lua_triggers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Comment on lines +285 to +291
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");
}
Comment on lines +301 to +307
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)
{
Expand Down
2 changes: 2 additions & 0 deletions src/lua_triggers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions src/magic_powers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down