Skip to content
Merged
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
7 changes: 6 additions & 1 deletion config/fxdata/lua/classes/Creature.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function Creature:teleport(location,effect) end
function Creature:kill(killer) end

---Stuns the creature
---@param turns ? Sets conscious_back_turns; the duration of the stun.
---@param turns? integer Sets conscious_back_turns; the duration of the stun.
function Creature:stun(turns) end

---increases creatures level by a given amount
Expand All @@ -64,6 +64,11 @@ function Creature:level_up(levels) end
---sends the creature to the next level, similar to using the special box and selecting said unit
function Creature:transfer() end

---Transforms the creature into another model
---@param creaturemodel creature_type type of creature to transform into
---@param level integer xp level the creature gets. Use 0 for random
function Creature:transform(creaturemodel,level) end

---Checks if the creature is under enemy custody (e.g. in prison or torture chamber)
---@return boolean in_enemy_custody If the creature is currently controlled by the enemy
function Creature:in_enemy_custody() end
Expand Down
2 changes: 1 addition & 1 deletion src/lua_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ static int lua_Set_next_level(lua_State *L)
static int lua_Add_creature_to_level(lua_State *L)
{
PlayerNumber plr_idx = luaL_checkPlayerSingle(L, 1);
long crtr_id = luaL_checkNamedCommand(L,2,creature_desc);
ThingModel crtr_id = luaL_checkNamedCommand(L,2,creature_desc);
TbMapLocation location = luaL_checkLocation(L, 3);
long crtr_level = luaL_checkinteger(L, 4);
long carried_gold = luaL_checkinteger(L, 5);
Expand Down
17 changes: 17 additions & 0 deletions src/lua_api_things.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,22 @@ static int lua_kill_creature(lua_State *L)
return 0;
}

static int lua_transform_creature(lua_State* L)
{
struct Thing* thing = luaL_checkCreature(L, 1);
ThingModel crtr_id = luaL_checkNamedCommand(L, 2, creature_desc);
int16_t crtr_level = luaL_checkinteger(L, 3);

if ((crtr_level < 0) || (crtr_level > CREATURE_MAX_LEVEL))
{
SCRPTERRLOG("Invalid CREATURE LEVEL parameter");
return 0;
}

grow_up_creature(thing, crtr_id, crtr_level);
return 0;
}

static int lua_stun_creature(lua_State* L)
{
struct Thing* thing = luaL_checkThing(L, 1);
Expand Down Expand Up @@ -673,6 +689,7 @@ static const struct luaL_Reg thing_methods[] = {
{"stun" ,lua_stun_creature },
{"destroy" ,lua_destroy_object },
{"delete" ,lua_delete_thing },
{"transform" ,lua_transform_creature },
{"isValid" ,lua_is_valid },
{"transfer" ,lua_Transfer_creature },
{"level_up" ,lua_Level_up_creature },
Expand Down