Author: Mock
Test in: TFS 0.3.4
Version: 2.0
At some time i see the otservers stop using UHs and start using potions, but UH you can have UHs of 99 charges and they are verry soft, but potions not, an knight in a long hunt need take an big amount of GHP and mana potions, it destroy him cap. So i have an idea, create an system to do potions with charges. ^^
You need folow this 3 stepts.
1º -- potions
Firts go to talkactions.xml and remove ALL tags of normal potions and change to this:
Code:
<action itemid="7588" event="script" value="liquids/potions charges.lua"/>
<action itemid="7589" event="script" value="liquids/potions charges.lua"/>
<action itemid="7590" event="script" value="liquids/potions charges.lua"/>
<action itemid="7591" event="script" value="liquids/potions charges.lua"/>
<action itemid="8472" event="script" value="liquids/potions charges.lua"/>
<action itemid="8473" event="script" value="liquids/potions charges.lua"/>
<action itemid="7618" event="script" value="liquids/hpotions charges.lua"/>
<action itemid="7620" event="script" value="liquids/potions charges.lua"/>
Next create an script called potions charges.lua in folder scripts/liquids and add it in him:
Code:
--- Script by Mock (the bear)
--- You are not authorized to:
--- Del the credits
--- Post it in another forum.
local storage = {
[1] = {17070,function(hmax,hmin,cid) doCreatureAddHealth(cid, math.random(hmin,hmax)) end},
[2] = {17071,function(hmax,hmin,cid) doCreatureAddMana(cid, math.random(hmin,hmax)) end},
[3] = {17072,function(hmax,hmin,cid) doCreatureAddHealth(cid, math.random(hmin[1],hmax[1])) doCreatureAddMana(cid, math.random(hmin[2],hmax[2])) end},
}
local potions = {
-- pequenas
[7620] = {lvl=0,tipo=2,hmax=101,hmin=100,vasio=7636,vocs={1,2,3,4,5,6,7,8},exaust=1},
[7618] = {lvl=0,tipo=1,hmax=100,hmin=50,vasio=7636,vocs={1,2,3,4,5,6,7,8},exaust=1}, -- HP
---medias
[7589] = {lvl=50,tipo=2,hmax=190,hmin=110,vasio=7634,vocs={1,2,3,5,6,7},exaust=1},
[7588] = {lvl=50,tipo=1,hmax=400,hmin=200,vasio=7634,vocs={3,4,7,8},exaust=1}, -- HP
-- grandes
[7591] = {lvl=80,tipo=1,hmax=800,hmin=600,vasio=7635,vocs={4,8},exaust=1}, -- hP
[7590] = {lvl=80,tipo=2,hmax=800,hmin=600,vasio=7635,vocs={1,2,5,6},exaust=1}, -- MP
[8472] = {lvl=80,tipo=3,hmax={400,190},hmin={200,110},vasio=7635,vocs={3,7},exaust=1},
--- grandonas ._.
[8473] = {lvl=130,tipo=1,hmax=1000,hmin=800,vasio=7635,vocs={4,8,0,0},exaust=1},
}
--- Script by Mock (the bear)
function onUse(cid, item, fromPosition, itemEx, toPosition)
if isPlayer(itemEx.uid) == false or potions[item.itemid] == nil or isCreature(itemEx.uid) == false then
return FALSE
elseif getPlayerStorageValue(itemEx.uid, storage[potions[item.itemid].tipo][1]) > os.time() and (type(getPlayerStorageValue(itemEx.uid, storage[potions[item.itemid].tipo][1])) == 'number' and getPlayerStorageValue(itemEx.uid, storage[potions[item.itemid].tipo][1]) ~= -1) then
doPlayerSendDefaultCancel(itemEx.uid, RETURNVALUE_YOUAREEXHAUSTED)
return TRUE
elseif getPlayerLevel(itemEx.uid) < potions[item.itemid].lvl or isInArray(potions[item.itemid].vocs,getPlayerVocation(itemEx.uid)) == FALSE then
doCreatureSay(itemEx.uid, "Only required vocation and level "..potions[item.itemid].lvl.." or above may drink this fluid.", TALKTYPE_ORANGE_1)
return TRUE
end
setPlayerStorageValue(itemEx.uid, storage[potions[item.itemid].tipo][1], os.time()+potions[item.itemid].exaust)
storage[potions[item.itemid].tipo][2](potions[item.itemid].hmax,potions[item.itemid].hmin,itemEx.uid)
local _, _, cnt =string.find(getItemName(item.uid),'(%d+)')
if tonumber(cnt) ~= nil and tonumber(cnt) > 1 then
local _, _, cnt =string.find(getItemName(item.uid),'(%d+)')
setItemName(item.uid, getItemNameById(item.itemid).." x "..cnt-1)
else
doTransformItem(item.uid,potions[item.itemid].vasio)
end
doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_MAGIC_BLUE)
doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1)
return TRUE --- Script by Mock (the bear)
end
Before it save and done.
2º -- Function
Add it on functions.lua:
Code:
function doAddPotWithCharges(cid,id,charge)
local pot = doPlayerAddItem(cid, id)
setItemName(pot, getItemNameById(id)..' x'..charge)
return pot
end
3º -- Command.
This its only an EXAMPLE to you know how to create potions with charges:
Add it on talkactions.lua
Code:
<talkaction log="yes" words="/chargepotion" event="script" access="5" value="pot.lua"/>
And next create pot.lua in scripts and add it:
Code:
function onSay(cid, words, param)
local st = string.explode(param, " ",2)
doAddPotWithCharges(cid,st[1],st[2])
return FALSE
end
7620 -- potion itemid
100 -- charges.
This talkactions its only an EXAMPLE it have many bugs (talk action only) and it's to you know how to use the function.
If action dont work in your server post the error here and your TFS version
You see a mana potion x99
Usign...
You see a mana potion x98
Using...
You see a mana potion x97
Using..
(...)
Using...
You see a mana potion x1
Using...
You see a empyt potion flask.
Last edited: