• 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!

Lua Checks the area for a player

natanal99

New Member
Joined
May 31, 2011
Messages
67
Reaction score
3
I need a function that gets a player name and a player cid as entry, and checks if in any square around player cid have any player with the name, and return true or false.

I tried but failed, can anyone do it pls? im on tfs 0.3.6 (i know)
ty guys :)
 
Last edited:
I need a function that gets a player name and a player cid as entry, and checks if in any square around player cid have any player with the name, and return true or false.

I tried but failed, can anyone do it pls? im on tfs 0.3.6 (i know)
ty guys :)
Show us what you have tried.
 
i tried this, always return false.

Code:
function isNearToPartner(cid, name)
  
    local pos = getCreaturePosition(cid)
    local check = false
    local starting = {x = (pos.x - 1), y = (pos.y - 1), z = pos.z}
    local ending = {x = (pos.x + 1), y = (pos.y + 1), 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 = 253}
                local thing = getThingfromPos(pos)
                    if thing.itemid > 0 then
                        if isPlayer(thing.uid) == TRUE then
                                    if (getCreatureName(thing.uid) == name) then
                                        check = true
                                        break
                                    end
                        end
                    end
            end
        end
    end
return check
end
 
I'm not fan of TFS 0.3.x , but this looks simple enough.

First of all, Why do you use "stackpos" is the pos variable? its not needed.

Why do you check if true value is TRUE?
isPlayer() function will prolly return ether true or false/nil anyway, no need to doublecheck it.

instead of breaking out of 3rd loop, return true when name was found and return nothing when nothing was found. In other words, instead of break, use return true.
then you can loose the check value all together.

Now the reason why it doesn't work (assuming all your functions return what they suppose to) is because the name you compare it with is not near the player.
You can check it like this:
at start of function write:
print()
print("name: "..tostring(name))

and after the statement where it says it found a creature write:
print("foundName: "..tostring(getCreatureName(thing.uid)))

This should make it quite clear if the names does not match.
If it doesn't show print with foundName then it means that other player is not near player. However IF IT IS (in game) You have to check your functions and see what they return and are you using them properly.
talking about:
isPlayer()
getThingFromPos()
etc.
 
You should think about using
getSpectators(centerPos, rangex, rangey[, multifloor = false])
as it is optimized for finding creatures.

Use pos as centerPos and rangex = rangey = 1.

I am not sure if it returns an empty array or nil if no creature was found.
 
Back
Top