• The Relic Castle Game Jam #4 is almost halfway done! From June 30th to August 10th, users have just a bit over a month to make an entire game. Check this thread for details!

Solved Deleting a specific Pokémon

xUMG

Elite Trainer
Member
Posts
106
#1
Deleting a specific Pokémon in the players part? I have red the manipulating Pokémon thread in Pokémon Essentials thread. But it only searches for an index of the players party i.e where the Pokémon is placed at.

I wouldn't wanna bother scramming my brain or brainstorming itself right now i'm working on my game so if anyone can find a method for it it'd be appreciated, even if the method is long it's fine.
 
Last edited:

xUMG

Elite Trainer
Member
Posts
106
#3
I found this, which seems to have the answer: https://www.pokecommunity.com/showthread.php?t=382910


Code:
for i in 0...$Trainer.party.length

 
if $Trainer.party[i].species==PBSpecies::RATTATA
$Trainer.party[i]=nil
$Trainer.party.compact
break
end
end
Seems like this should work, just replace RATTATA with whatever species you are after.
Oh! Thanks for that although the script didn't work i red the thread and ended up creating something like this!
 
Last edited:

EpiQ

Rookie
Member
Posts
7
#4
Oh! Thanks for that although the script didn't work i red the thread and ended up creating something like this!
Hello!
Nice idea!!! But what about If you haven't in party 6 pokemons? Just like this (5 pokemons in party):
:


Have you any solution? Thank you!
 
Last edited:

leilou

Elite Trainer
Member
Posts
172
#5
Change the condotion to
Code:
($Trainer.pokemonParty[i]!=nil) && $Trainer.pokemonParty[i].species == species
where i is the Position of the pokemon and species the species you're checking for

you could also make a Funktion in the scripts like this
Code:
def deleteSpecies(species)
	for i in 0...$Trainer.pokemonParty.length
		if ($Trainer.pokemonParty[i]!=nil) && ($Trainer.pokemonParty[i].species == species)
		   pbRemovePokemonAt(i)
		end
	end
end
if you don't want to delete eggs you need to put the check
Code:
$Trainer.pokemonParty[i].egg?
to the if condition(with another &&)

EDIT: I forgot to mention that if you do it with the function you just need to call the script command
Code:
deleteSpecies(PBSpecies::BULBASAUR)
EDIT end

I hope this helps
 

EpiQ

Rookie
Member
Posts
7
#6
Change the condotion to
Code:
($Trainer.pokemonParty[i]!=nil) && $Trainer.pokemonParty[i].species == species
where i is the Position of the pokemon and species the species you're checking for

you could also make a Funktion in the scripts like this
Code:
def deleteSpecies(species)
	for i in 0...$Trainer.pokemonParty.length
		if ($Trainer.pokemonParty[i]!=nil) && ($Trainer.pokemonParty[i].species == species)
		   pbRemovePokemonAt(i)
		end
	end
end
if you don't want to delete eggs you need to put the check
Code:
$Trainer.pokemonParty[i].egg?
to the if condition(with another &&)

EDIT: I forgot to mention that if you do it with the function you just need to call the script command
Code:
deleteSpecies(PBSpecies::BULBASAUR)
EDIT end

I hope this helps
Nice! Working!!Thank you!!!

But I need little bits edits.
This script delete all specific pokemons in party that you have 2 or more.
I need delete only one.
Also If you have only one pokemon in party do nothing. It will be good show in Kernel.pbMessage something like "You have only one pokemon!"
 

leilou

Elite Trainer
Member
Posts
172
#7
in that case:
Code:
def deleteSpecies(species)
	#if only one Pokémon is in the party send message and return
	if $Trainer.pokemonParty.length == 1
		Kernel.pbMessage("You only have one Pokémon!") #show the message
		return #end the function
	end
	#delete the first Pokémon in the party of the given species
	for i in 0...$Trainer.pokemonParty.length
		if ($Trainer.pokemonParty[i]!=nil) && ($Trainer.pokemonParty[i].species == species)
			pbRemovePokemonAt(i) #delete the mon
			break #break out of the for loop
		end
	end
end
ah yeah sry for the formatting ... not beeing able to type tab is messing me up

if you don't know scripting: everything behind a # is a comment and is only decorative
 

xUMG

Elite Trainer
Member
Posts
106
#9
Just like EpiQ said it will do a crash if that's the case, so I would like some edits on this too, so it checks for thet first pokémon in the party of the given species and also checks for the first pokémon in the party of the given form.
Code:
def deleteSpecies(species)
	#if only one Pokémon is in the party send message and return
	if $Trainer.pokemonParty.length == 1
		Kernel.pbMessage("You only have one Pokémon!") #show the message
		return #end the function
	end
	#delete the first Pokémon in the party of the given species
	for i in 0...$Trainer.pokemonParty.length
		if ($Trainer.pokemonParty[i]!=nil) && ($Trainer.pokemonParty[i].species == species)
			pbRemovePokemonAt(i) #delete the mon
			break #break out of the for loop
		end
	end
end
 

leilou

Elite Trainer
Member
Posts
172
#10
I don't quite follow you up on when the crash happens ... do you by some chance have an empty party?

But if I understand correctly you just want to additionally check for the form ... just add that check ...
I also moved the one pokemon check to only trigger when a pokemon of the species and form was found
You can either call this function like you did before
Code:
deleteSpecies(PBSpecies::BULBASAUR)
and it won't care about the form or call it or call it
Code:
deleteSpecies(PBSpecies::BULBASAUR,0)
and it will only delete bulbasaurs in normal form(0 is the normal form)
I also added the egg? check ... so if you want to be able to delete eggs then remove it
Additionally I added a return value so that you can do stuff like
Code:
if deleteSpecies(PBSpecies::BULBASAUR)
	#do stuff that only happens when Bulbasaur was deleted
else
	#do stuff that only happens when Bulbasaur isn't deleted
end
Anyways ... here is the new function:
Code:
def deleteSpecies(species, form="any")
	#delete the first Pokémon in the party of the given species
	for i in 0...$Trainer.pokemonParty.length
		if ($Trainer.pokemonParty[i]!=nil) && ($Trainer.pokemonParty[i].species == species) &&
				($Trainer.pokemonParty[i].form == form || $Trainer.pokemonParty[i].form == "any") &&
				!$Trainer.pokemonParty[i].egg?
			#if only one Pokémon is in the party send message and return
			if $Trainer.pokemonParty.length == 1
				Kernel.pbMessage("You only have one Pokémon!") #show the message
				return false #end the function
			else
				pbRemovePokemonAt(i) #delete the mon
				return true #end function and return that the Pokémon was deleted
			end
		end
	end
	return false #return that no Pokémon was deleted
end
kill me after that **** indenting in firefox -.-

hope that helps ...
the error you got will probably not be fixed so please make a screenshot of it or at least describe it properly so I have at least a chance of fixing it.
 

xUMG

Elite Trainer
Member
Posts
106
#11
I don't quite follow you up on when the crash happens ... do you by some chance have an empty party?

But if I understand correctly you just want to additionally check for the form ... just add that check ...
I also moved the one pokemon check to only trigger when a pokemon of the species and form was found
You can either call this function like you did before
Code:
deleteSpecies(PBSpecies::BULBASAUR)
and it won't care about the form or call it or call it
Code:
deleteSpecies(PBSpecies::BULBASAUR,0)
and it will only delete bulbasaurs in normal form(0 is the normal form)
I also added the egg? check ... so if you want to be able to delete eggs then remove it
Additionally I added a return value so that you can do stuff like
Code:
if deleteSpecies(PBSpecies::BULBASAUR)
	#do stuff that only happens when Bulbasaur was deleted
else
	#do stuff that only happens when Bulbasaur isn't deleted
end
Anyways ... here is the new function:
Code:
def deleteSpecies(species, form="any")
	#delete the first Pokémon in the party of the given species
	for i in 0...$Trainer.pokemonParty.length
		if ($Trainer.pokemonParty[i]!=nil) && ($Trainer.pokemonParty[i].species == species) &&
				($Trainer.pokemonParty[i].form == form || $Trainer.pokemonParty[i].form == "any") &&
				!$Trainer.pokemonParty[i].egg?
			#if only one Pokémon is in the party send message and return
			if $Trainer.pokemonParty.length == 1
				Kernel.pbMessage("You only have one Pokémon!") #show the message
				return false #end the function
			else
				pbRemovePokemonAt(i) #delete the mon
				return true #end function and return that the Pokémon was deleted
			end
		end
	end
	return false #return that no Pokémon was deleted
end
kill me after that **** indenting in firefox -.-

hope that helps ...
the error you got will probably not be fixed so please make a screenshot of it or at least describe it properly so I have at least a chance of fixing it.
Thanks! but I do have one more question, where do I place the script?
 

leilou

Elite Trainer
Member
Posts
172
#12
Thanks! but I do have one more question, where do I place the script?
The best would be to make a new script section beneath PSystem_Utilities(one of the last ones) with ight click -> insert. This will make an empty script ...then you just name it delete pokemon and paste the code in there. This way it will be easier to see what you changed from pure essentials which will make it easier to port your game to feature versions of essentials.

After doing this you can call the function from events or other scripts.
 

Marina

Novice
Member
Posts
33
#13
This is a nice script for an evil team/rival stealing one of your Pokémon.
This is great! I will look for this thread as soon as I need it!
thank you, 'cause I was wondering how to do delete Pokémon and adding them instead of a trade (but I just made a common trade)
 
Top