• 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 Health/Mana Charges

Aarthec

w0000t
Joined
Apr 25, 2009
Messages
129
Reaction score
0
Location
Sweden
Oioioi!

Here's a health/mana potion system (You use charges).

Information:
You have one mana potion in your backpack.
You buy 500 charges by typing: /charges 500
Now you can use your only mana potion and you will lose charges but the mana potion will stay.
If you don't have any charges left, you can't use the mana potion(ofcourse)
Each time you use a potion, it will send a message in the default channel: "You have 42 charges left"
When you're out of charges, it will say: "You don't have any charges left. To buy more charges type /charges |amount|"


First of all you have to delete your old mana/health potion scripts from your actions.xml.

Here we go...

actions/scripts/charges/mp
Lua:
local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, frompos, item2, topos)
	if(not isPlayer(item2.uid)) then
		return false
	end
	
	if(hasCondition(cid, CONDITION_EXHAUST)) then
		doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
		return true
	end
	
    if getPlayerStorageValue(cid, 19732) >= 1 then
		doCreatureAddMana(item2.uid, math.random(130, 160))
		setPlayerStorageValue(cid, 19732, getPlayerStorageValue(cid, 19732)-1)
		doPlayerSendTextMessage(cid, 19, "You have "..getPlayerStorageValue(cid, 19732).." charges left.")
		doCreatureSay(item2.uid, "Aaaah...", TALKTYPE_ORANGE_1)
		doAddCondition(cid, exhaust)
	end
	
	if getPlayerStorageValue(cid, 19732) <= 0 then
		doPlayerSendTextMessage(cid, 19, "You don't have any charges left.")
		doPlayerSendTextMessage(cid, 19, "Buy more charges by typing: /charges |amount|.")
	end
end

actions/scripts/charges/smp
Lua:
local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, frompos, item2, topos)
	if(not isPlayer(item2.uid)) then
		return false
	end
	
	if(hasCondition(cid, CONDITION_EXHAUST)) then
		doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
		return true
	end
	if getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 2 or getPlayerVocation(cid) == 3 or getPlayerVocation(cid) == 5 or getPlayerVocation(cid) == 6 or getPlayerVocation(cid) == 7 then
    if getPlayerStorageValue(cid, 19732) >= 1 and getPlayerLevel(cid) >= 50 then
		doCreatureAddMana(item2.uid, math.random(210, 390))
		setPlayerStorageValue(cid, 19732, getPlayerStorageValue(cid, 19732)-1)
		doPlayerSendTextMessage(cid, 19, "You have "..getPlayerStorageValue(cid, 19732).." charges left.")
		doCreatureSay(item2.uid, "Aaaah...", TALKTYPE_ORANGE_1)
		doAddCondition(cid, exhaust)
	end
	end
	if getPlayerStorageValue(cid, 19732) <= 0 then
		doPlayerSendTextMessage(cid, 19, "You don't have any charges left.")
		doPlayerSendTextMessage(cid, 19, "Buy more charges by typing: /charges |amount|.")
	end
end

actions/scripts/charges/gmp
Lua:
local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, frompos, item2, topos)
	if(not isPlayer(item2.uid)) then
		return false
	end
	
	if(hasCondition(cid, CONDITION_EXHAUST)) then
		doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
		return true
	end
	
	if getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 2 or getPlayerVocation(cid) == 5 or getPlayerVocation(cid) == 6 then
    if getPlayerStorageValue(cid, 19732) >= 1 and getPlayerLevel(cid) >= 80 then
		doCreatureAddMana(item2.uid, math.random(600, 700))
		setPlayerStorageValue(cid, 19732, getPlayerStorageValue(cid, 19732)-1)
		doPlayerSendTextMessage(cid, 19, "You have "..getPlayerStorageValue(cid, 19732).." charges left.")
		doCreatureSay(item2.uid, "Aaaah...", TALKTYPE_ORANGE_1)
		doAddCondition(cid, exhaust)
	end
	end
	
	if getPlayerStorageValue(cid, 19732) <= 0 then
		doPlayerSendTextMessage(cid, 19, "You don't have any charges left.")
		doPlayerSendTextMessage(cid, 19, "Buy more charges by typing: /charges |amount|.")
	end
end

actions/scripts/charges/hp
Lua:
local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, frompos, item2, topos)
	if(not isPlayer(item2.uid)) then
		return false
	end
	
	if(hasCondition(cid, CONDITION_EXHAUST)) then
		doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
		return true
	end
	
    if getPlayerStorageValue(cid, 19732) >= 1 then
		doCreatureAddHealth(item2.uid, math.random(100, 200))
		setPlayerStorageValue(cid, 19732, getPlayerStorageValue(cid, 19732)-1)
		doPlayerSendTextMessage(cid, 19, "You have "..getPlayerStorageValue(cid, 19732).." charges left.")
		doCreatureSay(item2.uid, "Aaaah...", TALKTYPE_ORANGE_1)
		doAddCondition(cid, exhaust)
	end
	
	if getPlayerStorageValue(cid, 19732) <= 0 then
		doPlayerSendTextMessage(cid, 19, "You don't have any charges left.")
		doPlayerSendTextMessage(cid, 19, "Buy more charges by typing: /charges |amount|.")
	end
end

actions/scripts/charges/shp
Lua:
local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, frompos, item2, topos)
	if(not isPlayer(item2.uid)) then
		return false
	end
	
	if(hasCondition(cid, CONDITION_EXHAUST)) then
		doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
		return true
	end
	
	if getPlayerVocation(cid) == 3 or getPlayerVocation(cid) == 4 or getPlayerVocation(cid) == 7 or getPlayerVocation(cid) == 8 then
    if getPlayerStorageValue(cid, 19732) >= 1 and getPlayerLevel(cid) >= 50 then
		doCreatureAddHealth(item2.uid, math.random(200, 400))
		setPlayerStorageValue(cid, 19732, getPlayerStorageValue(cid, 19732)-1)
		doPlayerSendTextMessage(cid, 19, "You have "..getPlayerStorageValue(cid, 19732).." charges left.")
		doCreatureSay(item2.uid, "Aaaah...", TALKTYPE_ORANGE_1)
		doAddCondition(cid, exhaust)
	end
	end
	
	if getPlayerStorageValue(cid, 19732) <= 0 then
		doPlayerSendTextMessage(cid, 19, "You don't have any charges left.")
		doPlayerSendTextMessage(cid, 19, "Buy more charges by typing: /charges |amount|.")
	end
end

actions/scripts/charges/ghp
Lua:
local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, frompos, item2, topos)
	if(not isPlayer(item2.uid)) then
		return false
	end
	
	if(hasCondition(cid, CONDITION_EXHAUST)) then
		doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
		return true
	end
	
	if getPlayerVocation(cid) == 4 or getPlayerVocation(cid) == 8 then
    if getPlayerStorageValue(cid, 19732) >= 1 and getPlayerLevel(cid) >= 80 then
		doCreatureAddHealth(item2.uid, math.random(500, 600))
		setPlayerStorageValue(cid, 19732, getPlayerStorageValue(cid, 19732)-1)
		doPlayerSendTextMessage(cid, 19, "You have "..getPlayerStorageValue(cid, 19732).." charges left.")
		doCreatureSay(item2.uid, "Aaaah...", TALKTYPE_ORANGE_1)
		doAddCondition(cid, exhaust)
	end
	end
	
	if getPlayerStorageValue(cid, 19732) <= 0 then
		doPlayerSendTextMessage(cid, 19, "You don't have any charges left.")
		doPlayerSendTextMessage(cid, 19, "Buy more charges by typing: /charges |amount|.")
	end
end

actions/scripts/charges/uhp
Lua:
local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, frompos, item2, topos)
	if(not isPlayer(item2.uid)) then
		return false
	end
	
	if(hasCondition(cid, CONDITION_EXHAUST)) then
		doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
		return true
	end
	
	if getPlayerVocation(cid) == 4 or getPlayerVocation(cid) == 8 then
    if getPlayerStorageValue(cid, 19732) >= 1 and getPlayerLevel(cid) >= 130 then
		doCreatureAddHealth(item2.uid, math.random(800, 900))
		setPlayerStorageValue(cid, 19732, getPlayerStorageValue(cid, 19732)-1)
		doPlayerSendTextMessage(cid, 19, "You have "..getPlayerStorageValue(cid, 19732).." charges left.")
		doCreatureSay(item2.uid, "Aaaah...", TALKTYPE_ORANGE_1)
		doAddCondition(cid, exhaust)
	end
	end
	
	if getPlayerStorageValue(cid, 19732) <= 0 then
		doPlayerSendTextMessage(cid, 19, "You don't have any charges left.")
		doPlayerSendTextMessage(cid, 19, "Buy more charges by typing: /charges |amount|.")
	end
end

actions/scripts/charges/gsp
Lua:
local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, frompos, item2, topos)
	if(not isPlayer(item2.uid)) then
		return false
	end
	
	if(hasCondition(cid, CONDITION_EXHAUST)) then
		doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
		return true
	end
	
	if getPlayerVocation(cid) == 3 or getPlayerVocation(cid) == 7 then
    if getPlayerStorageValue(cid, 19732) >= 1 and getPlayerLevel(cid) >= 80 then
		doCreatureAddHealth(item2.uid, math.random(300, 400))
		doCreatureAddMana(item2.uid, math.random(300, 400))
		setPlayerStorageValue(cid, 19732, getPlayerStorageValue(cid, 19732)-1)
		doPlayerSendTextMessage(cid, 19, "You have "..getPlayerStorageValue(cid, 19732).." charges left.")
		doCreatureSay(item2.uid, "Aaaah...", TALKTYPE_ORANGE_1)
		doAddCondition(cid, exhaust)
	end
	end
	
	if getPlayerStorageValue(cid, 19732) <= 0 then
		doPlayerSendTextMessage(cid, 19, "You don't have any charges left.")
		doPlayerSendTextMessage(cid, 19, "Buy more charges by typing: /charges |amount|.")
	end
end

data/talkactions/scripts/charges.lua
Lua:
  function onSay(cid, words, param)
local maxcharges = 3000;

        if param > 0 and getPlayerStorageValue(cid, 19732)+param <= maxcharges then
              if getPlayerMoney(cid) >= param*100 then
                    if doPlayerRemoveMoney(cid, param*100) == TRUE then
                              doPlayerSendTextMessage(cid, 22, 'You bought '.. param ..' charges for '.. param*100 ..' gold!')
                              setPlayerStorageValue(cid, 19732, getPlayerStorageValue(cid, 19732)+param)               
                                        end                                                      
                        else
                                doPlayerSendTextMessage(cid, 22, 'You don\'t have enough money.')
                                end
                                else
                                        doPlayerSendTextMessage(cid, 22, 'You can\'t have more than 3000 charges.')
                                end
return true
end

actions/actions.xml
PHP:
<action itemid="7620" event="script" value="charges/mp.lua" allowfaruse="1"/>
<action itemid="7589" event="script" value="charges/smp.lua" allowfaruse="1"/>
<action itemid="7590" event="script" value="charges/gmp.lua" allowfaruse="1"/>
<action itemid="7618" event="script" value="charges/hp.lua" allowfaruse="1"/>
<action itemid="7588" event="script" value="charges/shp.lua" allowfaruse="1"/>
<action itemid="7591" event="script" value="charges/ghp.lua" allowfaruse="1"/>
<action itemid="8473" event="script" value="charges/uhp.lua" allowfaruse="1"/>
<action itemid="8472" event="script" value="charges/gsp.lua" allowfaruse="1"/>

talkactions/talkactions.xml
PHP:
<talkaction words="/charges" script="charges.lua"/>
 
Last edited:
very nice script;), btw is it any way i can make that you only can buy charges in PZ(protection zone)?
 
Lua:
function onSay(cid, words, param)
local maxcharges = 3000;

	if #param > 0 and getPlayerStorageValue(cid, 19732)+#param <= maxcharges then
		if getTilePzInfo(getCreaturePosition(cid)) == TRUE then
              if getPlayerMoney(cid) >= #param*100 then
                    if doPlayerRemoveMoney(cid, #param*100) == TRUE then
                              doPlayerSendTextMessage(cid, 22, 'You bought '..#param..' charges for '.. #param*100 ..' gold!')
                              setPlayerStorageValue(cid, 19732, getPlayerStorageValue(cid, 19732)+#param)		
					end							  
			else
				doPlayerSendTextMessage(cid, 22, 'You don\'t have enough money.')
				end
			else
				doPlayerSendTextMessage(cid, 22, 'You can only buy charges in protection zone.')
			end
				else
					doPlayerSendTextMessage(cid, 22, 'You can\'t have more than 3000 charges.')
				end
return true
end

Should do it, tell me if you get any errors :)
 
I added charges to potions much easier in C++/items.xml/npc files (TFS 0.3.5) o0
Maybe someone need it too (when player look on potion server show in description 'bla bla bla... it has xxx charges' and when drink server send msg '... one of ... charges').
In item.h in function:
PHP:
Item::countByType(const Item* item, int32_t checkType, bool multiCount)
In place of:
PHP:
	if(item->isRune())
		return item->getCharges();
Paste:
PHP:
	if(item->isRune() || (item->getID() == 8472 || item->getID() == 8473 || item->getID() == 7591 || item->getID() == 7588 || item->getID() == 7618 || item->getID() == 7590 || item->getID() == 7589 || item->getID() == 7620))
		return item->getCharges();
In items.xml in every potion add line:
PHP:
<attribute key="charges" value="10"/>
in npc script add 10, (or other value) before name if you dont have it now:
...
shopModule:addBuyableItemContainer({'bp shp', 'bp strong health potion'}, 2000, 7588, 1000, 10, 'backpack of strong health potions')
shopModule:addBuyableItem({'strong health potion', 'strong healthpotion', 'shp'}, 7588, 50, 10, 'strong health potion')

...
I'm not sure is it all needed because I wrote this script ~half year ago.
 
Aarthec, The script is a bit bugged, When i type /charges 100, it stays that i have bought 3charages, i cant buy more then 3charges at a time, so if i want like 6Charges i have to type /charges 100 two times, i can write /charges 500, 600, 700, 900, but i still buy 3 charges, do u understand me?
 
Aarthec, The script is a bit bugged, When i type /charges 100, it stays that i have bought 3charages, i cant buy more then 3charges at a time, so if i want like 6Charges i have to type /charges 100 two times, i can write /charges 500, 600, 700, 900, but i still buy 3 charges, do u understand me?
Replace every #param with param in talkaction script.
 
I have the problem with the charges.. When i remove the "#" it doesnt work at all.. And when they are in.. i buy 1 charge and it works.. but when i buy say 300.. it gives me like 4 charges. Kinda weird.. If you can help me out aarthec that would be great.

By the way i am Jesus Our Saviour. if you remember me ;)
 
http://otland.net/f81/potions-charges-47102/

This it's better.
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=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

Lua:
function doAddPotWithCharges(cid,id,charge)
   local pot = doPlayerAddItem(cid, id)
   setItemName(pot, getItemNameById(id)..' x'..charge)
   return pot
end
 
[23/10/2009 21:40:07] Warning: [Event::loadScript] Can not load script. data/talkactions/scripts/charges.lua
[23/10/2009 21:40:07] data/talkactions/scripts/charges.lua:7: malformed number near '100..'
Can someone help me to fix this? ;o

I'm using The Forgotten Server, version 0.3.1 (Crying Damson)
Thanks, a lot!
 
Lua:
  function onSay(cid, words, param)
local maxcharges = 3000;

        if param > 0 and getPlayerStorageValue(cid, 19732)+param <= maxcharges then
              if getPlayerMoney(cid) >= param*100 then
                    if doPlayerRemoveMoney(cid, param*100) == TRUE then
                              doPlayerSendTextMessage(cid, 22, 'You bought '.. param ..' charges for '.. param*100 ..' gold!')
                              setPlayerStorageValue(cid, 19732, getPlayerStorageValue(cid, 19732)+param)               
                                        end                                                      
                        else
                                doPlayerSendTextMessage(cid, 22, 'You don\'t have enough money.')
                                end
                                else
                                        doPlayerSendTextMessage(cid, 22, 'You can\'t have more than 3000 charges.')
                                end
return true
end
 
Sorry for the necro!

When using /charges, how does it know what potion to add charges to, and the price per charge?
 
It's for all kinds of potions (100 gp each)
So you can have one health potion and one mana potion and the charges is the same for both of them.
 
[02/11/2016 15:00:02] [Error - TalkAction Interface]
[02/11/2016 15:00:02] data/talkactions/scripts/charges.lua:eek:nSay
[02/11/2016 15:00:02] Description:
[02/11/2016 15:00:02] data/talkactions/scripts/charges.lua:4: attempt to compare number with string
[02/11/2016 15:00:02] stack traceback:
[02/11/2016 15:00:02] data/talkactions/scripts/charges.lua:4: in function <data/talkactions/scripts/charges.lua:1>
 
[02/11/2016 15:00:02] [Error - TalkAction Interface]
[02/11/2016 15:00:02] data/talkactions/scripts/charges.lua:eek:nSay
[02/11/2016 15:00:02] Description:
[02/11/2016 15:00:02] data/talkactions/scripts/charges.lua:4: attempt to compare number with string
[02/11/2016 15:00:02] stack traceback:
[02/11/2016 15:00:02] data/talkactions/scripts/charges.lua:4: in function <data/talkactions/scripts/charges.lua:1>
add under onsay
local param = tonumber(param)
 
Back
Top