• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Stamina Doll :>

Rwynoha

New Member
Joined
Jan 20, 2015
Messages
14
Reaction score
0
Hiho Otlanders i've made this script by learning from this thread and added some from my experience
this is the post of guiding scripting
Code:
http://otland.net/threads/scripting-guide.74030/

action/script/staminadoll.lua
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,enjoy.")
doRemoveItem(item.uid)
end
return true
end
action.xml
Code:
    <action itemid="itemid" event="script" value="staminadoll.lua"/>
TFS 0.3.6
 
The reason we create tables is so that we can access them anywhere within the script, if you create a table inside of a function like you have in your current script and wanted to access that table in another function within your script you will get an error, this is because of a thing called scope

The scope of that table or its existence is only known to onUse and no where else, so get into the habit of creating tables outside of the functions so you can access them anywhere within the script.

1 other thing I wanted to mention was returning a boolean value, at the end of every script we return true to tell the server everything went ok, but if things did not go ok you set it to return false within 1 of the conditions where the condition was not met.

This is your script updated and how you should write your code from this point on, its not soo much you need to follow this method but you need to think how the code should execute especially when it shouldn't execute at all.
Code:
local cfg = {
    refuel = 42 * 60 * 1000
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerStamina(cid) >= cfg.refuel then
        doPlayerSendCancel(cid, "Your stamina is already full.")
        return false -- stop execution of this script
    elseif not isPremium(cid)  then
        doPlayerSendCancel(cid, "You must have a premium account.")
        return false -- stop execution of this script
    end
    -- if neither condition was met execute the code below and return true
    doPlayerSetStamina(cid, cfg.refuel)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina has been refilled, enjoy.")
    doRemoveItem(item.uid)
    return true
end
 
Last edited:
Also you originally used local cfg = {}, the way you had that setup had no use, you must insert a value in that table like Breed did, unless you are assigning one to that table later in the script.
 
The reason we create tables is so that we can access them anywhere within the script, if you create a table inside of a function like you have in your current script and wanted to access that table in another function within your script you will get an error, this is because of a thing called scope

The scope of that table or its existence is only known to onUse and no where else, so get into the habit of creating tables outside of the functions so you can access them anywhere within the script.

1 other thing I wanted to mention was returning a boolean value, at the end of every script we return true to tell the server everything went ok, but if things did not go ok you set it to return false within 1 of the conditions where the condition was not met.

This is your script updated and how you should write your code from this point on, its not soo much you need to follow this method but you need to think how the code should execute especially when it shouldn't execute at all.
Code:
local cfg = {
    refuel = 42 * 60 * 1000
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerStamina(cid) >= cfg.refuel then
        doPlayerSendCancel(cid, "Your stamina is already full.")
        return false -- stop execution of this script
    elseif not isPremium(cid)  then
        doPlayerSendCancel(cid, "You must have a premium account.")
        return false -- stop execution of this script
    end
    -- if neither condition was met execute the code below and return true
    doPlayerSetStamina(cid, cfg.refuel)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina has been refilled, enjoy.")
    doRemoveItem(item.uid)
    return true
end
mm thx for ur advice but i used this script and its working fine but i will try to make scripts like you do

Also you originally used local cfg = {}, the way you had that setup had no use, you must insert a value in that table like Breed did, unless you are assigning one to that table later in the script.
i'll try to be better
 
Last edited by a moderator:
Were just trying to teach you the basic concepts of programming logic

Remember if your sending a cancel message your returning false, if the player or creature doesn't meet the needs of the script your returning false.
If / else if & else statements are nice control statements but they can make scripts ugly and unmanageable this is why you need to learn when to use them and when to use return statements to control the execution of the program / script.
 
Were just trying to teach you the basic concepts of programming logic

Remember if your sending a cancel message your returning false, if the player or creature doesn't meet the needs of the script your returning false.
If / else if & else statements are nice control statements but they can make scripts ugly and unmanageable this is why you need to learn when to use them and when to use return statements to control the execution of the program / script.
okey thx but i used ur script on normal player but doesn't help me only gave me full stamina after then back to old one in 1 sec Lol! but mine is working
 
O well.. should work now, this makes more sense
Code:
local cfg = {
    refuel = 42 * 60 * 1000
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if not isPremium(cid) then
        doPlayerSendCancel(cid, "You must have a premium account.")
        return false
    end
    if getPlayerStamina(cid) >= cfg.refuel then
        doPlayerSendCancel(cid, "Your stamina is already full.")
        return false -- stop execution of this script
    else
        doPlayerSetStamina(cid, cfg.refuel)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina has been refilled, enjoy.")
        doRemoveItem(item.uid)
    end
    return true
end
 
Last edited:
okey thx but i used ur script on normal player but doesn't help me only gave me full stamina after then back to old one in 1 sec Lol! but mine is working
Lol your stamina went back after being added. Okay guy.
 
I wrote this stamina script years ago, lol. This exact script is used in many data packs.

You didn't code it, but that's okay. You're learning. ;)
 
Last edited:
I wrote this stamina script years ago, lol. This exact script is in many data packs.

You didn't code it, but that's okay. Good luck.
Do you have proof that it for you? If you do not just calm down and Drink juice
 
Last edited:
I don't think it really matters, just about every script on these forums is a copy of a copy, I don't even bother putting my name on scripts anymore.

I know. I'm just clearing it up.

Long ago I used to be like @Limos and wrote thousands of scripts for people, lol. Mostly small ones, but some good ones.
 
I do have some nice scripts I wrote for 8.6 and 1.x that no one has thought of yet at least nothing I have seen, not sure if i will ever release them tho.
 
i won't talk anymore but this one code by me that's what i will say only :) and thx for ur rep -.-
 
Back
Top