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

Action Potions with charges.

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Reaction score
106
Location
Brazil

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
Save and done.
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
Save, reboot your server, login in your ADM and say /chargepotion 7620 100
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 :p

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:
Lua:
--- 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=2},
[7618] = {lvl=0,tipo=1,hmax=100,hmin=50,vasio=7636,vocs={1,2,3,4,5,6,7,8},exaust=2},  -- HP
---medias
[7589] = {lvl=50,tipo=2,hmax=190,hmin=110,vasio=7634,vocs={1,2,3,5,6,7},exaust=2},
[7588] = {lvl=50,tipo=1,hmax=400,hmin=200,vasio=7634,vocs={3,4,7,8},exaust=2},    -- HP
-- grandes
[7591] = {lvl=80,tipo=2,hmax=300,hmin=200,vasio=7635,vocs={1,2,5,6},exaust=2}, -- MP
[7590] = {lvl=80,tipo=1,hmax=700,hmin=500,vasio=7635,vocs={4,8},exaust=2}, -- HP
[7591] = {lvl=80,tipo=3,hmax={400,190},hmin={200,110},vasio=7635,vocs={3,7},exaust=2},
--- grandonas ._.
[8473] = {lvl=130,tipo=1,hmax=1000,hmin=800,vasio=7635,vocs={4,8},exaust=2},
}
--- Script by Mock (the bear)
function onUse(cid, item, fromPosition, itemEx, toPosition)

I think "function onUse(cid, item, fromPosition, itemEx, toPosition)" have to come before "doCreatureAddMana(cid, math.random(hmin,hmax)", because "cid" don't exist else. :thumbup:

EDIT:
And if you give the potion with 1 charges left to another player, he will have 100 charges, because you are using storage values.
 
@shawak
Nope ^^
look it aigan.
storage[potions[item.itemid].tipo][2](potions[item.itemid].hmax,potions[item.itemid].hmin,itemEx.uid)
(cid it's not and global variable. in this function cid is itemEx.uid. I callit by an table.)

^ it call function in first table.
function(hmax,hmin,cid) doCreatureAddHealth(cid, math.random(hmin,hmax)) end
:p
And i used player storage value to Exaust system not to charges.
 
@shawak
Nope ^^
look it aigan.
storage[potions[item.itemid].tipo][2](potions[item.itemid].hmax,potions[item.itemid].hmin,itemEx.uid)
(cid it's not and global variable. in this function cid is itemEx.uid. I callit by an table.)

^ it call function in first table.
function(hmax,hmin,cid) doCreatureAddHealth(cid, math.random(hmin,hmax)) end
:p
And i used player storage value to Exaust system not to charges.

Ahh don't saw that it is the exhaustion (try tabbing :))
And please post screen, i want see how it looks ingame, ^_^.
 
@shawak
Dont need, the charges are in the name ^^
This is the secret.
when you look (eye) in potion you will se an normal potion, without difference to an normal potion. But if you look (tibia) you will se:
You see a mana potion x50.
You can put 999999999999999 charges in this script :p
 
I have seen this before on Kiwiserver, it is a nice idea.
Although I would rather take a dateditor/itemeditor and make my own custom items(potions), with charges.
 
@shawak
Dont need, the charges are in the name ^^
This is the secret.
when you look (eye) in potion you will se an normal potion, without difference to an normal potion. But if you look (tibia) you will se:
You see a mana potion x50.
You can put 999999999999999 charges in this script :p

:p
I know, but just wanted to see, how it's looks ingame when you look at it,:thumbup:.
So or so, very nice idea :).
 
Shaw
When you look will apear it:
You see a mana potion x99. oz 4...
 
nope...
mana potion x99
x($d) :p
(%d) depends by amount you say in /createpot
 
Can't you make it possible to add potions with charges to the shop ? :p

Would be alot better instead of the charge talkaction and it's a little RPG feel to it

Great script btw :) Rep4u
 
it doesn't work. 1'st step is go to talkaction.xml? please write it like:
actions/scripts/...
 
Back
Top