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

addEvent crashing the server.

Joined
Mar 14, 2020
Messages
139
Solutions
3
Reaction score
11
Hello guys, i have a problem with an addEvent. I need to reset a especific position inside of a array that is declarated in global.lua.
I have this array jogadorCasa = {} that have 40 slots, all 0's, when a player do a especific thing one especific storage is setted in a free space in the array.

Exemple:
Player did a thing.
jogadorCasa[1 (couse slot 1 is 0, so its a free slot)] = especific storage.
another player did the same thing
jogadorCasa[2] = especific storage
etc etc.

My problem is: How can i reset a especific position in the array after some time?

I tried to use addEvent like this:

Lua:
local flag = especificSpaceThatMustBeReseted
local tempo = (getPlayerStorageValue(cid,storageGlobal+flag)-os.time())*1000
      addEvent(function (flag)
               jogadorCasa[flag] = 0
              end,tempo,flag)

He does what i want, but if the player gets off then the server crashes. I'm not passing any userdata to the addEvent so why is crashing? And how should i do to reset the array without addEvent? Sorry for the bad english.
 
Solution
try this, not tested.

Lua:
local tileIndex = 5
local delay = ((getPlayerStorageValue(cid, storageGlobal + tileIndex) - os.time()) * 1000) or 1000
if delay > 0 then
    addEvent(function (tileIndex)
        jogadorCasa[tileIndex] = 0
    end, delay, tileIndex)
end

Also, I suggest keeping variables in English so its easier for people to help you :)
Not working :(, but my problem is solved, i just used another globalStorage to make a reference, when any player talk to the npc he verify what array has expired based on a globalStorage then he reset the position. xD
Hello guys, i have a problem with an addEvent. I need to reset a especific position inside of a array that is declarated in global.lua.
I have this array jogadorCasa = {} that have 40 slots, all 0's, when a player do a especific thing one especific storage is setted in a free space in the array.

Exemple:
Player did a thing.
jogadorCasa[1 (couse slot 1 is 0, so its a free slot)] = especific storage.
another player did the same thing
jogadorCasa[2] = especific storage
etc etc.

My problem is: How can i reset a especific position in the array after some time?

I tried to use addEvent like this:

Lua:
local flag = especificSpaceThatMustBeReseted
local tempo = (getPlayerStorageValue(cid,storageGlobal+flag)-os.time())*1000
      addEvent(function (flag)
               jogadorCasa[flag] = 0
              end,tempo,flag)

He does what i want, but if the player gets off then the server crashes. I'm not passing any userdata to the addEvent so why is crashing? And how should i do to reset the array without addEvent? Sorry for the bad english.

You cannot invoke methods on an object that doesn't exist.
Just check if you can create a Player object using the uid that you pass (case when player is online), if not - use SQL query to make sure that the value is changed (case when player is offline).

@Edit
the issue is might also be the fact that you are trying to addEvent with a negative value as a timer.
 
Last edited:
You cannot invoke methods on an object that doesn't exist.
Just check if you can create a Player object using the uid that you pass (case when player is online), if not - use SQL query to make sure that the value is changed (case when player is offline).
This method is in a NPC Script, i didnt get what is wrong, i know if i put userdata on it without check if isPlayer will crash but i'm passing just a integer :e
 
This method is in a NPC Script, i didnt get what is wrong, i know if i put userdata on it without check if isPlayer will crash but i'm passing just a integer :e

try this, not tested.

Lua:
local tileIndex = 5
local delay = ((getPlayerStorageValue(cid, storageGlobal + tileIndex) - os.time()) * 1000) or 1000
if delay > 0 then
    addEvent(function (tileIndex)
        jogadorCasa[tileIndex] = 0
    end, delay, tileIndex)
end

Also, I suggest keeping variables in English so its easier for people to help you :)
 
Last edited:
try this, not tested.

Lua:
local tileIndex = 5
local delay = ((getPlayerStorageValue(cid, storageGlobal + tileIndex) - os.time()) * 1000) or 1000
if delay > 0 then
    addEvent(function (tileIndex)
        jogadorCasa[tileIndex] = 0
    end, delay, tileIndex)
end

Also, I suggest keeping variables in English so its easier for people to help you :)
Not working :(, but my problem is solved, i just used another globalStorage to make a reference, when any player talk to the npc he verify what array has expired based on a globalStorage then he reset the position. xD
 
Solution
What error did it give? I'm not that familiar with 0.4~ distros.
Remember that iterating over a bunch of storages to look for expired positions frequently might be a performance issue.
 
I don't know what error couse the distro crashs :(, its tfs 1.3
Ooh, your script is not using metatables, that's why I assumed 0.4.
With 1.3 you can use Game.setStorageValue(storage, value) to set storage values that are independent from players.
Also, I recommend compiling with debug symbols and getting to know if the script is truly the issue.
 
Back
Top