Code:
recharging_ammo_quantity = ( #tuple begins
15, 0, 0, [ #conditions block begins
(get_player_agent_no, ":player_agent"),
(agent_has_item_equipped,":player_agent","itm_recharging_arrows"),
], #conditions block ends
[ #consequences block begins
(get_player_agent_no,":player_agent"),
(agent_get_ammo,":current_ammo",":player_agent",1), #get current ammo quantity
(assign,reg0,":current_ammo"),
(display_message,"@Your current ammo quantity is {reg0} arrows.",0xFFFFFFAA),
(try_begin),
(lt,":current_ammo",30),
(val_add,":current_ammo",1), #(val_add,<destination>,<value>),
(assign,reg1,":current_ammo"),
(display_message,"@current_ammo + 1 = {reg1}",0xFFFFFFFF),
(agent_set_ammo,":player_agent","itm_recharging_arrows",":current_ammo"), #set ammo quantity to the new sum
(display_message,"@Your ammunition recharged by 1 arrow!",0xFFAAFFAA),
(else_try),
(display_message,"@Your ammunition is full.",0xFFFFFFAA),
(try_end),
] #consequences block ends
) #tuple ends
All right, so I've been trying to create a mission-template trigger that causes equipped ammo to recharge at intervals. This code is essentially a test so that I can know the basic stuff will work before I start adding variations. However, I have run into a few problems. For one, I haven't been able to get 'agent_set_ammo' to actually set the player character's ammo to anything other than the maximum quantity possible. As the first picture shows, the addition calculation is not the culprit--it calculates the value correctly and stores it in the destination correctly as well. However, when it comes time to actually set the ammo to the new value, the ammo always gets set to the maximum, and I can't figure out why.
Another problem I've run into is that 'agent_get_ammo' has trouble getting the correct value when a non-bow weapon is wielded; it always gets -1 if this is the case. As you'll notice from the bottom picture, the value is incorrect. However, the ammo still gets set to the maximum, the same bug as when a bow weapon is wielded. EDIT: I figured out why this wasn't working--I had set <value> to 1 when it needed to be 0. Well, that one is solved.
The whole thing has given me a headache, and I'm doubting that the MS is at fault since this is my first trigger I've made from scratch. Any help would be very appreciated.
EDIT: the final version
Code:
recharging_ammo_quantity = (
15, 0, 0, [
(get_player_agent_no, ":player_agent"),
(agent_has_item_equipped,":player_agent","itm_recharging_arrows"),
],
[
(get_player_agent_no,":player_agent"),
(agent_get_ammo,":current_ammo",":player_agent",0),
(assign,reg0,":current_ammo"),
(display_message,"@Retrieved the value {reg0} as your current ammo quantity.",0xFFFFFFFF),
(try_begin),
(lt,":current_ammo",30),
(display_message,"@Your current ammo quantity is less than 30.",0xFFFFFFFF),
(agent_set_ammo,":player_agent","itm_recharging_arrows",1), #currently ADDS value to current ammo, does not set value of ammo
(display_message,"@Your ammunition should have increased by 1.",0xFFFFFFFF),
(else_try),
(display_message,"@Your ammunition is full.",0xFFFFFFAA),
(try_end),
]
)