Advertiser Content

Other Question Make NPC battle eachother

Started by CodeBreaker June 17th, 2019 1:24 PM
  • 2992 views
  • 34 replies
Seen June 29th, 2019
Posted June 29th, 2019
18 posts
147 Days
I just began using pokémon essentials and I can't seem to find how to accomplish what I desire.

I need 4 NPCS to battle eachother in 2 groups of 2.
It is kinda like when a character showed you how to catch a pokémon.

I'm not sure if this is even possible.

I'd love it if someone could assist me.
Go through all of the steps I have to do.
Cause I don't know if I have to make a trainer script for all 4 NPCS or not. As I don't want to end up battling them after the scene ends.

Ego13

hollow_ego

Male
Larua Region
Seen 14 Hours Ago
Posted 2 Days Ago
304 posts
2.3 Years
Weeell this can be done. And it can be done.... like super easily... I'm surprised how easy it is.
Technically all you need to do is hand te command phase to the AI instead of the player. and we can do this easily with one game switch and one line of code.

In PokeBattle_Battle find this line
if !pbOwnedByPlayer?(i) || @controlPlayer
and right before that line add the following
@controlPlayer=true if $game_switches[id]
where id refer to the number of the switch that you want to use.
if you for example use switch 103 the line would look like this
@controlPlayer=true if $game_switches[103]
Now all you need to do, is turn the switch on right before the battle and the AI will do the rest.

Edit: I forgot about the part where it was 4 NPCs battling withouth the player. That means you probably need to pass the NPCs as the trainers

Edit of the edit: I made a script that allows to initialize NPC battles. Will publish it on Relic Castle and post the link here
Looking for spriters to help with

Pokemon Hollow on pokecommunity.com
Seen June 29th, 2019
Posted June 29th, 2019
18 posts
147 Days
Hey, so I've been working on the real deal and I came across a certain thing.

So I got 2 enemies, team rocket, both go fine, but when we go to the 2 on the trainers team, only the latter appears to get their name shown. Is it correct to assume that this has to do with the "players" role by any chance?

I mean, in my case Trainer 2 is called Bill and Trainer 4 John. When the battle starts, however, it says: "John John sent out Growlithe" for instance XD Kinda funny but weird HAHA :D
Was wondering if I messed up somewhere XP

I also wondered if you had any advice on making sure a certain side wins? It's a kind of set scene. Should I give the Pokémon certain moves in the trainer listings or items?
Or do you think that still wouldn't guaranty it? Thanks for all the help :)

Ego13

hollow_ego

Male
Larua Region
Seen 14 Hours Ago
Posted 2 Days Ago
304 posts
2.3 Years
Hey,

I can't quite replicate your scenario. Could you attach some screenshot of how you set up your event and what the meontioned text looks like in battle?

Well you can't guarentee a certain outcome unless one side is truly overpowered (like a Lv80 Mon vs a Lv10 Mon). BUt it does help to make the losing sides Skill Levle the lowest possible and the winning sides one as high as possible. Also adding certain advantges to th winning side helps, like the mentioned moves or items.
Looking for spriters to help with

Pokemon Hollow on pokecommunity.com

Ego13

hollow_ego

Male
Larua Region
Seen 14 Hours Ago
Posted 2 Days Ago
304 posts
2.3 Years
RIght, so I'm guessing that the first "John" in "John John" is the trainer type. LIke it usually says "Birdkeeper Tobi" or "Rival Gary". If you rename the in game nam for the trainer type to "Ally" then it should show up as "Ally John".
Looking for spriters to help with

Pokemon Hollow on pokecommunity.com
Seen June 29th, 2019
Posted June 29th, 2019
18 posts
147 Days
73,ALLY_JOHN,John,100,Pokémon trainer,,,Male,,
this was what I have in trainer types. So, if anything I would expect Ally_John John then? Is it the second John it takes then?

And in the trainers.txt I might need to make it so it's Bill & John to show both npc's names? Correct? :) Sorry for all these questions and thanks for all the assistance =D

Ego13

hollow_ego

Male
Larua Region
Seen 14 Hours Ago
Posted 2 Days Ago
304 posts
2.3 Years
Yes, the second John in trainertypes is the display name of the trainer type. I recommend changing it to "Ally"

Well that depends on whether they are two separate trainers or just one. If they are just one appearing as a duo, then yes, you need to change the name too

Thanks for your appreciation :)
Looking for spriters to help with

Pokemon Hollow on pokecommunity.com

Ego13

hollow_ego

Male
Larua Region
Seen 14 Hours Ago
Posted 2 Days Ago
304 posts
2.3 Years
The only reason I could find why you wouldn't get any Exp is if its either an NPC battle or an internal battle
Can you show me your "def pbGainExp"?

Other than that I don't think there is anything else. Do you get exp when playing normally?
Looking for spriters to help with

Pokemon Hollow on pokecommunity.com
Seen June 29th, 2019
Posted June 29th, 2019
18 posts
147 Days
I'm not quite sure how large of a section I had to copy, I apologize
Spoiler:
def pbGainEXP
return if $game_switches[NPCBATTLE]
return if !@internalbattle
successbegin=true
for i in 0...4 # Not ordered by priority
if !@doublebattle && pbIsDoubleBattler?(i)
@battlers[i].participants=[]
next
end
if pbIsOpposing?(i) && @battlers[i].participants.length>0 &&
(@battlers[i].fainted? || @battlers[i].captured)
haveexpall=(hasConst?(PBItems,:EXPALL) && $PokemonBag.pbHasItem?(:EXPALL))
# First count the number of participants
partic=0
expshare=0
for j in @battlers[i].participants
next if !@party1[j] || !pbIsOwner?(0,j)
partic+=1 if @party1[j].hp>0 && !@party1[j].egg?
end
if !haveexpall
for j in 0...@party1.length
next if !@party1[j] || !pbIsOwner?(0,j)
expshare+=1 if @party1[j].hp>0 && !@party1[j].egg? &&
(isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE))
end
end
# Now calculate EXP for the participants
if partic>0 || expshare>0 || haveexpall
if !@opponent && successbegin && pbAllFainted?(@party2)
@scene.pbWildBattleSuccess
successbegin=false
end
for j in 0...@party1.length
next if !@party1[j] || !pbIsOwner?(0,j)
next if @party1[j].hp<=0 || @party1[j].egg?
haveexpshare=(isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE))
next if !haveexpshare && !@battlers[i].participants.include?(j)
pbGainExpOne(j,@battlers[i],partic,expshare,haveexpall)
end
if haveexpall
showmessage=true
for j in 0...@party1.length
next if !@party1[j] || !pbIsOwner?(0,j)
next if @party1[j].hp<=0 || @party1[j].egg?
next if isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE)
next if @battlers[i].participants.include?(j)
pbDisplayPaused(_INTL("The rest of your team gained Exp. Points thanks to the {1}!",
PBItems.getName(getConst(PBItems,:EXPALL)))) if showmessage
showmessage=false
pbGainExpOne(j,@battlers[i],partic,expshare,haveexpall,false)
end
end
end
# Now clear the participants array
@battlers[i].participants=[]
end
end
end

def pbGainExpOne(index,defeated,partic,expshare,haveexpall,showmessages=true)
thispoke=@party1[index]
# Original species, not current species
level=defeated.level
baseexp=defeated.pokemon.baseExp
evyield=defeated.pokemon.evYield
# Gain effort value points, using RS effort values
totalev=0
for k in 0...6
totalev+=thispoke.ev[k]
end
for k in 0...6
evgain=evyield[k]
evgain*=2 if isConst?(thispoke.item,PBItems,:MACHOBRACE) ||
isConst?(thispoke.itemInitial,PBItems,:MACHOBRACE)
case k
when PBStats::HP
evgain+=4 if isConst?(thispoke.item,PBItems,:POWERWEIGHT) ||
isConst?(thispoke.itemInitial,PBItems,:POWERWEIGHT)
when PBStats::ATTACK
evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBRACER) ||
isConst?(thispoke.itemInitial,PBItems,:POWERBRACER)
when PBStats::DEFENSE
evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBELT) ||
isConst?(thispoke.itemInitial,PBItems,:POWERBELT)
when PBStats::SPATK
evgain+=4 if isConst?(thispoke.item,PBItems,:POWERLENS) ||
isConst?(thispoke.itemInitial,PBItems,:POWERLENS)
when PBStats::SPDEF
evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBAND) ||
isConst?(thispoke.itemInitial,PBItems,:POWERBAND)
when PBStats::SPEED
evgain+=4 if isConst?(thispoke.item,PBItems,:POWERANKLET) ||
isConst?(thispoke.itemInitial,PBItems,:POWERANKLET)
end
evgain*=2 if thispoke.pokerusStage>=1 # Infected or cured
if evgain>0
# Can't exceed overall limit
evgain-=totalev+evgain-PokeBattle_Pokemon::EVLIMIT if totalev+evgain>PokeBattle_Pokemon::EVLIMIT
# Can't exceed stat limit
evgain-=thispoke.ev[k]+evgain-PokeBattle_Pokemon::EVSTATLIMIT if thispoke.ev[k]+evgain>PokeBattle_Pokemon::EVSTATLIMIT
# Add EV gain
thispoke.ev[k]+=evgain
if thispoke.ev[k]>PokeBattle_Pokemon::EVSTATLIMIT
print "Single-stat EV limit #{PokeBattle_Pokemon::EVSTATLIMIT} exceeded.\r\nStat: #{k} EV gain: #{evgain} EVs: #{thispoke.ev.inspect}"
thispoke.ev[k]=PokeBattle_Pokemon::EVSTATLIMIT
end
totalev+=evgain
if totalev>PokeBattle_Pokemon::EVLIMIT
print "EV limit #{PokeBattle_Pokemon::EVLIMIT} exceeded.\r\nTotal EVs: #{totalev} EV gain: #{evgain} EVs: #{thispoke.ev.inspect}"
end
end
end
# Gain experience
ispartic=0
ispartic=1 if defeated.participants.include?(index)
haveexpshare=(isConst?(thispoke.item,PBItems,:EXPSHARE) ||
isConst?(thispoke.itemInitial,PBItems,:EXPSHARE)) ? 1 : 0
exp=0
if expshare>0
if partic==0 # No participants, all Exp goes to Exp Share holders
exp=(level*baseexp).floor
exp=(exp/(NOSPLITEXP ? 1 : expshare)).floor*haveexpshare
else
if NOSPLITEXP
exp=(level*baseexp).floor*ispartic
exp=(level*baseexp/2).floor*haveexpshare if ispartic==0
else
exp=(level*baseexp/2).floor
exp=(exp/partic).floor*ispartic + (exp/expshare).floor*haveexpshare
end
end
elsif ispartic==1
exp=(level*baseexp/(NOSPLITEXP ? 1 : partic)).floor
elsif haveexpall
exp=(level*baseexp/2).floor
end
return if exp<=0
exp=(exp*3/2).floor if @opponent
if USESCALEDEXPFORMULA
exp=(exp/5).floor
leveladjust=(2*level+10.0)/(level+thispoke.level+10.0)
leveladjust=leveladjust**5
leveladjust=Math.sqrt(leveladjust)
exp=(exp*leveladjust).floor
exp+=1 if ispartic>0 || haveexpshare>0
else
exp=(exp/7).floor
end
isOutsider=(thispoke.trainerID!=self.pbPlayer.id ||
(thispoke.language!=0 && thispoke.language!=self.pbPlayer.language))
if isOutsider
if thispoke.language!=0 && thispoke.language!=self.pbPlayer.language
exp=(exp*1.7).floor
else
exp=(exp*3/2).floor
end
end
exp=(exp*3/2).floor if isConst?(thispoke.item,PBItems,:LUCKYEGG) ||
isConst?(thispoke.itemInitial,PBItems,:LUCKYEGG)
growthrate=thispoke.growthrate
newexp=PBExperience.pbAddExperience(thispoke.exp,exp,growthrate)
exp=newexp-thispoke.exp
if exp>0
if showmessages
if isOutsider
pbDisplayPaused(_INTL("{1} gained a boosted {2} Exp. Points!",thispoke.name,exp))
else
pbDisplayPaused(_INTL("{1} gained {2} Exp. Points!",thispoke.name,exp))
end
end
newlevel=PBExperience.pbGetLevelFromExperience(newexp,growthrate)
tempexp=0
curlevel=thispoke.level
if newlevel<curlevel
debuginfo="#{thispoke.name}: #{thispoke.level}/#{newlevel} | #{thispoke.exp}/#{newexp} | gain: #{exp}"
raise RuntimeError.new(_INTL("The new level ({1}) is less than the Pokémon's\r\ncurrent level ({2}), which shouldn't happen.\r\n[Debug: {3}]",
newlevel,curlevel,debuginfo))
return
end
if thispoke.respond_to?("isShadow?") && thispoke.isShadow?
thispoke.exp+=exp
else
tempexp1=thispoke.exp
tempexp2=0
# Find battler
battler=pbFindPlayerBattler(index)
loop do
# EXP Bar animation
startexp=PBExperience.pbGetStartExperience(curlevel,growthrate)
endexp=PBExperience.pbGetStartExperience(curlevel+1,growthrate)
tempexp2=(endexp<newexp) ? endexp : newexp
thispoke.exp=tempexp2
@scene.pbEXPBar(thispoke,battler,startexp,endexp,tempexp1,tempexp2)
tempexp1=tempexp2
curlevel+=1
if curlevel>newlevel
thispoke.calcStats
battler.pbUpdate(false) if battler
@scene.pbRefresh
break
end
oldtotalhp=thispoke.totalhp
oldattack=thispoke.attack
olddefense=thispoke.defense
oldspeed=thispoke.speed
oldspatk=thispoke.spatk
oldspdef=thispoke.spdef
if battler && battler.pokemon && @internalbattle
battler.pokemon.changeHappiness("levelup")
end
thispoke.calcStats
battler.pbUpdate(false) if battler
@scene.pbRefresh
pbDisplayPaused(_INTL("{1} grew to Level {2}!",thispoke.name,curlevel))
@scene.pbLevelUp(thispoke,battler,oldtotalhp,oldattack,
olddefense,oldspeed,oldspatk,oldspdef)
# Finding all moves learned at this level
movelist=thispoke.getMoveList
for k in movelist
if k[0]==thispoke.level # Learned a new move
pbLearnMove(index,k[1])
end
end
end
end
end
end
Advertiser Content