diff --git a/config/fxdata/lua/classes/Creature.lua b/config/fxdata/lua/classes/Creature.lua index 901dd62b21..f8805b98aa 100644 --- a/config/fxdata/lua/classes/Creature.lua +++ b/config/fxdata/lua/classes/Creature.lua @@ -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 @@ -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 diff --git a/src/lua_api.c b/src/lua_api.c index c5b0d0f457..e9d13c6d5a 100644 --- a/src/lua_api.c +++ b/src/lua_api.c @@ -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); diff --git a/src/lua_api_things.c b/src/lua_api_things.c index 6d75b3bd4a..b06f99d9ed 100644 --- a/src/lua_api_things.c +++ b/src/lua_api_things.c @@ -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); @@ -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 },