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

how to remove charges. on script using aid

Status
Not open for further replies.

Taurus

Texass
Joined
Jan 11, 2009
Messages
616
Solutions
2
Reaction score
30
Location
United States
I need to know how to make this script remove charges when i set it up like this in items.xml
Code:
	<item id="8473" article="an" name="ultimate health potion">
		<attribute key="charges" value="100"/>
		<attribute key="showcharges" value="1"/>
		<attribute key="weight" value="220"/>
		<attribute key="description" value="This potion can only be consumed by knights of level 130 or higher."/>
	</item>

Here is the script for the charges on the potion.

Code:
local config = {
	removeOnUse = "no",
	splashable = "no",
	realAnimation = "no", -- make text effect visible only for players in range 1x1
	healthMultiplier = 1.0,
	manaMultiplier = 1.0
}

config.removeOnUse = getBooleanFromString(config.removeOnUse)
config.splashable = getBooleanFromString(config.splashable)
config.realAnimation = getBooleanFromString(config.realAnimation)

local POTIONS = {
	[8704] = {empty = 7636, splash = 2, health = {50, 100}}, -- small health potion
	[7618] = {empty = 7636, splash = 2, health = {100, 200}}, -- health potion
	[7588] = {empty = 7634, splash = 2, health = {200, 400}, level = 50, vocations = {3, 4, 7, 8, 12, 11}, vocStr = "knights and paladins"}, -- strong health potion
	[7591] = {empty = 7635, splash = 2, health = {500, 700}, level = 80, vocations = {4, 8, 12}, vocStr = "knights"}, -- great health potion
	[8473] = {empty = 7635, splash = 2, health = {800, 1000}, level = 130, vocations = {4, 8, 12}, vocStr = "knights"}, -- ultimate health potion

	[7620] = {empty = 7636, splash = 7, mana = {70, 130}}, -- mana potion
	[7589] = {empty = 7634, splash = 7, mana = {110, 190}, level = 50, vocations = {1, 2, 3, 5, 6, 7, 9, 10, 11}, vocStr = "sorcerers, druids and paladins"}, -- strong mana potion
	[7590] = {empty = 7635, splash = 7, mana = {200, 300}, level = 80, vocations = {1, 2, 5, 6, 9, 10}, vocStr = "sorcerers and druids"}, -- great mana potion

	[8472] = {empty = 7635, splash = 3, health = {200, 400}, mana = {110, 190}, level = 80, vocations = {3, 7, 11}, vocStr = "paladins"} -- great spirit potion
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local potion = POTIONS[item.itemid]
	if(not potion) then
		return false
	end

	if(not isPlayer(itemEx.uid)) then
		if(not config.splashable) then
			return false
		end

		if(toPosition.x == CONTAINER_POSITION) then
			toPosition = getThingPos(item.uid)
		end

		doDecayItem(doCreateItem(2016, potion.splash, toPosition))
		doTransformItem(item.uid, potion.empty)
		return true
	end

	if(hasCondition(cid, CONDITION_EXHAUST_HEAL)) then
		doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
		return true
	end

	if(((potion.level and getPlayerLevel(cid) < potion.level) or (potion.vocations and not isInArray(potion.vocations, getPlayerVocation(cid)))) and
		not getPlayerCustomFlagValue(cid, PlayerCustomFlag_GamemasterPrivileges))
	then
		doCreatureSay(itemEx.uid, "Only " .. potion.vocStr .. (potion.level and (" of level " .. potion.level) or "") .. " or above may drink this fluid.", TALKTYPE_ORANGE_1)
		return true
	end

	local health = potion.health
	if(health and not doCreatureAddHealth(itemEx.uid, math.ceil(math.random(health[1], health[2]) * config.healthMultiplier))) then
		return false
	end

	local mana = potion.mana
	if(mana and not doPlayerAddMana(itemEx.uid, math.ceil(math.random(mana[1], mana[2]) * config.manaMultiplier))) then
		return false
	end

	doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_MAGIC_BLUE)
	if(not realAnimation) then
		doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1)
	else
		for i, tid in ipairs(getSpectators(getCreaturePosition(cid), 1, 1)) do
			if(isPlayer(tid)) then
				doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1, false, tid)
			end
		end
	end

	doAddCondition(cid, exhaust)
	if(not potion.empty or config.removeOnUse) then
		doRemoveItem(item.uid)
		return true
	end

local aidd = 
 {
  min = 10901,
   max = 11001
    }
     if item.actionid < aidd.min then
      doItemSetAttribute(item.uid, "aid", aidd.min)
       elseif item.actionid >= aidd.min and item.actionid <= aidd.max then
      doItemSetAttribute(item.uid, "aid", getItemAttribute(item.uid, "aid")+1)
     elseif item.actionid >= aidd.max then
    doTransformItem(item.uid, potion.empty)
   return TRUE
  end
 return true
end

I greatly appreciate any and all help thanks alot!

Version 0.3.6 is what im using
 
Thanks sythetic, im not great at scripting, got any ideas where to start?

I love your scripts btw, i know i have seen ur name, hope i remembered to rep u!

Thanks for the good OT work, thanks again.
 
I'll try to find my old potion script that I use to use for charges, ill look for it tomorrow and post if I find anything
 
Code:
local config = {
	removeOnUse = "no",
	splashable = "no",
	realAnimation = "no", -- make text effect visible only for players in range 1x1
	healthMultiplier = 1.0,
	manaMultiplier = 1.0
}

config.removeOnUse = getBooleanFromString(config.removeOnUse)
config.splashable = getBooleanFromString(config.splashable)
config.realAnimation = getBooleanFromString(config.realAnimation)

local POTIONS = {
	[8704] = {empty = 7636, splash = 2, health = {50, 100}}, -- small health potion
	[7618] = {empty = 7636, splash = 2, health = {100, 200}}, -- health potion
	[7588] = {empty = 7634, splash = 2, health = {200, 400}, level = 50, vocations = {3, 4, 7, 8, 12, 11}, vocStr = "knights and paladins"}, -- strong health potion
	[7591] = {empty = 7635, splash = 2, health = {500, 700}, level = 80, vocations = {4, 8, 12}, vocStr = "knights"}, -- great health potion
	[8473] = {[B][COLOR="Red"]charges = 100, [/COLOR][/B]empty = 7635, splash = 2, health = {800, 1000}, level = 130, vocations = {4, 8, 12}, vocStr = "knights"}, -- ultimate health potion

	[7620] = {empty = 7636, splash = 7, mana = {70, 130}}, -- mana potion
	[7589] = {empty = 7634, splash = 7, mana = {110, 190}, level = 50, vocations = {1, 2, 3, 5, 6, 7, 9, 10, 11}, vocStr = "sorcerers, druids and paladins"}, -- strong mana potion
	[7590] = {empty = 7635, splash = 7, mana = {200, 300}, level = 80, vocations = {1, 2, 5, 6, 9, 10}, vocStr = "sorcerers and druids"}, -- great mana potion

	[8472] = {empty = 7635, splash = 3, health = {200, 400}, mana = {110, 190}, level = 80, vocations = {3, 7, 11}, vocStr = "paladins"} -- great spirit potion
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local potion = POTIONS[item.itemid]
	if(not potion) then
		return false
	end

	if(not isPlayer(itemEx.uid)) then
		if(not config.splashable) then
			return false
		end

		if(toPosition.x == CONTAINER_POSITION) then
			toPosition = getThingPos(item.uid)
		end

		doDecayItem(doCreateItem(2016, potion.splash, toPosition))
		doTransformItem(item.uid, potion.empty)
		return true
	end

	if(hasCondition(cid, CONDITION_EXHAUST_HEAL)) then
		doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
		return true
	end

	if(((potion.level and getPlayerLevel(cid) < potion.level) or (potion.vocations and not isInArray(potion.vocations, getPlayerVocation(cid)))) and
		not getPlayerCustomFlagValue(cid, PlayerCustomFlag_GamemasterPrivileges))
	then
		doCreatureSay(itemEx.uid, "Only " .. potion.vocStr .. (potion.level and (" of level " .. potion.level) or "") .. " or above may drink this fluid.", TALKTYPE_ORANGE_1)
		return true
	end

	local health = potion.health
	if(health and not doCreatureAddHealth(itemEx.uid, math.ceil(math.random(health[1], health[2]) * config.healthMultiplier))) then
		return false
	end

	local mana = potion.mana
	if(mana and not doPlayerAddMana(itemEx.uid, math.ceil(math.random(mana[1], mana[2]) * config.manaMultiplier))) then
		return false
	end

	doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_MAGIC_BLUE)
	if(not realAnimation) then
		doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1)
	else
		for i, tid in ipairs(getSpectators(getCreaturePosition(cid), 1, 1)) do
			if(isPlayer(tid)) then
				doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1, false, tid)
			end
		end
	end

	doAddCondition(cid, exhaust)

[B][COLOR="Red"]	doItemSetAttribute(item.uid, 'aid', math.max(101, item.actionid + 1))
	if item.actionid >= 100 + potion.charges then
		doRemoveItem(item.uid)
	end[/COLOR][/B]
	return true
end
 
Last edited:
Oh wow, thanks!

Cyko I love your scripts thanks so much.
I know I ask you every time I see your post but,
-where did you start learning?-

edit;After testing the script i got these errors.

Code:
[27/05/2010 17:32:01] [Error - Action Interface] 
[27/05/2010 17:32:01] data/actions/scripts/liquids/potions.lua:onUse
[27/05/2010 17:32:01] Description: 
[27/05/2010 17:32:01] data/actions/scripts/liquids/potions.lua:85: attempt to call global 'doSetItemActionId' (a nil value)
[27/05/2010 17:32:01] stack traceback:
[27/05/2010 17:32:01] 	data/actions/scripts/liquids/potions.lua:85: in function <data/actions/scripts/liquids/potions.lua:30>

Line 30 is kinda over my head anyone got an idea?
 
Last edited:
Is there anyway to make it where the players can see how many charges?

This is so much easier to configure i love the script cyko, works great, no errors.

If it would only show charges I could use it.
Is there a way to make it remove it either the way you set in items .xml I tried this:
Code:
	<item id="8473" article="an" name="ultimate health potion">
		<attribute key="weight" value="220"/>
		<attribute key="charges" value="100"/>
		<attribute key="showCharges" value="1"/>
		<attribute key="description" value="This potion can only be consumed by knights of level 130 or higher."/>
	</item>

And heres the script u gave me (decided to go with disappearing bottles for now.)

Code:
local config = {
	removeOnUse = "no",
	splashable = "no",
	realAnimation = "no", -- make text effect visible only for players in range 1x1
	healthMultiplier = 1.0,
	manaMultiplier = 1.0
}

config.removeOnUse = getBooleanFromString(config.removeOnUse)
config.splashable = getBooleanFromString(config.splashable)
config.realAnimation = getBooleanFromString(config.realAnimation)

local POTIONS = {
	[8704] = {charges = 100, empty = 0, splash = 2, health = {50, 100}}, -- small health potion
	[7618] = {charges = 100, empty = 0, splash = 2, health = {100, 200}}, -- health potion
	[7588] = {charges = 100, empty = 0, splash = 2, health = {200, 400}, level = 50, vocations = {3, 4, 7, 8, 12, 11}, vocStr = "knights and paladins"}, -- strong health potion
	[7591] = {charges = 100, empty = 0, splash = 2, health = {500, 700}, level = 80, vocations = {4, 8, 12}, vocStr = "knights"}, -- great health potion
	[8473] = {charges = 100, empty = 0, splash = 2, health = {800, 1000}, level = 130, vocations = {4, 8, 12}, vocStr = "knights"}, -- ultimate health potion

	[7620] = {charges = 100, empty = 0, splash = 7, mana = {70, 130}}, -- mana potion
	[7589] = {charges = 100, empty = 0, splash = 7, mana = {110, 190}, level = 50, vocations = {1, 2, 3, 5, 6, 7, 9, 10, 11}, vocStr = "sorcerers, druids and paladins"}, -- strong mana potion
	[7590] = {charges = 100, empty = 0, splash = 7, mana = {200, 300}, level = 80, vocations = {1, 2, 5, 6, 9, 10}, vocStr = "sorcerers and druids"}, -- great mana potion

	[8472] = {charges = 100, empty = 0, splash = 3, health = {200, 400}, mana = {110, 190}, level = 80, vocations = {3, 7, 11}, vocStr = "paladins"} -- great spirit potion
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local potion = POTIONS[item.itemid]
	if(not potion) then
		return false
	end

	if(not isPlayer(itemEx.uid)) then
		if(not config.splashable) then
			return false
		end

		if(toPosition.x == CONTAINER_POSITION) then
			toPosition = getThingPos(item.uid)
		end

		doDecayItem(doCreateItem(2016, potion.splash, toPosition))
		doTransformItem(item.uid, potion.empty)
		return true
	end

	if(hasCondition(cid, CONDITION_EXHAUST_HEAL)) then
		doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
		return true
	end

	if(((potion.level and getPlayerLevel(cid) < potion.level) or (potion.vocations and not isInArray(potion.vocations, getPlayerVocation(cid)))) and
		not getPlayerCustomFlagValue(cid, PlayerCustomFlag_GamemasterPrivileges))
	then
		doCreatureSay(itemEx.uid, "Only " .. potion.vocStr .. (potion.level and (" of level " .. potion.level) or "") .. " or above may drink this fluid.", TALKTYPE_ORANGE_1)
		return true
	end

	local health = potion.health
	if(health and not doCreatureAddHealth(itemEx.uid, math.ceil(math.random(health[1], health[2]) * config.healthMultiplier))) then
		return false
	end

	local mana = potion.mana
	if(mana and not doPlayerAddMana(itemEx.uid, math.ceil(math.random(mana[1], mana[2]) * config.manaMultiplier))) then
		return false
	end

	doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_MAGIC_BLUE)
	if(not realAnimation) then
		doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1)
	else
		for i, tid in ipairs(getSpectators(getCreaturePosition(cid), 1, 1)) do
			if(isPlayer(tid)) then
				doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1, false, tid)
			end
		end
	end

	doAddCondition(cid, exhaust)

	doItemSetAttribute(item.uid, 'aid', math.max(101, item.actionid + 1))
	if item.actionid >= 100 + potion.charges then
		doRemoveItem(item.uid)
	end
	return true
end

Is there a way to make this script set the description to show charges in-game? Thanks again.

I gotta spread it around before I rep u again, but I do try every day!
 
Thanks Quas.

I'm not much of a scripter, i can modify them well enough (sometimes make it used for something totally different) but i have no idea where to start from blank.

Thanks tho.
 
Please help with this script, if you know how.

Thanks to those who tried.

(it seems like when people come on these forums and insult the scripters, they get these great masterpieces, i try to be polite, but i cant get anyone to help. ppl just come and give random advice that only makes sense to them.)
 
see, this is how people are responded to when they are polite like me.

i saw a thread once where a person called a scripter a "noob idiot" and the scripter came and made him some kind of npc. like, damn what am i supposed to say? I want a few scripts i know ppl can make them, it look slike u guys are all making for the wrong ppl, when i saw u had replied to my thread slaktaren, i was so excited, and nope, you were just being rude to a very respectful person (me)

Thanks anyway.

people double posting and bumping threads twice a day, hardly ever get as much BS as i do when i have been waiting patiently for like weeks lol. but its np, i have a nice game, alot of people like to play. once i get it filled with content it will be very respectable. I'm going to wait until i can actually learn to make my own scripts.

Otland is so wierdif you call names, break forum rules, and act like a child, then you get help.

If you ask politely wait patiently, bump your thread dilligently but within the 24h rules, you get rude comments which make your thread long and boring to read.

WOULD GOOD SCRIPTERS PLEASE STOP WORKING FOR PEOPLE WHO DONT APPRECIATE THEIR WORK!
 
Last edited:
If you want something done right; do it yourself. My point is, you could've made this script by the time you get any help.
Is there anyway to make it where the players can see how many charges?
Code:
local config = {
	realAnimation = true, -- make text effect visible only for players in range 1x1
	healthMultiplier = 1.0,
	manaMultiplier = 1.0
}

local POTIONS = {
	[8704] = {charges = 100, splash = 2, health = {50, 100}}, -- small health potion
	[7618] = {charges = 100, splash = 2, health = {100, 200}}, -- health potion
	[7588] = {charges = 100, splash = 2, health = {200, 400}, level = 50, vocations = {3, 4, 7, 8, 12, 11}, vocStr = "knights and paladins"}, -- strong health potion
	[7591] = {charges = 100, splash = 2, health = {500, 700}, level = 80, vocations = {4, 8, 12}, vocStr = "knights"}, -- great health potion
	[8473] = {charges = 100, splash = 2, health = {800, 1000}, level = 130, vocations = {4, 8, 12}, vocStr = "knights"}, -- ultimate health potion

	[7620] = {charges = 100, splash = 7, mana = {70, 130}}, -- mana potion
	[7589] = {charges = 100, splash = 7, mana = {110, 190}, level = 50, vocations = {1, 2, 3, 5, 6, 7, 9, 10, 11}, vocStr = "sorcerers, druids and paladins"}, -- strong mana potion
	[7590] = {charges = 100, splash = 7, mana = {200, 300}, level = 80, vocations = {1, 2, 5, 6, 9, 10}, vocStr = "sorcerers and druids"}, -- great mana potion

	[8472] = {charges = 100, splash = 3, health = {200, 400}, mana = {110, 190}, level = 80, vocations = {3, 7, 11}, vocStr = "paladins"} -- great spirit potion
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local potion = POTIONS[item.itemid]
	if(not potion or not isPlayer(itemEx.uid)) then
		return false
	end

	if(hasCondition(cid, CONDITION_EXHAUST_HEAL)) then
		return doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
	end

	if(((potion.level and getPlayerLevel(cid) < potion.level) or (potion.vocations and not isInArray(potion.vocations, getPlayerVocation(cid)))) and not getPlayerCustomFlagValue(cid, PlayerCustomFlag_GamemasterPrivileges)) then
		return doCreatureSay(itemEx.uid, "Only " .. potion.vocStr .. (potion.level and (" of level " .. potion.level) or "") .. " or above may drink this fluid.", TALKTYPE_ORANGE_1)
	end

	local health = potion.health
	if(health and not doCreatureAddHealth(itemEx.uid, math.ceil(math.random(health[1], health[2]) * config.healthMultiplier))) then
		return false
	end

	local mana = potion.mana
	if(mana and not doPlayerAddMana(itemEx.uid, math.ceil(math.random(mana[1], mana[2]) * config.manaMultiplier))) then
		return false
	end

	doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_MAGIC_BLUE)
	if(not realAnimation) then
		doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1)
	else
		for i, tid in ipairs(getSpectators(getCreaturePosition(cid), 1, 1)) do
			if(isPlayer(tid)) then
				doCreatureSay(itemEx.uid, "Aaaah...", TALKTYPE_ORANGE_1, false, tid)
			end
		end
	end

	doAddCondition(cid, exhaust)

	doItemSetAttribute(item.uid, 'aid', math.max(101, item.actionid + 1))
	doItemSetAttribute(item.uid, 'description', 'Charges: ' .. 100 + potion.charges - getItemAttribute(item.uid, 'aid'))
	if item.actionid >= 100 + potion.charges then
		doRemoveItem(item.uid)
	end
	return true
end
By using this script, players will be able to see the remaining charges by 'Looking' at the item.
Only after they've used the potion once, though.
Is there a way to make it remove it either the way you set in items .xml I tried this:
Code:
	<item id="8473" article="an" name="ultimate health potion">
		<attribute key="weight" value="220"/>
		<attribute key="charges" value="100"/>
		<attribute key="showCharges" value="1"/>
		<attribute key="description" value="This potion can only be consumed by knights of level 130 or higher."/>
	</item>
Is there a way to make this script set the description to show charges in-game? Thanks again.
It would require editing items.otb and also Tibia.dat, which means you would have to distribute it to the players (custom client[?])
 
Thanks yet again Cykotitan.

you're sure right.

this is exactly what I wanted.

it works perfectly. thanks.
 
Last edited:
Status
Not open for further replies.
Back
Top