Skeetendo

’Cause all games were better on the GBC

You are not logged in.

  • Index
  • → Generation II
  • → (Tutorial)How to add a tradeback guy like the one from crystal clear.

#1 2021-02-14 20:58:10

NoWestForTheRicked
New member
Registered: 2021-02-08
Post 2/2

(Tutorial)How to add a tradeback guy like the one from crystal clear.

This tutorial is for pokecrystal assembly, It's as noob friendly as possible. If you aren't using the assembly for your hack, you probably should be.

For all those like me who wanted the tradeback guy for their own hack and are annoyed that the source code isn't available, I made an NPC that functions identically. Follow this tutorial and you won't have to change the ways certain pokemon evolve. There are a lot of things that you can do differently than I did here, but we're going to pretend that you want to do things exactly as I did. So let's get started.

Anyway to get started, open up main.asm and find this SECTION
------------------------------------------------------------------------------------------------------------------------------------------
SECTION "bank3F", ROMX

INCLUDE "engine/tilesets/tileset_anims.asm"
INCLUDE "engine/events/npc_trade.asm"
INCLUDE "engine/events/mom_phone.asm"
------------------------------------------------------------------------------------------------------------------------------------------

We need to INCLUDE the file we're going to make shortly in this SECTION. I've stored the file "engine/events/trader.asm" so let's add that. You should end up with something that looks like this.
------------------------------------------------------------------------------------------------------------------------------------------
SECTION "bank3F", ROMX

INCLUDE "engine/tilesets/tileset_anims.asm"
INCLUDE "engine/events/npc_trade.asm"
INCLUDE "engine/events/mom_phone.asm"
INCLUDE "engine/events/trader.asm"
------------------------------------------------------------------------------------------------------------------------------------------
Easy peasy. So now the file (which we'll be making at the end) is included, save the changes and we can move on to the next step.

Next we'll be adding in a special to make this possible, this will require editing of two files.
First is "data/events/special_pointers.asm". Open it up and scroll down to the bottom, past the last line we're gonna add our trader, the bottom of the file should now look something like this, provided you haven't ever added anything else to this file. (the comment is not needed if you don't want it, but it can be useful to keep track of what you've added to the game.)
------------------------------------------------------------------------------------------------------------------------------------------
add_special LoadMapPalettes
add_special UnusedFindItemInPCOrBag

add_special InitialSetDSTFlag
add_special InitialClearDSTFlag
add_special UnusedDummySpecial ; unused

add_special trader ; Not part of Crystal originally
------------------------------------------------------------------------------------------------------------------------------------------
Make sure you save and let's continue.

The second part of this step is in "engine/events/specials.asm", let's go there and scroll to the bottom again. All we're doing here is making a special that hooks the NPC that we'll make in the next step to the file that we'll make in the last step. Anyway, we need to make a label that matches the add_special label we just added. Then we need to farcall the label that will be in the file we make at the end, I've named that label Trader. Finally we return to the place that called us here initially once everything is done. All of that should resemble this, which should now occupy the very bottom of "engine/events/specials.asm"
------------------------------------------------------------------------------------------------------------------------------------------
trader:
farcall Trader
ret
------------------------------------------------------------------------------------------------------------------------------------------
Save save save.

The final step before we add our routine is to make someone who can actually preform it, so pick where you want your trader to go. I'm using Kyle's house in Violet city because that's where most of my testing for the code was preformed, but you can put your trader wherever you'd like. Keep in mind that the example code I'm showing won't match yours exactly in another location though. First we need to add a constant for our guy. The top of your file should come out looking similar (not identical because kyle's house is probably not where you put him) to this:
------------------------------------------------------------------------------------------------------------------------------------------
object_const_def
const VIOLETKYLESHOUSE_POKEFAN_M
const VIOLETKYLESHOUSE_KYLE
const VIOLETKYLESHOUSE_TRADER ; Not from Crystal
------------------------------------------------------------------------------------------------------------------------------------------

Okay, let's add some code that hooks to the special we just added.
We want our new NPC to face the player when spoken to, we need to show a text box because the first thing we're going to do in the actual meat of the process is show some text, and we also need to close that textbox when everything's done. We'll also be including a line to make that final textbox wait for a button press to close. Here's what we've added:
------------------------------------------------------------------------------------------------------------------------------------------
Trader: ; not from Crystal
faceplayer
opentext
special trader
waitbutton
closetext
end
------------------------------------------------------------------------------------------------------------------------------------------
If you like to keep things neat like I do you've added this where all the other npcs were, but if you're a slob anywhere that's not interrupting other code and is between the constants and the object events is fine. We're almost there.

The last thing we have to do is make the NPC. Go nuts with the customization here you can change the way this guy moves, his appearance, his color, and where he stands(or starts when the map is loaded if you want him to walk around). For the purposes of this tutorial though, we're going to say you chose for him to look like your mom but green and have him slowly turn to face different directions randomly in place.
So we need to declare an object event for him, set his coordinates, which sprite he uses, his movement data, set his color, and attach him to the Trader code we just added. All of that goes under def_object_events in the code so if you were using kyle's house the bottom of your map.asm would look something like this:
------------------------------------------------------------------------------------------------------------------------------------------
def_object_events
object_event  2,  3, SPRITE_POKEFAN_M, SPRITEMOVEDATA_SPINRANDOM_SLOW, 0, 0, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, VioletKylesHousePokefanMScript, -1
object_event  6,  5, SPRITE_YOUNGSTER, SPRITEMOVEDATA_WALK_UP_DOWN, 0, 2, -1, -1, PAL_NPC_RED, OBJECTTYPE_SCRIPT, 0, Kyle, -1
object_event  0,  2, SPRITE_MOM, SPRITEMOVEDATA_SPINRANDOM_SLOW, 0, 2, -1, -1, PAL_NPC_GREEN, OBJECTTYPE_SCRIPT, 0, Trader, -1
------------------------------------------------------------------------------------------------------------------------------------------
Honestly I'm new to all of this, I have no idea what the numbers aside from the coordinates do, if someone wants to let me know I'll happily update this tutorial to include that information. But in the meantime, save, we're done with this file.

Ok, now for the pièce de résistance, the actual code that does all the heavy lifting here. Sorry to disappoint but I'm not going to explain it here the way I've explained everything else, I've commented the code pretty well I'd like to think. Well enough at least to get a general idea of what's going on. Copy and paste the following into a new .asm file and save it as "trader.asm" then put that file in "pokecrystal/engine/events".
------------------------------------------------------------------------------------------------------------------------------------------
;Fun fact, the 'trade' part of a trade isn't checked to evolve a pokemon, It seems that just the trade animation and the link state are enough
;No pokemon is ever removed from or added to your party using this code because of that fact
Trader::
ld hl, TraderText
call PrintText
call YesNoBox
ld hl, TraderCanceledText
jr c, .done

; Select givemon from party
ld b, PARTYMENUACTION_GIVE_MON
farcall SelectTradeOrDayCareMon
ld a, [wCurPartyMon]
ld hl, TraderCanceledText
jr c, .done

ld hl, NPCTradeCableText
call PrintText

call TradeWithTrader
call RestartMapMusic

ld hl, TraderCompleteText
call PrintText
ret
.done
call PrintText
ret
;Loads the appropriate data to prefor the trade animation,
TradeWithTrader:
;Sets the link state to trading so that evolution is possible.
ld a, LINK_TRADECENTER
ld [wLinkMode], a

;Establish names of trading trainers
ld hl, wPlayerName
ld de, wPlayerTrademonSenderName
ld bc, NAME_LENGTH
call CopyBytes

ld hl, .Trader
ld de, wOTTrademonSenderName
ld bc, NAME_LENGTH
call CopyBytes
.Trader:
db "TRADER@"

;Establish mon's species
ld a, [wCurPartyMon]
ld hl, wPartySpecies
ld b, 0
ld c, a
add hl, bc
ld a, [hl]
ld [wPlayerTrademonSpecies], a
ld [wOTTrademonSpecies], a


;Establish mon's ID number
ld hl, wPartyMon1ID
ld a, [wCurPartyMon]
call GetPartyLocation
ld a, [hli]
ld [wPlayerTrademonID], a
ld [wOTTrademonID], a
ld a, [hl]
ld [wPlayerTrademonID + 1], a
ld [wOTTrademonID + 1], a

;Establish mon's OT's name
ld a, [wCurPartyMon]
ld hl, wPartyMonOT
call SkipNames
ld de, wPlayerTrademonOTName
ld bc, NAME_LENGTH
call CopyBytes

ld hl, wPartyMonOT
ld de, wOTTrademonOTName
ld bc, NAME_LENGTH
call CopyBytes

;Makes it so that pressing B will not cancel the evolution, standard for trade based evolution
ld a, 1
ld [wForceEvolution], a

;run the trade animation/ evolves the mon if applicable
call DisableSpriteUpdates
; wTradeDialog aliases wFrameCounter, which TradeAnimation uses
ld a, [wTradeDialog]
push af
predef TradeAnimation
callfar EvolvePokemon
pop af
ld [wTradeDialog], a
call ReturnToMapWithSpeechTextbox

;Put's the link mode back to not linked, battles don't work right otherwise.
ld a, LINK_NULL
ld [wLinkMode], a
ret

TraderText::
text "Hello there! I'm"
line "the TRADER."

para "I can trade a"
line "#MON of your"
cont "choosing back to"
cont "you."

para "Would you like to"
line "trade?"
done

TraderCanceledText::
text "Oh, ok then."

para "Come back if you"
line "change your mind."
done

TraderCompleteText::
text "And... Done!"

para "I hope that"
line "was helpful!"
done

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

And congratulations! You should be able to make your pokecrystal rom now and go trade with your very own tradeback guy, evolve all your trade only evolution mons and stop making them use stones and levels to evolve!

For anyone curious I used npc_trade.asm as a base for this, though I'm pretty sure I edited/removed/added to it enough to call it my own at this point. Anyways, have a great day, and enjoy making your individual hacks!

Last edited by NoWestForTheRicked (2021-02-14 21:06:51)

Offline

  • Index
  • → Generation II
  • → (Tutorial)How to add a tradeback guy like the one from crystal clear.

Board footer

Powered by FluxBB