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

[TFS 1.1] Optimize My Antidote Herb

Jaed Le Raep

★Gaeming★
Joined
Sep 3, 2007
Messages
1,296
Reaction score
441
Could someone please optimize my Stone Herb script that turns it into an item with a 15 second cooldown but cures poison? It's important to keep the exhaust identity the same as it shares cooldown with other herbs.

Code:
local exhaust = createConditionObject(CONDITION_EXHAUST_HEAL)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, 1000)

local antidote = createCombatObject()
setCombatParam(antidote, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(antidote, COMBAT_PARAM_AGGRESSIVE, 0)
setCombatParam(antidote, COMBAT_PARAM_DISPEL, CONDITION_POISON)


function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureCondition(cid, CONDITION_EXHAUST_HEAL) == false then
    doAddCondition(cid, exhaust)
    doRemoveItem(item.uid, 1)
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
    return doCombat(cid, antidote, numberToVariant(cid))
else
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    doPlayerSendCancel(cid, "You cannot eat another herb yet.")
    return true
end
end
 
Last edited:
The real problem is that programmers have spent far too much time worrying about efficiency in the wrong places and at the wrong times; premature optimization is the root of all evil (or at least most of it) in programming.
The Art of Programming, Donald Knuth, 1974
 
The combat objected isn't needed because it isn't called anywhere in the script.
Code:
-- not needed
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, 0)
setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_POISON)
 
The other issue is that the script isn't even working in 1.1. It doesn't actually get rid of the poison, and thanks for pointing it out Codex, I forgot to strip that away from the script.
 
I've updated the first post.
Maybe you should check if the player is poisoned?
Sorry I don't really have the resources or time to setup servers on my old computer....

So all I can do is make nub suggestions :)

What I would do is comment out everything and only execute the important stuff 1st while working my way back to the original code.
Since the objective here is to remove poison comment everything else out besides the doCombat function
Also you might want to use the print() function to print to the console the values passed to the function, its very good way to debug a script. :)
Code:
local exhaust = createConditionObject(CONDITION_EXHAUST_HEAL)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, 15000)

local antidote = createCombatObject()
setCombatParam(antidote, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(antidote, COMBAT_PARAM_AGGRESSIVE, 0)
setCombatParam(antidote, COMBAT_PARAM_DISPEL, CONDITION_POISON)


function onUse(cid, item, fromPosition, itemEx, toPosition)
  --if getCreatureCondition(cid, CONDITION_EXHAUST_HEAL) == false then
  --doAddCondition(cid, exhaust)
  --doRemoveItem(item.uid, 1)
  --doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
  --return doCombat(cid, antidote, numberToVariant(cid))
--else
  --doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
  --doPlayerSendCancel(cid, "You cannot eat another herb yet.")
  --return true
--end
  doCombat(cid, antidote, numberToVariant(cid))
  return true
end
 
I've actually exhausted every effort I could think of, down to getting rid of the cooldown and keeping it a simple onUse script. What's weird is that I used a template of my mana and HP restoration herbs scripts to make this script, and those script work perfectly. However, the onUse for this script is giving me an error..
 
I've actually exhausted every effort I could think of, down to getting rid of the cooldown and keeping it a simple onUse script. What's weird is that I used a template of my mana and HP restoration herbs scripts to make this script, and those script work perfectly. However, the onUse for this script is giving me an error..
Can you post the error?

Also, not sure if that's what you wanted, but adding an exhaustion via this item using this: CONDITION_EXHAUST_HEAL will make the player unable to heal at all (with any other resource as well) for 15 seconds, if i'm not wrong.
Why don't you try using exhaustion.set / exhaustion.check / exhaustion.get for exhausting individual items?
 
This script is quite a throwback, and the honest truth is that I'm still getting used to the minute changes to scripting. In regards to the script, once I revert it to the the version that's in the first post it doesn't give an onUse error but when it's used it gives both a poff effect as well as the bluespark. In addition, it doesn't actually cure the poison but the exhaust works. The onUse issue occurs when I change the onUse to the one commonly used with 1.1
 
This script is quite a throwback, and the honest truth is that I'm still getting used to the minute changes to scripting. In regards to the script, once I revert it to the the version that's in the first post it doesn't give an onUse error but when it's used it gives both a poff effect as well as the bluespark. In addition, it doesn't actually cure the poison but the exhaust works. The onUse issue occurs when I change the onUse to the one commonly used with 1.1

I mean, here. I don't know if this will work on your version of TFS, but the script in the first post seems to be identical to this old scripting style:

Code:
        function onUse(cid, item, fromPosition, itemEx, toPosition)
       
       
            local exhTime = 15 -- 15 seconds cooldown on this item, if you want this item to share the cooldown with some other items, use the same kind of exhaustion on those items with the same storage   
            local exhStorage = 55555 --- Specific storage that will be used for storing the cooldown of this item/group of items
                   
                    if not(exhaustion.check(cid,exhStorage)) then
                            if getCreatureCondition(cid, CONDITION_POISON) then
                                    exhaustion.set(cid, exhStorage, exhTime) -- 15 sec cooldown
                                    doRemoveCondition(cid, CONDITION_POISON)
                                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
                                    doRemoveItem(item.uid, 1)
                                    return doCreatureSay(cid, "Healed poisoning.", TALKTYPE_MONSTER)
                            else
                                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
                                    return doPlayerSendCancel(cid, "You are not poisoned.")
                            end
                   
                    else
                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
                    return doPlayerSendCancel(cid, "You cannot eat another herb yet. Cooldown: " ..exhaustion.get(cid, exhStorage).. " s.")
                    end
                       
        end

Try that, see what happens.
 
I mean, here. I don't know if this will work on your version of TFS, but the script in the first post seems to be identical to this old scripting style:

Code:
        function onUse(cid, item, fromPosition, itemEx, toPosition)
    
    
            local exhTime = 15 -- 15 seconds cooldown on this item, if you want this item to share the cooldown with some other items, use the same kind of exhaustion on those items with the same storage
            local exhStorage = 55555 --- Specific storage that will be used for storing the cooldown of this item/group of items
                
                    if not(exhaustion.check(cid,exhStorage)) then
                            if getCreatureCondition(cid, CONDITION_POISON) then
                                    exhaustion.set(cid, exhStorage, exhTime) -- 15 sec cooldown
                                    doRemoveCondition(cid, CONDITION_POISON)
                                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
                                    doRemoveItem(item.uid, 1)
                                    return doCreatureSay(cid, "Healed poisoning.", TALKTYPE_MONSTER)
                            else
                                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
                                    return doPlayerSendCancel(cid, "You are not poisoned.")
                            end
                
                    else
                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
                    return doPlayerSendCancel(cid, "You cannot eat another herb yet. Cooldown: " ..exhaustion.get(cid, exhStorage).. " s.")
                    end
                    
        end

Try that, see what happens.

Apparently I don't have the exhaustion lib?

a24d74b35d.png




Edit:
Tried to add http://pastebin.com/zYCrBtM0 to my compat.lua and it allowed me to see the "You are not poisoned." message if I used the item while not poisoned, but then I debug when used and I AM poisoned.
 
Last edited:
Back
Top