MZ Trying to store weapon's and temporarily switch them out.

I'm working on a druid transformation system and the thing that for the life of me been unable to get working is storing the spell caster's current weapon to a variable and then changing it to the invisible dummy weapon and back once the transformation ends as obviously we don't want sword wielding rats or bears running around. (Or maybe we do... hmm...) here's the snippet of the code i'm using for the inital transformation state that's relevant to the specfic issue of the weapon changing.

user.addState(173);

$gameTemp.reserveCommonEvent(97);

user.forceChangeEquip(0, $DataWeapons[82]);


i've also tried using both $gameActors.actor(1)[0].forceChangeEquip(0, $DataWeapons[82]); and $gameActors.actor($gameVariables.value(13))[0].forceChangeEquip(0, $DataWeapons[82]); variable 13 being a actor check done in the initial common event. Which I will also post.
CommonEvent1.png


the full script for the Variable being: var w = $gameActors.actor($gameVariables.value(13)).weapons()[0]; w ? w.id : 0

I'll also post the second common event for this for completion's sake.

CommonEvent2.png
var w = $gameActors.actor($gameVariables.value(13)).weapons()[0]; w ? w.id : 0
This gets the actor with ID equal to the current value of variable 13. Then it stores the ID of the first weapon currently equipped by that actor, or 0 if they have no weapons equipped. Looks OK to me!

user.forceChangeEquip(0, $DataWeapons[82]);
This replaces the item in the first equip slot of user with $DataWeapons[82]. It's "forced", i.e. the new item doesn't have to be in the party inventory beforehand, and the item currently in that equip slot will vanish. Notes:
  • Code is case-sensitive: it should be $dataWeapons (lower-case d).

  • What is user? That variable doesn't exist by default in, say, Control Variables -> Script. Are you using it in a notetag from a plugin or something? 😅

This gets the actor with ID equal to the current value of variable 13. Then it tries to equip whatever is currently stored in variable 121 to their first equip slot. That "whatever" should be a reference to an item that currently exists in the party inventory. The currently-equipped item (if any) will be swapped to the inventory.

Since your first screenshot suggests that variable 121 holds a weapon ID (i.e. a number, not an item), you could try something like this instead:

$gameActors.actor($gameVariables.value(13)).forceChangeEquip(0, $dataWeapons[$gameVariables.value(121)]);

Otherwise, how are you detecting when to process the "end transform" effects? If you're using a plugin: which one are using, and how are you using it in this case?

For testing, it can help to use messages, e.g. Show Text: Transform Ends! That can help to distinguish between a component (e.g. event) that isn't working as intended, vs a system structure problem (e.g. event not running at the intended time).
This gets the actor with ID equal to the current value of variable 13. Then it stores the ID of the first weapon currently equipped by that actor, or 0 if they have no weapons equipped. Looks OK to me!


This replaces the item in the first equip slot of user with $DataWeapons[82]. It's "forced", i.e. the new item doesn't have to be in the party inventory beforehand, and the item currently in that equip slot will vanish. Notes:
  • Code is case-sensitive: it should be $dataWeapons (lower-case d).

  • What is user? That variable doesn't exist by default in, say, Control Variables -> Script. Are you using it in a notetag from a plugin or something? 😅


This gets the actor with ID equal to the current value of variable 13. Then it tries to equip whatever is currently stored in variable 121 to their first equip slot. That "whatever" should be a reference to an item that currently exists in the party inventory. The currently-equipped item (if any) will be swapped to the inventory.

Since your first screenshot suggests that variable 121 holds a weapon ID (i.e. a number, not an item), you could try something like this instead:

$gameActors.actor($gameVariables.value(13)).forceChangeEquip(0, $dataWeapons[$gameVariables.value(121)]);


Otherwise, how are you detecting when to process the "end transform" effects? If you're using a plugin: which one are using, and how are you using it in this case?

For testing, it can help to use messages, e.g. Show Text: Transform Ends! That can help to distinguish between a component (e.g. event) that isn't working as intended, vs a system structure problem (e.g. event not running at the intended time).
The transformation itself is being handled by a state (I apologize if that wasn't clear enough), and the weapon swapping is done 2 common events, called when the state is added and removed respectively. As for test messages, I actually removed them before posting for clarity sake. I've also attempted to intergrate your suggested changes and the weapon swapping sadly still doesn't work. weapon ID 82 doesn't get equipped.
the weapon swapping is done 2 common events, called when the state is added and removed respectively.
That seems inefficient - if you're using a plugin that can do things when states are added and removed (I presume the VisuStella Skills & States Core), why not put all of these script calls directly into those notetags instead of calling common events for it?

May I suggest an alternate route? Instead of going through all of this to change the weapon, why not use VisuStella's Weapon Animation plugin?

Give your druid state a Weapon Image and/or Weapon Motion notetag, and they'll visually appear to be wielding whatever you want.
That seems inefficient - if you're using a plugin that can do things when states are added and removed (I presume the VisuStella Skills & States Core), why not put all of these script calls directly into those notetags instead of calling common events for it?

May I suggest an alternate route? Instead of going through all of this to change the weapon, why not use VisuStella's Weapon Animation plugin?

Give your druid state a Weapon Image and/or Weapon Motion notetag, and they'll visually appear to be wielding whatever you want.
Once I can get this working I'm intending to condense it down to only use the state code as I want this to be able to very easily be copied and pasted for several other potential transformations. As for why I'm not using weapon animation plugin despite said plugin being great and probably the perfect solution to my problem, the reason is that I don't currently have 10.76 CAD to drop on the plugin right now. :hsad:
...will you at some point before the time you plan to release your game? 🤣

This probably doesn't need to be resolved immediately. You could take the time from being frustrated and reworking this and spend it on other parts of your development until you can save up ten bucks.

Just a thought 😉

Original thread: https://forums.rpgmakerweb.com/threads/trying-to-store-weapons-and-temporarily-switch-them-out.161307/