WIP: Garrymon Addon - Pokemon (Who are really NPCs!)

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:

http://dl.dropbox.com/u/9780864/garrymon%20catch.png

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.
[media]http://www.youtube.com/watch?v=cvJ7BInv-R0

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

http://archives.bulbagarden.net/media/upload/7/7e/Catch_formula_2.png

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?
[lua]
function ENT:DetermineCapture(ent)
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
break
end
end
return shakes
end
[/lua]

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:

http://archives.bulbagarden.net/media/upload/8/83/Catch_formula_3.png

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)

–Completed–
-Throwing
-“Absorb” effect
-Catching (For the most part)
-Pickup

–To do–
-Deploy system (large part of this project)
-Menu (partially complete)
-Evolution system

FAQ
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.

Looking forward to this, I’m pretty sure you can make the capture effects better though.

Yeah I was planning on improving them a bit. It’s currently too fast for what I would like, I’m just focusing on the mechanics of it before I get the “ooh shiny” done. I want to make it so the model kind of shrinks and LERPs into the ball, but thats inflater work and I haven’t messed with it yet.

[editline]27th March 2011[/editline]

Was just doing a little more theory crafting and even with an Antlion Guard at 1 health, there is still only about a 3% chance to catch him if he’s not on fire.
Difficult Garrymon are difficult O.o

For the past few weeks I’ve had a sudden Pokemon craze, and I am really liking this. How will the fighting work?

It’s nice you found a good catchrate formula.

When you “choose” your Garrymon and send it out, it will from then on hate anything that attacks you and automatically hate things that hate you to begin with (even if they aren’t attacking)
All the actual fighting will be done with their own abilities or what ever they can do. They will spawn with whatever weapon they had when you caught them (sort of like the abilities in real pokemon)

oh god damnit I was just about to do this too

oh well. It looks pretty good, at any rate. That ball-twitching seems really rigid though. Why not rope or ballsocket constrain it to the world or something and apply random or alternating force to it?

Very cool looking, if you can make it so that they follow your commands “kinda like Spacetech’s pet mod” then it’d be awesome.

Because that makes too much sense :facepalm:
I worked a WHILE on getting the ball to even twitch like it is, but the sound effect I’m using for it now makes me want to change that as well, even though it makes me sad.

However last time I tried using constraints in a SENT it didn’t work too well.

[editline]28th March 2011[/editline]

I just tried changing it to a ballsocket constraint when it lands, but you can’t constrain in ENT:PhysicsCollide() and there’s really no other good place to put it (I tried and I cant seem to get it to work either way)

you should make a gamemode and name it Pokemon:Source

Good news, everyone!

I got the Ballsocket idea to work - the wobble looks much better now. Will record a new video once I tweak it a little more.

+1 internets to Ghor for the idea

[editline]28th March 2011[/editline]

Updated OP with video of fluid wobble.

This is great! Will there be a release soon?

Wow. Amazing. You japanese OP? (Just though about it because its Pokemon :3)

Yea. Hes Japanese.

About Feihc
Location: Michigan, USA

Anyways, good work. The videos looks great!

So because I’m a Pokemon fan I must be from Japan, rite? XD

Still trying to think of the best way to save and store what you’ve caught and all - as well as waiting to see if Garry puts in a function I requested in the bug tracker (which would help a lot more people than just myself, I would think)

Nah bro, I’m just asking. This looks great, and I don’t mean it in any disrespecting way (:

[editline]29th March 2011[/editline]

And, I’m not even living near Japan and I’ve got many nintendo 64 pokemon games, and for my gameboy.

Diggin’ the new wobble. Looking good

Set damping to really high, use a user message and send the EntIndex and the number of wobbles, grab the entity and set a variable on it, meanwhile do a smooth wobble using math.sin() and Entity:SetAngle() on the ENT:Draw() hook if the variable is true.

Using physics to do the wobble sounds unoptimized and can look really bad if you’re on a slightly laggy server. It also has the con of friction when it rotates.

Hrm, didn’t think about an Ent:Draw() wobble. I can always disable the friction on it though. It seems to work fine now.

Amazing

Putting this on my “Anticipated Mods” list.