Welcome, Guest! Login | Register

Revamping the Player Model System [Print this Article]
Posted by: omega
Date posted: Aug 31 2003
User Rating: 4 out of 5.0
Number of views: 6083
Number of comments: 7
Description: A system to Revamp the Player Model system so that it doesn't use Infokeys (which are easily hackable, and insecure) this also prevents hltv bugs.
About a week ago on the forum someone was asking how to change the player models so that each class can have its own animations and hitboxes. The benefits of doing this means your models don't have to match skeleton wise, nor do they have to be the same size (you could make one class a large cyborg and another could be an average sized human). FLFII: Defiance uses a method very similar to this to distinguish between the male and female classes.

Here is a rundown on the required steps:
  • get rid of any "model" infokey usage
  • change the draw player function on the client to not use the infokey
  • create a method on the server to set and update the model
  • replace the old SET_MODEL() calls with said function
  • get rid of everything related to g_ulModelIndexPlayer, except in CreateBaseline, make that identical to the non-player version.
    An optional step could be:
  • create new animation functions to match different classes


Now that we've gathered the steps required, we have to establish where we need to make the changes. The first obvious location is inside the function StudioDrawPlayer, which is found in StudioModelRenderer.cpp. I mentioned in the steps that we need to change it to not use the infokey, which makes the model be drawn like regular models. Take a look at StudioDrawModel, compare the differences in where it grabs the modelindex and modify it accordingly.

On the server of course we need a function that can change the players model specific to what their class is. Assuming all models have been precached with PRECACHE_MODEL() all we have to do is something like this:

 CODE (C++) 

void SetCorrectModel()
{
    char modelname[512];

    switch(pev->playerclass)
    {
    case 1: //cyborg
    sprintf(modelname, "models/player/cyborg.mdl");
    break;
    case 2: //male human
    sprintf(modelname, "models/player/mhuman.mdl");
    break;
    }

    pev->modelindex = MODEL_INDEX(modelname);
    pev->model = MAKE_STRING(modelname);
}


I've realized when doing this myself that SET_MODEL doesn't always work correctly, so when I discovered this method I of course chose to use it.

Thats all I'm going to cover here. It should be self explanatory, obviously you can't just copy and paste this (I only gave you one block of code; You should already know how to use it, mind you!) and the other steps you'll have to figure out on your own.

Good Luck!

Rate This Article
This article is currently rated: 4 out of 5.0 (5 Votes)

You have to register to rate this article.
User Comments Showing comments 1-7

Posted By: imperio59 on Jun 15 2004 at 02:22:21
After some help on IRC i got this to work fine, it's really awesome :)
Basically, to ive you some more hints, you need to change the clientside function to use the modelindex instead of the infoKey. StudioDrawModel() uses the modelindex , and that's where you should look to find the right code to modify in StudioDrawPlayer(). After that, the rest is quite easy. Anywhere where you want to change your player model you would use the last 2 lines of the function in the tutorial above (assuming you have Prechached the model correctly) and all should be well! Enjoy :)

Posted By: ts2do on Aug 04 2004 at 23:58:13
I think MODEL_INDEX should have STRING(modelname)
ALSO, its g_ulModelIndexPlayerEdited by ts2do on Aug 05 2004, 00:27:32

Posted By: omega on Oct 31 2004 at 17:44:26
you only need STRING(modelname) if modelname is a string_t or integer, using the string table.

Posted By: omega on Oct 31 2004 at 22:26:55
i'm just too generous. i mean, this defeats the purpose of the tutorial. hopefully you LEARNED something from trying it yourself before using this.

http://omega.frontline2.com/revamped.txt

Posted By: cct on Oct 01 2005 at 17:52:02
does this txt exist somewhere?

nice tut btw

Posted By: omega on Oct 01 2005 at 19:29:29
i don't think so, i think i deleted it and don't have the file on my HD anymore.



[edit for archive purposes]
http://web.archive.org/web/20041210051803/...om/revamped.txt
[/edit]Edited by omega on Aug 03 2013, 21:59:08

Posted By: X{DE}X-metal_ace on Oct 30 2005 at 03:22:01
is there a plugin that u can just intall that admins can add more models to load or click on?


You must register to post a comment. If you have already registered, you must login.

Latest Articles
3rd person View in Multiplayer
Half-Life 2 | Coding | Client Side Tutorials
How to enable it in HL2DM

By: cct | Nov 13 2006

Making a Camera
Half-Life 2 | Level Design
This camera is good for when you join a map, it gives you a view of the map before you join a team

By: slackiller | Mar 05 2006

Making a camera , Part 2
Half-Life 2 | Level Design
these cameras are working monitors that turn on when a button is pushed.

By: slackiller | Mar 04 2006

Storing weapons on ladder
Half-Life 2 | Coding | Snippets
like Raven Sheild or BF2

By: British_Bomber | Dec 24 2005

Implementation of a string lookup table
Half-Life 2 | Coding | Snippets
A string lookup table is a set of functions that is used to convert strings to pre-defined values

By: deathz0rz | Nov 13 2005


Latest Comments
knock knock
General | News
By: omega | Dec 22 2016
 
knock knock
General | News
By: MIFUNE | Oct 10 2015
 
New HL HUD Message System
Half-Life | Coding | Shared Tutorials
By: chbrules | Dec 31 2011
 
knock knock
General | News
By: Whistler | Nov 05 2011
 
Particle Engine tutorial part 4
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 18 2010
 
Particle Engine tutorial part 2
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 11 2010
 
Particle Engine tutorial part 3
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 11 2010
 
Game Movement Series #2: Analog Jumping and Floating
Half-Life 2 | Coding | Shared Tutorials
By: mars3554 | Oct 26 2009
 
Particle Engine tutorial part 5
Half-Life | Coding | Client Side Tutorials
By: Deadpool | Aug 02 2009
 
Particle Engine tutorial part 5
Half-Life | Coding | Client Side Tutorials
By: Persuter | Aug 02 2009
 

Site Info
297 Approved Articless
8 Pending Articles
3940 Registered Members
0 People Online (7 guests)
About - Credits - Contact Us

Wavelength version: 3.0.0.9
Valid XHTML 1.0! Valid CSS!