Adding an NPC that gives you a Pokémon - pret/pokecrystal GitHub Wiki

This tutorial is for adding an NPC that gives you a Pokémon.

Contents

  1. Adding the required sprite to the overworld
  2. Creating the script for the NPC
  3. Event Flag to prevent farming

1. Adding the required sprite to the overworld

In this tutorial we will add an NPC that gives you a Pokémon of a certain species and level. We will add the NPC at the very beggining of Route 29, though any area will also follow the same steps.

Start by editing maps/Route29.asm

object_const_def
 const ROUTE29_COOLTRAINER_M1
 ...
+const ROUTE29_COOLTRAINER_M3
...
 def_object_events
 object_event 50, 12, SPRITE_COOLTRAINER_M, SPRITEMOVEDATA_SPINRANDOM_SLOW, 0, 0, -1, -1, PAL_NPC_RED, OBJECTTYPE_SCRIPT, 0, CatchingTutorialDudeScript, -1
 ...
+object_event 44,  9, SPRITE_COOLTRAINER_M, SPRITEMOVEDATA_STANDING_RIGHT, 0, 0, -1, -1, PAL_NPC_RED, OBJECTTYPE_SCRIPT, 0, GiftPokemonDudeScript, -1

This will add the cool trainer sprite to the beggining of Route 29.

2. Creating the script for the NPC

Next, we need to provide contents for GiftPokemonDudeScript, which is the script this NPC is assigned. We will use VAR_PARTYCOUNT to check if our party is full, if our party is full then the NPC will tell us so, and won't give us the Pokémon.

+GiftPokemonDudeScript:
+	faceplayer
+	readvar VAR_PARTYCOUNT
+	ifequal PARTY_LENGTH, .PartyFullGift
+	opentext
+	writetext GiftPokemonDudeGiftText
+	promptbutton
+	getmonname STRING_BUFFER_3, MEWTWO
+	writetext ReceivedGiftText
+	promptbutton
+	givepoke MEWTWO, 100, BERRY
+	closetext
+	end
	
+.PartyFullGift:
+	opentext
+	writetext PartyFullGiftText
+	waitbutton
+	closetext
+	end

+PartyFullGiftText:
+	text "I was going to"
+	line "give you something"

+	para "but your party"
+	line "seems to be full."
+	done

+GiftPokemonDudeGiftText:
+	text "I caught so"
+	line "many #MON!"

+	para "This guy seems"
+	line "weak though,"
+	cont "you can have it."

+	para "I only collect"
+	line "strong bug types"
+	cont "like Caterpie."
+	done

+ReceivedGiftText:
+	text "<PLAYER> received"
+	line "@"
+	text_ram wStringBuffer3
+	text "!"
+	done

Great!!! This code will make the NPC we talk to give us a specified Pokémon at a certain level after checking if we have space in our party for him (in our case, a level 100 MEWTWO, but you can decide what pokemon to add at what level). However, speaking to them again will give you another Pokémon (of the same species and level), and another for each time you speak to them. To combat this, we need to provide an EVENT_FLAG.

3. Setting an Event Flag to prevent farming

For this next step, add a new entry to constants/event_flags.asm.

...
; New to Crystal
+const EVENT_GOT_ROUTE_29_GIFT_POKE
...

We then need to go back to the NPC we created earlier and add the event to the script, so once the event is set, we don't gift another Pokémon. We could also make the NPC not appear again after the event has been set, by replacing the -1 at the end of their object_event data with EVENT_GOT_ROUTE_29_GIFT_POKE (like in the tutorial for the NPC that gives an item), but we won't be doing that in this tutorial, we want the character to stay there.

...
GiftPokemonDudeScript:
	faceplayer
+	checkevent EVENT_GOT_ROUTE_29_GIFT_POKE
+	iftrue .AlreadyGotGiftPoke
	readvar VAR_PARTYCOUNT
	ifequal PARTY_LENGTH, .PartyFullGift
	opentext
	writetext GiftPokemonDudeGiftText
	promptbutton
	getmonname STRING_BUFFER_3, MEWTWO
	writetext ReceivedGiftText
	promptbutton
	givepoke MEWTWO, 100, BERRY
+	setevent EVENT_GOT_ROUTE_29_GIFT_POKE
	closetext
	end
	
.PartyFullGift:
	opentext
	writetext PartyFullGiftText
	waitbutton
	closetext
	end

+.AlreadyGotGiftPoke:
+	opentext
+	writetext AlreadyGotGiftText
+	waitbutton
+	closetext
+	end

PartyFullGiftText:
	text "I was going to"
	line "give you something"

	para "but your party"
	line "seems to be full."
	done

GiftPokemonDudeGiftText:
	text "I caught so"
	line "many #MON!"

	para "This guy seems"
	line "weak though,"
	cont "you can have it."

	para "I only collect"
	line "strong bug types"
	cont "like Caterpie."
	done

ReceivedGiftText:
	text "<PLAYER> received"
	line "@"
	text_ram wStringBuffer3
	text "!"
	done

+AlreadyGotGiftText:
+	text "Take good care of"
+	line "that gift #MON!"
+	done

...

Now we are set! The NPC will check if the event flag has been set or not. If there is space for the gift Pokémon in your party, and the event has not been set, then you will recieve the gift Pokémon. Otherwise you get a message telling you to make space for the gift Pokémon, or, if you already got the Pokémon gift, it prints a different message, depending on what text you placed in AlreadyGotGiftText.

⚠️ **GitHub.com Fallback** ⚠️