Hello
I want give you library for creating, setting, removing exhaustion.
How use it:
:ninja:
I want give you library for creating, setting, removing exhaustion.
Code:
Exhaustion = {}
Exhaustion.__index = Exhaustion
function Exhaustion.__construct(cid, storage)
local new = {}
setmetatable(new, Exhaustion)
new.cid = cid
new.storage = storage
return new
end
function Exhaustion:isExhausted()
if(getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION)) then
return false
end
return getPlayerStorageValue(self.cid, self.storage) >= os.time(t)
end
function Exhaustion:getTime()
if(getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION)) then
return 0
end
return getPlayerStorageValue(self.cid, self.storage)
end
function Exhaustion:addTime(extraTime)
return setPlayerStorageValue(self.cid, self.storage, getPlayerStorageValue(self.cid, self.storage) + extraTime)
end
function Exhaustion:makeNew(time)
return setPlayerStorageValue(self.cid, self.storage, os.time(t) + time)
end
function Exhaustion:clean()
return setPlayerStorageValue(self.cid, self.storage, 0)
end
How use it:
Code:
function onSay(cid, words, param)
local Exhaustion = Exhaustion.__construct(cid, 1500)
if(Exhaustion:isExhausted == true) then
doPlayerSendTextMessage(cid, 22, 'You are exhausted. You must wait:'..Exhaustion:getTime()..'.')
else
doCreatureAddHealth(cid, 100)
doPlayerSendTextMessage(cid, 22, 'You are not exhuasted!')
Exhaustion:makeNew(5)
end
if(getCreatureHealth(cid) < 250) then
Exhaustion:remove()
elseif(getCreatureHealth(cid) > 1000) then
Exhaustion:addTime(2)
end
return true
end
:ninja: