Yan18
Member
- Joined
- Jun 14, 2014
- Messages
- 104
- Solutions
- 3
- Reaction score
- 17
Hello everyone!
I did a script to verify if there are players that aren't premium in specific positions in globalevents (just online players), but generates an error in the distro :
my code:
I tested with direct position and works, but with iterator, generates error.
I believe that error happened because when iterate in the first position and don't find a player, generates the error.
Where is the problem?
I did a script to verify if there are players that aren't premium in specific positions in globalevents (just online players), but generates an error in the distro :
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/Teste.lua:onThink
data/globalevents/scripts/Teste.lua:16: attempt to index a nil value
stack traceback:
[C]: in function '__index'
data/globalevents/scripts/Teste.lua:16: in function <data/globalevents/scripts/Teste.lua:8>
[Error - GlobalEvents::think] Failed to execute event: Teste
my code:
Lua:
local position_areavip = {
from_pos = {x= 1, y = 1, z= 7},
to_pos = {x= 150, y = 150, z= 7},
}
local position_templo = Position(97, 130, 7)
function onThink(interval)
if #getOnlinePlayers() > 0 then
for _, players in pairs (getOnlinePlayers()) do
local player = Player(players)
for i = position_areavip.from_pos.x, position_areavip.to_pos.x do
for j = position_areavip.from_pos.y, position_areavip.to_pos.y do
for k = position_areavip.from_pos.z, position_areavip.to_pos.z do
if Tile(Position(i, j, k)):getTopCreature():isPlayer() then
if player:getPremiumDays() <= 0 then
doTeleportThing(player, position_templo)
end
end
end
end
end
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have been teleported to temple because you lost your premium.")
end
else
return true
end
return true
end
I tested with direct position and works, but with iterator, generates error.
I believe that error happened because when iterate in the first position and don't find a player, generates the error.
Where is the problem?
Last edited: