Raised This Month: $32 Target: $400
 8% 

Entities on server


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
3jorn
Junior Member
Join Date: May 2007
Old 09-16-2007 , 18:04   Entities on server
Reply With Quote #1

I was playing around with the entities today, and made this command

Code:
CON_COMMAND( print_edicts, "print the edicts with classnames" )
{
    for(int i = 0; i < engine->GetEntityCount(); i++)
    {
        edict_t *pEntity = engine->PEntityOfEntIndex(i);
        if(pEntity)
        {
            CBaseEntity *cbe = pEntity->GetUnknown()->GetBaseEntity();
            Msg("%i\t: %s \n", i, pEntity->GetClassName() );
        }
    }
}
This will simply print the entire list of entities on the server. It will crash if you don't do the if(pEntity) test.

This can be expanded to filter out what you want. Example, getting the teams

Code:
if( FStrEq(pEntity->GetClassName(), "cs_team_manager") )
{
      CTeam *team = (CTeam*)pEntity->GetUnknown()->GetBaseEntity();
      Msg("Team name: \t%s \n", team->GetName() );
}
You'll need to include "cbase.h" and "team.h".

team->AddScore(2) adds 2 points to that team.
Just wanted to share in case someone could benefit from this code.
3jorn is offline
BAILOPAN
Join Date: Jan 2004
Old 09-16-2007 , 19:54   Re: Entities on server
Reply With Quote #2

There's no guarantee that a mod's CTeam or any of its members will exist, must less match, how your code compiles from the SDK.

Therefore be warned that your code will most likely not port to any other mod, and may even break across versions of CS:S.
__________________
egg
BAILOPAN is offline
3jorn
Junior Member
Join Date: May 2007
Old 09-17-2007 , 02:00   Re: Entities on server
Reply With Quote #3

My code is for CS:S only.
Please forgive me, I'm having trouble understanding why it might break if it compiles and work properly for both Windows and linux.
If compiled with the correct headers, I would assume it would work until Valve changes around they team-code?
3jorn is offline
BAILOPAN
Join Date: Jan 2004
Old 09-17-2007 , 18:54   Re: Entities on server
Reply With Quote #4

CTeam derives from CBaseEntity and that means changes to CTeam, CBaseEntity, or anything CBaseEntity derives from, that differ from the SDK, will result in a binary incompatibility. Anything that deals with member variables or the virtual table order (virtual functions) on a source-code level has to match.

The current SDK tends to somewhat match how Valve has compiled CS:S, but there have been periods where it has not. If the specific function/variable you're accessing works, that's great. But it may break in the future so my warning was to mentally prepare you for that if you weren't already ;)
__________________
egg
BAILOPAN is offline
3jorn
Junior Member
Join Date: May 2007
Old 09-17-2007 , 19:54   Re: Entities on server
Reply With Quote #5

hehe thanks, however when it breaks, I'll probably be left baffled anyways
I'm still pretty new at this, it takes a while to get a really good understanding of it.

But I do understand what you are saying now, and it makes perfect sense. I guess the safest would be to not make my code rely on something that cannot be fetched dynamically.

My goal was simply to be able to make a gametype that I can add points to a team without the round having to end - capture the flag much-alike.
Pretty good fun to play around with this
3jorn 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 09:27.


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