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

[Request] Stamina Refiller TFS 0.4

God Mythera

Veteran OT User
Joined
Aug 11, 2012
Messages
2,048
Solutions
2
Reaction score
256
Location
United States
I tried to find a script for 0.4 but when ever i use the item it disappears even when stamina is full. Does anyone have a script for tfs 0.4?
 
Just make it check if stamina is full before using the rune.. or make it check if 'happy hour' stamina is gone.
 
Just make it check if stamina is full before using the rune.. or make it check if 'happy hour' stamina is gone.
I am using this script, but even if my stamina is full it uses it...

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local cfg = {}
cfg.refuel = 42 * 60 * 1000
if(getPlayerStamina(cid) >= cfg.refuel) then
doPlayerSendCancel(cid, "Your stamina is already full.")
elseif(not isPremium(cid)) then
doPlayerSendCancel(cid, "You must have a premium account.")
else
doPlayerSetStamina(cid, cfg.refuel)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina has been refilled.")
doRemoveItem(item.uid)
end
return true
end
 
Code:
local maxStamina = 42 * 60 * 1000
local happyHour = getConfigValue("staminaRatingLimitTop")

function onUse(cid, item, fromPosition, itemEx, toPosition)
local staminaTime = getPlayerStamina(cid) - getConfigValue("staminaRatingLimitTop")
   
    if(getPlayerStamina(cid) >= happyHour) then
        doPlayerSendCancel(cid, "You still have ".. staminaTime .." minutes worth of happyHour.")
        return true
    end
   
    if(not isPremium(cid)) then
        doPlayerSendCancel(cid, "You must have a premium account.")
        return true
    end
   
    if doRemoveItem(item.uid) == TRUE then
        doPlayerSetStamina(cid, maxStamina)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina has been refilled.")
    end
    return true
end

Fixed your script. Now it can't be used during happy hour.
 
-- Edit wrote this in-between rushes at work. Didn't realise Cade submitted a reply. :oops:
I'm not at home to test and I'm not familiar with how getPlayerStamina returns values.
It's just a re-written version of the one you posted that should make debugging easier.
If it's all working, just remove the prints later on.
Code:
local refuel_time = 42 * 60 * 1000

function onUse(cid, item, fromPosition, itemEx, toPosition)

        -- console print to determine players stamina before executing the script.
        print(getPlayerStamina(cid))

        -- check if premium
        if not isPremium(cid) then
                doPlayerSendCancel(cid, "You must have a premium account to use this item.")
                return true
        end

        -- check if stamina is full
        if getPlayerStamina(cid) >= refuel_time then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina is full.")
                return true
        end

        -- if everything else checks out fine.. refuel stamina, remove item.
        doPlayerSetStamina(cid, refuel_time)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina has been refilled.")
        doRemoveItem(item.uid)

        -- console print to show what stamina is now that it's been refilled
        print(getPlayerStamina(cid))

        return true
end
 
it returns how many minutes of stamina a player has left :p
If it returns minutes.. why does it check in seconds? :/
42 * 60 * 1000

1 second * 60 = 1 minute
1 min x 42 = 42 minutes?

That's probably where the error is.

If the scripts don't work try changing the timer to
42 * 60 * 60 * 1000

1s -> 1m -> 1h -> 42h .. or do I have this wrong?

This is why I usually test things before posting. :(
 
-- Edit wrote this in-between rushes at work. Didn't realise Cade submitted a reply. :oops:
I'm not at home to test and I'm not familiar with how getPlayerStamina returns values.
It's just a re-written version of the one you posted that should make debugging easier.
If it's all working, just remove the prints later on.
Code:
local refuel_time = 42 * 60 * 1000

function onUse(cid, item, fromPosition, itemEx, toPosition)

        -- console print to determine players stamina before executing the script.
        print(getPlayerStamina(cid))

        -- check if premium
        if not isPremium(cid) then
                doPlayerSendCancel(cid, "You must have a premium account to use this item.")
                return true
        end

        -- check if stamina is full
        if getPlayerStamina(cid) >= refuel_time then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina is full.")
                return true
        end

        -- if everything else checks out fine.. refuel stamina, remove item.
        doPlayerSetStamina(cid, refuel_time)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina has been refilled.")
        doRemoveItem(item.uid)

        -- console print to show what stamina is now that it's been refilled
        print(getPlayerStamina(cid))

        return true
end
I tried this and it still removes item even if stamina is full : s

Code:
local maxStamina = 42 * 60 * 1000
local happyHour = getConfigValue("staminaRatingLimitTop")

function onUse(cid, item, fromPosition, itemEx, toPosition)
local staminaTime = getPlayerStamina(cid) - getConfigValue("staminaRatingLimitTop")
  
    if(getPlayerStamina(cid) >= happyHour) then
        doPlayerSendCancel(cid, "You still have ".. staminaTime .." minutes worth of happyHour.")
        return true
    end
  
    if(not isPremium(cid)) then
        doPlayerSendCancel(cid, "You must have a premium account.")
        return true
    end
  
    if doRemoveItem(item.uid) == TRUE then
        doPlayerSetStamina(cid, maxStamina)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina has been refilled.")
    end
    return true
end

Fixed your script. Now it can't be used during happy hour.
I am guessing the script will only work if you are under 40 hours?
 
Last edited:
Back
Top