On map weapon cycle?

Is there a way to button press switch/cycle to the next weapon available in the player inventory?
Is there a way to button press switch/cycle to the next weapon available in the player inventory?
So a lot of how you want to do this depends on how many weapons are in the game and how many weapons you'd expect your character to have, but I'm assuming it's something where each weapon has different functionality.

In that case you could use a plugin to set up keybinds, like here.

Then, just set up a specific keybind to cycle through whichever weapons you want with a script like this:



Code:
\\Returns the ID of the current equipped weapon as "current"
var current = $gameActors.actor(1).weapons()[0].id;
\\Increase by 1
current += 1;
\\For this test I only have weapon IDs 1-4
\\If 4 is equipped at the start of the script, then "current" should be 5
if(current < 5)
\\If "current" isn't 5, we equip the next ID up (1 -> 2, 2 -> 3, etc)
{ $gameActors.actor(1).ChangeEquip(0, $dataWeapons[current]) }
\\If "current" is 5, we equip ID 1 for a full cycle
else { $gameActors.actor(1).forceChangeEquip(0, $dataWeapons[1]) }

There's probably a cleaner way to do that, but that's what I managed to get working. If you only wanted this to work with specific IDs only, you'd have to set up a list, which is beyond what I can hammer out on my own right now. 😛

You could even set up two different keybinds to "scroll" different directions, in which case the other keybind would mostly be the same:


Code:
var current = $gameActors.actor(1).weapons()[0].id;
current -= 1;
\\0 is our value to cycle back up since we're descending now
if(current > 0) { $gameActors.actor(1).forceChangeEquip(0, $dataWeapons[current]) }
\\We want to equip the highest ID when this happens, which is 4 in this example
else { $gameActors.actor(1).ChangeEquip(0, $dataWeapons[4]) }

Hope this helps!
@twosnakes
why would you even need that?

by default weapons have absolutely no function on any map, so changing weapons on map is useless.

and if you have something like an ABS-plugin, then any form of cycling has to be programmed into the ABS itself, so you would have to give a link to whatever ABS you're using to check for compatibility.
So a lot of how you want to do this depends on how many weapons are in the game and how many weapons you'd expect your character to have, but I'm assuming it's something where each weapon has different functionality.

In that case you could use a plugin to set up keybinds, like here.

Then, just set up a specific keybind to cycle through whichever weapons you want with a script like this:



Code:
\\Returns the ID of the current equipped weapon as "current"
var current = $gameActors.actor(1).weapons()[0].id;
\\Increase by 1
current += 1;
\\For this test I only have weapon IDs 1-4
\\If 4 is equipped at the start of the script, then "current" should be 5
if(current < 5)
\\If "current" isn't 5, we equip the next ID up (1 -> 2, 2 -> 3, etc)
{ $gameActors.actor(1).ChangeEquip(0, $dataWeapons[current]) }
\\If "current" is 5, we equip ID 1 for a full cycle
else { $gameActors.actor(1).forceChangeEquip(0, $dataWeapons[1]) }

There's probably a cleaner way to do that, but that's what I managed to get working. If you only wanted this to work with specific IDs only, you'd have to set up a list, which is beyond what I can hammer out on my own right now. 😛

You could even set up two different keybinds to "scroll" different directions, in which case the other keybind would mostly be the same:


Code:
var current = $gameActors.actor(1).weapons()[0].id;
current -= 1;
\\0 is our value to cycle back up since we're descending now
if(current > 0) { $gameActors.actor(1).forceChangeEquip(0, $dataWeapons[current]) }
\\We want to equip the highest ID when this happens, which is 4 in this example
else { $gameActors.actor(1).ChangeEquip(0, $dataWeapons[4]) }

Hope this helps!
Exactly what I needed thank you!
Sorry, one thing I forgot to explain that forceChangeEquip forces the weapon change even if the character doesn't have it, and you asked for available weapons from inventory. That would be changeEquip, but then you'd have to handle instances where the weapons aren't in your inventory, and that kind of conditional loop would be beyond my current JavaScript knowledge.
Yeah it's more complicated than I thought. I'm using QABS. That's the issue I can't overcome, getting it to work only with weapons in the inventory.
This should check if you have the weapon in your inventory:


Weapon_Cycle.jpg

Original thread: https://forums.rpgmakerweb.com/threads/on-map-weapon-cycle.149994/