• Do not use Discord to host any images you post, these links expire quickly! You can learn how to add images to your posts here.

A couple of script questions

Nova Ozuka

Novice
Member
Joined
Apr 15, 2022
Posts
14
First question, is it possible to assign ratios to an array? I've got a script event that has several Pokemon in an array, but I want some Pokemon to have a higher rate than the others.

Second question, how do I assign a specific game variable to a script? Would it be as simple as BLANK = 30, or would that just set a variable called BLANK to have a value of 30 instead of whatever is stored in variable 30? I have to ask this because I'm trying to setup a script to track a variable, but I've also realized that if I simply did something like BLANK = 30 and then do "if BLANK < 2" then the script might actually think that BLANK is supposed to be 30 and not whatever is stored in variable 30. I was going to test this myself, but I'm stuck redoing a bunch of stuff before that script comes into play.
 

wrigty12

Tester-Coder Hybrid
Member
Joined
Jul 24, 2022
Posts
530
First question, is it possible to assign ratios to an array? I've got a script event that has several Pokemon in an array, but I want some Pokemon to have a higher rate than the others.

Second question, how do I assign a specific game variable to a script? Would it be as simple as BLANK = 30, or would that just set a variable called BLANK to have a value of 30 instead of whatever is stored in variable 30? I have to ask this because I'm trying to setup a script to track a variable, but I've also realized that if I simply did something like BLANK = 30 and then do "if BLANK < 2" then the script might actually think that BLANK is supposed to be 30 and not whatever is stored in variable 30. I was going to test this myself, but I'm stuck redoing a bunch of stuff before that script comes into play.
1) Just do an array of arrays.
array = [[:PIKACHU, 50], [:ENTEI, 30], [:MEW, 20]]
Depending on what you're trying to do, you'd likely generate a random number, then run through a loop of array.length, and at each step subtract the index 1 value. If the value is < 0, it returns the index 0 value (the Pokemon). Else, move on to the next iteration and repeat until it returns a Pokemon. That's how wild encounter selection happens as an example

2) pbGet(30) gives you the value of variable 30. Or $game_variables[30]. So just do "if pbGet(30) < 2"
 
Last edited:

Nova Ozuka

Novice
Member
Joined
Apr 15, 2022
Posts
14
1) Just do an array of arrays.
array = [[:PIKACHU, 50], [:ENTEI, 30], [:MEW, 20]]
Depending on what you're trying to do, you'd likely generate a random number, then run through a loop of array.length, and at each step subtract the index 1 value. If the value is < 0, it returns the index 0 value (the Pokemon). Else, move on to the next iteration and repeat until it returns a Pokemon. That's how wild encounter selection happens as an example

2) pbGet(30) gives you the value of variable 30. Or $game_variables[30]. So just do "if pbGet(30) < 2"
I'll try that solution. Hopefully it doesn't just end up giving me Pokemon of that level instead.

As for the second question, I ended up finding the answer on my own today. Unfortunately, my attempts to edit a script have been less than successful, and I don't really know ruby script well enough to get my edits working. It acts like I'm missing an "end" line, but I can't see anywhere I'm missing one. All I know is that it has something to do with my edit. All I know is that whatever I'm really missing, it's in this section of code.
Ruby:
Expand Collapse Copy
if $game_variables[30] < 2
        ratio=[247,247,247,247,10,1,1]
        craft=items[rand(items.length)]
        case craft
        when :BLACKAPRICORN
          table=[:POKEBALL,:GREATBALL,:DUSKBALL,:LUXURYBALL,:HEAVYBALL,:SAFARIBALL,:SPORTBALL]
        when :BLUEAPRICORN
          table=[:POKEBALL,:GREATBALL,:DIVEBALL,:NETBALL,:LUREBALL,:SAFARIBALL,:SPORTBALL]
        when :GREENAPRICORN
          table=[:POKEBALL,:GREATBALL,:ULTRABALL,:NESTBALL,:FRIENDBALL,:SAFARIBALL,:SPORTBALL]
        when :PINKAPRICORN
          table=[:POKEBALL,:GREATBALL,:ULTRABALL,:HEALBALL,:LOVEBALL,:SAFARIBALL,:SPORTBALL]
        when :REDAPRICORN
          table=[:POKEBALL,:GREATBALL,:ULTRABALL,:REPEATBALL,:LEVELBALL,:SAFARIBALL,:SPORTBALL]
        when :WHITEAPRICORN
          table=[:POKEBALL,:GREATBALL,:PREMIERBALL,:TIMERBALL,:FASTBALL,:SAFARIBALL,:SPORTBALL]
        when :YELLOWAPRICORN
          table=[:POKEBALL,:GREATBALL,:ULTRABALL,:QUICKBALL,:MOONBALL,:SAFARIBALL,:SPORTBALL]
      if $game_variables[30] >= 2 and $game_variables[30] < 4
        ratio=[123,247,247,247,120,8,8]
        craft=items[rand(items.length)]
        case craft
        when :BLACKAPRICORN
          table=[:POKEBALL,:GREATBALL,:DUSKBALL,:LUXURYBALL,:HEAVYBALL,:SAFARIBALL,:SPORTBALL]
        when :BLUEAPRICORN
          table=[:POKEBALL,:GREATBALL,:DIVEBALL,:NETBALL,:LUREBALL,:SAFARIBALL,:SPORTBALL]
        when :GREENAPRICORN
          table=[:POKEBALL,:GREATBALL,:ULTRABALL,:NESTBALL,:FRIENDBALL,:SAFARIBALL,:SPORTBALL]
        when :PINKAPRICORN
          table=[:POKEBALL,:GREATBALL,:ULTRABALL,:HEALBALL,:LOVEBALL,:SAFARIBALL,:SPORTBALL]
        when :REDAPRICORN
          table=[:POKEBALL,:GREATBALL,:ULTRABALL,:REPEATBALL,:LEVELBALL,:SAFARIBALL,:SPORTBALL]
        when :WHITEAPRICORN
          table=[:POKEBALL,:GREATBALL,:PREMIERBALL,:TIMERBALL,:FASTBALL,:SAFARIBALL,:SPORTBALL]
        when :YELLOWAPRICORN
          table=[:POKEBALL,:GREATBALL,:ULTRABALL,:QUICKBALL,:MOONBALL,:SAFARIBALL,:SPORTBALL]
      if $game_variables[30] >= 4 and $game_variables[30] < 6
        ratio=[247,123,247,247,67,67,1]
        craft=items[rand(items.length)]
        case craft
        when :BLACKAPRICORN
          table=[:HEAVYBALL,:GREATBALL,:DUSKBALL,:LUXURYBALL,:SAFARIBALL,:SPORTBALL,:MASTERBALL]
        when :BLUEAPRICORN
          table=[:LUREBALL,:GREATBALL,:DIVEBALL,:NETBALL,:SAFARIBALL,:SPORTBALL,:MASTERBALL]
        when :GREENAPRICORN
          table=[:FRIENDBALL,:GREATBALL,:ULTRABALL,:NESTBALL,:SAFARIBALL,:SPORTBALL,:MASTERBALL]
        when :PINKAPRICORN
          table=[:LOVEBALL,:GREATBALL,:ULTRABALL,:HEALBALL,:SAFARIBALL,:SPORTBALL,:MASTERBALL]
        when :REDAPRICORN
          table=[:LEVELBALL,:GREATBALL,:ULTRABALL,:REPEATBALL,:SAFARIBALL,:SPORTBALL,:MASTERBALL]
        when :WHITEAPRICORN
          table=[:FASTBALL,:GREATBALL,:PREMIERBALL,:TIMERBALL,:SAFARIBALL,:SPORTBALL,:MASTERBALL]
        when :YELLOWAPRICORN
          table=[:MOONBALL,:GREATBALL,:ULTRABALL,:QUICKBALL,:MOONBALL,:SAFARIBALL,:SPORTBALL,:MASTERBALL]
      if $game_variables[30] >= 6 and $game_variables[30] < 8
        ratio=[247,247,247,119,119,10,1]
        craft=items[rand(items.length)]
        case craft
        when :BLACKAPRICORN
          table=[:HEAVYBALL,:DUSKBALL,:LUXURYBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :BLUEAPRICORN
          table=[:LUREBALL,:DIVEBALL,:NETBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :GREENAPRICORN
          table=[:FRIENDBALL,:ULTRABALL,:NESTBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :PINKAPRICORN
          table=[:LOVEBALL,:ULTRABALL,:HEALBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :REDAPRICORN
          table=[:LEVELBALL,:ULTRABALL,:REPEATBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :WHITEAPRICORN
          table=[:FASTBALL,:PREMIERBALL,:TIMERBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :YELLOWAPRICORN
          table=[:MOONBALL,:ULTRABALL,:QUICKBALL,:MOONBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
      if $game_variables[30] >= 8
        ratio=[247,247,247,119,119,10,1]
        craft=items[rand(items.length)]
        case craft
        when :BLACKAPRICORN
          table=[:HEAVYBALL,:DUSKBALL,:LUXURYBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :BLUEAPRICORN
          table=[:LUREBALL,:DIVEBALL,:NETBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :GREENAPRICORN
          table=[:FRIENDBALL,:ULTRABALL,:NESTBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :PINKAPRICORN
          table=[:LOVEBALL,:ULTRABALL,:HEALBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :REDAPRICORN
          table=[:LEVELBALL,:ULTRABALL,:REPEATBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :WHITEAPRICORN
          table=[:FASTBALL,:PREMIERBALL,:TIMERBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :YELLOWAPRICORN
          table=[:MOONBALL,:ULTRABALL,:QUICKBALL,:MOONBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
 
Last edited:

Vendily

Elite Trainer
Member
I'll try that solution. Hopefully it doesn't just end up giving me Pokemon of that level instead.

As for the second question, I ended up finding the answer on my own today. Unfortunately, my attempts to edit a script have been less than successful, and I don't really know ruby script well enough to get my edits working. It acts like I'm missing an "end" line, but I can't see anywhere I'm missing one. All I know is that it has something to do with my edit. All I know is that whatever I'm really missing, it's in this section of code.
Ruby:
Expand Collapse Copy
if $game_variables[30] < 2
        ratio=[247,247,247,247,10,1,1]
        craft=items[rand(items.length)]
        case craft
        when :BLACKAPRICORN
          table=[:POKEBALL,:GREATBALL,:DUSKBALL,:LUXURYBALL,:HEAVYBALL,:SAFARIBALL,:SPORTBALL]
        when :BLUEAPRICORN
          table=[:POKEBALL,:GREATBALL,:DIVEBALL,:NETBALL,:LUREBALL,:SAFARIBALL,:SPORTBALL]
        when :GREENAPRICORN
          table=[:POKEBALL,:GREATBALL,:ULTRABALL,:NESTBALL,:FRIENDBALL,:SAFARIBALL,:SPORTBALL]
        when :PINKAPRICORN
          table=[:POKEBALL,:GREATBALL,:ULTRABALL,:HEALBALL,:LOVEBALL,:SAFARIBALL,:SPORTBALL]
        when :REDAPRICORN
          table=[:POKEBALL,:GREATBALL,:ULTRABALL,:REPEATBALL,:LEVELBALL,:SAFARIBALL,:SPORTBALL]
        when :WHITEAPRICORN
          table=[:POKEBALL,:GREATBALL,:PREMIERBALL,:TIMERBALL,:FASTBALL,:SAFARIBALL,:SPORTBALL]
        when :YELLOWAPRICORN
          table=[:POKEBALL,:GREATBALL,:ULTRABALL,:QUICKBALL,:MOONBALL,:SAFARIBALL,:SPORTBALL]
      if $game_variables[30] >= 2 and $game_variables[30] < 4
        ratio=[123,247,247,247,120,8,8]
        craft=items[rand(items.length)]
        case craft
        when :BLACKAPRICORN
          table=[:POKEBALL,:GREATBALL,:DUSKBALL,:LUXURYBALL,:HEAVYBALL,:SAFARIBALL,:SPORTBALL]
        when :BLUEAPRICORN
          table=[:POKEBALL,:GREATBALL,:DIVEBALL,:NETBALL,:LUREBALL,:SAFARIBALL,:SPORTBALL]
        when :GREENAPRICORN
          table=[:POKEBALL,:GREATBALL,:ULTRABALL,:NESTBALL,:FRIENDBALL,:SAFARIBALL,:SPORTBALL]
        when :PINKAPRICORN
          table=[:POKEBALL,:GREATBALL,:ULTRABALL,:HEALBALL,:LOVEBALL,:SAFARIBALL,:SPORTBALL]
        when :REDAPRICORN
          table=[:POKEBALL,:GREATBALL,:ULTRABALL,:REPEATBALL,:LEVELBALL,:SAFARIBALL,:SPORTBALL]
        when :WHITEAPRICORN
          table=[:POKEBALL,:GREATBALL,:PREMIERBALL,:TIMERBALL,:FASTBALL,:SAFARIBALL,:SPORTBALL]
        when :YELLOWAPRICORN
          table=[:POKEBALL,:GREATBALL,:ULTRABALL,:QUICKBALL,:MOONBALL,:SAFARIBALL,:SPORTBALL]
      if $game_variables[30] >= 4 and $game_variables[30] < 6
        ratio=[247,123,247,247,67,67,1]
        craft=items[rand(items.length)]
        case craft
        when :BLACKAPRICORN
          table=[:HEAVYBALL,:GREATBALL,:DUSKBALL,:LUXURYBALL,:SAFARIBALL,:SPORTBALL,:MASTERBALL]
        when :BLUEAPRICORN
          table=[:LUREBALL,:GREATBALL,:DIVEBALL,:NETBALL,:SAFARIBALL,:SPORTBALL,:MASTERBALL]
        when :GREENAPRICORN
          table=[:FRIENDBALL,:GREATBALL,:ULTRABALL,:NESTBALL,:SAFARIBALL,:SPORTBALL,:MASTERBALL]
        when :PINKAPRICORN
          table=[:LOVEBALL,:GREATBALL,:ULTRABALL,:HEALBALL,:SAFARIBALL,:SPORTBALL,:MASTERBALL]
        when :REDAPRICORN
          table=[:LEVELBALL,:GREATBALL,:ULTRABALL,:REPEATBALL,:SAFARIBALL,:SPORTBALL,:MASTERBALL]
        when :WHITEAPRICORN
          table=[:FASTBALL,:GREATBALL,:PREMIERBALL,:TIMERBALL,:SAFARIBALL,:SPORTBALL,:MASTERBALL]
        when :YELLOWAPRICORN
          table=[:MOONBALL,:GREATBALL,:ULTRABALL,:QUICKBALL,:MOONBALL,:SAFARIBALL,:SPORTBALL,:MASTERBALL]
      if $game_variables[30] >= 6 and $game_variables[30] < 8
        ratio=[247,247,247,119,119,10,1]
        craft=items[rand(items.length)]
        case craft
        when :BLACKAPRICORN
          table=[:HEAVYBALL,:DUSKBALL,:LUXURYBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :BLUEAPRICORN
          table=[:LUREBALL,:DIVEBALL,:NETBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :GREENAPRICORN
          table=[:FRIENDBALL,:ULTRABALL,:NESTBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :PINKAPRICORN
          table=[:LOVEBALL,:ULTRABALL,:HEALBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :REDAPRICORN
          table=[:LEVELBALL,:ULTRABALL,:REPEATBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :WHITEAPRICORN
          table=[:FASTBALL,:PREMIERBALL,:TIMERBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :YELLOWAPRICORN
          table=[:MOONBALL,:ULTRABALL,:QUICKBALL,:MOONBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
      if $game_variables[30] >= 8
        ratio=[247,247,247,119,119,10,1]
        craft=items[rand(items.length)]
        case craft
        when :BLACKAPRICORN
          table=[:HEAVYBALL,:DUSKBALL,:LUXURYBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :BLUEAPRICORN
          table=[:LUREBALL,:DIVEBALL,:NETBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :GREENAPRICORN
          table=[:FRIENDBALL,:ULTRABALL,:NESTBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :PINKAPRICORN
          table=[:LOVEBALL,:ULTRABALL,:HEALBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :REDAPRICORN
          table=[:LEVELBALL,:ULTRABALL,:REPEATBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :WHITEAPRICORN
          table=[:FASTBALL,:PREMIERBALL,:TIMERBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
        when :YELLOWAPRICORN
          table=[:MOONBALL,:ULTRABALL,:QUICKBALL,:MOONBALL,:SAFARIBALL,:SPORTBALL,:DREAMBALL,:MASTERBALL]
You need an end after each case/when block, and one to close off the if/elsif/else block.Though you seem to have multiple if statements rather than if/elsif/else, so if you want to keep it that way, each if needs an end too.
not much of a fan of using a global game variable when a local one would do
Is that the Cram-o-matic? If it's my script, just below that block there's the same weighted ratio random selection that Wrigty described.
 
Back
Top