Raised This Month: $ Target: $400
 0% 

Custom Variables


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ajaxx
Senior Member
Join Date: Oct 2009
Old 01-14-2010 , 08:20   Custom Variables
Reply With Quote #1

Is it possible to add my own variables, like a double, an int, and a bool, to the edict_t or IPlayerInfo objects? Or would I have to make my own structure to track my extra variables and tie it to the in-game userId somehow?
Ajaxx is offline
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 01-14-2010 , 13:28   Re: Custom Variables
Reply With Quote #2

Use CUtlVector or CUtlMap (if that exists I don't know). Access items via userids or client indexes or edict_t* or CBE*, your choice. Then use structs, right.

Chris
Chrisber is offline
Ajaxx
Senior Member
Join Date: Oct 2009
Old 01-14-2010 , 18:09   Re: Custom Variables
Reply With Quote #3

Doesn’t the userid change sometimes for example during a map change? What is CUtlVector? Say I want to attach a double variable to a user, how would I go about doing that?
Ajaxx is offline
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 01-15-2010 , 08:08   Re: Custom Variables
Reply With Quote #4

If you want data to store consistent, use steamids. Userid, Index and (caused by that) CBE* and edict_t* changes on every mapchange because every client will be fully disconnected and reconnected.

I would create a struct with the following pointers/vars:
Code:
struct Player_s
{
    CBaseEntity *m_pEntity;
    edict_t *m_pEdict;
    IPlayerInfo *m_pInfo;
    int m_iIndex; // if needed
    int m_iUserID; // if needed
    char *m_pszSteamID; // if I remember, there was a class called CSteamID, may you can use that instead
}

CUtlVector<Player_s*> vecPlayers;

Player_s *getPlayerInfo(char *pszSteamID)
{
    for (int i = 0; i < vecPlayers.Count(); i++) // or Size(), one of them is deprecated
    {
        Player_s *pPlayer = vecPlayers[i];
        
        if (!strcmp(pPlayer->m_pszSteamID, pszSteamID))
        {
            return pPlayer;
        }
    }
    
    return (Player_s*)NULL;
}
The advantage of this method is, that you can search for everything you want, you've only to create a search function for example CBE or Index.

Chris
Chrisber is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:32.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode