W
Wardog
Guest
Good Evening,
I'm currently trying to code up a cave ore spawning system. Currently, the code asks three questions and rolls for each, assuming the previous condition passes:
1. Will a node spawn?
2. Is the node stone?
3. If not stone, what kind of node is it?
The way question 3 is currently coded, it rolls noderoll once, and sees where the number falls. I suspect this isn't the best way to do probability, and would like suggestions on how to improve this. I was hoping for something simple like "Node 1 has a 5% chance, Node 2 has a 10% chance", but I wasn't successful in searching for GML coding like that.
For instance, let's say I order the list of possible nodes by rarity, and have noderoll re-roll for each item in the list, starting at the top. Would the repeat function allow this, or does it have to be some cumbersome multi-layered if-then statement?
Thanks again for your continued guidance and advice.
I'm currently trying to code up a cave ore spawning system. Currently, the code asks three questions and rolls for each, assuming the previous condition passes:
1. Will a node spawn?
2. Is the node stone?
3. If not stone, what kind of node is it?
Code:
if(room = rm_cavelevel1 or rm_cavelevel2){
spawnroll = random(1);
if(spawnroll < min((0.30+(obj_player_stats.cavelevel/300)), 0.85)){ // Determines if a node spawns, better odds deeper you go, up to 85%.
stoneroll = random(1);
if(stoneroll < 0.800) {nodetype = 17} // 80% chance of being a regular stone
else {
noderoll = (random_range(1,2)/5) + (obj_player_stats.cavelevel/300)); // Determines what kind of rarer resource it will be
if(noderoll < 0.005) {nodetype = 5}
else if(noderoll < 0.010) {nodetype = 2}
else if(noderoll < 0.015) {nodetype = 21}
else if(noderoll < 0.020) {nodetype = 15}
else if(noderoll < 0.025) {nodetype = 6}
else if(noderoll < 0.030) {nodetype = 13}
else if(noderoll < 0.040) {nodetype = 1}
else if(noderoll < 0.050) {nodetype = 3}
else if(noderoll < 0.070) {nodetype = 10}
else if(noderoll < 0.090) {nodetype = 11}
else if(noderoll < 0.115) {nodetype = 7}
else if(noderoll < 0.145) {nodetype = 16}
else if(noderoll < 0.180) {nodetype = 9}
else if(noderoll < 0.250) {nodetype = 0}
else {nodetype = 4}
}
} else { instance_destroy(); } // Destroys Instance if Spawnroll Fails
}
For instance, let's say I order the list of possible nodes by rarity, and have noderoll re-roll for each item in the list, starting at the top. Would the repeat function allow this, or does it have to be some cumbersome multi-layered if-then statement?
Thanks again for your continued guidance and advice.