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

Lua adding maxhealth and maxmana to an item

RazorBlade

Retired Snek
Joined
Nov 7, 2009
Messages
2,015
Solutions
3
Reaction score
629
Location
Canada
I'm having trouble with a script. It doesn't add health/mana when it's told to.
Code:
local choice2 = math.random(1, 2)
				if (choice2 == 1) then
					maxhp = math.random(250, 500)
					hp = (hp + maxhp)
					doItemSetAttribute(itemEx.uid, 'maxhealthpoints', hp)
					points2 = (jewel2Point + 1)
					doItemSetAttribute(itemEx.uid, "jewel2", points2)
					doSendAnimatedText(toPosition, "Upgraded!", TEXTCOLOR_GREEN)
					doSendMagicEffect(toPosition, CONST_ME_MAGIC_GREEN)
It's supposed to add a random amount of maxhealth or maxmana between 250 and 500 (code above is just the maxhealth part) There are no console errors and it sends the magic effect so I know it gets past adding the health, it just doesn't add it. what's wrong?
I'm using TFS 0.4, some rev in the 8.62 range.
 
You can do a equip / deEquip script which set player healthmax when wearing the item and returning to his normal health when deEquiping it.
 
But this is an upgrade system which allows an undefined amount of health or mana to be added, meaning there has to be something keeping track of the amount on each individual item. I'll have to make additional source edits for this to work :/
 
bad news

the attribute is actually being set, but only as an attribute. the array with stats is left unchanged, and is only accessed when reading attributes from items.xml:
Code:
			else if(tmpStrValue == "maxhealthpoints" || tmpStrValue == "maxhitpoints")
			{
				if(readXMLInteger(itemAttributesNode, "value", intValue))
					[B][COLOR="red"]it.abilities.stats[STAT_MAXHEALTH][/COLOR][/B] = intValue;
			}
stats modifiers are not per-single-item, but for all items of that id (which is why this can't be made to work the normal way).
 
So basically the stats will return their values but cannot be used? In which case if I use a move event I can just check them and use the returned values with setPlayerMaxHealth(cid, value) and the same for mana upon equip and remove the values upon unequip?
 
The way the system works, it adds it to any weapon or armor/legs/helmet/boots/shield and if I want a movement I have to give it a slot and an itemid. What would I put in movements.xml if I want it to work based on actionid and any slot?
 
kay so I put the slot in but since I can't really base it on actionid as far as I know, it won't work. Is there any other way to make it work with any weapon/armor-type item without having to redo the entire movements.xml?
 
add a dummy actionid every time an item is enchated, in case it doesn't have one already.
something like 123, you get the idea
 
Yes, I have all that in place. But an item will only be checked if it's told to check when being equipped. The movement script is done, the actionid is set. I did all that long ago. The problem is how can I check EVERY item that is equipped to see if it has that actionid or not? the script won't execute unless the itemid in movements.xml is equipped.

I have this but it doesn't take the actionid tag and it doesn't execute. No errors in console.
Code:
<movevent type="Equip" actionid="8647" slot="wherever" event="script" value="upgrade.lua"/>
<movevent type="DeEquip" actionid="8647" slot="wherever" event="script" value="upgrade.lua"/>
 
Straight answers of whether or not it's possible, and maybe source edits needed to make it possible if it isn't? Please? /sadface
 

Similar threads

Back
Top