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

Lua (0.4) Storage value for 12 hours.

marek12

Available for sprite works
Joined
Apr 8, 2020
Messages
398
Solutions
4
Reaction score
394
Hello guys, would anyone be able to share with me a function that will apply xxxx STORAGE VALUE for 12 hours?

for example, I use a talkaction and I will get a storage 5050 set to 1 for 12 hours, and after this time it will go back to -1.

TFS 0.4
LUA

More than appreciate your help
 
Solution
what I am looking for, thank you. will try this on :D
lmao it's literally identical to what I showed you.

almost what I ment.
You asked for a talkaction, so you got a talkaction. 🤷‍♂️

but what I exactly looking for is to let someone pass the door as many times as he likes, but in duration of 12 hours.
so setstorage 5050 (to pass the door) for 12 hours.
any idea how to do it this way? :D
Post automatically merged:


yeah, this is more accurate to what I am looking for, thank you. will try this on :D

You'll need to give the person the storage from a separate script, but it works exactly the same as the talkaction I showed you.

doCreatureSetStorage(cid, storage, os.time() + 10) -- gives access for 10 seconds....
So the thing is.. it's technically possible to change the storage value like you said, using a combination of a talkaction and login events along with an addEvent..

But it's going to be astronomically better to simply compare the time, and then decide if it's on/off

so I'm going to show you that way instead.
Lua:
local timer_in_seconds = 10
local storage = 5050

function onSay(cid, words, param)

    local cur_time, cur_storage = os.time(), getCreatureStorage(cid, storage)
    
    -- if storage is 'on'
    if cur_storage > cur_time then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need to wait " .. (cur_storage - cur_time) .. " seconds before using this talkaction again.")
        return true
    end
    
    -- if storage is 'off'
    local new_storage_value = cur_time + timer_in_seconds
    doCreatureSetStorage(cid, storage, new_storage_value)
    return true
end
 
So the thing is.. it's technically possible to change the storage value like you said, using a combination of a talkaction and login events along with an addEvent..

But it's going to be astronomically better to simply compare the time, and then decide if it's on/off

so I'm going to show you that way instead.
Lua:
local timer_in_seconds = 10
local storage = 5050

function onSay(cid, words, param)

    local cur_time, cur_storage = os.time(), getCreatureStorage(cid, storage)
   
    -- if storage is 'on'
    if cur_storage > cur_time then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need to wait " .. (cur_storage - cur_time) .. " seconds before using this talkaction again.")
        return true
    end
   
    -- if storage is 'off'
    local new_storage_value = cur_time + timer_in_seconds
    doCreatureSetStorage(cid, storage, new_storage_value)
    return true
end
almost what I ment.
but what I exactly looking for is to let someone pass the door as many times as he likes, but in duration of 12 hours.
so setstorage 5050 (to pass the door) for 12 hours.
any idea how to do it this way? :D
Post automatically merged:

That's how you can do it.
Edit : Didn't notice @Xikini already replied.
yeah, this is more accurate to what I am looking for, thank you. will try this on :D
 
what I am looking for, thank you. will try this on :D
lmao it's literally identical to what I showed you.

almost what I ment.
You asked for a talkaction, so you got a talkaction. 🤷‍♂️

but what I exactly looking for is to let someone pass the door as many times as he likes, but in duration of 12 hours.
so setstorage 5050 (to pass the door) for 12 hours.
any idea how to do it this way? :D
Post automatically merged:


yeah, this is more accurate to what I am looking for, thank you. will try this on :D

You'll need to give the person the storage from a separate script, but it works exactly the same as the talkaction I showed you.

doCreatureSetStorage(cid, storage, os.time() + 10) -- gives access for 10 seconds.
Lua:
local storage = 5050
local teleport_location = {x = 1000, y = 1000, z = 7}

function onStepIn(cid, item, position, fromPosition)

    local cur_time, cur_storage = os.time(), getCreatureStorage(cid, storage)
    
    if cur_storage > cur_time then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You were allowed to access the area.")
        return true
    end
    
    doTeleportThing(cid, teleport_location)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You were NOT allowed to access the area.")
    return true
end
 
Solution
lmao it's literally identical to what I showed you.


You asked for a talkaction, so you got a talkaction. 🤷‍♂️



You'll need to give the person the storage from a separate script, but it works exactly the same as the talkaction I showed you.

doCreatureSetStorage(cid, storage, os.time() + 10) -- gives access for 10 seconds.
Lua:
local storage = 5050
local teleport_location = {x = 1000, y = 1000, z = 7}

function onStepIn(cid, item, position, fromPosition)

    local cur_time, cur_storage = os.time(), getCreatureStorage(cid, storage)
   
    if cur_storage > cur_time then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You were allowed to access the area.")
        return true
    end
   
    doTeleportThing(cid, teleport_location)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You were NOT allowed to access the area.")
    return true
end
asked for talkaction cause it will be talkaction.
same idea of how you buy houses, but instead you will buy a pass trough the doors for 12 hours, then player will be kicked if he not extend the duration.
I just don't know yet how time.os function are working, looking pretty straight forward so with all that you both said I am sure I will manage to solve what I am looking for.
Thank both of you :)
Post automatically merged:

I understand that it has to be 2 different scripts for allowing/not allowing to pass the door and for setting the storage.
 
Back
Top