• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Development: RNG and Weather

interdpth

I've seen things, man.
275
Posts
19
Years
  • Seen Jun 8, 2021
I'd prefer seeing the RNG script as assembly and not a script and it'd be able to store the value in lastresult pretty easily.

Then an example script would be like

#define normal 1
#define cloudy 2
etc

call asm $blah 'rng number will be stored here
cmp lastresult normal
if 1 goto normalscript
cmp lastresult cloudy
if 1 goto cloudyscript
etc
I see something like that being much perferable
 

interdpth

I've seen things, man.
275
Posts
19
Years
  • Seen Jun 8, 2021
Hmm, a easy solution i'd see is to make the script for one town, make sure it'd work, then place a hook in the level loading script before the map script( so map script over rides your weather) the asm hook would make your script execute every time a level loads, I see that as very feasible, i'd be willing to make the hook for FR/LG if you or some one can do the scripting
 

DreadWaffle

LOVE AND PEACE!
165
Posts
14
Years
first off, i like where this is going
second, when you enter the maps like indoors it would run by your last comment, but i believe that you could get around that, or that it isn't even a problem to start with.
and interdpth, with the RTC for Fr/Lg you have, this could inevitably be a staple for all hacking

third, i wish i new more about this stuff 0.o
 

interdpth

I've seen things, man.
275
Posts
19
Years
  • Seen Jun 8, 2021
This huge script by colcolstyles has an implementation of the weatherwork above. Thing is, I haven't actually been able to work it.

heh, I think that that's just an example what with those variables and all.

DreadWaffles post made me think of numerous possibilities this effect could have with the day and night systems.

I think amazing effects can be pulled off with this.
 

DreadWaffle

LOVE AND PEACE!
165
Posts
14
Years
DreadWaffles post made me think of numerous possibilities this effect could have with the day and night systems.

SUCSESS!

This huge script by colcolstyles has an implementation of the weatherwork above. Thing is, I haven't actually been able to work it.

that helps me understand it a bit more, so thanks Anthony colcolstyles
just so many things, and it seems simple, but it isn't i believe
this kind of opens up a whole new world of scripting ideas for me, i would make a thread but i don't know to much hex :laugh:

but i have some ideas like adding onto what was already there
EX: if it is 6:00pm-6:00am chances from sunny(clear) to: Clouds 7/20, Rain 3/20, the same 8/20 and, Thunderstorm 2/20.
and also for different areas like snow/ice, lake affect, valleys, and droughts
I have realized that if this works out possibilities are near endless

just wish i could help :'(
 

Darthatron

巨大なトロール。
1,152
Posts
18
Years
This probably won't be anything interdpth doesn't know already but here is some information about the RAM regarding weather:

The default weather for a map is stored at 0x02036E12 in the RAM, it's 8 bit by the way. Surely this can be used to create maps with a higher chance of a certain weather than other.

And the 8 bit value at 0x02036E13 contains the type of map.
Code:
0x01 - Village/Town
0x02 - City
0x03 - Route
[B]0x04 - Underground
0x05 - Underwater
0x08 - Inside
0x09 - Secret base[/B]
Obviously the ones in bold would not be effected by weather.

EDIT: Tell me if you think I should just edit this new information into the script that has been posted, it won't be difficult.

EDIT2: As it turns out I have already created a similar script a while ago, though I only have the compiled version at the moment I can easily edit it to your needs... I'll implement my RAM data and also your preferred likeliness of weather, then post it.
 
Last edited:

Darthatron

巨大なトロール。
1,152
Posts
18
Years
There actually a command that reads the set map value, though?

Not for someone who doesn't know there way around the ROM:
Code:
setvar 0x8000 0x0000
copybyte 0x020370B8 0x02036E12
setvar 0x8001 0x0000
copybyte 0x020370BA 0x02036E13

That script will store the default weather in variable 0x8000, and the map type in variable 0x8001.
 

Darthatron

巨大なトロール。
1,152
Posts
18
Years
However, the point is for the script to read a variable that's stored - preferably permanently. The "current condition" in this script intentionally reads from a stored value to determine what the weather was at one point. Once the current variable is found, the script runs an RNG specified by the hacker to determine the next condition. There is little use in reading the variable for the map's weather unless one of the bytes determined whether to disable the script.

To an extent, yes. But think of it this way: You're more likely to have snow in the mountains than, say, the beach. Simply enabling certain maps to have more of a chance of certain weather may be an upside. I do see your point, however.

EDIT: One working natural weather script that won't work indoors.

Code:
#dynamic 0x800000

#define V_MAPTYPE 0x8000
#define V_WEATHER 0x7000  //This must be set to a value between 1 and 4 to work.
#define V_RANDVAL 0x7001

#define W_SUNNY 0x02
#define W_CLOUDY 0x0B
#define W_RAIN 0x03
#define W_THUNDER 0x0D

[I][COLOR="Red"]#org @Setup
setvar V_WEATHER 0x01
setweather W_SUNNY
doweather
end[/COLOR][/I]

#org @Main
[B][COLOR="Red"]setvar 0x8000 0x0000
copybyte 0x020370B8 0x02036E13
compare 0x8000 0x03
if B_>> goto @Quit[/COLOR][/B]
random 0x13 //Create a random value between 0 and 19.
copyvar V_RANDVAL LASTRESULT
compare V_WEATHER 0x01
if B_TRUE call @CurrentlySunny
compare V_WEATHER 0x02
if B_TRUE call @CurrentlyCloudy
compare V_WEATHER 0x03
if B_TRUE call @CurrentlyRaining
compare V_WEATHER 0x04
if B_TRUE call @CurrentlyStorming
doweather
end

#org @Quit
end

#org @BecomeSunny
setweather W_SUNNY
setvar V_WEATHER 0x01
setvar V_RANDVAL 0xFF //Make the random value an impossible number to make sure it can't mess up.
return

#org @BecomeCloudy
setweather W_CLOUDY
setvar V_WEATHER 0x02
setvar V_RANDVAL 0xFF //Make the random value an impossible number to make sure it can't mess up.
return

#org @BecomeRaining
setweather W_RAIN
setvar V_WEATHER 0x03
setvar V_RANDVAL 0xFF //Make the random value an impossible number to make sure it can't mess up.
return

#org @BecomeStorming
setweather W_THUNDER
setvar V_WEATHER 0x04
setvar V_RANDVAL 0xFF //Make the random value an impossible number to make sure it can't mess up.
return

#org @CurrentlySunny
compare V_RANDVAL 0x01 //10% chance of becoming cloudly.
if B_<= call @BecomeCloudy
compare V_RANDVAL 0x02 //5% chance of it raining.
if B_<= call @BecomeRaining
compare V_RANDVAL 0x13 //85% chance of the weather staying the same.
if B_<= call @BecomeSunny
return

#org @CurrentlyCloudy
compare V_RANDVAL 0x04 //25% chance of becoming sunny.
if B_<= call @BecomeSunny
compare V_RANDVAL 0x06 //10% chance of it staying cloudy.
if B_<= call @BecomeCloudy
compare V_RANDVAL 0x10 //50% chance that it will start raining.
if B_<= call @BecomeRaining
compare V_RANDVAL 0x13 //15% chance that a thunder storm will start.
if B_<= call @BecomeStorming
return

#org @CurrentlyRaining
compare V_RANDVAL 0x06 //35% chance that it will keep raining.
if B_<= call @BecomeRaining
compare V_RANDVAL 0x08 //10% chance of it becoming sunny.
if B_<= call @BecomeSunny
compare V_RANDVAL 0x10 //40% chance that it will become cloudy.
if B_<= call @BecomeCloudy
compare V_RANDVAL 0x13 //15% chance that a thunder storm will start.
if B_<= call @BecomeStorming
return

#org @CurrentlyStorming
compare V_RANDVAL 0x0C //65% chance that it will start raining.
if B_<= call @BecomeRaining
compare V_RANDVAL 0x0F //15% chance of it becoming cloudy
if B_<= call @BecomeCloudy
compare V_RANDVAL 0x13 //20% chance that the thunder storm will continue.
if B_<= call @BecomeStorming
return

I tested it quite a bit and it worked fine, but if you find a problem, just tell me...

You won't need the bold lines if you're manually putting them on each map.
The italic lines are there merely the set up the script to work, you don't run this from the level script, you run @Main.
 
Last edited:

Pokepal17

More cowbell~
1,519
Posts
15
Years
Hmm, there is one other graphical problem you need to get around. As in Liquid Crystal, when the weather is forced to be changed by the "setweather" command, sometimes the weather palette doesn't refresh. I don't know whether that's secific to that hack, but I believe it will apply to all ROMs because I've noticed that the natural weather change from maps is not immediate. I would say that instead of using "setweather" edit it directly from the ram. (However this might still do the same things which would cause for maybe a big recoding :0)
 

Pokepal17

More cowbell~
1,519
Posts
15
Years
Is it just an issue with FRLG (because weather almost doesn't exist in the game by default) or is the issue also there in RSE?

I don't know. I assume it probably is since FRLG was built of the RSE engine. It's okay switching back and forth from one weather effect, but when it's 3 or 4 different forced weather effects, the palette bug kicks in. Recoding would probably work, but I'm wondering if there's a less tedious way.
 

Darthatron

巨大なトロール。
1,152
Posts
18
Years
Hmm, there is one other graphical problem you need to get around. As in Liquid Crystal, when the weather is forced to be changed by the "setweather" command, sometimes the weather palette doesn't refresh. I don't know whether that's secific to that hack, but I believe it will apply to all ROMs because I've noticed that the natural weather change from maps is not immediate. I would say that instead of using "setweather" edit it directly from the ram. (However this might still do the same things which would cause for maybe a big recoding :0)

I've never experienced that problem and last night I spent over an hour testing that script. :\ Think you can make a video example of it happening?
 

Pokepal17

More cowbell~
1,519
Posts
15
Years
I've never experienced that problem and last night I spent over an hour testing that script. :\ Think you can make a video example of it happening?

There probably is in a lot of Liquid Crystal walkthroughs. However, I have never encountered ot myself, so I don't know whether it was specific to that hack, but I was just making you guys aware of it, I'll find a vid of it, however if testing doesn't prove it, then it can be said that the bug is only limited to that hack.

EDIT: It seems that his bug was confined to Liquid Crystal only, so ignore it for now.
 
Last edited:

colcolstyles

Yours truly
1,588
Posts
15
Years
I was using a Fire Red ROM when I was testing my script and I never encountered any problems. I was using a "01 'setmaptile' script" level script, if that makes any difference.
 

Darthatron

巨大なトロール。
1,152
Posts
18
Years
I was using a Fire Red ROM when I was testing my script and I never encountered any problems. I was using a "01 'setmaptile' script" level script, if that makes any difference.
I saw a pretty major problem in your script:

Say V_RANDVAR = 1...
Code:
#org @sunnyscript
compare V_RANDVAR 0x1 ' 2/20 chance of becoming cloudy
if B_<= goto @becomecloudy
compare V_RANDVAR 0x2 ' 1/20 chance of spontaneous rain
if B_<= goto @becomerainy
setweather W_SUNNY ' 17/20 chance of remaining the same
return
It would set the weather cloudy, then set the weather to rain, and finally set it back to sunny. This is because the value of V_RANDVAR is kept the entire script, so nothing can ever change.

I don't know how you would have got it to work. :\
 

colcolstyles

Yours truly
1,588
Posts
15
Years
I saw a pretty major problem in your script:

Say V_RANDVAR = 1...
Code:
#org @sunnyscript
compare V_RANDVAR 0x1 ' 2/20 chance of becoming cloudy
if B_<= goto @becomecloudy
compare V_RANDVAR 0x2 ' 1/20 chance of spontaneous rain
if B_<= goto @becomerainy
setweather W_SUNNY ' 17/20 chance of remaining the same
return
It would set the weather cloudy, then set the weather to rain, and finally set it back to sunny. This is because the value of V_RANDVAR is kept the entire script, so nothing can ever change.

I don't know how you would have got it to work. :\

I'm going to say right now that this explanation is going to suck but I'll give it my best shot.

In @main, @sunnyscript is called. However, in @sunnyscript (and the other corresponding scripts), @becomecloudy is accessed with 'goto'. So when the GBA reads the 'return' statement in @becomecloudy, it actually picks up where it left off all the way back in @main.

Hopefully you see what I did. It's a little hard to read because Pokémon scripting doesn't have "else if" statements.

I tested it quite a bit and it worked pretty darn well, if I may say so myself.
 

Darthatron

巨大なトロール。
1,152
Posts
18
Years
I'm going to say right now that this explanation is going to suck but I'll give it my best shot.

In @main, @sunnyscript is called. However, in @sunnyscript (and the other corresponding scripts), @becomecloudy is accessed with 'goto'. So when the GBA reads the 'return' statement in @becomecloudy, it actually picks up where it left off all the way back in @main.

Hopefully you see what I did. It's a little hard to read because Pokémon scripting doesn't have "else if" statements.

I tested it quite a bit and it worked pretty darn well, if I may say so myself.

I see your point now actually, I completely ignored that fact, sorry. Well then... I wonder why your script didn't work for Anthony La. :\

On a side note, your script should have "random 0x13" since it would give a random value between 0 and 19. Your current script is out of 21 possible situations, not 20. ;)
 

colcolstyles

Yours truly
1,588
Posts
15
Years
I see your point now actually, I completely ignored that fact, sorry. Well then... I wonder why your script didn't work for Anthony La. :\

On a side note, your script should have "random 0x13" since it would give a random value between 0 and 19. Your current script is out of 21 possible situations, not 20. ;)

Ah, good catch. Strange, though, because I factored the possibility of 'random' returning zero into several parts of the script. You would think that I would have picked up on that. Oh well, simple fix.

Though the part that you originally pointed out seems to be correct, I think I just spotted another bug. Again, I'm terrible at explaining things but bear with me here:

Let's say the weather is currently sunny. Control would branch off to @sunnyscript. Now let's say the random number that was returned 0x1, which would therefore activate @becomecloudy. However, in @becomecloudy, V_WEATHER is actually changed to W_CLOUDY. This might cause a bug when control returns to @main because the script will check if V_WEATHER is set to W_CLOUDY. Because of this, it would be possible for it to go straight to a thunderstorm from sunny and it also increases chances of spontaneous rain too.
It can be fixed by replacing all the "call"s in @main to "goto"s and then changing the "return"s in @becomesunny/cloudy/etc. to "goto @end" and adding:
Code:
#seek @end
doweather
end
... I think. But then again, you're the programmer. :P
 

Darthatron

巨大なトロール。
1,152
Posts
18
Years
Ah, good catch. Strange, though, because I factored the possibility of 'random' returning zero into several parts of the script. You would think that I would have picked up on that. Oh well, simple fix.

Though the part that you originally pointed out seems to be correct, I think I just spotted another bug. Again, I'm terrible at explaining things but bear with me here:

Let's say the weather is currently sunny. Control would branch off to @sunnyscript. Now let's say the random number that was returned 0x1, which would therefore activate @becomecloudy. However, in @becomecloudy, V_WEATHER is actually changed to W_CLOUDY. This might cause a bug when control returns to @main because the script will check if V_WEATHER is set to W_CLOUDY. Because of this, it would be possible for it to go straight to a thunderstorm from sunny and it also increases chances of spontaneous rain too.
It can be fixed by replacing all the "call"s in @main to "goto"s and then changing the "return"s in @becomesunny/cloudy/etc. to "goto @end" and adding:
Code:
#seek @end
doweather
end
... I think. But then again, you're the programmer. :P

That definitely seems logical. Try it out and if it doesn't work then no harm is done, right? :P But yeah, from my point of view that should work. Good catch, by the way.

EDIT: It would save space to just replace the "return"s with the code you posted. "goto" uses 5 bytes, but...
Code:
doweather
end
...uses 2 bytes. ;)

EDIT2: Here is my script which will be quicker and save space. :)
Code:
#dynamic 0x800000

#define V_MAPTYPE 0x8000
#define V_WEATHER 0x7000  //This must be set to a value between 1 and 4 to work.
#define V_RANDVAL 0x7001

#define W_SUNNY 0x02
#define W_CLOUDY 0x0B
#define W_RAIN 0x03
#define W_THUNDER 0x0D

#org @Setup
setvar V_WEATHER 0x01
setweather W_SUNNY
doweather
end

#org @Main
setvar 0x8000 0x0000
copybyte 0x020370B8 0x02036E13
compare 0x8000 0x03
if B_>> goto @Quit
random 0x13 //Create a random value between 0 and 19.
copyvar V_RANDVAL LASTRESULT
compare V_WEATHER 0x01
if B_TRUE goto @CurrentlySunny
compare V_WEATHER 0x02
if B_TRUE goto @CurrentlyCloudy
compare V_WEATHER 0x03
if B_TRUE goto @CurrentlyRaining
compare V_WEATHER 0x04
if B_TRUE goto @CurrentlyStorming
end

#org @Quit
end

#org @BecomeSunny
setweather W_SUNNY
setvar V_WEATHER 0x01
doweather
end

#org @BecomeCloudy
setweather W_CLOUDY
setvar V_WEATHER 0x02
doweather
end


#org @BecomeRaining
setweather W_RAIN
setvar V_WEATHER 0x03
doweather
end

#org @BecomeStorming
setweather W_THUNDER
setvar V_WEATHER 0x04
doweather
end

#org @CurrentlySunny
compare V_RANDVAL 0x01 //10% chance of becoming cloudly.
if B_<= goto @BecomeCloudy
compare V_RANDVAL 0x02 //5% chance of it raining.
if B_<= goto @BecomeRaining
compare V_RANDVAL 0x13 //85% chance of the weather staying the same.
if B_<= goto @BecomeSunny
end

#org @CurrentlyCloudy
compare V_RANDVAL 0x04 //25% chance of becoming sunny.
if B_<= goto @BecomeSunny
compare V_RANDVAL 0x06 //10% chance of it staying cloudy.
if B_<= goto @BecomeCloudy
compare V_RANDVAL 0x10 //50% chance that it will start raining.
if B_<= goto @BecomeRaining
compare V_RANDVAL 0x13 //15% chance that a thunder storm will start.
if B_<= goto @BecomeStorming
end

#org @CurrentlyRaining
compare V_RANDVAL 0x06 //35% chance that it will keep raining.
if B_<= goto @BecomeRaining
compare V_RANDVAL 0x08 //10% chance of it becoming sunny.
if B_<= goto @BecomeSunny
compare V_RANDVAL 0x10 //40% chance that it will become cloudy.
if B_<= goto @BecomeCloudy
compare V_RANDVAL 0x13 //15% chance that a thunder storm will start.
if B_<= goto @BecomeStorming
end

#org @CurrentlyStorming
compare V_RANDVAL 0x0C //65% chance that it will start raining.
if B_<= goto @BecomeRaining
compare V_RANDVAL 0x0F //15% chance of it becoming cloudy
if B_<= goto @BecomeCloudy
compare V_RANDVAL 0x13 //20% chance that the thunder storm will continue.
if B_<= goto @BecomeStorming
end
 
Last edited:

colcolstyles

Yours truly
1,588
Posts
15
Years
That definitely seems logical. Try it out and if it doesn't work then no harm is done, right? :P But yeah, from my point of view that should work. Good catch, by the way.

Man, all that time spent coordinating the "call"s and "goto"s and now I don't even need them. :'(

I don't know if I should even bother fixing it as it seems like interdpth has some snazzy ASM plan which makes my method look pretty rudimentary. With mine, you have to add a level script for every single map that you want random weather on. Though the fact that you don't have to edit indoor maps (unless you want it to rain inside^^) makes things easier, it's still a hassle.

Still, I'm interested in seeing what you guys come up with. I could try to help out but my ASM knowledge is pretty pathetic. :(

Best of luck.
 

Darthatron

巨大なトロール。
1,152
Posts
18
Years
Man, all that time spent coordinating the "call"s and "goto"s and now I don't even need them. :'(

I don't know if I should even bother fixing it as it seems like interdpth has some snazzy ASM plan which makes my method look pretty rudimentary. With mine, you have to add a level script for every single map that you want random weather on. Though the fact that you don't have to edit indoor maps (unless you want it to rain inside^^) makes things easier, it's still a hassle.

Still, I'm interested in seeing what you guys come up with. I could try to help out but my ASM knowledge is pretty pathetic. :(

Best of luck.
The only thing he is planning on doing is making it so your or my script is called every time a map is loaded. I'll keep you updated. I think I have you added on MSN? :\
 
Back
Top