• 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 SetstorageValue with addEvent

lucastiond

New Member
Joined
Jul 14, 2013
Messages
35
Reaction score
0
Hello guys.
I really want to know how can I set a storageValue with addEvent after x time.

Thank you very much!
 
Last edited:
Code:
local function setStorage(cid, key, val)
    local player = Player(cid)
    if not player then
        return
    end
    player:setStorageValue(key, val)
end

addEvent(setStorage, 3000, player:getId(), 12345, 1)

send cid through function and reconstruct player userdata incase the player is nonexistant at time of execution
 
It worked. Thank you!

But I don't know what "recreate player userdata" means.
Can you please clarify me this?
there are constructor functions for objects, such as Player, Creature, Item, ItemType, which are used to create userdata so you can execute methods with them (such as player:getHealth())
a userdata is a data type in Lua which provides a block of memory to store something in (this is why when you print a userdata you get userdata: 0x12e05d18 for example (a memory address))
i believe pointers are stored in userdatas in c++ though i could be wrong
you can construct player userdata by using name, creatureid or an existing userdata.
by passing creature id through addEvent (since addEvent warns you about passing userdata through it, because the object may not be existent at time of execution) you can reconstruct player userdata when the function is executed, and stop the function from executing if the reconstruction fails, which will stop any errors from occuring (trying to execute a method on a nonexistent object)
 
Can I ask what you need this for? I'm pretty sure there's a better solution for what you're trying to do. Setting storage value alone after some time just feels odd, unless the code will perform other actions in the event callback aside from setting a storage value.
 
As I am not a good scripter, I figured out a way of doing the storage value do not apply if the player get out of one specific tile before the exact time, using stopEvent().

This way I was able to do the "Ear Examination" mission of recruitment from "Bigfoot's Burden Quest" 100% like global.

I know I could use os.time to make the storage value apply after some time, but I didn't know how to stop this from happen if the player got out of that tile.

I am pretty sure there are other ways, better ways, of doing this. But I did as i could.
 
Back
Top