• 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.

CFRU Tutorial: Raid Battle Basics

42
Posts
2
Years
Hello 😁,

I've been working on my hack Unofficial Crystal to be a base for the CFRU and I wanted to take full advantage of all the features it offers but it was rather unfortune that I could not find any tutorials or anything on the Raid Battles section of the CFRU and the actual CFRU Documentation lacks much explanation so I wanna share what I did to get this potentially wonderful feature working.

As of writing this I still do not understand how to actually configure the CFRU source files for Raid Battles nor do I understand the use of their script specials but I did come up with a script that initiates a raid battle and still gives us a reward.

This is just scratching the surface of the raid battles feature. If anyone knows more about this feature please let me know! I'm open to anyone willing to educate me and I'll be glad to learn!

I've also embedded a video of the script in action, this was done on a vanilla test FireRed Rom.

CREDITS TO GREEN JERRY CAUSE I USED HIS TEXTBOX PATCH IN THE VIDEO



Heres a direct video link cause for some reason the embedded video doesn't work:
https://www.youtube.com/watch?v=EZopqcJeIzs

checkitemroom was not used in this script because any way I tried to insert it just caused a chain reaction of "No that won't work" and was a headache but the CFRU has the ability to store 778 unique items in the players bag which in my opinion is more than enough bag space. If anyone is willing to educate me on a way to insert the checkitemroom portion, I'm willing to learn! 😄

Here is the script in quotes with some comments to explain what each part of the script does:
#dynamic 0x800000
#define VAR_RESULT 0x800D // LASTRESULT
#define FLAG_RAID_BATTLE 0x919 // Same as CFRU Special 0x118 Start Raid Battle
#define FLAG_RAID_NO_FORCEEND 0x91A // Optional Raid Flag, was defined here but not used in the test script

//////////This section is basically setting up the script, give a intro message and details about which raids they might encounter, recommended level, and a disclaimer message about rewards and give the player the option to confirm the raid before it starts.//////////////////////////////////////////
#org @start
lock
msgbox @intro 0x6
msgbox @startraid 0x5
compare VAR_RESULT 0x0
if 0x1 goto @cancelled
setflag FLAG_RAID_BATTLE // sets flag 0x919 to inititate a raid
goto @chooseraid // Next section the script chooses which raid we get //

//////////This section of the script randomly chooses a value between 0-2 and places it in LASTRESULT 0x800D or in this script VAR_RESULT to decide which raid the player gets///////////
#org @chooseraid
random 0x3
compare VAR_RESULT 0x0
if 0x1 goto @squirtleraid
compare VAR_RESULT 0x1
if 0x1 goto @pikachuraid
compare VAR_RESULT 0x2
if 0x1 goto @charmanderraid

#org @squirtleraid
wildbattle 0x7 0x1 0x0 // the wildbattle command actually starts the raid if flag 0x919 is set
goto @battleoutcome // continues to next section after battle //

#org @pikachuraid
wildbattle 0x19 0x30 0x0 // the wildbattle command actually starts the raid if flag 0x919 is set
goto @battleoutcome // continues to next section after battle //

#org @charmanderraid
wildbattle 0x4 0x1 0x0 // the wildbattle command actually starts the raid if flag 0x919 is set
goto @battleoutcome [COLOR="Red"// continues to next section after battle //[/COLOR]

#org @battleoutcome // all this section does is check to see if we lost or ran away from the raid and if we did we don't get a reward //
special2 VAR_RESULT 0xB4 // checks our battle outcome and places it in LASTRESULT 0x800D or in this script VAR_RESULT //
compare VAR_RESULT 0x4 [COLOR="Red"]// if we ran away we don't the reward[/COLOR]
if 0x1 goto @cancelled
compare VAR_RESULT 0x5 // if we lost the raid we don't get the reward //
if 0x1 goto @cancelled
clearflag FLAG_RAID_BATTLE // clears flag 0x919 so we don't have every battle encounter be a raid battle
goto @reward1 // goes to the reward section of the script

///////This is what I came up with for the reward secton. In the little time I've messed with the raid feature(all of maybe 4 hours 😂), I couldn't think of any other way to script the reward sequence, but I'm sure I'll come up with something better in the future. It stills gives us a reward like special 0x11C but with the way its scripted there is a chance that we won't get a reward due to the random nature of the "random" command. ////////

#org @reward1
random 0x6
compare VAR_RESULT 0x0
if 0x1 goto @potion
compare VAR_RESULT 0x1
if 0x1 goto @masterball
compare VAR_RESULT 0x2
if 0x1 goto @rarecandy
compare VAR_RESULT 0x3
if 0x1 goto @fullrestore
compare VAR_RESULT 0x4
if 0x1 goto @fullheal
compare VAR_RESULT 0x5
if 0x1 goto @completed

#org @potion
giveitem 0xD 0x1 MSG_FIND
goto @reward1

#org @masterball
giveitem 0x1 0x1 MSG_FIND
goto @reward1

#org @rarecandy
giveitem 0x44 0x1 MSG_FIND
goto @reward1

#org @fullrestore
giveitem 0x13 0x1 MSG_FIND
goto @reward1

#org @fullheal
giveitem 0x17 0x1 MSG_FIND
goto @reward1

////Script is complete and tells the player the raid was completed/////
#org @completed
msgbox @done 0x6
release
end

/////If the script was ended prematurely/////
#org @cancelled
release
end

/////Text Strings//////
#org @intro
= [black_fr]You have requested a Raid Battle.\pRecommended Lvl: 5\pPotential Raids: Squirtle,\pPikachu, Charmander\pA MESSAGE ABOUT REWARDS\pIf you don't have enough bag space\nfor reward items then you simply\lwill not receive them.


#org @startraid
= [black_fr]Start the Raid Battle?

#org @done
= [black_fr]Raid battle has been completed.
 
106
Posts
4
Years
Here's some stuff I learnt while looking into it:

You can find a very basic raid battle script in CFRU's documentation.
Here's the script, with some comments:
Code:
#org @RaidScript_Start
special SPECIAL_IS_RAID_BATTLE_AVAILABLE //this special checks if there is a raid battle available, returns 0 (i believe) if there isn't.
compare LASTRESULT 0x0
if == goto @RaidScript_NoBattle //Stop the script if there is no battle.
msgbox @StartRaidBattle MSG_SIGN //Display a message about the battle
fadescreen FADEOUT_BLACK //Fade the screen to black
special SPECIAL_RAID_BATTLE_INTRO //display the raid battle screen
waitstate
compare LASTRESULT 0x0
if == goto @RaidScript_End //if b is pressed end the script?
setflag FLAG_TAG_BATTLE //make the battle a 2 on 1 battle
msgbox @PartnerTeamedUp MSG_SIGN //display a message
special SPECIAL_CREATE_RAID_MON //create the raid mon based on src/Tables/raid_encounters.h
special SPECIAL_START_RAID_BATTLE //start the battle
waitstate
special2 LASTRESULT 0xB4 //Get battle outcome
compare LASTRESULT 0x4 //Ran
if == goto @RaidScript_End
compare LASTRESULT 0x5 //Teleported / Lost Battle
if == goto @RaidScript_End
special SPECIAL_SET_RAID_BATTLE_FLAG //set a var that says there is no raid for this route
setvar 0x4000 0x0
#org @RaidScript_GiveReward
special SPECIAL_GIVE_RAID_BATTLE_REWARDS //give the rewards based on src/Tables/raid_encounters.h
compare LASTRESULT 0x0
if != goto @RaidScript_End //Done giving rewards
callstd MSG_FIND //show the [player] found [item] message
goto @RaidScript_GiveReward //go again

#org @RaidScript_End
release
end

That will make a raid battle, but if you copy and paste this into a script and compile, nothing will happen. Why? Because you haven't defined any raid partners or encounters.
For encounters, go to src/Tables/raid_encounters.h, first delete the Unbound stuff (in the #ifdef Unbound block) and copy and paste this template above gRaidsByMapSection and adjust it:
Code:
static struct Raid sRoute/*ROUTE_NUM*/Raids/*STAR_NUM (1-6)*/Star[] =
{
	{
		.species = SPECIES_, //species, examples: SPECIES_SQUIRTLE, SPECIES_CHARMANDER.
		.ability = RAID_ABILITY_2, //ability. can be RAID_ABILITY_1, (first ability), RAID_ABILITY_2, (second), RAID_ABILITY_HIDDEN, (hidden), RAID_ABILITY_RANDOM_1_2, (first or second), RAID_ABILITY_RANDOM_ALL, (any).
		.drops =
		{
		/*100 %*/ ITEM_ , //define items here, such as ITEM_FIRE_GEM, ITEM_CHOICE_BAND, ITEM_CLEVER_WING, etc.
		/* 80 %*/ ITEM_ ,
		/* 80 %*/ ITEM_ ,
		/* 50 %*/ ITEM_ ,
		/* 50 %*/ ITEM_ ,
		/* 30 %*/ ITEM_ ,
		/* 30 %*/ ITEM_ ,
		/* 25 %*/ ITEM_ ,
		/* 25 %*/ ITEM_ ,
		/*  5 %*/ ITEM_ , 
		/*  4 %*/ ITEM_ ,
		/*  1 %*/ ITEM_ ,
		},
	},
};
Inside of the gRaidsByMapSection table add this template and adjust it:
Code:
	[MAPSEC_ROUTE_/*ROUTE NUM*/ -  MAPSEC_DYNAMIC] =
	{
		[ONE_STAR_RAID] = {sRoute/*ROUTE_NUM*/Raids/*STAR_NUM*/Star, NELEMS(sRoute/*ROUTE_NUM*/Raids/*STAR_NUM*/Star)},
	},
Do this multiple times for each route and star. When you are done, open up raid_partners.h. I won't explain how to do this one, so before you delete the Unbound block check that and use it as a template to make your own.
If you do all of that, you should have raid battles!
Here's an example screenshot of what a raid might look like:
JwWKVFq.png
 
42
Posts
2
Years
Here's some stuff I learnt while looking into it:

You can find a very basic raid battle script in CFRU's documentation.
Here's the script, with some comments:
Code:
#org @RaidScript_Start
special SPECIAL_IS_RAID_BATTLE_AVAILABLE //this special checks if there is a raid battle available, returns 0 (i believe) if there isn't.
compare LASTRESULT 0x0
if == goto @RaidScript_NoBattle //Stop the script if there is no battle.
msgbox @StartRaidBattle MSG_SIGN //Display a message about the battle
fadescreen FADEOUT_BLACK //Fade the screen to black
special SPECIAL_RAID_BATTLE_INTRO //display the raid battle screen
waitstate
compare LASTRESULT 0x0
if == goto @RaidScript_End //if b is pressed end the script?
setflag FLAG_TAG_BATTLE //make the battle a 2 on 1 battle
msgbox @PartnerTeamedUp MSG_SIGN //display a message
special SPECIAL_CREATE_RAID_MON //create the raid mon based on src/Tables/raid_encounters.h
special SPECIAL_START_RAID_BATTLE //start the battle
waitstate
special2 LASTRESULT 0xB4 //Get battle outcome
compare LASTRESULT 0x4 //Ran
if == goto @RaidScript_End
compare LASTRESULT 0x5 //Teleported / Lost Battle
if == goto @RaidScript_End
special SPECIAL_SET_RAID_BATTLE_FLAG //set a var that says there is no raid for this route
setvar 0x4000 0x0
#org @RaidScript_GiveReward
special SPECIAL_GIVE_RAID_BATTLE_REWARDS //give the rewards based on src/Tables/raid_encounters.h
compare LASTRESULT 0x0
if != goto @RaidScript_End //Done giving rewards
callstd MSG_FIND //show the [player] found [item] message
goto @RaidScript_GiveReward //go again

#org @RaidScript_End
release
end

That will make a raid battle, but if you copy and paste this into a script and compile, nothing will happen. Why? Because you haven't defined any raid partners or encounters.
For encounters, go to src/Tables/raid_encounters.h, first delete the Unbound stuff (in the #ifdef Unbound block) and copy and paste this template above gRaidsByMapSection and adjust it:
Code:
static struct Raid sRoute/*ROUTE_NUM*/Raids/*STAR_NUM (1-6)*/Star[] =
{
	{
		.species = SPECIES_, //species, examples: SPECIES_SQUIRTLE, SPECIES_CHARMANDER.
		.ability = RAID_ABILITY_2, //ability. can be RAID_ABILITY_1, (first ability), RAID_ABILITY_2, (second), RAID_ABILITY_HIDDEN, (hidden), RAID_ABILITY_RANDOM_1_2, (first or second), RAID_ABILITY_RANDOM_ALL, (any).
		.drops =
		{
		/*100 %*/ ITEM_ , //define items here, such as ITEM_FIRE_GEM, ITEM_CHOICE_BAND, ITEM_CLEVER_WING, etc.
		/* 80 %*/ ITEM_ ,
		/* 80 %*/ ITEM_ ,
		/* 50 %*/ ITEM_ ,
		/* 50 %*/ ITEM_ ,
		/* 30 %*/ ITEM_ ,
		/* 30 %*/ ITEM_ ,
		/* 25 %*/ ITEM_ ,
		/* 25 %*/ ITEM_ ,
		/*  5 %*/ ITEM_ , 
		/*  4 %*/ ITEM_ ,
		/*  1 %*/ ITEM_ ,
		},
	},
};
Inside of the gRaidsByMapSection table add this template and adjust it:
Code:
	[MAPSEC_ROUTE_/*ROUTE NUM*/ -  MAPSEC_DYNAMIC] =
	{
		[ONE_STAR_RAID] = {sRoute/*ROUTE_NUM*/Raids/*STAR_NUM*/Star, NELEMS(sRoute/*ROUTE_NUM*/Raids/*STAR_NUM*/Star)},
	},
Do this multiple times for each route and star. When you are done, open up raid_partners.h. I won't explain how to do this one, so before you delete the Unbound block check that and use it as a template to make your own.
If you do all of that, you should have raid battles!
Here's an example screenshot of what a raid might look like:
JwWKVFq.png

Thank you for sharing! 😁

It's starting to make more sense the more I mess with it. The problem I had before was getting the CFRU to compile after adding the raid battle data in src/Tables/raid_encounters.h and src/Tables/raid_partners.h. I'll attach a screenshot of the error when I get a chance. I do have a couple questions.
Do you have to have raid partners in order for the specials to work?
Do you have to insert entries for every location and every encounter for each star raid before you try to compile?
When I tested I only had one entry for one encounter for only a one star raid and it threw an error when I tried to compile.
 
106
Posts
4
Years
Thank you for sharing! 😁

It's starting to make more sense the more I mess with it. The problem I had before was getting the CFRU to compile after adding the raid battle data in src/Tables/raid_encounters.h and src/Tables/raid_partners.h. I'll attach a screenshot of the error when I get a chance. I do have a couple questions.
Do you have to have raid partners in order for the specials to work?
Do you have to insert entries for every location and every encounter for each star raid before you try to compile?
When I tested I only had one entry for one encounter for only a one star raid and it threw an error when I tried to compile.
Sorry, didn't see you asked questions when you responded.
If you have discord, add me: Greenphx#5428 and I'll try and help you
If not just post the images of errors here.
 
Back
Top