0.4
Hi guys, I am trying to learn more about getSpectators to make creative spells for monsters.
I tried to make a simple script that would do the following: teleport the monster to a random player near it and start attacking that player, changing its target.
But I keep getting this error:
attempt to index a number value
Can someone help?
Thank you.
Hi guys, I am trying to learn more about getSpectators to make creative spells for monsters.
I tried to make a simple script that would do the following: teleport the monster to a random player near it and start attacking that player, changing its target.
Code:
function onCastSpell(cid, creaturePos, level, maglv, var)
local target = getSpectators(creaturePos, 2, 2, 2, false)
if target == nil or type(target) ~= "table" or #target == 0 then
return false
end
target = target[math.random(#target)]
if isPlayer(target) == true then
local targetPos = getThingPos(target)
if isWalkable(targetPos, false, false, false) then
doTeleportThing(cid, targetPos)
doSetCreatureTarget(cid, target)
return true
end
end
return false
end
attempt to index a number value
Can someone help?
Thank you.