Skip to content

Commit

Permalink
Method setMasterPosition
Browse files Browse the repository at this point in the history
System that uses this method, https://otland.net/threads/1-x-boss-system-with-checker-auto-respawn-and-day-configuration.281920/

The method by Gigastar, https://otland.net/threads/ghazbaran-onstartup.281739/#post-2700646

Co-Authored-By: gigastar <26754137+gigastar@users.noreply.github.com>
  • Loading branch information
ralke23 and NRH-AA committed Sep 9, 2022
1 parent 8215ac6 commit 8f2d82a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/luascript.cpp
Expand Up @@ -2467,6 +2467,7 @@ void LuaScriptInterface::registerFunctions()
registerMethod("Monster", "getType", LuaScriptInterface::luaMonsterGetType);

registerMethod("Monster", "rename", LuaScriptInterface::luaMonsterRename);
registerMethod("Monster", "setMasterPosition", LuaScriptInterface::luaMonsterSetMasterPosition);

registerMethod("Monster", "getSpawnPosition", LuaScriptInterface::luaMonsterGetSpawnPosition);
registerMethod("Monster", "isInSpawnRange", LuaScriptInterface::luaMonsterIsInSpawnRange);
Expand Down Expand Up @@ -9913,6 +9914,36 @@ int LuaScriptInterface::luaMonsterRename(lua_State* L)
return 1;
}

int LuaScriptInterface::luaMonsterSetMasterPosition(lua_State* L)
{
// monster:setMasterPosition(pos)
Monster* monster = getUserdata<Monster>(L, 1);
if (!monster) {
lua_pushnil(L);
return 1;
}

Position position;
if (isTable(L, 2)) {
position = getPosition(L, 2);
}
else {
position.x = getNumber<uint16_t>(L, 2);
position.y = getNumber<uint16_t>(L, 3);
position.z = getNumber<uint16_t>(L, 4);
}

Tile* tile = g_game.map.getTile(position);
if (!tile) {
lua_pushnil(L);
return 1;
}

monster->setMasterPos(position);
pushBoolean(L, true);
return 1;
}

int LuaScriptInterface::luaMonsterGetSpawnPosition(lua_State* L)
{
// monster:getSpawnPosition()
Expand Down
1 change: 1 addition & 0 deletions src/luascript.h
Expand Up @@ -998,6 +998,7 @@ class LuaScriptInterface
static int luaMonsterGetType(lua_State* L);

static int luaMonsterRename(lua_State* L);
static int luaMonsterSetMasterPosition(lua_State* L);

static int luaMonsterGetSpawnPosition(lua_State* L);
static int luaMonsterIsInSpawnRange(lua_State* L);
Expand Down

0 comments on commit 8f2d82a

Please sign in to comment.