Random item get event

Can make Random item get event not using conditional branch?

in my game rare item can get in random box but armor,weapon,accesary is too many

almost 200 item in game...

i know in common event, 『conditional branch variable a = 1, get A』 like this

but 200 item, so tired
Yep 😉

1587960470941.png

1587960419882.png

Code:
var temp = [];
$dataItems.forEach(function(v) {if (v && v.name) {temp.push(v);}});
$gameParty.gainItem(temp[Math.floor(Math.random()*temp.length)],1);
Above is a very basic version of how to do that.
That will get all items (and only items) that aren't empty and return a random item.
Yep 😉

View attachment 141129
View attachment 141128
Code:
var temp = [];
$dataItems.forEach(function(v) {if (v && v.name) {temp.push(v);}});
$gameParty.gainItem(temp[Math.floor(Math.random()*temp.length)],1);
Above is a very basic version of how to do that.
That will get all items (and only items) that aren't empty and return a random item.

Thank you, but i don't understand exactlly

can you get some example?

where am i get into item ID number that script?


in this case.
get armor random in armor ID 201 ~ 231
1587969723394.png

I use a variable to store a random number between the items I want to give out, in your case, 201 - 231. Then, the script call awards the item ID that matches the random number chosen.

Your script call would look like this:
var item = $gameVariables.value(3);
$gameParty.gainItem($dataArmors[item], 1);

For $gameVariables.value(3); replace the '3' with which ever variable you store your random number in.

The '1' at the end of the second line is the amount to award.
View attachment 141150
I use a variable to store a random number between the items I want to give out, in your case, 201 - 231. Then, the script call awards the item ID that matches the random number chosen.

can i get text that script?

and what script are Armor and weapon tap?
To give armor:
$gameParty.gainItems($dataArmors(X));
replace X with the ID of the armor you want to give.

To give a weapon:
$gameParty.gainItems($dataWeapons(X));
again, replace X with the ID of the weapon you want to give.

1587971430743.png

The 'Show Text' command is there to let the player know they have received an item.

This is a common event. Call the common event from a local event:
1587971806041.png
To give armor:
$gameParty.gainItems($dataArmors(X));
replace X with the ID of the armor you want to give.

To give a weapon:
$gameParty.gainItems($dataWeapons(X));
again, replace X with the ID of the weapon you want to give.

View attachment 141152
The 'Show Text' command is there to let the player know they have received an item.

This is a common event. Call the common event from a local event:
View attachment 141153

Thx it working!
but how text show up? to get item

i mean exactlly what i get something

if 220 = A armor and text showup [Get a A armor]

or it can't ?
I use Yanfly's message core plugin to reference the name and icon in the text window with \ii[x], where 'x' is the item id
Made a plugin for you 🙂
1587977809753.png



Extra Info:
Spoiler
Script Calls:
Code:
$gameParty.gainRandomLoot([start], [max], [data], [howMany])
$gameParty.gainRandomItem(start, max, howMany)
$gameParty.gainRandomWeapon(start, max, howMany)
$gameParty.gainRandomArmor(start, max, howMany)

Examples:
Code:
$gameParty.gainRandomLoot([start], [max], [data], [howMany])

$gameParty.gainRandomLoot()                        // This will give a random item from the entire Item database
$gameParty.gainRandomLoot(31, 20, $dataWeapons, 2)    // This will 2 a a random weapon of an ID 31 to 51
$gameParty.gainRandomLoot(14, 3, null, 10)            // This is the same as the below
$gameParty.gainRandomLoot(14, 3, $dataItems, 10)    // This will 10 a a random items of an ID 14 to 17
Items:
Code:
$gameParty.gainRandomItem(start, max, howMany)

$gameParty.gainRandomItem()                        // This will give a random item from the entire Item database
$gameParty.gainRandomItem(31, 20)                    // This will 1 a a random items of an ID 31 to 51
$gameParty.gainRandomItem(31, 20,  2)                // This will 2 a a random items of an ID 31 to 51
$gameParty.gainRandomItem(14,  3, 10)                // This will 10 a a random items of an ID 14 to 17
Weapons:
Code:
$gameParty.gainRandomWeapon(start, max, howMany)

$gameParty.gainRandomWeapon()                        // This will give a random item from the entire Item database
$gameParty.gainRandomWeapon(31, 20)                    // This will 1 a a random items of an ID 31 to 51
$gameParty.gainRandomWeapon(31, 20,  2)                // This will 2 a a random items of an ID 31 to 51
$gameParty.gainRandomWeapon(14,  3, 10)                // This will 10 a a random items of an ID 14 to 17
Armor
Code:
$gameParty.gainRandomArmor(start, max, howMany)

$gameParty.gainRandomArmor()                        // This will give a random item from the entire Item database
$gameParty.gainRandomArmor(31, 20)                    // This will 1 a a random items of an ID 31 to 51
$gameParty.gainRandomArmor(31, 20,  2)                // This will 2 a a random items of an ID 31 to 51
$gameParty.gainRandomArmor(14,  3, 10)                // This will 10 a a random items of an ID 14 to 17
More Info/Examples:
Set Game Variable #1 to the name of last random item received:
Code:
$gameVariables.setValue(1, $gameParty._lastRandomLoot.name)
Set Game Variable #1 to the last random item choices (raw data):
Code:
$gameVariables.setValue(1, $gameParty._lastRandomLootChoices)
I use Yanfly's message core plugin to reference the name and icon in the text window with \ii[x], where 'x' is the item id

oh ok that's another thing.
I'll study that later and thx for helping
Made a plugin for you 🙂
View attachment 141158

Extra Info:
Spoiler
Code:
Script Calls:
$gameParty.gainRandomLoot([start], [max], [data], [howMany])
$gameParty.gainRandomItem(start, max, howMany)
$gameParty.gainRandomWeapon(start, max, howMany)
$gameParty.gainRandomArmor(start, max, howMany)

Examples:
Code:
$gameParty.gainRandomLoot([start], [max], [data], [howMany])
Code:
ex. $gameParty.gainRandomLoot()                        // This will give a random item from the entire Item database
$gameParty.gainRandomLoot(31, 20, $dataWeapons, 2)    // This will 2 a a random weapon of an ID 31 to 51
$gameParty.gainRandomLoot(14, 3, null, 10)            // This is the same as the below
$gameParty.gainRandomLoot(14, 3, $dataItems, 10)    // This will 10 a a random items of an ID 14 to 17
Code:
$gameParty.gainRandomItem(start, max, howMany)
Code:
ex. $gameParty.gainRandomItem()                        // This will give a random item from the entire Item database
$gameParty.gainRandomItem(31, 20)                    // This will 1 a a random items of an ID 31 to 51
$gameParty.gainRandomItem(31, 20,  2)                // This will 2 a a random items of an ID 31 to 51
$gameParty.gainRandomItem(14,  3, 10)                // This will 10 a a random items of an ID 14 to 17
Code:
$gameParty.gainRandomWeapon(start, max, howMany)
ex. $gameParty.gainRandomWeapon()                        // This will give a random item from the entire Item database
$gameParty.gainRandomWeapon(31, 20)                    // This will 1 a a random items of an ID 31 to 51
$gameParty.gainRandomWeapon(31, 20,  2)                // This will 2 a a random items of an ID 31 to 51
$gameParty.gainRandomWeapon(14,  3, 10)                // This will 10 a a random items of an ID 14 to 17

$gameParty.gainRandomArmor(start, max, howMany)
ex. $gameParty.gainRandomArmor()                        // This will give a random item from the entire Item database
$gameParty.gainRandomArmor(31, 20)                    // This will 1 a a random items of an ID 31 to 51
$gameParty.gainRandomArmor(31, 20,  2)                // This will 2 a a random items of an ID 31 to 51
$gameParty.gainRandomArmor(14,  3, 10)                // This will 10 a a random items of an ID 14 to 17

More examples:
Set Game Variable #1 to the name of last random item reveived:
$gameVariables.setValue(1, $gameParty._lastRandomLoot.name)

Set Game Variable #1 to the last random item choices (raw data):
$gameVariables.setValue(1, $gameParty._lastRandomLootChoices)

WAHT~!? OMG

Thankyou very much!
I have something to do now, so I will use it later.

VERY THX!
WAHT~!? OMG

Thankyou very much!
I have something to do now, so I will use it later.

VERY THX!
No prob. Works great for me. Should do everything you need 😉
Let me know how it goes when you get to try it ☺️ :popcorn:
To give armor:
$gameParty.gainItems($dataArmors(X));
replace X with the ID of the armor you want to give.

To give a weapon:
$gameParty.gainItems($dataWeapons(X));
again, replace X with the ID of the weapon you want to give.

View attachment 141152
The 'Show Text' command is there to let the player know they have received an item.

This is a common event. Call the common event from a local event:
View attachment 141153


Can i get some question one more?

your image's script

var armor = $gameVariables.value(299);
$gameParty.gainItem($dataArmors[armor], 1);

like this

but i was testing

var item = $gameVariables.value(299);
$gameParty.gainItem($dataArmors[item], 1);

and that is working too

what is different var OOO dataAAA[OOO] 's OOO?

and...
$gameParty.gainItems($dataArmors(X));
replace X with the ID of the armor i want to give.
what is this exactlly???

if i put the number in X to 233
then i can get ID 233's armor?

If what I think is right
var item = this is a script for Replace the letter or number after "=" with the letter item.
In this case, variable. with random 201~231
and
$gameParty.gainItems($dataArmors(X));
here's X, in this case, word "item".
so am i right them
$gameParty.gainItems($dataArmors(item));
is
$gameParty.gainItems($dataArmors(random 201~231));
and get the item $dataArmors ID 201~231 chosen that right?

I don't speak English very well so I hope you understand.
@Dehsalp,
'var item =' is javascript code. 'var' creates a new variable, 'item' becomes the name of the variable. The '=' assigns the value of the code placed after it to the variable.
So,
var item = $gameVariables.value(3);
assigns the value of variable #3 in the editor to the newly created variable named 'item'

The name of the variable will not change the function of the script:

var item = $gameVariables.value(299);
$gameParty.gainItem($dataArmors[item], 1);

And,

var armor = $gameVariables.value(299);
$gameParty.gainItem($dataArmors[armor], 1);

are essentially the same, other than the name of the newly created variable, both will award the same armor piece.

In:
$gameParty.gainItems($dataArmors(X));
X is merely a place holder for the created variable, in this case 'armor' or 'item'.



if i put the number in X to 233
then i can get ID 233's armor?

Yes, that is correct.

Also,
$gameParty.gainItem($dataArmors[item], 1); only awards a random armor between 201 and 231 IF you set a game variable to a random number between 201 and 231 and the set var item to the value of that game variable.

Original thread: https://forums.rpgmakerweb.com/threads/random-item-get-event.120702/