• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Problems with script tfs 1.2

president vankk

Web Developer & AuraOT Owner
Joined
Jul 10, 2009
Messages
5,719
Solutions
9
Reaction score
339
Hi folks! Actually I'm having three problems with my new script, and I hope someone can help me fix that.

Script: http://pastebin.com/v5QTHBHb
Error 1: attempt to index global 'player' <a nil value> line 27
Error 2: attempt to index global 'player' <a nil value> line 37
Error 3: attempt to index global 'item' <a nil value> line 40


Thanks.
 
Forgive me if my answers don't work - I usually trial & error my way through things. These are only suggestions based on that truth :p

Error 1: player isn't defined as anything currently I think, you might be able to do 'player = playerId' or move the message sending inside the startsBoss spectators loop and define 'player = spectators{i}' <-- I had to wrap it in curly brackets because otherwise the post went into italics! Change it to square brackets [ ]

Error 2: related to the above, player isn't defined. Can you maybe put player = playerId at the very start of the script? I don't know :p

Error 3: Not entirely sure how this function works, but I guess it needs to know where and what item is being transformed, so 'item' needs to be defined as something first

Yeaaah, reading back on that I'm not sure how helpful it is really going to be, but best of luck anyway! Maybe somebody with more skill than me can chime in :p
 
aff vank, you don't pass the parameter in the call of the function
need pass it to this function
Code:
addEvent(startsBoss,1*60*1000, boss)
right...
Code:
addEvent(startsBoss,1*60*1000, boss, player)
also, when you declare the function
Code:
local function startsBoss(boss)
need to pass the "player" parameter
Code:
local function startsBoss(boss, player)
then you have a declared player to call the function player:say
 
@mdwilliams @silveralol

Lua Script Error: [Action Interface]
data/actions/scripts/lever.lua:onUse
luaAddEvent(). Argument #4 is unsafe
stack traceback:
[C]: in function 'addEvent'
data/actions/scripts/lever.lua:149: in function <data/actions/scripts/lever.lua:127>

Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/actions/scripts/lever.lua:114: attempt to index local 'player' (a number value)
stack traceback:
[C]: in function '__index'
data/actions/scripts/lever.lua:114: in function <data/actions/scripts/lever.lua:102>

line 149:
Code:
addEvent(startsBoss, 1 * 60 * 1000, boss, player)

also the function is already declared..
Code:
local function startsBoss(boss, player)
 
Can you move all use of player: inside the respective spectator loops with
Code:
player = spectators[i]

I do something somewhat similar in one of my scripts:
Code:
..
  local players = Game.getPlayers()
  for i = 1, #players do
    player = players[i]
    player:setStorageValue(votedStor, 0)
  end
..
 
Last edited:
Can you move all use of player: inside the respective spectator loops with
Code:
player = spectators[i]

I do something somewhat similar in one of my scripts:
Code:
..
  local players = Game.getPlayers()
  for i = 1, #players do
    player = players[i]
    player:setStorageValue(votedStor, 0)
  end
..

I am not interest in doing like this, I don't want a message for each player :p
 
post the entire script, what is the line 149? ¬¬
for me test I need the entire script to try in my personal server
 
It don't seem like it is full script, so don't expect it to be working 100% :D, but try this:
Code:
function clearBossRoom(playerId, bossId, centerPosition, rangeX, rangeY, exitPosition)
    local spectators, spectator = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY)
    for i = 1, #spectators do
        spectator = spectators[i]
        if spectator:isPlayer() and spectator:getId() == playerId then
            spectator:teleportTo(boss.exitPosition)
            boss.exitPosition:sendMagicEffect(CONST_ME_TELEPORT)
        end
        if spectator:isMonster() and spectator:getId() == bossId then
            spectator:remove()
        end
    end
end
local function startsBoss(boss, player, item)
    -- We are checking players in waitRoom and teleport to bossRoom
    local spectators = Game.getSpectators(boss.waitRoom.position, false, true, boss.waitRoom.waitRoomX, boss.waitRoom.waitRoomX, boss.waitRoom.waitRoomY, boss.waitRoom.waitRoomY)
    for i = 1, #spectators do
        spectator = spectators[i]
        spectator:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        spectator:teleportTo(boss.newPos)
        boss.newPos:sendMagicEffect(CONST_ME_TELEPORT)
    end
  
    -- Now we are sending a message
    player:say(boss.message.enterBossRoom, TALKTYPE_MONSTER_SAY, false, player, boss.message.whereinBossRoom)
  
    -- Now we create the monsters
    local monster = Game.createMonster(boss.bossName, boss.bossPosition)
    if not monster then
        print(">> Houston, we have a problem to create boss ".. boss.bossName ..".")
        return true
    end
  
    -- addEvent to clearBossRoom
    addEvent(clearBossRoom, boss.bossRoom.timeToKick * 60 * 1000, player:getId(), monster:getId(), boss.centerRoom, boss.bossRoom.rangeX, boss.bossRoom.rangeY, fromPosition)
  
    -- Back the lever
    item:transform(9827)
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local boss = bosses[item.uid]
    if not boss then
        return true
    end
    -- No one will enter in the room anymore.
    Game.setStorageValue(boss.globalStorage, 1)
  
    -- Transport to Room
    addEvent(startsBoss, 1 * 60 * 1000, boss:getId(), player:getId(), item:getId())
    return true
end
 
It don't seem like it is full script, so don't expect it to be working 100% :D, but try this:
Code:
function clearBossRoom(playerId, bossId, centerPosition, rangeX, rangeY, exitPosition)
    local spectators, spectator = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY)
    for i = 1, #spectators do
        spectator = spectators[i]
        if spectator:isPlayer() and spectator:getId() == playerId then
            spectator:teleportTo(boss.exitPosition)
            boss.exitPosition:sendMagicEffect(CONST_ME_TELEPORT)
        end
        if spectator:isMonster() and spectator:getId() == bossId then
            spectator:remove()
        end
    end
end
local function startsBoss(boss, player, item)
    -- We are checking players in waitRoom and teleport to bossRoom
    local spectators = Game.getSpectators(boss.waitRoom.position, false, true, boss.waitRoom.waitRoomX, boss.waitRoom.waitRoomX, boss.waitRoom.waitRoomY, boss.waitRoom.waitRoomY)
    for i = 1, #spectators do
        spectator = spectators[i]
        spectator:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        spectator:teleportTo(boss.newPos)
        boss.newPos:sendMagicEffect(CONST_ME_TELEPORT)
    end
 
    -- Now we are sending a message
    player:say(boss.message.enterBossRoom, TALKTYPE_MONSTER_SAY, false, player, boss.message.whereinBossRoom)
 
    -- Now we create the monsters
    local monster = Game.createMonster(boss.bossName, boss.bossPosition)
    if not monster then
        print(">> Houston, we have a problem to create boss ".. boss.bossName ..".")
        return true
    end
 
    -- addEvent to clearBossRoom
    addEvent(clearBossRoom, boss.bossRoom.timeToKick * 60 * 1000, player:getId(), monster:getId(), boss.centerRoom, boss.bossRoom.rangeX, boss.bossRoom.rangeY, fromPosition)
 
    -- Back the lever
    item:transform(9827)
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local boss = bosses[item.uid]
    if not boss then
        return true
    end
    -- No one will enter in the room anymore.
    Game.setStorageValue(boss.globalStorage, 1)
 
    -- Transport to Room
    addEvent(startsBoss, 1 * 60 * 1000, boss:getId(), player:getId(), item:getId())
    return true
end

Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/actions/scripts/lever.lua:113: attempt to index local 'player' (a number value)
stack traceback:
[C]: in function '__index'
data/actions/scripts/lever.lua:113: in function <data/actions/scripts/lever.lua:102>

@Ninja do you have any idea?
 
@Ninja do you have any idea?
Look at the error message carefully. "Attempt to index local 'player' (a number value)", this occurs when the script is trying to use a Creature method (Creature.say) with a numeric value, and why does this happen? Well, you're passing Player ID to the function startsBoss, and you're not constructing a new Player object before using meta method(s). You will receive a similar error message when the script tries to transform the lever.
 
Look at the error message carefully. "Attempt to index local 'player' (a number value)", this occur when the script is trying to use a Creature method (Creature.say) with a numeric value, and why does this happen? Well, you're passing Player ID to the function startsBoss, and you're not constructing a new Player object before using meta method(s). You will receive a similar error message when the script tries to transform the lever.

How I can construct a new player object?
 
you try by yourself it?
Code:
addEvent(startsBoss, 1 * 60 * 1000, boss:getMonster(), player, item)
now the player is the Player Object, and the item is Item Object
 
How I can construct a new player object?
Code:
local tmpPlayer = Player(cid)
if tmpPlayer then
    -- some method
end

I also suggest that you take some time to rewrite this script of yours. Not sure why you're using Game.getSpectators, Game.setStorageValue, and addEvent for startsBoss.

-- Edit --
you try by yourself it?
Code:
addEvent(startsBoss, 1 * 60 * 1000, boss:getMonster(), player, item)
now the player is the Player Object, and the item is Item Object
You should never pass Userdata objects when using addEvent.
 
you try by yourself it?
Code:
addEvent(startsBoss, 1 * 60 * 1000, boss:getMonster(), player, item)
now the player is the Player Object, and the item is Item Object

Yes I did, and is getting the same errors :p

Code:
local tmpPlayer = Player(cid)
if tmpPlayer then
    -- some method
end

I also suggest that you take some time to rewrite this script of yours. Not sure why you're using Game.getSpectators, Game.setStorageValue, and addEvent for startsBoss.

I am using Game.getSpectadors to transport the players to the room, and also using Game.setStorageValue on a NPC to check if can transport to wait room.

I did not follow your thinking, don't understand what suppost to use on -- some method.
 
Back
Top