Best way to approach an RNG weapon system?

E

entegrade

Guest
Hey all, I’m trying to think of ways to make an RNG weapon system with rarities and attributes (Like Borderlands, Anthem, Destiny)


For example, the system would first choose a rarity, then a manufacturer, a weapon type, and finally different “perks” that could increase/decrease stats. After all that it would generate the weapon based on these values and set their respective sprites and animations.


I was wondering what the best way to approach this would be without a ton of messy if statements/case switches. And since this system could potentially generate thousands of combinations, I think an array for different weapon stats might be too long. (Unless its really needed)
 

vdweller

Member
Items usually have a rarity modifier computed based on their traits (damage, perks etc). A simple approach may be to compute an integer rarity then populate a ds_list. For example an item with a rarity of 5 (very rare - the lower the rarer) gets added 5 times in the list, an item with 50 rarity gets added 50 times etc. Then shuffle the list with ds_list_shuffle and choose index 0, or choose a random index (it's much faster).

This is a naive approach which may be slow for thousands of potential items. Another approach would be using ds_grids and even an experimental method I came up with using Gauss sums, see the end of this post, but you need to be a bit into mathematics.
 
E

entegrade

Guest
Items usually have a rarity modifier computed based on their traits (damage, perks etc). A simple approach may be to compute an integer rarity then populate a ds_list. For example an item with a rarity of 5 (very rare - the lower the rarer) gets added 5 times in the list, an item with 50 rarity gets added 50 times etc. Then shuffle the list with ds_list_shuffle and choose index 0, or choose a random index (it's much faster).

This is a naive approach which may be slow for thousands of potential items. Another approach would be using ds_grids and even an experimental method I came up with using Gauss sums, see the end of this post, but you need to be a bit into mathematics.
ooooh i just checked that out and it looks interesting, thanks!

one question though, what does the [ | 0 ] mean? i dont think ive seen that before
 

vdweller

Member
ooooh i just checked that out and it looks interesting, thanks!

one question though, what does the [ | 0 ] mean? i dont think ive seen that before
It's the same as ds_list_find_value(list,0)

Read documentation about "accessors", it's mainly a faster way to write stuff.
 
T

trentallain

Guest
Hey all, I’m trying to think of ways to make an RNG weapon system with rarities and attributes (Like Borderlands, Anthem, Destiny)


For example, the system would first choose a rarity, then a manufacturer, a weapon type, and finally different “perks” that could increase/decrease stats. After all that it would generate the weapon based on these values and set their respective sprites and animations.


I was wondering what the best way to approach this would be without a ton of messy if statements/case switches. And since this system could potentially generate thousands of combinations, I think an array for different weapon stats might be too long. (Unless its really needed)
What I would do is create a ds_map for the weapon. Each component in the map is a different part of the gun (manufacturer, perks, etc), that can be chosen using choose(). Then your weapon can always be referenced by that unique ds_map to find the damage or to add it to your inventory etc.

For rarity, what I would do is use irandom between 0 and 100. Then you can calculate the rarity rates from it. For example, white rarity might be if the number is less than 40, else if it is less than 60 it could be green, and then else if it less than 70 it could be blue. You just have to find the ratios that work for you.

Don't forget to call randomise() so that everything is random.

To draw the correct sprites etc, just get them from the keys that you put into the map, so to get the correct sprite you would do gun_map[? "sprite"]. Same goes for the other values.
 
R

Rukiri

Guest
ds_maps or ds_lists is what you want.

You can then put all your weapons and stats in a nicely neat array and call them when you need them.
For example you could create several weapons, have a database variable storing them in a ds_map, then you can add them by.
Code:
// rpg_group_member_add(mapindex);
// This script adds a party member by their mapindex. Will not add if there is no room in the group.
if(rpg_group_size() >= 3) {
    show_debug_message("Woh! Call Lucca, we have a problem! '" + string(argument0) + "' to the group.");
    return 0; // There was no room for the character!
}

// Check to make sure there isn't already a copy of this member in the party.
if(rpg_group_member_find_index(argument0) >= 0) {
    show_debug_message("Woh! Call Lucca, we have a problem! '" + string(argument0) + "' was already found in the group.");
    return 0;
}

ds_list_add(_rpg_group, argument0);
return 1;
This is a simple script that would add a character to my party group, you'd pretty much do the same for your RNG system but add random.
 
E

entegrade

Guest
It's the same as ds_list_find_value(list,0)

Read documentation about "accessors", it's mainly a faster way to write stuff.
ah gotcha i know about accessors, just found out yesterday they use a different one from ds maps, thanks again!

What I would do is create a ds_map for the weapon. Each component in the map is a different part of the gun (manufacturer, perks, etc), that can be chosen using choose(). Then your weapon can always be referenced by that unique ds_map to find the damage or to add it to your inventory etc.

For rarity, what I would do is use irandom between 0 and 100. Then you can calculate the rarity rates from it. For example, white rarity might be if the number is less than 40, else if it is less than 60 it could be green, and then else if it less than 70 it could be blue. You just have to find the ratios that work for you.

Don't forget to call randomise() so that everything is random.

To draw the correct sprites etc, just get them from the keys that you put into the map, so to get the correct sprite you would do gun_map[? "sprite"]. Same goes for the other values.
ds_maps or ds_lists is what you want.

You can then put all your weapons and stats in a nicely neat array and call them when you need them.
For example you could create several weapons, have a database variable storing them in a ds_map, then you can add them by.
Code:
// rpg_group_member_add(mapindex);
// This script adds a party member by their mapindex. Will not add if there is no room in the group.
if(rpg_group_size() >= 3) {
    show_debug_message("Woh! Call Lucca, we have a problem! '" + string(argument0) + "' to the group.");
    return 0; // There was no room for the character!
}

// Check to make sure there isn't already a copy of this member in the party.
if(rpg_group_member_find_index(argument0) >= 0) {
    show_debug_message("Woh! Call Lucca, we have a problem! '" + string(argument0) + "' was already found in the group.");
    return 0;
}

ds_list_add(_rpg_group, argument0);
return 1;
This is a simple script that would add a character to my party group, you'd pretty much do the same for your RNG system but add random.
thank you so much for the input !! these were all really helpful and made me more confident in my initial plans. thank you all so much!
 
Top