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

Player.setExhaustion, Player.getExhaustion [TFS 1.0]

Printer

if Printer then print("LUA") end
Senator
Premium User
Joined
Dec 27, 2009
Messages
5,782
Solutions
31
Reaction score
2,284
Location
Sweden?
Code:
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end

function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end

    return storage - os.time()
end

function Player:hasExhaustion(value)
    return self:getExhaustion(value) >= os.time() and true or false
end

Here is example how you using it:
Code:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    if player:getExhaustion(1000) <= 0 then
        player:setExhaustion(1000, 10)
    else
        print('You\'re exhausted for: '..player:getExhaustion(1000)..' seconds.')
    end
    return true
end
 
Last edited:
For the hell of it, you could try pushing it into the official TFS 1.0, I don't think it'd hurt for them to add it.
 
For the hell of it, you could try pushing it into the official TFS 1.0, I don't think it'd hurt for them to add it.
Well, i could do that. When my other pull request has been accepted :p
 
it would be could if you can add exhaust to some talkactions like:
Code:
if string.lower(param) == "exeta coin" then doSome
player:setExhaustion("exeta coin", 10) end
 
it would be could if you can add exhaust to some talkactions like:
Code:
if string.lower(param) == "exeta coin" then doSome
player:setExhaustion("exeta coin", 10) end
What do you mean? Just set exhaust when they execute the talkaction.
 
Can you give me example of what you want todo.
 
if storage <= 0 then
return 0

what should return 0 do?

when i setExhaustion(20100, 10)
i get 10sec countdown, but it keeps going forever after it reaches 0 (-1, -2, -3, -4, -5 and so on)
And whatver i write inside the if statement in the global script. it doesn't seem to work
Its like the storage value never reaches to 0
(well it kinda doesnt, because when i call for getStorageValue(value) i always get BIG NUMBER, what doesn't change)
 
Rather than return 0 you would return false
This is because 0 does not equal false

Code:
    local test = 0
    if test then
        print("test equals true")
    else
        print("test equals false")
    end 
-- prints test equals true
 
Last edited:
this is because 0 does not equal false
rather than return 0 you would return false

actaully right now i jsut figured out why its not working.
i have to do this:
if storage - os.time() <= 0 then

Edit: if you set it to false its gone give all kind of funky errors when you try call for exhuastion, so default return 0 is better
 
Last edited:
actaully right now i jsut figured out why its not working.
i have to do this:
if storage - os.time() <= 0 then

Edit: if you set it to false its gone give all kind of funky errors when you try call for exhuastion, so default return 0 is better
We don't use return 0 in lua :(
This isn't c++ where return 0 means everything went ok
We return false when we want the script to know things didn't go ok & return true when things went well.
Believe me get into the habit of using true and false rather than 1 or 0 because 1 & 0 are both true ;)
 
We don't use return 0 in lua :(
This isn't c++ where return 0 means everything went ok
We return false when we want the script to know things didn't go ok & return true when things went well.
Believe me get into the habit of using true and false rather than 1 or 0 because 1 & 0 are both true ;)

well if its true or false i get errors: attempt to concatenate a boolean value
 
In this case it should return 0, when the time is 0 or under. It works for me, you doing something wrong.
 
We don't use return 0 in lua :(
This isn't c++ where return 0 means everything went ok
We return false when we want the script to know things didn't go ok & return true when things went well.
Believe me get into the habit of using true and false rather than 1 or 0 because 1 & 0 are both true ;)

Really? I thought that 0 was same as false???? Are you sure??? So what you are saying is the only thing that is false is false, nothing else? What about nil, thought nil was equivalent to false as well... :( Guess I didn't know as much as I thought....

@Topic

Thanks printer for yet another wonderful (and very useful) release...
Even if we could have already found that function in the lib files for your ORTS project :D
 
Really? I thought that 0 was same as false???? Are you sure??? So what you are saying is the only thing that is false is false, nothing else? What about nil, thought nil was equivalent to false as well... :( Guess I didn't know as much as I thought....

@Topic

Thanks printer for yet another wonderful (and very useful) release...
Even if we could have already found that function in the lib files for your ORTS project :D
I didn't mention nil because that is just another error, but then i realized why he was returning 0 and agreed with @whitevo because originally i just glanced over Printer's code

well if its true or false i get errors: attempt to concatenate a boolean value
ok I see
 
Last edited:
In this case it should return 0, when the time is 0 or under. It works for me, you doing something wrong.

It doesn't

Test like this:
player:setExhaustion(100, 1)
addEvent(function() print(player:getExhaustion(100)) end, 3 * 1000)
 
what about Player.hasExhaustion?
 
Back
Top