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

TFS 1.X+ check if someone is in the room

ssiwyy158

Member
Joined
Jan 24, 2011
Messages
128
Solutions
2
Reaction score
13
Hello. Trying to install a script that allows only one player to enter the teleport, when he leaves the room then another player can enter (Sorry google translate)
Lua:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition)
 
local pos = {x = 908, y = 696, z = 9}
 
local area = {
    fromPos = {x = 901, y = 689, z = 9},
    toPos = {x = 915, y = 700, z = 9}
    }

    if not isPlayer(cid) then
        return true
    end

    local amount = 0
    for x = fromPos.x, toPos.x do
        for y = fromPos.y, toPos.y do
            for z = fromPos.z, toPos.z do
                if isPlayer(getTopCreature({x=x,y=y,z=z}).uid) then
                    amount = amount+1
                end   
            end
        end
    end
    if amount >= 1 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Someone is already in the room.")
        doTeleportThing(cid,fromPosition)
    else
        doTeleportThing(cid,pos)
              doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Welcome")
    end
end

but it doesn't work. I use tfs 1.2 8.6
 
Solution
Try this.
Lua:
function areaHasPlayer(center, radiusX, radiusY)
    return #Game.getSpectators(center, false, true, radiusX, radiusX, radiusY, radiusY) > 0
end


local roomCenter = Position(907, 693, 9)
local radius = {6, 8}
local destination = Position(908, 696, 9)

function onStepIn(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        creature:teleportTo(fromPosition, true)
        return true
    end

    if areaHasPlayer(roomCenter, unpack(radius)) then
        creature:sendTextMessage(MESSAGE_INFO_DESCR, "Someone is already in the room.")
        creature:teleportTo(fromPosition, true)
    else
        creature:teleportTo(destination)
        creature:sendTextMessage(MESSAGE_INFO_DESCR, "Welcome.")...
Try this.
Lua:
function areaHasPlayer(center, radiusX, radiusY)
    return #Game.getSpectators(center, false, true, radiusX, radiusX, radiusY, radiusY) > 0
end


local roomCenter = Position(907, 693, 9)
local radius = {6, 8}
local destination = Position(908, 696, 9)

function onStepIn(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        creature:teleportTo(fromPosition, true)
        return true
    end

    if areaHasPlayer(roomCenter, unpack(radius)) then
        creature:sendTextMessage(MESSAGE_INFO_DESCR, "Someone is already in the room.")
        creature:teleportTo(fromPosition, true)
    else
        creature:teleportTo(destination)
        creature:sendTextMessage(MESSAGE_INFO_DESCR, "Welcome.")
    end
    return true
end
 
Solution
Back
Top