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: 3494
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 14 2004 at 20: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 17:58:13
I think MODEL_INDEX should have STRING(modelname)
ALSO, its g_ulModelIndexPlayerEdited by ts2do on Aug 04 2004, 18:27:32

Posted By: omega on Oct 31 2004 at 11: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 16: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 11:52:02
does this txt exist somewhere?

nice tut btw

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

Posted By: X{DE}X-metal_ace on Oct 29 2005 at 22: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 04 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
Where do we go from here
General | News
By: MIFUNE | Jun 09 2008
 
The Input/Output system
Half-Life 2 | Level Design
By: nazitaco | Dec 23 2007
 
Where do we go from here
General | News
By: Rob_F | Nov 22 2007
 
Rescaling Half-Life
Half-Life | Coding | Shared Tutorials
By: christoph | Nov 12 2007
 
GameUI
Half-Life 2 | Coding | Client Side Tutorials
By: Evil_j | Oct 29 2007
 
3 State Zoom For Any Weapon
Half-Life 2 | Coding | Server Side Tutorials
By: Ennuified | Oct 18 2007
 
Storing weapons on ladder
Half-Life 2 | Coding | Snippets
By: cct | Sep 07 2007
 
CTF Gameplay Part 1
Half-Life | Coding | Shared Tutorials
By: DarkNight | Aug 28 2007
 
CTF Gameplay Part 1
Half-Life | Coding | Shared Tutorials
By: deedok | Aug 20 2007
 
Debugging your half-life 2 mod
Half-Life 2 | Coding | Articles
By: blackshark | Aug 17 2007
 

Site Info
296 Approved Articless
5 Pending Articles
3940 Registered Members
0 People Online (11 guests)
About - Credits - Contact Us

Wavelength version: 3.0.0.9
Valid XHTML 1.0! Valid CSS!