From 8f2d82ad839cde1612cc8ac6dc9c8f0ecbc855d6 Mon Sep 17 00:00:00 2001 From: Felipe Del Curto Date: Fri, 9 Sep 2022 02:46:06 -0300 Subject: [PATCH] Method setMasterPosition 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> --- src/luascript.cpp | 31 +++++++++++++++++++++++++++++++ src/luascript.h | 1 + 2 files changed, 32 insertions(+) diff --git a/src/luascript.cpp b/src/luascript.cpp index c8e8158b6..e0a36c6c7 100644 --- a/src/luascript.cpp +++ b/src/luascript.cpp @@ -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); @@ -9913,6 +9914,36 @@ int LuaScriptInterface::luaMonsterRename(lua_State* L) return 1; } +int LuaScriptInterface::luaMonsterSetMasterPosition(lua_State* L) +{ + // monster:setMasterPosition(pos) + Monster* monster = getUserdata(L, 1); + if (!monster) { + lua_pushnil(L); + return 1; + } + + Position position; + if (isTable(L, 2)) { + position = getPosition(L, 2); + } + else { + position.x = getNumber(L, 2); + position.y = getNumber(L, 3); + position.z = getNumber(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() diff --git a/src/luascript.h b/src/luascript.h index d7faf11a8..fbae84668 100644 --- a/src/luascript.h +++ b/src/luascript.h @@ -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);