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

TFS 1.X+ //EDIT 05/08 - if player is offline then add storage by database

Naimad4

New Member
Joined
Jul 27, 2018
Messages
16
Reaction score
1
//EDIT

I don't know how to add the storage value if the player is offline..










Hello everyone!

I have a problem.

How do I set time, so the player receives the storagevalue only after certain time?
for example in this script?

Code:
local keywordHandler = KeywordHandler:new()local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)             npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)     npcHandler:onCreatureSay(cid, type, msg) end
function onThink()                         npcHandler:onThink() end

local storage = 5006


function creatureSayCallback(cid, type, msg)

    if msgcontains(msg, "hi") and (not npcHandler:isFocused(cid)) then
        if getPlayerStorageValue(cid, storage) < 1 then
            npcHandler:say("text?", cid, TRUE)       
        elseif getPlayerStorageValue(cid, storage) == 1 then
            npcHandler:say("text.", cid, TRUE)
        end
        elseif msgcontains(msg, "yes") then
            if getPlayerStorageValue(cid, storage) < 1 then
            npcHandler:say("text.", cid, TRUE)    
            setPlayerStorageValue(cid, storage, 1)
        end
        elseif msgcontains(msg, "no") then
            if getPlayerStorageValue(cid, storage) < 1 then
            npcHandler:say(" text", cid, TRUE)   
            setPlayerStorageValue(cid, storage, 1)
        end
    elseif (not npcHandler:isFocused(cid)) then
        return false
    end
    return true
end

npcHandler:setCallback(CALLBACK_FAREWELL, creatureFarewell)
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye then.")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

Code:
            setPlayerStorageValue(cid, storage, 1)

after I say yes or no it should pass x time before the player gets the storage

thanks alot :)
 
Last edited:
Solution
Lua:
addEvent(setPlayerStorageValue, 60 * 1000, cid, storage, storageValue)

This will set the storage to storageValue on player of cid cid after 60 seconds.
Lua:
addEvent(setPlayerStorageValue, 60 * 1000, cid, storage, storageValue)

This will set the storage to storageValue on player of cid cid after 60 seconds.
 
Solution
You should create a function that sets the storage and check if the player exists, otherwise you'll get an error if the player logs out before the 60 seconds have passed
 
You should create a function that sets the storage and check if the player exists, otherwise you'll get an error if the player logs out before the 60 seconds have passed

Thats already it. If the OP has the correct compat.lua, the setPlayerStorageValue is just that, take a look:

Lua:
function setPlayerStorageValue(cid, key, value) local p = Player(cid) return p and p:setStorageValue(key, value) or false end
 
Thank you for this fast replies guys! I am truly amazed

Altho Rombadr has right. When the player is offline, it doesn't add the storage :|

@gudan garam
Where do I add the function ?
 
Thank you for this fast replies guys! I am truly amazed

Altho Rombadr has right. When the player is offline, it doesn't add the storage :|

@gudan garam
Where do I add the function ?

Thats is right, if the player logs out you should update the storage value directly in the database.

You should add the addEvent function wherever you want to set storage after x time, for instance:

This:
Lua:
elseif msgcontains(msg, "no") then
     if getPlayerStorageValue(cid, storage) < 1 then
         npcHandler:say(" text", cid, TRUE)
         setPlayerStorageValue(cid, storage, 1)
     end
end

Would become this:
Lua:
elseif msgcontains(msg, "no") then
     if getPlayerStorageValue(cid, storage) < 1 then
         npcHandler:say(" text", cid, TRUE)
         addEvent(setPlayerStorageValue, 60 * 1000, cid, storage, 1)
     end
end

Edit---

I think I miss understood your question.

What Rombadr said is that if the "setPlayerStorageValue" function didn't check if the player was a valid player (existed) it would result in an error or possibly a crash, but in reality it won't because "setPlayerStorageValue" already checks if the player is a valid player before setting the storage, what it doesn't do is the storage value if the player is offline, that you would have to write a function to update the storage value in the database directly.

I'm sure there are examples on the forum for that.
 
Back
Top