Hello, I've noticed alot of people use loops to check if someone's in an area. Sure it's needed sometimes, but not as often as you use it.
When shall you use loops for checking areas? Well, never because you shall use my mapArea heuaheuah xD But well that's classed as looping too! But seriously, when loops should be used is if you want to for example, check how many creatures is in an area, or to see if any players remain in an area.
However, when you are going to check if a certain creature is in an area, for example when you use a rune you only want the rune to be used in depot... Then you do not loop through the depot area to check if the player's in there.
Here's how you'd do:
And the isInArea function:
No loops, just if-statements
Also, if you don't like it to return true and false, just change it to TRUE and FALSE
Enjoy,
Colandus
When shall you use loops for checking areas? Well, never because you shall use my mapArea heuaheuah xD But well that's classed as looping too! But seriously, when loops should be used is if you want to for example, check how many creatures is in an area, or to see if any players remain in an area.
However, when you are going to check if a certain creature is in an area, for example when you use a rune you only want the rune to be used in depot... Then you do not loop through the depot area to check if the player's in there.
Here's how you'd do:
PHP:
fromPos = {x=455, y=344, z=7}
toPos = {x=499, y=389, z=7}
if isInArea(getPlayerPosition(cid), fromPos, toPos) then
-- Action! ;D
end
And the isInArea function:
PHP:
-- Function by Colandus!
function isInArea(pos, fromPos, toPos)
if pos.x >= fromPos.x and pos.x <= toPos.x then
if pos.y >= fromPos.y and pos.y <= toPos.y then
if pos.z >= fromPos.z and pos.z <= toPos.z then
return true
end
end
end
return false
end
Also, if you don't like it to return true and false, just change it to TRUE and FALSE
Enjoy,
Colandus