Assigning Current Equipment to Var

Hey all,

I'm very new to RPGmaker in general, as well as mv in specific.

Something I'm trying to figure out in my current project is how to assign an actor's current equipment to a variable for manipulation. My specific need is that when you enter a bar, a bouncer will tell you no weapons are allowed and will have you check your currently equipped weapon at the door. When you leave, he will give it back to you. From a programming perspective this is fairly simple, I just don't know how to do within mv. Thanks for any help, and let me know if this is the wrong place for this.

Ax
'Game Mechanics Design' is for looking at aspect of gameplay at a more conceptual level. "How do I...?" questions go in the Support forum for the engine you are using.

Moved to: RPGMaker MV
Thanks for the clarification and I will post these questions here next time. Sorry for the mix up.
Like this:
Screenshot (11).png


Since you just want weapons then you need to use:
$gameParty.members()[x].equips()[0]
assuming you only have one weapon.

if you're dual weilding(using 2 weapons at once) then you need
$gameParty.members()[x].equips()[0]
$gameParty.members()[x].equips()[1]

where x is the id of the party member party position minus 1.
So the first party member has x = 0.
the second party member has x = 1.
the third has x = 2;
and so on.

So lets say you have 4 characters, 2 are dual wielders and 2 just use one weapon.
Then you need 6 variables or 1 variable for each weapon per character.
Thanks for your reply.

So I added the control variable as you said, and when the player heads in, I added a control variable 0001 -=1, and a += 1 when you leave. Unfortunately this doesn't seem to work, because when I tested it I still had my weapon equipped after it should have been subtracted.


Thanks for the help so far and I'll keep trying.
@Axfinger General question: Do you want all of the party's weapons taken away, or just the actively equipped one?
Meaning, if the player walks into the bar and her battle axe is taken away, will she still have access to the dagger in her inventory?

In general, this would require 3 things:
  1. The game needs to remember what weapon(s) the player currently has (storing that data into a variable)
  2. The game needs to take away the weapon(s)
  3. The game needs to give back the weapon(s)
Zarsla has explained #1 about how to store the data into a variable for later use.
#2 and #3 are typically accomplished through Event Commands, there is one called Change Items or Change Weapons (there are also scripting ways to do this).

This thread might also help. The post is about a 'jail' system where all the party's items are taken away until they escape the jail and get the items back. Unfortunately the thread was not named well which makes it hard to search for (I only remember because I commented on it before).
https://forums.rpgmakerweb.com/index.php?threads/script-help.88933/
That's not going to work.
The variable is holding the info of what the person had equip.

So for example if Theres had an axe equip, then the variable says "Therese's Axe"

What you want to do is this, when you want to de-equip:
$gameParty.members()[x].changeEquip(y, 0);

where x is the id of the party member party position minus 1.
So the first party member has x = 0.
the second party member has x = 1.
the third has x = 2;
and so on.

Replace y with 0 or 1. Ie if you have 1 weapon replace y with 1. Dual weilders replace y with 0 or 1.

When it's time to re-equip.
Do this:
var wep = $gameVariable.value(a);
$gameParty.members()[x].changeEquip(0, wep);

So if you were messing with the party leader.
Then:

var wep = $gameVariable.value(a);
$gameParty.members()[0].changeEquip(0, wep);
Thanks for the replies to both of you. @Aloe Guvner to answer your question my end goal would be to really unequip the actor and disable equipping anything in the bar. If it's easier to take all the weapons that could be another way to do it, whichever way is more efficient would be fine. The change weapon command only seems to take named weapons in the database though, and I want to name the variable that the current equipment was to unequip. I just need hand holding because I don't know how to do things in MV. I have a bit of JS coding experience, and I know what I want to do is conceptually simple. I just struggle to use the engine effectively. Thanks for the help (and the link) and I'll try this later when I am at home.
So I think I'm missing some information on this...

So far you guys have given me some scripts to play around with but I think I need a little more basic help than that. Where exactly do I put the scripts? Adding a script to a control variable with the variable I set the weapon to and SUB 1 doesn't seem to subtract it. Neither does adding SUB and the script from the other thread that you linked to. The only way I seem to be able to remove my weapon is by adding a change equipment event and specifically targeting a weapon in the database (ex: "sword"). This obviously won't work because I can't keep track of all possible equipment and I wouldn't know what to give the player back. What am I missing?
@Axfinger - One simple way to do this: change the equipped item to a dummy item, like a nerfbat or an item named "Empty-Handed". Then "curse" it - I'm currently redownloading MV so I can't show you exactly where, but in the item settings you can set an item to seal an equipment slot (in this case weapons) on equip. Then they can't switch their weapon out for anything else. When they leave the bar, just de-equip the nerfbat and let the player re-equip their weapon themselves.

(This might leave the player with a cursed nerfbat in their inventory or something, though?)
That's a clever thought but I think there is a problem with doing it that way. The bouncer is supposed to take your weapon, and if it's just sitting in your inventory that doesn't really make sense. Functionally it sort of works though, and I can always remove the cursed item from the inventory when you leave. Thanks for the thought but I'm going to hold out to try and properly remove and re-add the weapon.
Well, isn't there a plot hole in that? Unless the bouncer is actively pat-down searching you, it's entirely possible for you (in-character) to sneak in a dagger or something - so the bar pretty much has to work on code of honor, plus no obviously equipped weapons.
While I agree that in this theoretical world it would be possible for someone to sneak a weapon in if they tried to, no I'm not going to allow the player to do this. I do want to get the code working in the way I described as A a learning experience for me and B because I want the system to work like this. Thanks for the comments.
@linkhyrule5 I actually like the idea of being able to sneak in a weapon 🙂 I remember being able to do that in games like Fallout: New Vegas with a high enough Sneak level.

@Axfinger This is going to be a kinda long explanation.

========== Entering the bar ==========
1.) Store the weapon data into a variable for later use
2.) De-equip the weapon from the Actor and remove it from the Party
3.) Add and equip the blank/fake weapon which will prevent the player from equipping new weapons in the bar
========== Leaving the bar ==========
4.) De-equip the fake weapon from the Actor and remove it from the Party

5.) Return the original weapon to the Party and equip it to the Actor
========== Appendix ==========



1.) Store the weapon data into a variable for later use
We need to store the weapon into a variable. Normally, Game Variables (notice the capital letters) are integers and when you act upon then in the editor, it's just numbers. But in JavaScript, variables (lowercase) are 'loosely typed' which means that the type can still be changed after the variable is declared. Meaning, we can actually store anything in Game Variables.
In this case, we are storing an object.
Spoiler: Set a Game Variable to the currently equipped weapon
ControlVariables.png
Replace Game Variable 41 with whatever Variable ID# you will use.

2.) De-equip the weapon from the Actor and remove it from the Party
Use the Script Event Command:
Spoiler: How to use the Script Event Command
AddScriptCommand.png

Code:
var weapon = $gameVariables.value(41);
$gameParty.members()[0].discardEquip(weapon);
Replace '41' with the Variable ID# that you are using.

3.) Add and equip the blank/fake weapon which will prevent the player from equipping new weapons in the bar
Spoiler: Set up an item in the Database like this
WeaponDatabase.png

Use a Script Event Command like this:
Code:
var slotId = 0;
var item = $dataWeapons[7];
$gameParty.gainItem(item, 1);
$gameParty.members()[0].changeEquip(slotId, item);
Change the '7' to be the ID# of your blank/fake weapon in the database.

===============================
========== Leaving the bar ==========
===============================


4.) De-equip the fake weapon from the Actor and remove it from the Party

Use a Script Event Command like this:
Code:
var weapon = $gameParty.members()[0].equips()[0];
$gameParty.members()[0].discardEquip(weapon);

5.) Return the original weapon to the Party and equip it to the Actor

Use a Script Event Command like this:

Code:
var slotId = 0;
var item = $gameVariables.value(41);
$gameParty.gainItem(item, 1);
$gameParty.members()[0].changeEquip(slotId, item);

========== Appendix ==========

Spoiler: Sample Event Page 1
EventPage1.png

Spoiler: Sample Event Page 2
EventPage2.png

Is if there is more than 1 party member, you'll have to repeat each of these things, and each Actor needs its own variable.
  • $gameParty.members()[0] --> 1st member
  • $gameParty.members()[1] --> 2nd member
  • $gameParty.members()[2] --> 3rd member
  • $gameParty.members()[3] --> 4th member
Is there a way to do it more efficiently for all the party members using code/loops? Definitely, but I'm not going to describe it here. I think you should be able to get this to work as-is.
Thank you for taking the time to write up this very detailed explanation. I will test it when. I get the chance.

Ax
I implemented this last night and it works perfectly. Thanks a ton to all who commented, and a big thanks to @Aloe Guvner for the detailed solution.

One quick question I had if anyone knows/wants to comment, is how RPGMMV deals with script events. Is each script event a js function? The reason I ask is because in vanilla js declaring variables inside of a function gives them a different scope (local) rather than a global variable declared outside of a function. So, if I declare a variable inside an event, would another event be able to see that variable or not?

Ax
Try it yourself 🙂

Here's an example, can you guess what will happen?

DifferentScriptCommands.png


Spoiler: Answer
Variables declared within a Script Event Command are local to that Script Event Command (not the Event in general, but the specific Script Event Command!).

Each time the interpreter runs into the Script Event Command, it runs function .command355() . Which means that each Script Event Command is a different run of the function and therefore has different scope.
Code:
// Script
Game_Interpreter.prototype.command355 = function() {
    var script = this.currentCommand().parameters[0] + '\n';
    while (this.nextEventCode() === 655) {
        this._index++;
        script += this.currentCommand().parameters[0] + '\n';
    }
    eval(script);
    return true;
};

Original thread: https://forums.rpgmakerweb.com/threads/assigning-current-equipment-to-var.89974/