Script Call to Equip Weapons

Status
Not open for further replies.

Faherya

The Knight of the Sad Figure
Veteran
Joined
Jul 25, 2013
Messages
256
Reaction score
582
First Language
Portuguese
Primarily Uses
RMVXA
Hello guys, how are you?
Well, I am having a problem with the following call. I need this command to immediately equip a character with a weapon:
Code:
$gameActors.actor(1).changeEquip(1, $dataWeapons[1]);
The program documentation doesn't help, so I'm guessing that the argument specifications listed here are correct (slotID, equipmentID). However, the command does not work or return any errors. It is simply ignored. Any idea what the error might be? For registration, I already checked and the character can be equipped with the specified weapon type. It is for a challenge from a local forum, so I cannot insert any external plugins, even if to facilitate the configuration.
 

ct_bolt

Creator
Veteran
Joined
May 3, 2012
Messages
954
Reaction score
526
First Language
Javascript
Primarily Uses
RMMZ
I need this command to immediately equip a character with a weapon
At work now on my phone so can't help much but I'll try to look it up on my phone...
I think maybe like...
Code:
$gameActors.actor(1).changeEquip(0, $dataWeapons[1])
(0 = weapon, 1 = shield, 2 = headgear, 3 = chest armor, 4 = accessory)
Use 0 & $dataWeapons[n] for weapons
Use 1 through 4 & $dataArmors[n] for armor.

Well let me know if that works for ya.
(Ps. I changed it since my first post)
@Faherya
Pretty sure but... can't really try it yet.
 
Last edited:

Faherya

The Knight of the Sad Figure
Veteran
Joined
Jul 25, 2013
Messages
256
Reaction score
582
First Language
Portuguese
Primarily Uses
RMVXA

Thanks for the answer. I tried to switch between the object and the ID, in addition to trying all possible slots. The result was the same. I was here looking at the method in question, but I don't know much about Js to understand. :kaoswt:
Code:
Game_Actor.prototype.changeEquip = function(slotId, item) {
    if (this.tradeItemWithParty(item, this.equips()[slotId]) &&
            (!item || this.equipSlots()[slotId] === item.etypeId)) {
        this._equips[slotId].setObject(item);
        this.refresh();
    }
};

Edit: Thanks again, I was also testing gameActors haha. But now I got an error (with or without the "_" in front of an actor):

JavaScript:
TypeError: Cannot read property '1' of undefined
    at eval (eval at Game_Interpreter.command355 (rpg_objects.js:10500), <anonymous>:1:19)
    at Game_Interpreter.command355 (rpg_objects.js:10500)
    at Game_Interpreter.executeCommand (rpg_objects.js:8930)
    at Game_Interpreter.update (rpg_objects.js:8838)
    at Game_Map.updateInterpreter (rpg_objects.js:6115)
    at Game_Map.update (rpg_objects.js:6022)
    at Scene_Map.updateMain (rpg_scenes.js:608)
    at Scene_Map.updateMainMultiply (rpg_scenes.js:600)
    at Scene_Map.update (rpg_scenes.js:589)
    at Function.SceneManager.updateScene (rpg_managers.js:2024)
 
Last edited:

ct_bolt

Creator
Veteran
Joined
May 3, 2012
Messages
954
Reaction score
526
First Language
Javascript
Primarily Uses
RMMZ
Did you try this?
Code:
$gameActors.actor(1).changeEquip(0, $dataWeapons[1])
(0 = weapon, 1 = shield, 2 = headgear, 3 = chest armor, 4 = accessory)
Use 0 & $dataWeapons[n] for weapons
Use 1 through 4 & $dataArmors[n] for armor.

Pretty sure that's it but can't really try it yet.

(Sooo pretty sure you were very close just needed to change the 1 to a 0 lol)
 

Faherya

The Knight of the Sad Figure
Veteran
Joined
Jul 25, 2013
Messages
256
Reaction score
582
First Language
Portuguese
Primarily Uses
RMVXA
Yes, I tried, I'm following your edits. :D
However, it was the same. It does not change the equipment, it does not generate an error. I don't have any extra code installed, so there can't be any interference.
 

ct_bolt

Creator
Veteran
Joined
May 3, 2012
Messages
954
Reaction score
526
First Language
Javascript
Primarily Uses
RMMZ
Yes, I tried, I'm following your edits. :D
However, it was the same. It does not change the equipment, it does not generate an error. I don't have any extra code installed, so there can't be any interference.
Hmmmm odd using the 0 instead of 1 should have worked.
just so I'm sure you're trying to change actor I'd #1's weapon right? Not party member #1?
Pretty sure but... can't really try it yet.

Edit:
maybe try this using Id instead?
 
Last edited:

Faherya

The Knight of the Sad Figure
Veteran
Joined
Jul 25, 2013
Messages
256
Reaction score
582
First Language
Portuguese
Primarily Uses
RMVXA
[...]
just so I'm sure you're trying to change actor I'd #1's weapon right? Not party member #1?
[...]

Yes, but now that you mention it, it makes no difference. It is a micro project, there is only one character and there are never changes in the group. I'll try with gameParty. o/
 

rainyday

Veteran
Veteran
Joined
Nov 5, 2019
Messages
77
Reaction score
48
First Language
English
Primarily Uses
RMMV
Do you have the weapon you want to equip onto the actor in your inventory? changeEquip needs an unused copy of that weapon or armor in your inventory to work. If you don't want this for whatever reason, use forceChangeEquip instead(it takes the same parameters as input).
 

Faherya

The Knight of the Sad Figure
Veteran
Joined
Jul 25, 2013
Messages
256
Reaction score
582
First Language
Portuguese
Primarily Uses
RMVXA
Ah, that worked perfectly. Many thanks to both! :kaoluv:
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
8,034
Reaction score
5,336
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

I feel like banging my head against a wall every time I want to find that post that shows all the plugin header codes. Then I think "next time I find it, I'm going to bookmark it". Then I think "wait a minute ... maybe I bookmarked it last time because it took me so long to find it". Check bookmarks, and there it is :)
... a few of my main characters standing around doing nothing lol. I mostly wanted to see them together on screen.
Today I drove through my city of 100,000+ people during rush hour and the streets were nearly empty. Just so I could go get my favorite burger. There a dental assistant (she said that's her other job, even though I didn't ask) took my order and handed me a burger. I know it's bad out there... But wow, she's either atrocious with her money, or "it really be like that".
Chilling out while toodling around someone's painstaking Minecraft recreation of Disneyland. It is mind-boggling and probably as close as I'll ever be to going.

Forum statistics

Threads
107,813
Messages
1,032,408
Members
139,963
Latest member
FibS
Top