Hello I'm trying to have a trigger pick an item in my inventory and modify the number of charges on that item. Turns out this wouldn't be as simple as you'd think. All the obvious/normal methods I've tried have failed. Anyone have any ideas?
That would be because you are likely thinking about it in the wrong way. You need to modify charges used, not charges left. Also, you'll need to know the charge link exact name (as seen in data). Here is a line out of my project script on how I did it:
First parameter is the unit/item I'm changing charges on, lv_search is the exact charge link, and the third parameter is how many chargeused to set it to.
I was helping vincent out with this; without the editor I cannot recall everything I tried; but with the set charges remaining I tried every aspect I could think of, and could not get anything to change. The debugger was returning no errors. if you could convert your variables and arrays above into something comprehensible to anyone not looking at your variables, it might help a bit.
Using a catalog field value set I was able to change it, but that wont work in this situation.
Does anyone know why the simple action:
modify charges used +1 for (item) on (picked unit)
Explain why this isnt working, and I think the case will be solved (Picked unit is being picked properly)
... I know I will feel like an idiot at how simple this answer will end up being; but I spent maybe 2 hours fidgeting with this and getting nowhere.
First parameter is the unit/item I'm changing charges on(type unit), second parameter is the exact charge link(type string), and the third parameter is how many charges used to set it to(type fixed). I thought the first explanation was highly simple with the extremely visible commas and all, but perhaps not.
My main guess about your other problem is, it probably isn't happy w/ your charge link value, Effect Cost - Charge - Link in the wiki, parameter2 in my example. Here is another line of script from my project about it:
It is the exact same function as before as you can see. You just have to get it the appropriate unit and charge link values for it to work.
Edit:
Just wanted to add, was relooking over my old code, if you are by chance trying to bank load a stackable potion with say 13 charges left out of 20 or something like that, you will need to take these steps:
Create said unit in inventory
Use the function libNtve_gfUnitRemoveChargeUsed(parameter1(Unit),parameter2(Charge link string)) (Optional if charge used start at 0 by default, mine starts at 19 used to give the illusion of 1 potion that stacks to 20).
Use the function UnitAddChargeUsed(parameter1, parameter2, parameter3); to add charges used as appropriate.
Seems that is pretty much what I'm already doing. Here is the trigger
Unit - Any Unit is issued an order to Consume Rations
Local Variables
Conditions
Actions
Unit Group - Pick each unit in (All items carried by (Triggering unit)) and do (Actions)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
(Unit type of (Picked unit)) == Item- Small Energy Ration
Then
Environment - Execute Small Energy Ration on (Triggering unit) from (Triggering unit)
Unit - Add 1.0 charges used for charge SmallEnergyRation/Revive on unit (Picked unit)
Hello I'm trying to have a trigger pick an item in my inventory and modify the number of charges on that item. Turns out this wouldn't be as simple as you'd think. All the obvious/normal methods I've tried have failed. Anyone have any ideas?
@JacktheArcher: Go
That would be because you are likely thinking about it in the wrong way. You need to modify charges used, not charges left. Also, you'll need to know the charge link exact name (as seen in data). Here is a line out of my project script on how I did it:
UnitAddChargeUsed(gv_inventory[lp_p].lv_potion[0][lv_i], lv_search, IntToFixed(gv_inventory[lp_p].lv_chargesUsed[lv_i]));
First parameter is the unit/item I'm changing charges on, lv_search is the exact charge link, and the third parameter is how many chargeused to set it to.
I was helping vincent out with this; without the editor I cannot recall everything I tried; but with the set charges remaining I tried every aspect I could think of, and could not get anything to change. The debugger was returning no errors. if you could convert your variables and arrays above into something comprehensible to anyone not looking at your variables, it might help a bit.
Using a catalog field value set I was able to change it, but that wont work in this situation.
Does anyone know why the simple action:
modify charges used +1 for (item) on (picked unit)
Explain why this isnt working, and I think the case will be solved (Picked unit is being picked properly)
... I know I will feel like an idiot at how simple this answer will end up being; but I spent maybe 2 hours fidgeting with this and getting nowhere.
Skype: [email protected] Current Project: Custom Hero Arena! US: battlenet:://starcraft/map/1/263274 EU: battlenet:://starcraft/map/2/186418
@GlornII: Go
UnitAddChargeUsed(gv_inventory[lp_p].lv_potion[0][lv_i], lv_search, IntToFixed(gv_inventory[lp_p].lv_chargesUsed[lv_i]));
UnitAddChargeUsed(parameter1, parameter2, parameter3);
First parameter is the unit/item I'm changing charges on(type unit), second parameter is the exact charge link(type string), and the third parameter is how many charges used to set it to(type fixed). I thought the first explanation was highly simple with the extremely visible commas and all, but perhaps not.
My main guess about your other problem is, it probably isn't happy w/ your charge link value, Effect Cost - Charge - Link in the wiki, parameter2 in my example. Here is another line of script from my project about it:
UnitAddChargeUsed(gv_inventory[lp_p].lv_potion[0][lv_i], lv_strLink, 1.0);
UnitAddChargeUsed(parameter1, parameter2, parameter3);
It is the exact same function as before as you can see. You just have to get it the appropriate unit and charge link values for it to work.
Edit:
Just wanted to add, was relooking over my old code, if you are by chance trying to bank load a stackable potion with say 13 charges left out of 20 or something like that, you will need to take these steps:
Create said unit in inventory
Use the function libNtve_gfUnitRemoveChargeUsed(parameter1(Unit),parameter2(Charge link string)) (Optional if charge used start at 0 by default, mine starts at 19 used to give the illusion of 1 potion that stacks to 20).
Use the function UnitAddChargeUsed(parameter1, parameter2, parameter3); to add charges used as appropriate.
Seems that is pretty much what I'm already doing. Here is the trigger
Unit - Any Unit is issued an order to Consume Rations
Local Variables
Conditions
Actions
Unit Group - Pick each unit in (All items carried by (Triggering unit)) and do (Actions)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
(Unit type of (Picked unit)) == Item- Small Energy Ration
Then
Environment - Execute Small Energy Ration on (Triggering unit) from (Triggering unit)
Unit - Add 1.0 charges used for charge SmallEnergyRation/Revive on unit (Picked unit)
bump... nothings working still
Solved it. Turns out my data was a bit faulty. The item cost link was non existing.