• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Linux Fix Potion, its simple.

Vrotz

Member
Joined
Apr 7, 2011
Messages
1,071
Reaction score
7
Location
Brazil
Hi,
How I do to this doesn't end when the player logout / die. Only when the time runs out?

PHP:
local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, 10 * 60 * 1000) -- 10 minutes
setConditionParam(condition, CONDITION_PARAM_STAT_MAGICLEVEL, 50)
setConditionParam(condition, CONDITION_PARAM_SKILL_SHIELD, -10)
setConditionParam(condition, CONDITION_PARAM_SUBID, 99)

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if(not isSorcerer(cid) and not isDruid(cid)) then
		doCreatureSay(cid, "Only sorcerers and druids may drink this fluid.", TALKTYPE_ORANGE_1, cid)
		return true
	end

	if(doAddCondition(cid, condition)) then
		doSendMagicEffect(fromPosition, CONST_ME_MAGIC_RED)
		doRemoveItem(item.uid, 1)
		doCreatureSay(cid, "You feel smarter.", TALKTYPE_ORANGE_1, cid)
	end

	return true
end
 
Last edited:
LUA:
local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, 10* 60 * 1000) -- 10 minutes
setConditionParam(condition, CONDITION_PARAM_STAT_MAGICLEVEL, 50)
setConditionParam(condition, CONDITION_PARAM_SKILL_SHIELD, -10)
setConditionParam(condition, CONDITION_PARAM_SUBID, 99)


function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(not isSorcerer(cid) and not isDruid(cid)) then
        return doCreatureSay(cid, "Only sorcerers and druids may drink this fluid.", TALKTYPE_ORANGE_1, cid)
    end
    
    if exhaustion.get(cid, 20251) then
        return doCreatureSay(cid, "Your latest used potion has not expired its effect yet.", TALKTYPE_ORANGE_1, cid)
    end


    if doAddCondition(cid, condition) then
        doRemoveItem(item.uid, 1)
        doSendMagicEffect(fromPosition, CONST_ME_MAGIC_RED)
exhaustion.set(cid, 20251, 60*10)
        doCreatureSay(cid, "You feel smarter.", TALKTYPE_ORANGE_1, cid)
    end
    return true
end

create @\data\creaturescripts\scripts\potion.lua
LUA:
local condition = {}
for n = 1, 10 do
    condition[n] = createConditionObject(CONDITION_ATTRIBUTES)
    setConditionParam(condition[n], CONDITION_PARAM_TICKS, n * 60 * 1000)
    setConditionParam(condition[n], CONDITION_PARAM_STAT_MAGICLEVEL, 50)
    setConditionParam(condition[n], CONDITION_PARAM_SKILL_SHIELD, -10)
    setConditionParam(condition[n], CONDITION_PARAM_SUBID, 99)
end


function onLogin(cid)


    local i = math.floor(exhaustion.get(cid, 20251)/60)
    if i > 0 then
        doAddCondition(cid, condition[i])
        doCreatureSay(cid, "Healing...", TALKTYPE_ORANGE_1, cid)
    end
    
    return true
end

add @creaturescripts.xml
XML:
<event type="login" name="potion" event="script" value="potion.lua"/>
 
Last edited:
I didn't understand well what you last wrote, but if you want this to work with different potions, post the other potion scripts
 
this?
use onLogin creaturescript with storage based on os.time()
exhaustion lib is useful once in a while

the creaturescript checks if player still has the potion exhaustion active, so it will give player the healing condition again,
that's why there's a iterator that creates 10 conditions(10 minutes), it will check player's exhaustion and apply the proper condition with time, just that it gets reduced by -1 minute

If you want it with more potions, the code can be rewritten
 
LUA:
local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, 10* 60 * 1000) -- 10 minutes
setConditionParam(condition, CONDITION_PARAM_STAT_MAGICLEVEL, 50)
setConditionParam(condition, CONDITION_PARAM_SKILL_SHIELD, -10)
setConditionParam(condition, CONDITION_PARAM_SUBID, 99)


function onUse(cid, item, fromPosition, itemEx, toPosition)
    if not isSorcerer(cid) or not isDruid(cid) then
        return doCreatureSay(cid, "Only sorcerers and druids may drink this fluid.", TALKTYPE_ORANGE_1, cid)
    end
    
    if exhaustion.get(cid, 20251) then
        return doCreatureSay(cid, "Your latest used potion has not expired its effect yet.", TALKTYPE_ORANGE_1, cid)
    end


    if doAddCondition(cid, condition) then
        doRemoveItem(item.uid, 1)
        doSendMagicEffect(fromPosition, CONST_ME_MAGIC_RED)
exhaustion.set(cid, 20251, 60*10)
        doCreatureSay(cid, "You feel smarter.", TALKTYPE_ORANGE_1, cid)
    end
    return true
end

create @\data\creaturescripts\scripts\potion.lua
LUA:
local condition = {}
for n = 1, 10 do
    condition[n] = createConditionObject(CONDITION_ATTRIBUTES)
    setConditionParam(condition[n], CONDITION_PARAM_TICKS, n * 60 * 1000)
    setConditionParam(condition[n], CONDITION_PARAM_STAT_MAGICLEVEL, 50)
    setConditionParam(condition[n], CONDITION_PARAM_SKILL_SHIELD, -10)
    setConditionParam(condition[n], CONDITION_PARAM_SUBID, 99)
end


function onLogin(cid)


    local i = math.floor(exhaustion.get(cid, 20251)/60)
    if i > 0 then
        doAddCondition(cid, condition[i])
        doCreatureSay(cid, "Healing...", TALKTYPE_ORANGE_1, cid)
    end
    
    return true
end

add @creaturescripts.xml
XML:
<event type="login" name="potion" event="script" value="potion.lua"/>

I still don't understand anything and don't know what do make with scripts

What I do with this? Substituted with the potion to ml?
PHP:
local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, 10* 60 * 1000) -- 10 minutes
setConditionParam(condition, CONDITION_PARAM_STAT_MAGICLEVEL, 50)
setConditionParam(condition, CONDITION_PARAM_SKILL_SHIELD, -10)
setConditionParam(condition, CONDITION_PARAM_SUBID, 99)
 
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if not isSorcerer(cid) or not isDruid(cid) then
        return doCreatureSay(cid, "Only sorcerers and druids may drink this fluid.", TALKTYPE_ORANGE_1, cid)
    end
 
    if exhaustion.get(cid, 20251) then
        return doCreatureSay(cid, "Your latest used potion has not expired its effect yet.", TALKTYPE_ORANGE_1, cid)
    end
 
 
    if doAddCondition(cid, condition) then
        doRemoveItem(item.uid, 1)
        doSendMagicEffect(fromPosition, CONST_ME_MAGIC_RED)
exhaustion.set(cid, 20251, 60*10)
        doCreatureSay(cid, "You feel smarter.", TALKTYPE_ORANGE_1, cid)
    end
    return true
end


And why create an file in creature script? this is for scan the storage per potion i'm using?
PHP:
create @\data\creaturescripts\scripts\potion.lua

I saw that you created a storage within the first potion. I substitute it for first script?
 
yes... replace your potion script with my first code.. and create the creaturescript if you want the potion to keep healing players even after re-log

you can change the storage if you need to, just make sure the key number is the same in both scripts(20251)
 
Ok, and if i need 60 minutes, i've changed for:

PHP:
60 * 60 * 1000

Correct?

Need add in login.lua
PHP:
      registerCreatureEvent(cid, "Potion")
too?
 
no, exhaustion lib's time is in seconds, for 1 hour:

potion script
LUA:
...
exhaustion.set(cid, 20251, 60*60)
...etc

creaturescript
LUA:
...
for n = 1, 60 do
...etc

and login/logout creature events do not need to be registered, they only will work for players anyways
 

Similar threads

Back
Top