Shawak
Intermediate OT User
Hello,
here are 3 usefull functions,..
1. getMonstersFromArena()
Put the code in data/lib/functions.lua
Example:
-> The monsters in the red circle will be teleportet.
The same with,..
2. getPlayersFromArena()
..and..
3. getNpcsFromArena()
I hope you like it :thumbup:.
Regards,
Shawak
here are 3 usefull functions,..
Code:
1. getMonstersFromArena()
2. getPlayersFromArena()
3. getNpcsFromArena()
1. getMonstersFromArena()
Put the code in data/lib/functions.lua
Lua:
function getMonstersFromArena(pos, radiusx, radiusy, stack)
local monsters = {}
local starting = {x = (pos.x - radiusx), y = (pos.y - radiusy), z = pos.z}
local ending = {x = (pos.x + radiusx), y = (pos.y + radiusy), z = pos.z}
for x = starting.x, ending.x do
for y = starting.y, ending.y do
for z = starting.z, ending.z do
local pos = {x=x, y=y, z=z,stackpos = stack}
local thing = getThingfromPos(pos)
if thing.itemid > 0 then
if isMonster(thing.uid) == TRUE then
table.insert (monsters, thing.uid)
end
end
end
end
end
return monsters
end
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local monsters = getMonstersFromArena({x=100,y=100,z=7}, 3, 3, 253})
local newpos = {x=200,y=200,z=7}
for i = 1, #monsters do
doSendMagicEffect(getCreaturePosition(monsters[i]),2)
doTeleportThing(monsters[i],newpos)
doSendMagicEffect(getCreaturePosition(monsters[i]),10)
end
return TRUE
end
-> The monsters in the red circle will be teleportet.
The same with,..
2. getPlayersFromArena()
Lua:
function getPlayersFromArena(pos, radiusx, radiusy, stack)
local players = {}
local starting = {x = (pos.x - radiusx), y = (pos.y - radiusy), z = pos.z}
local ending = {x = (pos.x + radiusx), y = (pos.y + radiusy), z = pos.z}
for x = starting.x, ending.x do
for y = starting.y, ending.y do
for z = starting.z, ending.z do
local pos = {x=x, y=y, z=z,stackpos = stack}
local thing = getThingfromPos(pos)
if thing.itemid > 0 then
if isPlayer(thing.uid) == TRUE then
table.insert (players, thing.uid)
end
end
end
end
end
return players
end
3. getNpcsFromArena()
Lua:
function getNpcsFromArena(pos, radiusx, radiusy, stack)
local npcs = {}
local starting = {x = (pos.x - radiusx), y = (pos.y - radiusy), z = pos.z}
local ending = {x = (pos.x + radiusx), y = (pos.y + radiusy), z = pos.z}
for x = starting.x, ending.x do
for y = starting.y, ending.y do
for z = starting.z, ending.z do
local pos = {x=x, y=y, z=z,stackpos = stack}
local thing = getThingfromPos(pos)
if thing.itemid > 0 then
if isNpc(thing.uid) == TRUE then
table.insert (npcs, thing.uid)
end
end
end
end
end
return npcs
end
I hope you like it :thumbup:.
Regards,
Shawak
Last edited: