Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Reloading System with Macros

January 17 (11 years ago)
Hey guys, I have been wanting to implement a reloading system into my campaign.However, with macros being a butt, i was wondering if you guys could assist me in my quest.

Lets say i have 2 Attributes: Max Ammo and Magazine (mag for short)

Max ammo has all the ammunition not being used, mag has the current bullets in the magazine ( lets say 6 for this example)

When the player fires the gun (which will be the attack macro) it will subtract 1 bullet from the current magazine. Once the magazine is empty, there will be a macro called "reload" where 6 bullets will be subtracted from max ammo and 6 will be added to the magazine attribute. No where in any macro tutorial i could find helped me find something like this, adding and subtracting from attributes.

I was hoping you guys could either 1. Tell me how the coding for this would work or 2. Point me to some tutorial that can cater to my needs

All help is appreicated!
January 17 (11 years ago)
Macros would not be able to do what you want. You'll need an API script that you would send a command to like !ammo <AmmoUsed>|<CharacterID>, then use that command in any macro.

The script would do the following:
  1. Listen for the !ammo command in chat.
  2. use substr to get all the text after "!ammo "
  3. Create an array using split to break the rest of the text by the "|" between attributes
  4. Create variables for each element of the array you just created.
  5. once you have the ammo being used and the character ID who used them, you would use the get and set options on the character object to look at current stats, do some math and make some changes.

Once that is set up you could add !ammo into any macro to tell it to use ammo. You could even make a !reload command that would similarly take the character ID, and shift some numbers around from one stat to another.

Thats the best description i've got for the process without writing the code for you. Which i don't think is what you wanted. Be sure to examine some other scripts that do something similar with commands and adjusting stats etc. Also read the API documentation thoroughly.