Recharging Ammo Quantity Problems

Users who are viewing this thread

Apthorpe

Knight at Arms
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.

debug_screen_1.png


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),
  ]
	)

 
Lumos said:
If you want the ammo to fully recharge, try using (agent_refill_ammo, <agent_id>), - it should simplify things a lot.

I don't want it to fully recharge in an instant. I want it to slowly recharge by moving up in small increments over time.
 
The code looks good Nate. My assumption is that it is an issue with the operation.

One note on your use of terminology however--what you've posted here is a trigger, not a mission template. A "mission template" includes many triggers as well as entry-point instructions, etc, governing the various scenes of the game other than the world map (walking around a town or village, a battle or siege, what have you). Since this trigger is specifically for mission templates and not for the world map (so it isn't found in module_triggers or module_simple_triggers), it can be called a mission template trigger, but it isn't a mission template itself.
 
Another example of brilliant naming and documentation. :grin:
agent_set_ammo should be called agent_add_ammo. :wink:

To add 1 to the current ammo you simply need to do:
Code:
(agent_set_ammo, ":player_agent", "itm_recharging_arrows", 1)

Also, it doesn't work with negative values.
 
Caba`drin said:
The code looks good Nate. My assumption is that it is an issue with the operation.

One note on your use of terminology however--what you've posted here is a trigger, not a mission template. A "mission template" includes many triggers as well as entry-point instructions, etc, governing the various scenes of the game other than the world map (walking around a town or village, a battle or siege, what have you). Since this trigger is specifically for mission templates and not for the world map (so it isn't found in module_triggers or module_simple_triggers), it can be called a mission template trigger, but it isn't a mission template itself.

Thanks for the inspection, Caba`drin. I've posted the problem in the bugtracker.

Also, thanks for the terminology correction + the extra info. I didn't have a clear understanding of the distinctions between module_mission_templates, module_triggers, and module_simple_triggers until after reading this.
cmpxchg8b said:
Another example of brilliant naming and documentation. :grin:
agent_set_ammo should be called agent_add_ammo. :wink:

To add 1 to the current ammo you simply need to do:
Code:
(agent_set_ammo, ":player_agent", "itm_recharging_arrows", 1)

Also, it doesn't work with negative values.

Whoa. Dude, I never would have figured that out. Well, time to edit my code and the bugtracker submission.

EDIT: Done. The new code works like a charm. Thanks for all the help guys.
 
Back
Top Bottom