• 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 problem teleport player random

Scrappy Coco

Member
Joined
Dec 27, 2014
Messages
95
Reaction score
17
I have problems to randomly select a player from a specific area and transport . Thanks for all the help

this code ...


Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
                print('bien hasta aqui')
            local test = {}
            local specs1 = Game.getSpectators(Wait_Place, false, true, 0, ctfWaitingRoomRadiusX, 0, ctfWaitingRoomRadiusY)
                for i = 1, #specs1 do
           local tid = specs1[i]
           local tid2 = specs1[uid]
           table.insert(test, tid2)
            table.insert(test, tid)
            end
                        local R_out = test[math.random(1,#specs1)]
                        local play = specs1:getName()
                        if R_out then
                        R_out:teleportTo(R_out:getTown():getTemplePosition(), false)

                   print("player  " ..n_r..  "  pl")
        end


            return true
            end
 
I have problems to randomly select a player from a specific area and transport . Thanks for all the help

this code ...


Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
                print('bien hasta aqui')
            local test = {}
            local specs1 = Game.getSpectators(Wait_Place, false, true, 0, ctfWaitingRoomRadiusX, 0, ctfWaitingRoomRadiusY)
                for i = 1, #specs1 do
           local tid = specs1[i]
           local tid2 = specs1[uid]
           table.insert(test, tid2)
            table.insert(test, tid)
            end
                        local R_out = test[math.random(1,#specs1)]
                        local play = specs1:getName()
                        if R_out then
                        R_out:teleportTo(R_out:getTown():getTemplePosition(), false)

                   print("player  " ..n_r..  "  pl")
        end


            return true
            end
About this part of getSpectators:
PHP:
0, ctfWaitingRoomRadiusX, 0, ctfWaitingRoomRadiusY
Read what means min/max 'range' in:
https://otland.net/threads/tfs-1-x-getcustomspectators-show-player-monster-npc-on-off.235900/

Your 0 (zero) means for TFS 11 (eleven), in case on 'min range' it's -11 tiles from center position.
Your function should be:
PHP:
Game.getSpectators(Wait_Place, false, true, ctfWaitingRoomRadiusX, ctfWaitingRoomRadiusX, ctfWaitingRoomRadiusY, ctfWaitingRoomRadiusY)


FULL SCRIPT FOR YOU:
PHP:
ctfWaitingRoomRadiusX = 7 -- +/- 7 tiles from center position
ctfWaitingRoomRadiusY = 5 -- +/- 5 tiles from center position

Wait_Place = {x=1234, y=1235, z=7} -- center position

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    print('bien hasta aqui')

    -- get players in range from current floor [only players, not monsters/NPC]
    local specs = Game.getSpectators(Wait_Place, false, true, ctfWaitingRoomRadiusX, ctfWaitingRoomRadiusX, ctfWaitingRoomRadiusY, ctfWaitingRoomRadiusY)

    if #specs > 0 then -- only if there is more then 0 players
        local randomPlayer = specs[math.random(#specs)] -- math random 1 to count of players
        randomPlayer:teleportTo(randomPlayer:getTown():getTemplePosition(), true)

        print("randomPlayer name: " .. randomPlayer:getName())
    end

    return true
end
 
About this part of getSpectators:
PHP:
0, ctfWaitingRoomRadiusX, 0, ctfWaitingRoomRadiusY
Read what means min/max 'range' in:
https://otland.net/threads/tfs-1-x-getcustomspectators-show-player-monster-npc-on-off.235900/

Your 0 (zero) means for TFS 11 (eleven), in case on 'min range' it's -11 tiles from center position.
Your function should be:
PHP:
Game.getSpectators(Wait_Place, false, true, ctfWaitingRoomRadiusX, ctfWaitingRoomRadiusX, ctfWaitingRoomRadiusY, ctfWaitingRoomRadiusY)


FULL SCRIPT FOR YOU:
PHP:
ctfWaitingRoomRadiusX = 7 -- +/- 7 tiles from center position
ctfWaitingRoomRadiusY = 5 -- +/- 5 tiles from center position

Wait_Place = {x=1234, y=1235, z=7} -- center position

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    print('bien hasta aqui')

    -- get players in range from current floor [only players, not monsters/NPC]
    local specs = Game.getSpectators(Wait_Place, false, true, ctfWaitingRoomRadiusX, ctfWaitingRoomRadiusX, ctfWaitingRoomRadiusY, ctfWaitingRoomRadiusY)

    if #specs > 0 then -- only if there is more then 0 players
        local randomPlayer = specs[math.random(#specs)] -- math random 1 to count of players
        randomPlayer:teleportTo(randomPlayer:getTown():getTemplePosition(), true)

        print("randomPlayer name: " .. randomPlayer:getName())
    end

    return true
end
there no errors in console but the player is not transported to the temple
 
there no errors in console but the player is not transported to the temple
Does is show name of player in console? If it works, then it should, because of:
PHP:
print("randomPlayer name: " .. randomPlayer:getName())

If it does not show name of player in console, it means that you got wrong configured position/range, because it cant find any player on that area.
 
Back
Top