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

Solved TFS 1.1 Help With a script

Xarly

Member
Joined
Mar 9, 2015
Messages
360
Reaction score
20
Hello guys, we have a little problem we have a script for prison keys, but got a little problem with the golden key so when i try to use it, only 1 player get teleported, and the rest of players stay on the same place, too another thing its if someone try to use the key when he is alone it says u need 5 players so its ok but it remove the key so if someone can help me for fix will be great^^ , thanks in advance guys!
There is the script:
Code:
local config = {
    playerPositions = {
        Position(33607, 32362, 11),
        Position(33608, 32362, 11),
        Position(33609, 32362, 11),
        Position(33610, 32362, 11),
        Position(33611, 32362, 11)
    },
    newPositions = {
        Position(33533, 32414, 12),
        Position(33533, 32414, 12),
        Position(33533, 32414, 12),
        Position(33533, 32414, 12)
    }
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid == 22641 then
        local storePlayers, playerTile = {}
item:remove(22607)
for i = 1, #config.playerPositions do
            playerTile = Tile(config.playerPositions):getTopCreature()
            if not playerTile or not playerTile:isPlayer() then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need 5 players.")
                return true
            end
end
player:teleportTo(Position(33533, 32414, 12), false)
end
     return true
end
 
Last edited by a moderator:
try this.

Code:
local playerPositions = {
Position(33607, 32362, 11),
Position(33608, 32362, 11),
Position(33609, 32362, 11),
Position(33610, 32362, 11),
Position(33611, 32362, 11),
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid == 22641 then
        for i = 1, #playerPositions do
            if Tile(playerPositions[i]):getTopCreature() then
                if not Tile(playerPositions[i]):getTopCreature():isPlayer() then
                    player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need 5 players.")
                    return true
                end
            else
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need 5 players.")
                return true
            end
        end
        item:remove(22607)
        for x=1, #playerPositions do
            Tile(playerPositions[x]):getTopCreature():teleportTo(Position(33533, 32414, 12), false)
        end
    end
return true
end
 
Last edited:
try this.

Code:
local playerPositions = {
Position(33607, 32362, 11),
Position(33608, 32362, 11),
Position(33609, 32362, 11),
Position(33610, 32362, 11),
Position(33611, 32362, 11),
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid == 22641 then
        local playerTile = {}
        for i = 1, #playerPositions do
            playerTile = Tile(playerPositions)
            if playerTile:getTopCreature() then
                if not playerTile:getTopCreature():isPlayer() then
                    player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need 5 players.")
                    return true
                end
            else
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need 5 players.")
                return true
            end
        end
        item:remove(22607)
        for x=1, #playerTile do
            playerTile[x]:getTopCreature():teleportTo(Position(33533, 32414, 12), false)
        end
    end
return true
end
oki bro! i try in one moment thanks

try this.

Code:
local playerPositions = {
Position(33607, 32362, 11),
Position(33608, 32362, 11),
Position(33609, 32362, 11),
Position(33610, 32362, 11),
Position(33611, 32362, 11),
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid == 22641 then
        local playerTile = {}
        for i = 1, #playerPositions do
            playerTile = Tile(playerPositions)
            if playerTile:getTopCreature() then
                if not playerTile:getTopCreature():isPlayer() then
                    player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need 5 players.")
                    return true
                end
            else
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need 5 players.")
                return true
            end
        end
        item:remove(22607)
        for x=1, #playerTile do
            playerTile[x]:getTopCreature():teleportTo(Position(33533, 32414, 12), false)
        end
    end
return true
end
get error onUse line 14 attempt to index local 'playerTile <a nil value>
:14: in function
:9:
 
Last edited by a moderator:
if line 12 is: if not Tile(playerPositions[x]):getTopCreature():isPlayer() then
it cant give you error on line 12 :eek:
5md4px.png

that sthe error xd
 
When i say: You can't have this error, means you did not update your script. Because you literally can't have this error..
 
When i say: You can't have this error, means you did not update your script. Because you literally can't have this error..
line 12 would be this if I count right
Code:
if Tile(playerPositions[x]):getTopCreature() then
1. Tile does not exist (seems to not be the case)
2. There is no creature on the tile (hence you cannot call :getTopCreature())

it has to be one of the two.
 
Try this
Code:
local playerPositions = {
    Position(33607, 32362, 11),
    Position(33608, 32362, 11),
    Position(33609, 32362, 11),
    Position(33610, 32362, 11),
    Position(33611, 32362, 11)
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid ~= 22641 then
        return false
    end

    local players, creature = {}
    for i = 1, #playerPositions do
        creature = Tile(playerPositions[i]):getTopCreature()
        if not creature or not creature:isPlayer() then
            player:sendCancelMessage("You need 5 players.")
            break
        end

        players[i] = creature
    end

    item:remove()

    for i = 1, #players do
        players[i]:teleportTo(Position(33533, 32414, 12))
    end
    return true
end
 
Try this
Code:
local playerPositions = {
    Position(33607, 32362, 11),
    Position(33608, 32362, 11),
    Position(33609, 32362, 11),
    Position(33610, 32362, 11),
    Position(33611, 32362, 11)
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target.itemid ~= 22641 then
        return false
    end

    local players, creature = {}
    for i = 1, #playerPositions do
        creature = Tile(playerPositions[i]):getTopCreature()
        if not (creature or creature:isPlayer()) then
            player:sendCancelMessage("You need 5 players.")
            break
        end

        players[i] = creature
    end

    item:remove()

    for i = 1, #players do
        players[i]:teleportTo(Position(33533, 32414, 12))
    end
    return true
end
Now got error onUse
:17: attempt to index local 'creature' a nil value
:17: in function
>.<
 
MY GOD xD i used variable "x" in these brackets [] instead of "i" xD
LE typos ftw.

EDIT: fixed the typo on post 2
 
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
  if target.itemid ~= 22641 then
     return false
  end

  local players, creature = {}
  for i = 1, #playerPositions do
     creature = Tile(playerPositions[i]):getTopCreature()
     if creature == nil then
       player:sendCancelMessage("You need 5 players.")
       return false
     end

     if not creature:isPlayer() then
       player:sendCancelMessage("You need 5 players.")
       return false
     end

     players[i] = creature
  end

  item:remove()

  for i = 1, #players do
     players[i]:teleportTo(Position(33533, 32414, 12))
  end
  return true
end
 
MY GOD xD i used variable "x" in these brackets [] instead of "i" xD
LE typos ftw.

EDIT: fixed the typo on post 2
it only removes 1 key.
you want it to remove key from all players? hence does all of them need to have a key?
Nono its perfect only 1 key the problem its now when there are the 5 players and i use the key i get this error
Onuse
:23:attempt to get lenght of global' playertile' a nil value
:23: in function xd
 
another typo xD [but seriously you should understand these on your won very easily by now.]

#playerTile > #playerPositions
 
Back
Top