Shawak
Intermediate OT User
creature.h add below
add
inside creature.cpp search for
inside the onWalk() function and replace it with
Also search for
and add
luascript.h below
add
luascript.cpp below
add
and after
add
That's it, now you should be able to use creature:setNoMove(bool) and creature:canMove() for any creature (player, monster, npc)
Example usage:
Regards
Code:
virtual bool isInGhostMode() const {
return false;
}
add
Code:
bool noMove;
bool canMove() const {
return !noMove;
}
void setNoMove(bool noMove) {
this->noMove = noMove;
}
inside creature.cpp search for
Code:
ReturnValue ret = g_game.internalMoveCreature(this, dir, flags);
inside the onWalk() function and replace it with
Code:
ReturnValue ret = canMove() ? g_game.internalMoveCreature(this, dir, flags) : RETURNVALUE_NOTPOSSIBLE;
Also search for
Code:
hiddenHealth = false;
and add
Code:
noMove = false;
luascript.h below
Code:
static int luaCreatureGetPathTo(lua_State* L);
add
Code:
static int luaCreatureCanMove(lua_State* L);
static int luaCreatureSetNoMove(lua_State* L);
luascript.cpp below
Code:
int LuaScriptInterface::luaCreatureGetPathTo(lua_State* L)
{
[...]
}
add
Code:
int LuaScriptInterface::luaCreatureSetNoMove(lua_State* L)
{
// creature:setNoMove(canMove)
Player* player = getUserdata<Player>(L, 1);
if (!player) {
lua_pushnil(L);
return 1;
}
bool noMove = getBoolean(L, 2);
if (player->canMove() == noMove) {
player->setNoMove(noMove);
}
pushBoolean(L, true);
return 1;
}
int LuaScriptInterface::luaCreatureCanMove(lua_State* L)
{
// creature:canMove()
Player* player = getUserdata<Player>(L, 1);
if (player) {
pushBoolean(L, player->canMove());
} else {
lua_pushnil(L);
}
return 1;
}
and after
Code:
registerMethod("Creature", "getPathTo", LuaScriptInterface::luaCreatureGetPathTo);
add
Code:
registerMethod("Creature", "canMove", LuaScriptInterface::luaCreatureCanMove);
registerMethod("Creature", "setNoMove", LuaScriptInterface::luaCreatureSetNoMove);
That's it, now you should be able to use creature:setNoMove(bool) and creature:canMove() for any creature (player, monster, npc)
Example usage:
Code:
function onSay(player, words, param)
local monster = Game.createMonster("wolf", player:getPosition())
monster:setNoMove(true)
addEvent(function(mid)
Monster(mid):setNoMove(false)
end, 3000, monster:getId())
addEvent(function(mid)
Monster(mid):setNoMove(true)
end, 6000, monster:getId())
addEvent(function(mid)
Monster(mid):setNoMove(false)
end, 9000, monster:getId())
return true
end
Regards
Last edited: