[solved] Have as many weapons as a variable

Im trying to force how many swords hero has with a variable but eventing only let me add weapons, not set to a variable.

Can something like this work?

$gameParty.setItem($dataWeapons[1], $gameVariables.value(259), true);
$game_actors[1].setItem($dataWeapons[1], $gameVariables.value(259));

this gives me countless of swords
$gameParty.gainItem($dataWeapons[1], $gameVariables.value(259), true)
Can you step by step explain what you want exactly?
I dont understand your request and what i get seems to vague or contradictory.

Big Guess: =)
Eventcommand Control Variables - Game Data - Weapon - Choose Weapon, for example the Sword.
The Variable will be set to the amount of Swords you got in your Inventory at that moment of Time in the Game. It will not automatically update itself.
No the other way around. I want the variable to set how many weapons player currently has. if variable is 10 then we have 10 swords in weaponScreen🙂
Eventcommand - Control Variables - Set Variable 10 to 5000
Eventcommands - Category Party - Change Weapons, Sword inrease by Variable10

That gives you the amount of Swords determind in Variable 10.
But i believe you dont get 5000 Swords, the Item Limit per stack is around 99 Swords.
Iam sure there are Plugins if you want to allow bigger stacks of Items.
how many weapons
how many weapons where?

are you talking about an inventory limit, about how many weapons to equip, or something entirely else?
Please give an example of what you want to do in ingame terms, not how you want to do something. What is the hero supposed to do with that number and how and when should it be changed?
How does your party get swords? If by event, just count how many swords the player has (including equipment) before giving the next one. If they already have the maximum, don't allow them to get more. If by shop, you will need a plugin.
Spoiler: Equalise inventory sword count (eventing only)
Code:
◆Comment:Count extra swords needed to reach 4 total
:       :(Does not include equipment)
◆Control Variables:#0041 count = 4
◆Control Variables:#0041 count -= The number of Sword
◆If:count < 0
  ◆Comment:Remove excess swords
  ◆Change Weapons:Sword - {count}
  ◆
:Else
  ◆Comment:Add extra swords
  ◆Change Weapons:Sword + {count}
  ◆
:End
If you need to count currently-equipped swords, then generally speaking that'll need a script call. You can use this in Control Variables > Script:
Code:
var item = $dataWeapons[1]; $gameParty.members().reduce(function(a, c) { return a += c.equips().reduce(function(b, d) { return b += d === item ? 1 : 0; }, 0); }, 0);
This'll check all party members' equipment for weapon 1, change the number in $dataWeapons[1] as needed to reference a different weapon ID. You can adapt this to check for armor items instead by swapping $dataWeapons for $dataArmors. 😮‍💨

Including that in my above example yields this:
Spoiler: Equalise sword count (inventory + equipment) with help from a script
Code:
◆Comment:Count extra swords needed to reach 4 total
◆Control Variables:#0041 count = 4
◆Control Variables:#0041 count -= The number of Sword
◆Comment:  This script counts equipped swords:
◆Control Variables:#0041 count -= var item = $dataWeapons[1]; $gameParty.members().reduce(function(a, c) { return a += c.equips().reduce(function(b, d) { return b += d === item ? 1 : 0; }, 0); }, 0);
◆If:count < 0
  ◆Comment:Remove excess swords
  ◆Change Weapons:Sword - {count} (Include Equipment)
  ◆
:Else
  ◆Comment:Add extra swords
  ◆Change Weapons:Sword + {count}
  ◆
:End
Notice that the first Control Variables command uses the Set operator, and the second two use the Sub operator. I.e. the resultant value is:
  • Target number - number in inventory - number equipped
Hopefully that's clear! 😂
Okay, ill try to explain 🙂

My question in plain:
How can player have just as many swords as the number in a variable.

Example that worked with player Hp controlled by a variable:
$gameActors.actor(1).setHp($gameVariables.value(196))

I guess maybe my question is how to SET weapon? instead og increase or decrease.

Why I need this?
I have swords set up as items, not weapons. So im using some eventing to count how many swords there is in items and then setting that to amount of swords in weapons menu. I need the weapons menu just for visual references.
how many weapons where?

are you talking about an inventory limit, about how many weapons to equip, or something entirely else?
Please give an example of what you want to do in ingame terms, not how you want to do something. What is the hero supposed to do with that number and how and when should it be changed?
How many weapons player has in weapon menu stock. Like if variable is 10, and i run common event, then player has 10 swords in weaponsmenu
Why dont you use the first solution i blindly guessed? Aint it doing what you want?
Storing the actual amount of Swords in Inventory into a Variable.
Big Guess: =)
Eventcommand Control Variables - Game Data - Weapon - Choose Weapon, for example the Sword.
The Variable will be set to the amount of Swords you got in your Inventory at that moment of Time in the Game. It will not automatically update itself.

My question in plain:
How can player have just as many swords as the number in a variable.
This does not explain it better. Its same confusing as the first explanation.
Thanks 🙂 But as far as I can see it can only increase or decrease the amount of swords?
Why dont you use the first solution i blindly guessed? Aint it doing what you want?
Storing the actual amount of Swords in Inventory into a Variable.



This does not explain it better. Its same confusing as the first explanation.
I dont get how that can be confusing 😮 I really dont. But I can try to put it in a eventing kind of way

is this better? How can player have just as many swords as the number OF a variable.
(Im from Sweeden so English is not my native) Swords are just a name of a Weapon

Control variables : #0259 CountAmountOfSwords = The number of swords (item)
Script: (this I need help for) SET.weapon number 1. to match current value of variable 259

Any other way I tried with rpg maker is adding or subtracting to a variable solutions, nowhere I can find set to variable with the weapons

In my first post I wrote:

$gameParty.setItem($dataWeapons[1], $gameVariables.value(259), true);
And I mean like this
Hero set swords(weaponID1) to match variable 259. (not add or subrtract, just a fixed set)
But as far as I can see it can only increase or decrease the amount of swords?
and that is all you ever need.

the key is mathematics.

1) control variable 80 = weapon in inventory
2) control variable 81 = weapon number wanted by developer
3) control variable 81 - 80 (mathematical operation, substract one variable from the other)
4) change weapon: increase by variable 81

and you'll have the number of swords you want in inventory.

EDIT:
and the confusion was caused by you insisting on calling weapon numbers (wich is an equipment to be used/equipped by the actor) instead of saying that you were talking about an item number in inventory)
Here another theoretically Way like Andar's.

Control Variable 1 = "Item Sword" Amount (For example 10 Items)
Change "Weapon Sword" decrease 9999
Change "Weapon Sword" increase by Variable1
Yeah, ah okay thanks to both of you. I was to fixated on finding a script to change amount of weapons, exactly like this script does with health: $gameActors.actor(1).setHp($gameVariables.value(196))

But if we cant reach dataWeapons and set that to a variable I guess this is the next best thing 🙂 thanks
The issue is that there is no "dataWeapons" like you're suggesting. Possessed items are split into inventory and actor containers: each container must be checked separately to count the total, as highlighted in my earlier response. (And $dataWeapons is the info you enter into the editor database, thus is not saved on a per-playthrough basis.)
Here another theoretically Way like Andar's.

Control Variable 1 = "Item Sword" Amount (For example 10 Items)
Change "Weapon Sword" decrease 9999
Change "Weapon Sword" increase by Variable1
This sort of thing is probably the simplest solution if you don't mind either ignoring or mass-unequipping all currently-equipped swords. 🙂
Thanks
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/solved-have-as-many-weapons-as-a-variable.112745/