Aleada
Unknown Member
- Joined
- Mar 14, 2013
- Messages
- 231
- Reaction score
- 7
Hey guys, I was trying to make a spell that would push the monster back 1 square and I'm using this script from Mock:
But I can't figure out how to make it bounce the monster back just 1 square (If it's not a PZ zone or a nonwalkable area)
Any help is very appreciated! Thank you!
LUA:
local function choose(...) -- by mock
local arg = {...}
return arg[math.random(1,#arg)]
end
local function isWalkable(pos, creature, proj, pz)-- by Nord
if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
if getTopCreature(pos).uid > 0 and creature then return false end
if getTileInfo(pos).protection and pz then return false, true end
local n = not proj and 3 or 2
for i = 0, 255 do
pos.stackpos = i
local tile = getTileThingByPos(pos)
if tile.itemid ~= 0 and not isCreature(tile.uid) then
if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
return false
end
end
end
return true
end
function onCastSpell(cid, var) -- By Mock the bear
local c = getCreatureTarget(cid)
local cid2 = cid
if isCreature(c) then
if math.random(1,2) == 1 then
local p = getCreaturePosition(cid)
local n = 0
while true do
n = n+1
p.x = p.x+choose(-1,1)
p.y = p.y+choose(-1,1)
if isWalkable(p,true) or n > 15 then
doTeleportThing(c,p)
break
else
p = getCreaturePosition(cid)
end
end
else
local p = getCreaturePosition(c)
local n = 0
while true do
n = n+1
p.x = p.x+choose(-1,1)
p.y = p.y+choose(-1,1)
if isWalkable(p,true) or n > 15 then
doTeleportThing(cid,p)
break
else
p = getCreaturePosition(c)
end
end
end
doCreatureSay(cid2,'Muhuhaha!!',19)
end
return false
end
But I can't figure out how to make it bounce the monster back just 1 square (If it's not a PZ zone or a nonwalkable area)
Any help is very appreciated! Thank you!