whitevo
Feeling good, thats what I do.
I tried to remove player target, but apparently this is not simple to do with Lua.
the only function we get to use is: creature:setTarget(target)
but the problem with that is, the target must exist near the creature
Is there any network message to remove current focus target from player/creature?
If not what should be done in sources so that creature:setTarget() will remove focus from targets?
related codes in luascript.cpp and creature.cpp
EDIT:
Pfft didn't even matter when the creature is player.
cant change player target.
So what I did was this.
The tokenPos is set into middle of nowhere and when player teleported there, then it will loose target.
Still looking for better solutions.
the only function we get to use is: creature:setTarget(target)
but the problem with that is, the target must exist near the creature
Is there any network message to remove current focus target from player/creature?
If not what should be done in sources so that creature:setTarget() will remove focus from targets?
related codes in luascript.cpp and creature.cpp
Code:
int LuaScriptInterface::luaCreatureSetTarget(lua_State* L)
{
// creature:setTarget(target)
Creature* creature = getUserdata<Creature>(L, 1);
if (creature) {
Creature* target = getCreature(L, 2);
pushBoolean(L, creature->setAttackedCreature(target));
} else {
lua_pushnil(L);
}
return 1;
}
bool Creature::setAttackedCreature(Creature* creature)
{
if (creature) {
const Position& creaturePos = creature->getPosition();
if (creaturePos.z != getPosition().z || !canSee(creaturePos)) {
attackedCreature = nullptr;
return false;
}
attackedCreature = creature;
onAttackedCreature(attackedCreature);
attackedCreature->onAttacked();
} else {
attackedCreature = nullptr;
}
for (Creature* summon : summons) {
summon->setAttackedCreature(creature);
}
return true;
}
EDIT:
Pfft didn't even matter when the creature is player.
cant change player target.
So what I did was this.
Code:
if target and target:getId() == cid then
if enemy:isPlayer() then
local previousPos = enemy:getPosition()
teleport(enemy, tokenPos)
teleport(enemy, previousPos)
else
target:setTarget()
end
end
Still looking for better solutions.
Last edited: