How to make the Ace VX recognize that the hero has 3 equal weapons + 1 different weapon?

Rayner

Villager
Member
Joined
Aug 22, 2015
Messages
6
Reaction score
0
First Language
Portuguese
Primarily Uses
N/A
In one condition I used a standard Script of Ace's own to make a message appear if the hero has 4 identical weapons. If the hero has 3, another message appears, being that when it has 3 and I put another different weapon, the condition does not happen and jump right into the else.
Weapon has 4 slots.

Example:
If Hero has 4 equal weapons equipped
Something happens
else
If Hero has 3 equal weapons equipped (I discovered the "Bug" in that part)
Something happens
else
"Message that appears"
end
end


Equip the hero with 3 identical weapons and 1 different one and the conditions are not being activated. They are jumping straight to the last else.
I use this script:
$game_player.actor.weapons.size === 3 && $game_player.actor.weapons.all? {|w| w.id === 3 }

1 - How can I solve this problem?
2 - In the case of an armor, what would this script look like?
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
34,131
Reaction score
8,663
First Language
German
Primarily Uses
RMMV
That depends on which script you're using to give the actor four weapon spots, because Dach such script can work differently and you can't give an actor more than one or two weapons by default.
 

Rayner

Villager
Member
Joined
Aug 22, 2015
Messages
6
Reaction score
0
First Language
Portuguese
Primarily Uses
N/A
I'm not using any additional script. I only increased the number of slots in the Game_Actor.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
34,131
Reaction score
8,663
First Language
German
Primarily Uses
RMMV
That is a script (or a script modification), and you need to show what exactly you changed before anyone can tell you what else you have to change to get what you want.

Because as already said what you want doesn't exist in default.
 

Rayner

Villager
Member
Joined
Aug 22, 2015
Messages
6
Reaction score
0
First Language
Portuguese
Primarily Uses
N/A
LvjQkK5.png

I only increased 3 slots. By hunt them, I accidentally deleted a slot. .-.
cabz10f.png

4 weapon slots. In the first image I accidentally deleted 1 slot.
 
Last edited:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,201
Reaction score
853
First Language
Hungarian
Primarily Uses
RMVXA
You can drop this little snippet anywhere in the script editor:
Code:
class Game_Interpreter
 
  def same_weapons(num=1,all=true)
    wps = $game_player.actor.weapons
    val = wps.inject(0) {|r,wp| r += wp.id == wps[0].id ? 1 : 0 }
    return val >= num && (!all || wps.size == num)
  end

  def same_armors(num=1,all=true)
    ars = $game_player.actor.armors
    val = ars.inject(0) {|r,ar| r += ar.id == ars[0].id ? 1 : 0 }
    return val >= num && (!all || ars.size == num)
  end

end
And use the script calls to check the number of same equipment on the leader.
These are the script calls you can use:
Code:
same_weapons(amount,all?)
same_armors(amount,all?)
Replace the amount with the amount of identical weapons/armors you want your condition to check.
If you want to check for 2 of the same weapons equipped, use same_weapons(2), for example.
The all? argument can be true or false. If true, all equipped weapons/armors must be the same, if false, the condition will be true even if there are some other weapons equipped aside from the required amount of identical weapons.
For example, same_weapons(2,false) will return true if the leader got at least 2 identical weapons equipped, even if there are other, different weapons equipped on him/her.
But same_weapons(2,true) will only be true if the leader got at least 2 identical weapons equipped with no other different weapons equipped at all.
The default value for the all? argument is true, so if you omit it, that will be used automatically.
And of course, the same thing applies for the armor check method too.

For future reference, == and === are not the same thing.
=== will check if the 2 objects are the same ones or not, while == will check if the values of the objects are same or not. It is a huge difference.
 

Rayner

Villager
Member
Joined
Aug 22, 2015
Messages
6
Reaction score
0
First Language
Portuguese
Primarily Uses
N/A
You can drop this little snippet anywhere in the script editor:
Code:
class Game_Interpreter

def same_weapons(num=1,all=true)
wps = $game_player.actor.weapons
val = wps.inject(0) {|r,wp| r += wp.id == wps[0].id ? 1 : 0 }
return val >= num && (!all || wps.size == num)
end

def same_armors(num=1,all=true)
ars = $game_player.actor.armors
val = ars.inject(0) {|r,ar| r += ar.id == ars[0].id ? 1 : 0 }
return val >= num && (!all || ars.size == num)
end

end
And use the script calls to check the number of same equipment on the leader.
These are the script calls you can use:
Code:
same_weapons(amount,all?)
same_armors(amount,all?)
Replace the amount with the amount of identical weapons/armors you want your condition to check.
If you want to check for 2 of the same weapons equipped, use same_weapons(2), for example.
The all? argument can be true or false. If true, all equipped weapons/armors must be the same, if false, the condition will be true even if there are some other weapons equipped aside from the required amount of identical weapons.
For example, same_weapons(2,false) will return true if the leader got at least 2 identical weapons equipped, even if there are other, different weapons equipped on him/her.
But same_weapons(2,true) will only be true if the leader got at least 2 identical weapons equipped with no other different weapons equipped at all.
The default value for the all? argument is true, so if you omit it, that will be used automatically.
And of course, the same thing applies for the armor check method too.
Wow! Thank you very much!! Thank you anyway. I'll test.

For future reference, == and === are not the same thing.
=== will check if the 2 objects are the same ones or not, while == will check if the values of the objects are same or not. It is a huge difference.
Ah yes. I did not know. There have been events here that replace this "===" with this "==". Thanks anyway. ;)
Edit:
@Sixth There is a small problem ... There are 4 weapons. 2 equals each pair of weapon. One pair works and the other does not. Ex
I put 2 identical and then 2 more. I get one and I get 1 weapon only and there are 2 other similar ones. In the other 2, the condition jumps straight to the else. Script is only checking the first weapons. The same goes for armor. Why exactly does this happen?
 
Last edited:

Latest Threads

Latest Posts

Latest Profile Posts

I think those extra pixels did it. ^_^ Now to work on the front and back views.
PlusTest-02.gif
What props/tiles are missing from this scene?

My team recruitment thread is finally online. Please, if you guys are interested in language learning, take a look. Even if you don't join, a word of encouragement is always welcome.
Rats! These Rats are pretty cute!

can I say the opposite of "tech savvy" is "tech noob" ?

Forum statistics

Threads
116,469
Messages
1,098,902
Members
152,053
Latest member
GrayGriffin
Top