Scripts, Tutorials & Tools This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit! The thread revival limit does not apply here.

#1
October 6th, 2018 (3:11 AM). Edited October 6th, 2018 by rekman.
 rekman Join Date: Jan 2018 Posts: 19
Hello everyone!
Today I will treat an important feature of Pokemon Fan games: EVs of Trainers' Pokémon.
For those who doesn't know, the formula provided by the standard Essentials engine lacks of flexibility due to the fact that it must be applied to every pokémon and it's not easy to adapt different EV builds based on the specific species. It already exists a script to manually build the EVs of each pokémon. It can be a bit tedious but it provides an useful feature. For those interested, I will link it at the bottom of the post.

Now I will describe the features of the formula:
• Applies AUTOMATICALLY to every trainer's pokémon to set EVs (and IVs) based on the Base Stats of the pokémon;
• The levelcap parameter denotes the level from where all the 510 EVs will be distributed and all IVs will be equal to 31; The use of a quadratic ratio helps to smooth the proportion of the total 510 in the level below levelcap. Note: that levelcap is set at level 50 now, you can change as you prefer, basing your choice on the difficulty curve you desire for your game.
e.g. Consider a pokémon at level 10 with levelcap=50. Then the total EVs that will be distributed among the stats will be: 510*(10/50)^2=20;
Other examples:
level 20 and levelcap=50 -> Total Evs=82
level 30 and levelcap=50 -> Total Evs=184
level 40 and levelcap=50 -> Total Evs=326
level 50 and levelcap=50 -> Total Evs=510
level 60 and levelcap=50 -> Total Evs=510
(changing the levelcap we could have:
level 65 and levelcap=70 -> Total EVs= 440)
• There is the possibility to have builds with EVs more concentrated in less Stats ( think about a sweeper with most EVs on Attack and Speed). To use this feature, just set to true a game switch XXX and use the number of the switch that you prefer and insert that number in the appropriate spot inside the formula instead of XXX. In the formula the exact place is :if \$game_switches[XXX]==true
• In case your game features EVs greater than 510 ( the standard value of every pokémon series), change the parameter remaining_ev

Installation:
Find in PTrainer_NPCTrainers the following code (around line 82, right after pokemon.setNature(poke[TPNATURE]) )
Code:
```iv=poke[TPIV]
for i in 0...6
pokemon.iv[i]=iv&0x1F
pokemon.ev[i]=[85,level*3/2].min
end```
And replace it with:
Code:
```#EV IV Formula by Rekman. Credit Pokémon Winter Memories ONLY if you want.
#No credit needed. Enjoy :)
bs=pokemon.baseStats
levelcap=50
levelperc=[100*pokemon.level**2/levelcap**2,100].min
bsmin=bs.min
remaining_ev=510
for i in 0...6
bs[i]-=bsmin-1
end
if \$game_switches[XXX]==true    #insert here the number of the switch instead of XXX
if bs[1]> 2*bs[4]
bs[1]+=bs[4]-1
bs[4]=1
elsif bs[4]> 2*bs[1]
bs[4]+=bs[1]-1
bs[1]=1
end
if bs[0]> 2*bs[3]
bs[0]+=bs[3]-1
bs[3]=1
else           #elsif bs[3]> 2*bs[0]
bs[3]+=bs[0]-1
bs[0]=1
end
end
sumbs=0
reserve_ev=0
for i in 0...6
sumbs+=bs[i]
end
for i in 0...6
pokemon.iv[i]=31*levelperc/100
pokemon.ev[i]=[levelperc*remaining_ev*bs[i]/(100*sumbs),252].min
remaining_ev-=pokemon.ev[i]
sumbs-=bs[i]
reserve_ev+=pokemon.ev[i] % 4
pokemon.ev[i]-=pokemon.ev[i] % 4
if pokemon.ev[i]==4
reserve_ev+=pokemon.ev[i]
pokemon.ev[i]-=pokemon.ev[i]
end
end
pokemon.ev[pokemon.ev.index(pokemon.ev.max)]=[252,pokemon.ev[pokemon.ev.index(pokemon.ev.max)]+reserve_ev].min```
So, everything nice, but how does it actually work? Let's see some examples: (results will be proportionated based on level and levelcap, but for sake of simplicity and comparability matters, all of the following example will be at level equal or greater than levelcap, and with the dedicated Switch set to TRUE)
• Starmie, level 50 or more with levelcap=50: (Special attacker)
EV: hp=0,atk=0,def=76,speed=182,sp.atk=172,sp.def=80 (IVs= all 31)
EV: hp=0,atk=204,def=24,speed=246,sp.atk=0,sp.def=36
• Salamence (Mixed attacker)
EV: hp=0,atk=242,def=0,speed=144,sp.atk=124,sp.def=0
• Shuckle (Defensive)
EV: hp=16,atk=0,def=252,speed=0,sp.atk=0,sp.def=240
• Nidoqueen (all stats are similar)
EV: hp=140,atk=154,def=108,speed=8,sp.atk=8,sp.def=92

I hope everything is alright, let me know and report potential errors!
COMPATIBLE WITH 17.2! (can't ensure it works for other versions)
Thanks to mgriffin and WolfPP for the support :)
__________
The MANUAL alternative to this script by
DoesntKnowHowToPlay:
P.S. If someone is enough able with coding, a great idea would be using my formula to set EVs and IVs in case the parameter of DoesntKnowHowToPlay's Script are not specified. (I am not that able ahaha)
__________________
Pokemon Winter Memories ~ Developing..
________________________
Defining trainers' EV through formula: https://www.pokecommunity.com/showthread.php?t=414192
#2
October 6th, 2018 (5:36 AM).
 WolfPP Join Date: Aug 2018 Location: Brazil Gender: Male Nature: Jolly Posts: 164
I've been waiting for this. Thanks for sharing!