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

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?
```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
```

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
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)
-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.
x 49 x 5 x 1 x 1 x 1 (list)

2. Looking forward to this, I'm pretty sure you can make the capture effects better though.
Dumb x 1 (list)

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

Edited:

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

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

5. It's nice you found a good catchrate formula.

6. For the past few weeks I've had a sudden Pokemon craze, and I am really liking this. How will the fighting work?
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)

7. 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?
Winner x 2 (list)

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

9. 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?
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.

Edited:

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)
Useful x 1 (list)

10. you should make a gamemode and name it Pokemon:Source
Agree x 3 (list)

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

Edited:

Updated OP with video of fluid wobble.
Winner x 3 (list)

12. This is great! Will there be a release soon?

13. Wow. Amazing. You japanese OP? (Just though about it because its Pokemon :3)
Dumb x 10 Funny x 1 Disagree x 1 (list)

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

Location: Michigan, USA

Anyways, good work. The videos looks great!
Zing x 8 Funny x 1 (list)

15. Wow. Amazing. You japanese OP? (Just though about it because its Pokemon :3)
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)
Agree x 3 (list)

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

Edited:

And, I'm not even living near Japan and I've got many nintendo 64 pokemon games, and for my gameboy.
Dumb x 4 (list)

17. Diggin' the new wobble. Looking good

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

Edited:

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)
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.
Lua Helper x 1 (list)

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

20. Amazing

Putting this on my "Anticipated Mods" list.

21. Starting work on the selection menu - let me know what you think
Lua King x 3 (list)

22. Starting work on the selection menu - let me know what you think
Pictureszzzz
Looks cool. I like how the top left cornor is cutted of. Maybe make the pokeball spin around? And remove the white background of the picture/making the picture background transperant.

23. It's a DModelPanel - it does spin around, the pokeball model is just a placeholder for whatever Garrymon that you'll be displaying in that main display window (the rest will be on the right in a simple list)

Edited:

Anyone have the equation or whatever to slowly change a health bar from green to red the lower your health gets? I forgot the math and lost my copies of it =(

24. here ya go
```local percentCalc = 255 * (traceEntHealth / traceEntMaxHealth)

greenToRed = Color(255-percentCalc,percentCalc,0,255)
```
Friendly x 1 (list)

25. here ya go
```local percentCalc = 255 * (traceEntHealth / traceEntMaxHealth)

greenToRed = Color(255-percentCalc,percentCalc,0,255)
```
Thank you, kind sir!

Edited:

'nother update

26. This is awesome, so what exactly can be catchable, any NPC?

And also, we really need a gamemode for this.
Agree x 1 (list)

27. This is awesome, so what exactly can be catchable, any NPC?
And also, we really need a gamemode for this.
Someone will probably do a gamemode when this is released.
Agree x 2 Informative x 1 (list)

28. Thank you, kind sir!

Edited:

'nother update
Wow. Realy, wow. This looks god damn epic.

29. Pokeball should stay still after darkening, emit some stars and play the caught pokemon theme for a while.

Edited:

Duh-duh-du-duh duh duh, dum-de-dum doo...
Agree x 2 Funny x 1 (list)

30. Thank you, kind sir!

Edited:

'nother update
Looks really good, but it's spelled "Controller"

31. Looks really good, but it's spelled "Controller"
s'what I get for coding in the middle of the night again XD

Edited:

This is awesome, so what exactly can be catchable, any NPC?

And also, we really need a gamemode for this.
My end goal: you have discovered it.

32. I don't think the bar should smoothly go down to red, it should go green, yellow, red, like in the game.

33. Back from the first gamemode I started working on, my code for that looked like this:
```(HPPercent > 0.5) and Color(113, 247, 168) or ((HPPercent > 0.25) and Color(224, 219, 57) or Color(237, 91, 60))
```
Those are the colors from the actual game, too.
Looking through this code, it's absolutely terrible. I can't believe it got me an interview and everything..

34. This looks pretty cool so far, any plans to make it available on Toybox too?

Are you basing the wobble off of the one shown in the anime, or the "1...2...3...DING" they use in the games? Your current effect seems to point to the former, whereas before it didn't.

35. This looks pretty cool so far, any plans to make it available on Toybox too?

Are you basing the wobble off of the one shown in the anime, or the "1...2...3...DING" they use in the games? Your current effect seems to point to the former, whereas before it didn't.
I've gone through tons of different versions of the wobble, not exactly sure what I planned for it, but this one looks OK for now.

Updating health bar to use set health points.
Winner x 1 (list)

36. This is... amazing.
Agree x 1 (list)

37. I'm really in need of a few models for this, but the modeling request section never yields me any results. If anyone can model, or knows someone whose willing to help me that would be awesome.

I need an animated pokeball - one that has an animation for opening and closing, because just having it stay closed all the time looks wonky.
Also if you could put the garrysmod "g" on top of it like the masterball has an "M" that would be awesome. The font for it is "coolvectica".

I also need some kinda pokecenter type thing with 6 attachments - one for each possible ball to be placed onto it.

In my wildest dreams I'd have a view model with several awesome animations:
1) When you draw out the weapon, you'd hold a tiny pokeball in your fingers that would slowly grow out to be the full sized one, like in the anime
2) A good throwing animation or two, perhaps an overhead and a side throw
3) Rotate the pokeball forward for the return command.

Granted I know I'm probably not gonna get any of these, but a coder can dream right?

Edited:

Or if someone wanted to make a pokemon map with Pokecenter, Gym, Arena and a wilds area that would be awesome =P
Friendly x 2 Agree x 1 (list)

38. Talk to FluxMage, he could give you a hand if he isn't busy. If not, I think Generic could be good also.

I've been wanting to try some modelling meself, so if I get any time soon, I could toss in my own attempt, if you don't mind. Shouldn't be hard...I'm just a complete novice at texturing.

39. Found a much better model on gamebanana that solves a lot of the sticking problems it had when wobbling, and doesn't have the vertex issues on the front face that the original model did. Only problem now the wobble goes from slow to spinning OUT OF FUCKING CONTROL - working on it still.

Edited:

Added stars - shows new model (not visibly different from the back)
Artistic x 2 (list)

40. does A+B+DOWN help?
Funny x 4 Winner x 1 Lua Helper x 1 (list)