Skeetendo

’Cause all games were better on the GBC

You are not logged in.

#1 2012-10-04 14:33:22

Zarator
Member
Registered: 2012-09-30
Post 7/49

A clarification about flags

Hello, sorry for bothering you again with a question that could be seen as banal, but after making some research there are still some unclear things I'd like to understand. Basically, I wanted to understand how to make a certain people event (like a person, an item, a legendary, etc) appear/disappear according to a certain event.

In order to understand something, I read the stuff I found in this topic (http://hax.iimarck.us/topic/186/), as well as analyzing two events in Blackthorn City (the guy standing in front of gym and the one in front of Dragon Den's entrance). As far as I could understand, the flags have nothing to do with the script you decompile via PKSV in this case. I decompiled the guy in front of Dragon Den and nothing in the script hinted to flags. So I concluded that it was probably all about the "Flag Index" and "Flag Bit" windows in Johtomap.

Furthermore, I supposed that, since the Flag Index changes with the guys' position (like, the person in front of the Gym door has E3 for when he blocks door and E4 for when he doesn't), probably it was Flag Index that identifies a certain event happened / didn't happen. However I'm unclear about the role of the Flag Bit.
For example, the guy who blocks Dragon Den has Flag Bit 7. The same guy, when he doesn't block Dragon Den anymore, still has Flag Bit 7. Santos, the Day of the Week Sibling who appears on Saturday, has Flag Bit 7 too. I really don't understand how to consider this value - maybe it's something akin to banks and headers, but for flags? I really don't know...

Now, even assuming I find the right "Flag Index" and "Flag bit" for a certain event, are they universal? For example, the Flag Index for beating Clair in Blackthorn City before getting the medal (I suppose it's 4D since the guy who doesn't block Dragon Den has it)... is it the same for all the events activated by it? Even in maps other than Blackthorn City?

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Now, this is for the general questions. My aim in particular would be to make a Celebi in Ilex Forest who is visible only after you get the 8th Badge from Clair. I can make the Celebi event, but I'd like to know how to manage the appearing/disappearing of it properly with flags.

Thanks for the help.

Offline

#2 2012-10-04 14:39:13

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 1,621/3,508

Re: A clarification about flags

Johtomap is confusing like that. They reall are not two separate values, but one two-byte value. Koolboyman made a list of most if not all of the flags used by the game, and you can find a link to it in kkj1116's stickied thread. Flags are universal, though. Any person with the same flag will be hidden or shown at the same time. You could remove an itemball in Mt Silver and use it to add Celebi to Ilex Forest, for example.

Offline

#3 2012-10-04 15:33:24

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 1,622/3,508

Re: A clarification about flags

Particularly, This thread on Pokecommunity is the one I was referencing that Koolboyman made. It was linked in This thread. I would have linked earlier, but I was on my phone and its more annoying to do it that way.

Offline

#4 2012-10-04 15:33:42

Zarator
Member
Registered: 2012-09-30
Post 8/49

Re: A clarification about flags

Well, I did check that list some time ago, and I found:

2100 = Clair

I was wondering, though:
1) Is this flag for getting the badge from Clair? Or does it mean something else?
2) How can I set a person event to be hidden, and then visible after flag is checked? And what about viceversa?
3) If I change an itemball to a legendary encounter, and that itemball has been looted already in someone's game, will they still get to battle the legend or not?

Offline

#5 2012-10-04 15:46:51

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 1,623/3,508

Re: A clarification about flags

1)Okay, Table 2 is NOT the same as the ones used for showing/hiding events, which are Table 1. Setting that flag will mark you as having Claire's badge on the trainer card, so you are right.
2)A person event is hidden if its flag is set, and shown if it is not. If you want to temporarily show one that is already hidden, you can use the show and hide commands to make them come back and go away again though.
3)If you turned an item ball into a pokemon, and someone had already taken that item ball, then it would treat that as you having already battled the Pokemon. But if you remove the item ball, there is no way for them to get it. You just tell them not to use a saved game from original gold. It's pretty standard to expect people to start a hack from a new game, and not continue from a normal gold save. If you tried to use a normal gold save to play the Christmas Hack, you would be in a mess lol.

Offline

#6 2012-10-04 16:21:31

Zarator
Member
Registered: 2012-09-30
Post 9/49

Re: A clarification about flags

So, just to be sure... On table 1 Clair's flag seems to be C404. However, I don't understand how to use it with Index and Bit. For example, Santos's Flag Index is 5D, his Flag Bit is 7... what does it have to do with the two flags I found in the thread you linked? I'm talking about:

6C00 = Santos
6D00 = Santos Flag 2

Is there some way to translate them, like with pointers and offsets? And btw, you mentioned some posts before that I can simply move one itemball from a map to another. I'm a bit unclear on what you mean, so far I always used people events that were already in the map, just changing the script and the pointer accordingly. If you mean adding an event like you showed in this topic (http://hax.iimarck.us/topic/18/) I tried and got some bugs, so I'll figure it out later most likely. I was just interested to know if this is what you were suggesting or if it was something simpler.

Offline

#7 2012-10-04 16:59:25

Miksy91
Member
Registered: 2010-10-16
Post 1,136/2,317

Re: A clarification about flags

5D07 is the bit number that's used for Santos' person in Blackthorn City's map (was it Blackthorn City, whatever...). You won't get far by playing around with PKSV and Johtomap though, the best way to learn would be by doing stuff first with a hex editor and seeing how PKSV and Johtomap show the event datas and scripts you write with it.

According to what I said about 5D07, you can probably guess Clair's flag being C4 4 as what Johtomap would show it in Flag Index/Flag Bit boxes.

Not sure what I should reply to rest of your post so stuff wouldn't get too complicated as of now...
Open the G/S scripting compendium, check how event structure works and how simple scripts can be built with a hex editor and you're good to go. There is no point in trying to learn how bit numbers work properly before you can actually script events that use bit table checks.

Offline

#8 2012-10-04 20:57:45

Zarator
Member
Registered: 2012-09-30
Post 10/49

Re: A clarification about flags

Well, I try to do what I can via hexes. For example, I used only hexes to change trainer rosters and such. But when I tried to read Tauwasser's compendium about event structures, I couldn't actually understand it very well. Anyway, for reference I checked Lugia's script (since Lugia too is initially hidden and then it appears after a certain event happens), and well... it has a setbit1 0x318 in the script, but its Flag Index is 3D and its Flag Bit is 7 (I compared it to Ho-Oh too... Ho-Oh has setbit1 0x317, Flag Index 3C and Flag Bit 7). If the Flag Index is C4 and the Flag Bit is 4 for my event... what should I write in the script? It doesn't look exactly as a pointer - well, not one I can decodify with Pointer Berechner

Offline

#9 2012-10-05 05:31:02

Miksy91
Member
Registered: 2010-10-16
Post 1,139/2,317

Re: A clarification about flags

Lugia being hidden/shown is probably programmed this way (which goes for Ho-Oh as well):

Bit No.: 3D07

Script called from map's script header:
checkbit1 0x318
if true @hide
checkitem SILVER WING
if true ("in pocket") @appear
disappear 0x2 (hide lugia)
return

@hide
disappear 0x2
return

@appear
appear 0x2
return

When the game starts, certain bit numbers are set from the beginning of which 3D07 is one of. So, lugia will be hidden when you approach that room without getting SILVER WING first. When you've that item, lugia is made to appear and as you fight it, bit 3108 is set making it so that when the room is entered again, lugia will always be hidden no matter whether you've SILVER WING or not. Kind of complicated way to create this hiding script for it if you ask me but it works...

Last edited by Miksy91 (2012-10-05 05:33:06)

Offline

#10 2012-10-05 14:31:21

Zarator
Member
Registered: 2012-09-30
Post 11/49

Re: A clarification about flags

See, the reason why I'm asking is because Lugia's script is not as intuitive as you may think. This is what it appears in PKSV:

#org 0x11C1A0
'-----------------------------------
faceplayer
loadfont
2writetext 0x41C8 ' 0x11C1C8
cry 0xF9
pause 0xF
loadmovesprites
setbit1 0x318
checkver
if true 0x41BD ' 0x11C1BD
writecode 0x3 0xA
loadpokedata 0xF9 0x46
startbattle
disappear 0x2
returnafterbattle
end

#org 0x11C1BD
'-----------------------------------
writecode 0x3 0xA
loadpokedata 0xF9 0x28
startbattle
disappear 0x2
returnafterbattle
end


#org 0x11C1C8
= Gyaaas!\e

I'm not considering the last two offsets since they're seemingly unimportant in this context. However, if you look at the first part, you'll see that there is nothing like a HIDE script of sorts, besides that setbit1 0X318. Heck, I even tried to write hide and it is not among PKSV's recognized scripts (like, say, writecode or disappear). What I wanted to ask is: is there some way to find a correspondence between the Flag Index + Flag Bit and the setbit1 I likely need to use to show the event? Because if I could find it I would likely have all I need to set up Celebi's event...

Offline

#11 2012-10-05 14:52:43

comet
Member
Registered: 2012-04-09
Post 19/679

Re: A clarification about flags

Miksy91 wrote:

Script called from map's script header:

Offline

#12 2012-10-05 15:54:11

Zarator
Member
Registered: 2012-09-30
Post 12/49

Re: A clarification about flags

Yeah sorry my bad. I'm still such an amateur at this <.< Still, after decompiling the map script header for Lugia's map (0x11C187 according to Johtomap) I feel even more confused.

#org 0x11C187
'-----------------------------------
2call 0x201 ' 0xFFFFFFFF
priorityjump 0x3141 ' 0xFFFFFFFF

What does this have to do with what Miksy91 said?

Offline

#13 2012-10-05 17:38:26

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 1,627/3,508

Re: A clarification about flags

Johtomap doesn't properly read the pointers for script headers. The pointer for the script header that it reads doesn't actually point directly to the script, it points to the format detailed in the compendium. What you can do however is to go the offset that Johtomap gives you in a hex editor, find the actual pointer there (the compendium will explain) and then tell PKSV to decompile from that offset.

Offline

#14 2012-10-06 09:45:38

Zarator
Member
Registered: 2012-09-30
Post 13/49

Re: A clarification about flags

Just to be sure, the "proper pointer" to the script header I need to look for is the "two bytes" you talk about here? http://hax.iimarck.us/topic/18/

"This has taken us into the map header. You will notice that there are two more bytes between the first byte of the event pointer and the last two we saw in Goldmap. These point to the map script, so we ignore them for now. Take the pointer you found in step two and type the last two bytes of it over the ones for the old event data. In my case, I typed 8061 over AA47. Save your rom with a new name so you have the original as a backup. You'll see why in the next step. Congratulations! You've just repointed the event data!"

EDIT: I'm asking because I tried that, and when I put 8741 (still for Lugia's map) in the pointer calculator, I got Offset 187, which seems quite... improbable. Also, I read Tauwasser's event structure and I found it as incomprehensible as the script structure.

[[Number1 of pointers] Number1 * [2byte pointer to script][00][00]][[Number2 of pointers] Number2 * [Number][2byte pointer to script]]

IMO it'd be much simpler if he posted an example and said, say:

01 87 44 18 25 A6 (just putting random numbers here, in the proper example you'd probably put a real header of sorts)

and then explain what 01 is, what 87 is, and so on. Those brackets are really confusing, and I don't even understand what byte refers to what thing in the structure... or even how long is the byte string supposed to be!

Last edited by Zarator (2012-10-06 09:48:44)

Offline

#15 2012-10-06 14:03:18

Miksy91
Member
Registered: 2010-10-16
Post 1,140/2,317

Re: A clarification about flags

Zarator wrote:

Just to be sure, the "proper pointer" to the script header I need to look for is the "two bytes" you talk about here? http://hax.iimarck.us/topic/18/

"This has taken us into the map header. You will notice that there are two more bytes between the first byte of the event pointer and the last two we saw in Goldmap. These point to the map script, so we ignore them for now. Take the pointer you found in step two and type the last two bytes of it over the ones for the old event data. In my case, I typed 8061 over AA47. Save your rom with a new name so you have the original as a backup. You'll see why in the next step. Congratulations! You've just repointed the event data!"

EDIT: I'm asking because I tried that, and when I put 8741 (still for Lugia's map) in the pointer calculator, I got Offset 187, which seems quite... improbable. Also, I read Tauwasser's event structure and I found it as incomprehensible as the script structure.

Script Header and Event data are always in the same rom bank pointed by a 3-byte pointer:
[Rom Bank][Pointer to Script Header (2 bytes)][Pointer to Event data (2 bytes)]

So where the script header is is not 0x187 but 0x187 + 0x11C000 (rom bank * 0x4000) = 0x11C187

Zarator wrote:

[[Number1 of pointers] Number1 * [2byte pointer to script][00][00]][[Number2 of pointers] Number2 * [Number][2byte pointer to script]]

IMO it'd be much simpler if he posted an example and said, say:

01 87 44 18 25 A6 (just putting random numbers here, in the proper example you'd probably put a real header of sorts)

and then explain what 01 is, what 87 is, and so on. Those brackets are really confusing, and I don't even understand what byte refers to what thing in the structure... or even how long is the byte string supposed to be!

The only "confusing" thing about the structure is that if the [Number1 of pointers] byte is 00 which it is for most maps, it's followed by [Number2 of pointers]. If this value is also 00, script header ends. Open up offset 0x11C187 with a hex editor and see how scripts are called through that script header. The scripts themselves are very likely programmed to start right after the header ends so that way, you'll also see how long it is.

Offline

#16 2012-10-06 15:01:34

Zarator
Member
Registered: 2012-09-30
Post 14/49

Re: A clarification about flags

Well, I did like you said and went at offset 0x11c187 to try and read through the code. Out of caution I read until the first time I met 00 00, to be sure the script was finished. This is what I found:

0011C180 ............................... 00 01 02 8C 41 31 18 03 09
0011C190 9D 41 21 47 09 9A 41 03 9D 41 6E 02 8F 6D 02 8F
0011C1A0 6A 47 4C C8 41 83 F9 00 8A 0F 49 33 18 03 18 09
0011C1B0 BD 41 1E 03 0A 5C F9 46 5E 6D 02 5F 90 1E 03 0A
0011C1C0 5C F9 28 5E 6D 02 5F 90 00 86 B8 A0 A0 A0 B2 E7
0011C1D0 57............

I assumed 00 01 02 should be read according to that table Tauwasser added when explaining the second part, namely:

01  Map data has already been loaded to ram, tileset and sprites still missing
02 Map data, tileset and sprites are all loaded

It did make sense to me, to a certain extent, although I wouldn't be surprised if I were wrong. The 8C is the Priorityjump1, followed by its 2bit pointer to the script. However, I do not understand what does the rest of the bytes mean. And I do not understand how, from the 2bit pointer 41 31, to calculate the offset. I tried to put 41 31 Pointer in the Pointer Calculator, but I got FFFFF14 Offset, which is obviously wrong. How should I manage to find the offset of the script I'm looking for?

Offline

#17 2012-10-06 16:52:13

Tauwasser
Member
Registered: 2010-10-16
Post 306/448

Re: A clarification about flags

You read it wrong, it's this:

                      00 01 02 8C 41
0x00 "first part" pointers  -/  |  |  \__/
0x01 "second part" pointer  ----/  |   |
  Type 0x02                 -------/   |
  Pointer to script         -----------/

So there are no first part scripts and one second part script executed for type 0x02, whose script starts at 0x418C -- the byte after the pointer.

According to your dump (I did not double-check):

@418C:
31 18 03
09 9D 41 ;; if flag 0x0318 is set, goto 0x419D
21 47
09 9A 41 ;; if item 0x47 is in possession, goto 0x419A
03 9D 41 ;; goto 0x419D
@419A:
6E 02    ;; show event no 0x02
8F
@419D:
6D 02    ;; hide event no 0x02
8F

I suppose the people event 0x02 will trigger a script when talking to it that sets flag 0x0318, therefore making it a one-time event.

cYa,

Tauwasser

Last edited by Tauwasser (2012-10-06 17:04:52)

Offline

#18 2012-10-08 16:15:14

Zarator
Member
Registered: 2012-09-30
Post 15/49

Re: A clarification about flags

Thanks, now it is admittenly more clear^^ What I still don't understand is how those two-bit pointers work. Like, how do you know that 419D, for example, actually redirects to 0x11C19D? When I try to use the pointer calculator it gives me something completely different. If I want to add my Celebi event I need to know how to properly point.

And speaking of it, it is clear to me now that I need to manage the hide/show mechanics from the map script of Ilex Forest. Probably something like:

31 XX XX (If the flag for Clair's defeat is set)
09 YY YY (go to YYYY)
03 ZZ ZZ (else go to ZZZZ)
@YYYY:
6E HH (show event no. HH, which will be Celebi's one)
8F
@ZZZZ:
6F HH (hide event no. HH)
8F

I didn't include the disappear mechanic connected with you beating Celebi in the offset (like it is with Lugia) in order to simplify things, since I can simply put disappear 0X3 in the event script. However I don't understand how am I supposed to add this part to Ilex Forest's map script. I looked at the corresponding offset, and there doesn't seem to be any space at all. My idea was to copy the entire offset to a different place (where I get more space, possibly with same bank) and add my script there.
However, is there something else I should change if I do so? Like, some pointers that point to the map script that I should change? I was thinking about the one close to the map header and the event script header but then again I have the problem of how to understand where pointers... point^^



P.S.: I'm really, REALLY sorry for how long I'm dragging this. I'm probably annoying a lot of you this way and I'm sorry for it, but I want to learn and while some things seemed very intuitive to me so far, this thing with flags really doesn't (and even the way to read scripts that Tauwasser descripted, while I understood it now, is all but immediate from the Compendium he made - especially the part about 03 and 09 being employed as ELSE and THEN, respectively)

Offline

#19 2012-10-08 20:03:43

Miksy91
Member
Registered: 2010-10-16
Post 1,149/2,317

Re: A clarification about flags

419D is (in this case) big indian form of little endian pointer 9D 41 like it would be written in rom.
9D 41 leads to [start of the rom bank] + 0x419D - 0x4000 = 0x11C000 + 0x19D = 0x11C19D

Also, personally, I wouldn't script Celebi's "appearance" in the way you've intended. I'd make the event have its Bit Number ("Flag Index + Bit") being set before the map can be entered for the first time. Either by having its bit number set as one of the bits that are set when you "arrive" in your room for the first time OR by making a storyline-related event (that has to be gone through to get access to this place) set the bit number this person event (Celebi) uses.

Then when Clair is defeated, this bit number would be cleared and Celebi seen in the forest that way. After you defeat Celebi, it would be made hidden again and that way, you wouldn't even need to call anything from the script header.

Last edited by Miksy91 (2012-10-08 20:04:16)

Offline

#20 2012-10-08 21:40:21

Zarator
Member
Registered: 2012-09-30
Post 16/49

Re: A clarification about flags

Well, I could use "Falkner defeated" as an event, since there's no way you can get to Ilex Forest without beating Falkner first. So, according to your suggestion I would put something like:

31 XX XX (If the flag for Falkner defeated is set)
33 YY YY (Sets Celebi's Event flag to 1)
31 ZZ ZZ (If the flag for Clair's event is set)
32 YY YY (Sets Celebi's Event flag to 0)

Right?

Offline

#21 2012-10-09 15:03:30

Miksy91
Member
Registered: 2010-10-16
Post 1,150/2,317

Re: A clarification about flags

No that's not what you want to do, don't call anything from the map's script header.
On the other hand, this kind of script code would do no good because it would set celebi event's bit number every time the place would be entered. Even after you've beaten Clair, you'd have beaten Falkner at the same time.

Expand Falkner's script so that along with the other bits that are set after he's beaten, the game will also set the bit number used by the celebi event in ilex forest. And if you "for no reason" want to make it so that after Clair is beaten, Celebi can be seen in the forest, expand Clair's script too by adding a "clearbit1" command for reseting the bit number used by the celebi event.

Notice that you don't want to make these scripting commands so that they can be accessed more than once. Otherwise, you could "awaken" celebi in the forest every time you talked to Clair and also "kill the event" every time you talked to Falkner.

Last edited by Miksy91 (2012-10-09 15:06:47)

Offline

#22 2012-10-09 15:46:20

RPD490
Member
From: Blackthorn City, Johto
Registered: 2012-09-29
Post 65/260
Website

Re: A clarification about flags

This is pretty much why I just have Celebi in the wild in Illex Forest XD

Offline

#23 2012-10-09 16:47:16

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 1,664/3,508

Re: A clarification about flags

In Pokemon Christmas, I did this for the Celebi Event, if you are interested:

#org 0x116F40
'-----------------------------------
loadfont
checkbit1 0x598
if true 0x6F82 ' 0x116F82
checkbit1 0x597
if false 0x6F82 ' 0x116F82
checkitem 0xB2
if false 0x6F82 ' 0x116F82
2writetext 0x6F88 ' 0x116F88
closetext
loadmovesprites
takeitem 0xB2 0x1
cry 0xFB
appear 0xB
loadfont
2writetext 0x701F ' 0x11701F
closetext
loadmovesprites
setlasttalked 0xFF
writecode 0x3 0x1 ' Normal fight
loadpokedata 0xFB 0x28
startbattle
disappear 0xB
appear 0x2
returnafterbattle
spriteface 0x0 0x0
loadfont
2writetext 0x7025 ' 0x117025
closetext
loadmovesprites
disappear 0x2
setbit1 0x598
end

#org 0x116F82
'-----------------------------------
2writetext 0x6E11 ' 0x116E11
closetext
loadmovesprites
end


#org 0x116F88
= ILEX FOREST\nSHRINE\pIt's in honor of\nthe forest's\lprotector\hF2\pHey!\pIt looks like the\nGS BALL would fit\lin this slot\hF2\p[PLAYER] put the\nGS BALL inside the\lshrine\hF2\e


#org 0x11701F
= [PLAYER]: !\e


#org 0x117025
= KURT: [PLAYER]!\nYou did it!\pYou have restored\nbalance to ILEX\lFOREST\hF2\pWe cannot thank\nyou enough for\lsetting things\lright\hF2\pBut I need to get\ninside from the\lcold\hF2\pTake care,\n[PLAYER]!\pKURT used an\nESCAPE ROPE\hF2\e


#org 0x116E11
= ILEX FOREST\nSHRINE[.]\pIt's in honor of\nthe forest's\lprotector[.]\e

This script is run from the signpost event on the shrine itself, and the item it checks for and takes from you is the GS Ball in Pokemon Christmas of course.
Celebi's depiction on the map was just an "object event" person, and his flag to be hidden was BD 4 in Johtomap. That same flag was used to hide Kurt's representation in the forest as well. I forget what this flag is used for in the original game, but I want to assume it would work for you as well. You could also use BE 6 to have him hidden by default, and then hide him again when its done. This flag is used to hide the rival in Cherrygrove. I doubt that the other flags I used are free by default, I borrowed them from other places.

EDIT:
A less clean way you could make the event only run once without needing a new flag would be to have it check for a key item (the GS Ball). If you have it, it runs the event. If you don't have it, it runs the normal shrine script. Since it removes the GS Ball after you are done, the event would only run once unless you cheated to get another item. To keep the object events hidden the rest of the time, you could use any flag that is already set. This isn't the best way to do it, but it should technically work if you were in a fix.

Last edited by Mateo (2012-10-09 16:54:01)

Offline

#24 2012-10-16 15:48:31

Zarator
Member
Registered: 2012-09-30
Post 17/49

Re: A clarification about flags

Hello again^^ It's been a busy week, so I couldn't tackle this in the last days. Anyway, I tried to it with Mateo's second system and it works! I sacrificed Brick Piece to make GS Ball, modified dialogues accordingly and it worked perfectly. The event is a bit unelegant in its execution (you don't get to see Celebi's overworld sprite, just the different dialogue, the "!" and battle starts) but otherwise it works as intended. It is triggered only with GS Ball, and GS Ball is taken away from inventory correctly after battle.

I'm a bit sad that, in the end, I didn't make use of flags at all - and hence of your beautiful suggestions. But I'm still pretty bad at this scripting thing, so I may have to lurk and test more before I get a grip on the more complex stuff. Thank you anyway for your help!

Kindly, Zarator

Offline

#25 2012-10-16 17:05:14

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 1,715/3,508

Re: A clarification about flags

Glad you got it working in the end, even if you never got flags properly figured out. You'll get the hang of it eventually though.

Offline

Board footer

Powered by FluxBB