• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[3 Functions] get...FromArena()

Shawak

Intermediate OT User
Joined
Sep 11, 2008
Messages
1,984
Solutions
2
Reaction score
119
Location
Germany
GitHub
Shawak
Hello, ;)
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
Example:
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
no8t4p.jpg


-> 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
..and..
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:
Seems to be very good this script, but I have a doubt:
I want to say teleport players that are in an arena, how so?
function onUse(cid, item, fromPosition, itemEx, toPosition)
local players = getPlayersFromArena({x=100,y=100,z=7}, 20, 20,253})
local newpos = {x=200,y=200,z=7}
for i = 1, #players do
doSendMagicEffect(getCreaturePosition(players),2)
doTeleportThing(players,newpos)
doSendMagicEffect(getCreaturePosition(players),10)
end
return TRUE
end


My question is as follows stackpos = 253 is only for monsters, and if using in players.
 
Stackpos 253 is for "creatures".

Code:
STACKPOS_GROUND = 0
STACKPOS_FIRST_ITEM_ABOVE_GROUNDTILE = 1
STACKPOS_SECOND_ITEM_ABOVE_GROUNDTILE = 2
STACKPOS_THIRD_ITEM_ABOVE_GROUNDTILE = 3
STACKPOS_FOURTH_ITEM_ABOVE_GROUNDTILE = 4
STACKPOS_FIFTH_ITEM_ABOVE_GROUNDTILE = 5
STACKPOS_TOP_CREATURE = 253
STACKPOS_TOP_FIELD = 254
STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE = 255

And I think that a player is a creature :thumbup:.

Regards,
Shawak
 
lol, better make getCreaturesFromArea(pos, radiusx, radiusy, stack, type)

then type:
1 - monsters
2 - npcs
3 - players

It'll be better, all in one function :p
 
;)
Now it's to late :D.
It's no different, if i add types, or i write "get...FromArena()".
 
Untested (with types)

Lua:
function getCreaturesFromArea(pos, radiusx, radiusy, stack, type)

	if type == 1 then
		func = isPlayer
	elseif type == 2 then
		func = isMonster
	elseif type == 3 then
		func = isNpc
	else
		return LUA_ERROR
	end
        local creatures = {}
        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 func(thing.uid) == TRUE then
                                                table.insert (creatures, thing.uid)
                                        end
                                end                      
                        end
                end
        end
        return creatures
end

Types:
1 = players
2 = monsters
3 = npcs
 
better way use classes no? or no one know how to use it? /gg
 
I like the red you had to draw "around" the bears butt. :eek:
 
how can i use it that a monster that i want is the only teleorted like

only teleport demon from the area
on 0.3.5pl1
 
HTML:
@up
You will have to use something like this i think

Code:
local creaturename = getCreatureName(cid)
if creaturename == 'Demon' then

Dunno how the code would look like, but probably this part is needed in it :)
Im not a scripter
 
I think better function would be:
Lua:
getThingFromArea(center, radiusx, radiusy, f)

Where "f" is function and will be tested "local ret = f(uid)" where uid is thing found on tile (could be item or creature) and then if "ret" is true it will add this thing to table.

E.g.
Lua:
local items = getThingFromArea(center, 5, 5, isItem)

or isCreature, isMonster, isPlayer or custom function like:
Lua:
local players = getThingFromArea(center, radiusx, radiusy, function(uid)
    if(isPlayer(uid) == TRUE) then
        return(getPlayerGroupId(uid) == 1 and getPlayerLevel(uid) >= 100)
    end
    return false
end)


It's more flexible and does not require 3 functions that pretty much do the same thing.
 
Back
Top