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

Storage script and advanced time

mmheo

New Member
Joined
Sep 14, 2017
Messages
157
Reaction score
1
i need spell when use it change storage value + 10

example
player have storage 12454 value 30 i need when use this spell storage value will be 40 for 10 sec and then back to 30 again



more one scripter advanced time

example
you advanced from level 227 to level 228 in 20 minutes and 40 seconds


Tfs 0.4

Pumb
 
Last edited by a moderator:
Solution
first thx
how to save it when logout ?
nice idea and work fine what about other script advanced time

Was about to say the same but @heba already did :D

About the other script, I'll explain:

In your 050-functions.lib, add this new function to your library, it will come handy. Also notice STORAGE_FOR_TIMESTAMP here is being added as new constant, make sure to set it to some number of storage that you haven't used before.

Lua:
STORAGE_FOR_TIMESTAMP = 15854 -- Some storage that will save the times of player's level advancements
   
-- Description of function below:
-- Returns inputted seconds as a formatted string in HH:MM:SS format.
-- If the parameter "worded" is set to true, it returns a string like: "HH hours, MM...
1. setPlayerStorageValue(cid, 12454, getPlayerStorageValue(12454) + 10)

2. Like an experience counter or what?
 
1. setPlayerStorageValue(cid, 12454, getPlayerStorageValue(12454) + 10)

2. Like an experience counter or what?

look bro do you know spells add more 10 ml for 10 seconds like utito vita in masiyah and after 10 sec player get normal ml >>> i need somthing like this but with storage if my storage 30 and i used this spell my storage will be 40 for 10 sec and then get normal storage {30 or whatever} so spell give me +10 in storage value for 10 sec
 
something like this:

Code:
local function changeStorage()
player:setStorageValue(12454 , 30)
end

player:setStorageValue(12454 , 40)
addEvent(changeStorage, 1000*40)
 
something like this:

Code:
local function changeStorage()
player:setStorageValue(12454 , 30)
end

player:setStorageValue(12454 , 40)
addEvent(changeStorage, 1000*40)

Since it's in another scope you need to reference player (since it's 1.x you need use the player id)
Also please tab scripts you upload :p

Lua:
local function changeStorage(playerId)
    local player = Player(playerId)
    if player then
        player:setStorageValue(12454 , 10 + player:getStorageValue(12454))
    end
end

player:setStorageValue(12454 , 40)
addEvent(changeStorage, 40 * 1000, player:getId())
 
Since it's in another scope you need to reference player (since it's 1.x you need use the player id)
Also please tab scripts you upload :p

Lua:
local function changeStorage(playerId)
    local player = Player(playerId)
    if player then
        player:setStorageValue(12454 , 10 + player:getStorageValue(12454))
    end
end

player:setStorageValue(12454 , 40)
addEvent(changeStorage, 40 * 1000, player:getId())
i think this code for tfs 1.+ im use 0.4 guys
 
i think this code for tfs 1.+ im use 0.4 guys

Ok then this should work I guess;
Lua:
local function changeStorage(cid)
    doCreatureSetStorage(cid, getCreatureStorage(cid, 12454) + 10)
end


getCreatureStorage(cid, 12454 , 40)
addEvent(changeStorage, 40 * 1000, cid)

Function names on 0.x is a huge mess, so you might need to change the get / set storage functions depending on your version and rev.
 
Add yourself this function and it should do the trick:

Lua:
function temporaryStorageIncrease(cid, storage, amount, duration)
    setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) + amount)
  
    addEvent(function()
        if isCreature(cid) then
            setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - amount)
        end
    end, duration)
end

Then you can use it in your spell as:
Lua:
temporaryStorageIncrease(cid, 12454, 10, 40*1000)

However, warning - if the creature that is using this gets removed (log out, dies, etc.) before his storage is returned to normal value, it will not happen, thus permanently increasing this storage.
To avoid this, you'd probably need to make some extra security onLogout, etc. So keep this in mind.
 
Add yourself this function and it should do the trick:

Lua:
function temporaryStorageIncrease(cid, storage, amount, duration)
    setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) + amount)
 
    addEvent(function()
        if isCreature(cid) then
            setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - amount)
        end
    end, duration)
end

Then you can use it in your spell as:
Lua:
temporaryStorageIncrease(cid, 12454, 10, 40*1000)

However, warning - if the creature that is using this gets removed (log out, dies, etc.) before his storage is returned to normal value, it will not happen, thus permanently increasing this storage.
To avoid this, you'd probably need to make some extra security onLogout, etc. So keep this in mind.
first thx
how to save it when logout ?
 
you can use Shadowsong script but with small edit to look like this

Code:
function temporaryStorageIncrease(cid, storage, amount, duration)
    setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) + 10)
    doCreatureSetStorage(cid, 45011, 1) --- this is new storage for check when login
    addEvent(function()
        if isCreature(cid) then
            setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - 10)
            doCreatureSetStorage(cid, 45011, 0) --- this is new storage for check when login
        end
    end, duration)
end

now login.lua under
function onLogin(cid) add
if getPlayerStorageValue(cid, 45011) == 1 then
setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - 10)
setPlayerStorageValue(cid, 45011, -1)
end

now if player logout or dead with storage when login again oto will check this storage 45011 if 1 player will losse the amount u add if 0 player don't losse anything
 
Last edited:
you can use Shadowsong script but with small edit to look like this

Code:
function temporaryStorageIncrease(cid, storage, amount, duration)
    setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) + 10)
    doCreatureSetStorage(cid, 45011, 1) --- this is new storage for check when login
    addEvent(function()
        if isCreature(cid) then
            setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - 10)
            doCreatureSetStorage(cid, 45011, 0) --- this is new storage for check when login
        end
    end, duration)
end

now login.lua under
function onLogin(cid) add
if getPlayerStorageValue(cid, 45011) == 1 then
setPlayerStorageValue(cid, 45001, getPlayerStorageValue(cid, 45001) - 10)
setPlayerStorageValue(cid, 45011, -1)
end

now if player logout or dead with storage when login again oto will check this storage 45011 if 1 player will losse the amount u add if 0 player don't losse anything
nice idea and work fine what about other script advanced time
 
first thx
how to save it when logout ?
nice idea and work fine what about other script advanced time

Was about to say the same but @heba already did :D

About the other script, I'll explain:

In your 050-functions.lib, add this new function to your library, it will come handy. Also notice STORAGE_FOR_TIMESTAMP here is being added as new constant, make sure to set it to some number of storage that you haven't used before.

Lua:
STORAGE_FOR_TIMESTAMP = 15854 -- Some storage that will save the times of player's level advancements
   
-- Description of function below:
-- Returns inputted seconds as a formatted string in HH:MM:SS format.
-- If the parameter "worded" is set to true, it returns a string like: "HH hours, MM minutes, and SS seconds" instead.

local function secondsToClock(seconds, worded) -- Returns inputted seconds as a formatted string
  local seconds = tonumber(seconds)

  if seconds <= 0 then
    if worded == true then return "0 seconds."; else return "00:00:00"; end
  else
    local hours = string.format("%02.f", math.floor(seconds/3600));
    local mins = string.format("%02.f", math.floor(seconds/60 - (hours*60)));
    local secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60));
    if worded == true then
        return ((seconds<3600 and "") or ((math.floor(seconds/3600) == 1 and "1 hour, ") or (math.floor(seconds/3600)) .. " hours, ")) .. ((seconds < 60 and "") or ((math.floor(seconds/60 - (hours*60)) == 1 and "1 minute, and ") or (math.floor(seconds/60 - (hours*60)).. " minutes, and "))) .. ((math.floor(seconds - hours*3600 - mins *60) == 1 and "1 second") or (math.floor(seconds - hours*3600 - mins *60).. " seconds")) .. "."
    else
    return hours..":"..mins..":"..secs
    end
  end
end

Now make a new advance type creaturescript, description included:

Lua:
-- Description:
-- If player advances in level, we check the saved timestamp and compare it to current time.
-- The difference between these 2 times is how many seconds passed since he last got timestamped for leveling up.
-- Important: Make sure to timestamp the player when he logs in for the first time. We will do this in an onLogin script.

function onAdvance(cid, skill, oldLevel, newLevel)
   
    local seconds = os.time() - getPlayerStorageValue(cid, STORAGE_FOR_TIMESTAMP)
    if newLevel > oldLevel and skill == SKILL__LEVEL then
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You advanced from level " ..oldLevel.. " to level " ..newLevel.. " in " .. secondsToClock(seconds, true))
    end
    setPlayerStorageValue(cid, STORAGE_FOR_TIMESTAMP, os.time())
    return true
end

And lastly we need a bit of onLogin code to take care of when player logs in for the first time.

Lua:
-- If this is the first time the player is logging in, we timestamp the time when he logged in.
function onLogin(cid)
    if getPlayerStorageValue(cid, STORAGE_FOR_TIMESTAMP) == -1 then
        setPlayerStorageValue(cid, STORAGE_FOR_TIMESTAMP, os.time())
    end
    return true
end

I'm pretty sure this time (first time the player has logged in) is already saved somewhere, i think database, but it's easier to write this than make a db query for me, sue me.
That should do the trick.
 
Solution
Was about to say the same but @heba already did :D

About the other script, I'll explain:

In your 050-functions.lib, add this new function to your library, it will come handy. Also notice STORAGE_FOR_TIMESTAMP here is being added as new constant, make sure to set it to some number of storage that you haven't used before.

Lua:
STORAGE_FOR_TIMESTAMP = 15854 -- Some storage that will save the times of player's level advancements
  
-- Description of function below:
-- Returns inputted seconds as a formatted string in HH:MM:SS format.
-- If the parameter "worded" is set to true, it returns a string like: "HH hours, MM minutes, and SS seconds" instead.

local function secondsToClock(seconds, worded) -- Returns inputted seconds as a formatted string
  local seconds = tonumber(seconds)

  if seconds <= 0 then
    if worded == true then return "0 seconds."; else return "00:00:00"; end
  else
    local hours = string.format("%02.f", math.floor(seconds/3600));
    local mins = string.format("%02.f", math.floor(seconds/60 - (hours*60)));
    local secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60));
    if worded == true then
        return ((seconds<3600 and "") or ((math.floor(seconds/3600) == 1 and "1 hour, ") or (math.floor(seconds/3600)) .. " hours, ")) .. ((seconds < 60 and "") or ((math.floor(seconds/60 - (hours*60)) == 1 and "1 minute, and ") or (math.floor(seconds/60 - (hours*60)).. " minutes, and "))) .. ((math.floor(seconds - hours*3600 - mins *60) == 1 and "1 second") or (math.floor(seconds - hours*3600 - mins *60).. " seconds")) .. "."
    else
    return hours..":"..mins..":"..secs
    end
  end
end

Now make a new advance type creaturescript, description included:

Lua:
-- Description:
-- If player advances in level, we check the saved timestamp and compare it to current time.
-- The difference between these 2 times is how many seconds passed since he last got timestamped for leveling up.
-- Important: Make sure to timestamp the player when he logs in for the first time. We will do this in an onLogin script.

function onAdvance(cid, skill, oldLevel, newLevel)
  
    local seconds = os.time() - getPlayerStorageValue(cid, STORAGE_FOR_TIMESTAMP)
    if newLevel > oldLevel and skill == SKILL__LEVEL then
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You advanced from level " ..oldLevel.. " to level " ..newLevel.. " in " .. secondsToClock(seconds, true))
    end
    setPlayerStorageValue(cid, STORAGE_FOR_TIMESTAMP, os.time())
    return true
end

And lastly we need a bit of onLogin code to take care of when player logs in for the first time.

Lua:
-- If this is the first time the player is logging in, we timestamp the time when he logged in.
function onLogin(cid)
    if getPlayerStorageValue(cid, STORAGE_FOR_TIMESTAMP) == -1 then
        setPlayerStorageValue(cid, STORAGE_FOR_TIMESTAMP, os.time())
    end
    return true
end

I'm pretty sure this time (first time the player has logged in) is already saved somewhere, i think database, but it's easier to write this than make a db query for me, sue me.
That should do the trick.

you are good man

edit
i got 2 msg
21:39 You advanced from Level 252 to Level 253.
21:39 You advanced from level 252 to level 253 in 1 minute, and 25 seconds.
 
you are good man

edit
i got 2 msg
21:39 You advanced from Level 252 to Level 253.
21:39 You advanced from level 252 to level 253 in 1 minute, and 25 seconds.

Yeah well, 21:39 You advanced from Level 252 to Level 253. is a default advance message, you need to go to your sources and delete it so the player only receives the one from your lua script, otherwise he will keep getting both.

you can use Shadowsong script but with small edit to look like this

Code:
function temporaryStorageIncrease(cid, storage, amount, duration)
    setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) + 10)
    doCreatureSetStorage(cid, 45011, 1) --- this is new storage for check when login
    addEvent(function()
        if isCreature(cid) then
            setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - 10)
            doCreatureSetStorage(cid, 45011, 0) --- this is new storage for check when login
        end
    end, duration)
end

now login.lua under
function onLogin(cid) add
if getPlayerStorageValue(cid, 45011) == 1 then
setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - 10)
setPlayerStorageValue(cid, 45011, -1)
end

now if player logout or dead with storage when login again oto will check this storage 45011 if 1 player will losse the amount u add if 0 player don't losse anything

He would also have to use a different storage for checks for each time temporaryStorageIncrease is used, because it can only serve as a reference to one single use the way this is scripted atm. I suppose that's not a problem, but all in all it's a mess. Would be better to code a new condition altogether.
 
Yeah well, 21:39 You advanced from Level 252 to Level 253. is a default advance message, you need to go to your sources and delete it so the player only receives the one from your lua script, otherwise he will keep getting both.



He would also have to use a different storage for checks for each time temporaryStorageIncrease is used, because it can only serve as a reference to one single use the way this is scripted atm. I suppose that's not a problem, but all in all it's a mess. Would be better to code a new condition altogether.

the time start when player login right??

where i can delete this msg from source
 
the time start when player login right??

where i can delete this msg from source

When player logs in for the first time, it will remember that time, and use it as a reference for how much time passed between level 1 and 2. After that, the advance script will keep counting.

You can find that message in source file player.cpp
 
When player logs in for the first time, it will remember that time, and use it as a reference for how much time passed between level 1 and 2. After that, the advance script will keep counting.

You can find that message in source file player.cpp
yea really you are good man
 
Back
Top