So I was looking around for TF2 skins the other day when I came across this pokeball model for the scouts Sandman ball, when the idea for a Pokeball SWEP hit me. I did some searching and found that there were indeed a few of them already out there, but none lived up to the standards that I was looking for. In my day we only have 151 Pokemon and we were damn proud of them!
So I started coding my own and man, it’s been a lot more tricky that I anticipated but I am keeping with it!
I think I have enough done (about half) of this to make a WIP thread for it.
Have some media:
Updated: Improved wobble of ball
Added: Darkening on successful capture
Highly highly highly improbable capture of a full health antlion guard - 1% chance of ever happening.
The formula I used (which I’m hoping is correct) is from: http://bulbapedia.bulbagarden.net/wiki/Catch_rate
and is as follows (copy pasta win)
There are a multitude of factors that go into determining whether or not you catch an NPC, such as:
-Their max health (ent:GetMaxHealth())
-Their current health (ent:Health())
-The rate of catch for each NPC (Determined by their size ent:GetPhysicsObject():GetVolume() / 1000) - I had to divide by 1000 to make it easier to work with
-Any status ailments on them (currently only checks for ent:IsOnFire(), will probably add a system later to determine if they were hit with poison damage recently for a poison check)
-There currently is no bonus provided by the ball, because it is simply the 1x Pokeball, but if I make more later (if I get the models) then I will add this variable in
These factors also determine how many times the ball twitches on the ground
Once you have that value (the “a” value) you then go on to calculate b, which is more directly related to determining the catch
Then generate 4 random numbers between 0 and 65535, inclusive. For each number, check whether it’s less than b; if so, the ball shakes once. If any number is greater than or equal to b, the Pokémon immediately breaks free. If all four of the numbers are less than b, then the Pokémon is caught. Note that if a is 255 or greater, then b is 65535 or greater, and then the Pokémon is guaranteed to be caught.
So how does all of that nonsense translate into code?
if not ent then return end
local shakes, maxhp, curhp, size, maxsize, pctrate, rate, a, b
shakes = 1
maxhp = ent:GetMaxHealth()
curhp = ent:Health()
size = ent:GetPhysicsObject():GetVolume() / 1000
maxsize = 650
pctrate = (maxsize - math.Clamp(size, 0, maxsize)) / maxsize
if pctrate == 0 then pctrate = .0005 end --To make it not impossible to catch really big shit
rate = 255 * pctrate
if ent:IsOnFire() then bonus = 1.5 else bonus = 1 end
a = (((3 * maxhp - 2 * curhp) * rate) / (3 * maxhp)) * bonus
if a > 255 then return 5 end --Instant catch
b = 1048560 / math.sqrt(math.sqrt(16711680/a))
for i = 1, 4 do
local rand = math.random(0, 65535)
if rand < b then
shakes = shakes + 1
elseif rand >= b then
shakes = 0
Expensive? Yes. Awesome? Yes. Could probably use some work? Most definitely.
With the rates and everything that I’m using currently, out of all of the default NPC’s, an antlion guard with full health and not on fire will be the hardest thing to catch
Lets show you some math to show you what I mean:
An antlion guard has 500 health when you spawn him.
His rate is around 7.85
Non-burning bonus = 1
a = (((3 * 500 - 2 * 500) * 7.85) / (3 * 500)) * 1
a = 2.62
Then b would = 1048560 / sqrt(sqrt(16711680/2.62))
b = 20864.77
The probability p of catching a Pokémon, given the values a and b calculated above, is:
p = ((b+1)/(2^16))^4
p = .010275
Giving you a 1.0275% chance to catch a non-burning, full health Antlion Guard (And I caught it on film, suckas!)
PROTIP: Damaging NPC’s before trying to capture them makes it MUCH MUCH easier! (so does setting them on fire)
So not only will this have the fancy, shiny, awesome effects of a real pokeball (I’m being a stickler on that one) but it also uses the same formula that the gameboy games do.
Your Garrymon will also (in the end product) be able to evolve! (Because NPC’s as large/larger than the Antlion Guard are damn near impossible to catch)
Evolution tree’s are as follows:
City/Shield Scanner -> Manhack
–(Not quite sure how the Scanners are going to gain experience, but I’ll figure that out when I get to that point)
Rollermine -> Hunter
Headcrab -> Zombie Torso -> Zombie -> Zombine
Fast Headcrab -> Fast Zombie Torso -> Fast Zombie
Black Headcrab -> Poison Zombie
Antlion -> Antlion Worker -> Antlion Guard
–(Reasoning for why Worker comes after regular: they can both do the same things melee wise, can both fly, but the Worker can spit, giving it a ranged advantage, i.e. higher level skill)
-Catching (For the most part)
-Deploy system (large part of this project)
-Menu (partially complete)
Q: Can you catch other players Garrymon
A: No. This is not meant to be a fight over who has what, its supposed to be a fight between the Garrymon
Q: Can you catch players
A: No. I’m not going to enable someone to carry you around on their waist for the entire time that you’re on their server.
Q: What’s the point of all the complicated math?
A: Because I can and I want it to resemble the games
Q: Can I beta test it?
A: No. If I want testers I will let you know.