Raised This Month: $51 Target: $400
 12% 

Change Points Awarded


Post New Thread Reply   
 
Thread Tools Display Modes
Keeper
Senior Member
Join Date: Nov 2006
Old 10-19-2009 , 13:46   Re: Change Points Awarded
Reply With Quote #11

Here's how I have it in mine, you may or may not need all three:
Code:
#define GAME_DLL 1 
#include "cbase.h"
#include "baseentity.h"
#include "team.h"
Keeper is offline
Ajaxx
Senior Member
Join Date: Oct 2009
Old 10-19-2009 , 21:34   Re: Change Points Awarded
Reply With Quote #12

Thanks Keeper, that worked! It's compiling fine but always returning null. I'm getting the teamNum with:

Code:
void CEmptyServerPlugin::BombExploded( IGameEvent * event )
  {
        int userid = event->GetInt("userid");
   
        IPlayerInfo *pUser = PlayerOfUserId(userid);
   
        if( pUser )
        {
              CTeam * team = GetTeam( pUser->GetTeamIndex()  );
   
              if( team )
              {
                    team->SetScore( team->GetScore() + 1 );
              }
        }
  }
   
  CTeam * CEmptyServerPlugin::GetTeam( int teamNum )
  {
      for( int i = 0; i < engine->GetEntityCount(); i++ )
        {
          edict_t *pEntity = engine->PEntityOfEntIndex(i);
   
          if( pEntity && FStrEq(pEntity->GetClassName(), "team_manager" ) )
              {
              CTeam *team = (CTeam*)pEntity->GetUnknown()->GetBaseEntity();
   
              if ( team && team->GetTeamNumber() == teamNum )
                  return team;
          }
      }
      return NULL;
  }
Ajaxx is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 10-19-2009 , 22:44   Re: Change Points Awarded
Reply With Quote #13

I'm not sure, because I haven't worked much with CSS, but I think the team manager is called "cs_team" instead of "team_manager". Sorry about that
Keeper is offline
Ajaxx
Senior Member
Join Date: Oct 2009
Old 10-20-2009 , 00:53   Re: Change Points Awarded
Reply With Quote #14

Keeper you're the bomb. You gave me what I was asking for, but I think I was asking for the wrong thing What the above code does is added 1 to the actual Terrorist team score on the scoreboard. What I want to do is add 1 to the individual players on the Terrorist team.

With your help I was able to find: CBaseEntity::AddPoints( int score, bool bAllowNegativeScore ). I'm trying to use it like so:
Code:
CBaseEntity* pBaseEnt = GetBaseEnt( userid );
pBaseEnt->AddPoints( 1, true );
  -- snip --

  CBaseEntity* CEmptyServerPlugin::GetBaseEnt( int userid )
  {
      for( int i = 0; i < engine->GetEntityCount(); i++ )
      {
          edict_t* pEntity = engine->PEntityOfEntIndex(i);
   
              if( pEntity && !pEntity->IsFree() )
              {
                    if( FStrEq( pEntity->GetClassName(), "player" ) )
                    {
                          CBaseEntity* baseEnt = pEntity->GetUnknown()->GetBaseEntity();
   
                          if( engine->GetPlayerUserId( pEntity ) == userid )
                          {
                                return baseEnt;
                          }
                    }
            }
      }
      return NULL;
  }

But I get the folling linking error on line pBaseEnt->AddPoints( 1, true);
Error 4 error LNK2019: unresolved external symbol "public: void __thiscall CBaseEntity::AddPoints(int,bool)".

I know this is more of a C++ question. But what am I missing?
Ajaxx is offline
pRED*
Join Date: Dec 2006
Old 10-20-2009 , 01:32   Re: Change Points Awarded
Reply With Quote #15

I would strongly recommend not including cbase.h/baseentity.h ever. The fact that the CTeam code works is relying on CS:S using identical code to the sdk, which is far from guaranteed. It may work for now, but it's not a great thing to rely on.

Your error comes from the fact that AddPoints is defined in a .cpp file instead of the baseentity., so the compiler can't find the code for this.

The obvious (but incorrect) solution would be to try and drag baseentity.cpp into your project and compile with that. The code for this function modifies the m_iScore variable and the chances of this matching between SDK and CS:S is very unlikely.
A much safer method is noticing that the m_iScore member is exposed as a sendprop (and appears in sendprop dumps like this). Sendprops can be looked up at runtime from a string identifier and will find the correct offset for the current codebase. Have a look at SourceMod's code for a great example of how to access this (it's all from the public folder in the sdk and thus much less likely to change on you).
pRED* is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 10-20-2009 , 09:33   Re: Change Points Awarded
Reply With Quote #16

You're probably right. Having only dealt in HL2MP plugins I've been spoiled by no updates for years now Not to mention the SDK is darn close to that game.
Keeper is offline
Ajaxx
Senior Member
Join Date: Oct 2009
Old 10-20-2009 , 13:48   Re: Change Points Awarded
Reply With Quote #17

Thanks pRED* and Keeper. I’ve been looking through the SourcMod code… that’s a lot of code! I’m trying to find an example of the proper use of m_iScore in SendProp. I found SendProp in the IGameConfigs.h file. I know this is not what I’m looking for. Can you point me to the right location where I can see m_iScore in use?
Ajaxx is offline
pRED*
Join Date: Dec 2006
Old 10-20-2009 , 15:54   Re: Change Points Awarded
Reply With Quote #18

CHalfLife2::FindSendPropInfo in core/HalfLife2.cpp

Takes a server classname (like CTFPlayer) and the property string you want to lookup. Returns a sm_sendprop_info_t struct which wraps the SendProp* (see dt_send.h in hl2sdk/public) and the correctly computed offset from a CBaseEntity*.

Accessing the value is done by casting the CBaseEntity* to a pointer to a type that has a sizeof() == 1 (unsigned char *?) and then adding the offset, and casting to the correct type pointer.
pRED* is offline
Ajaxx
Senior Member
Join Date: Oct 2009
Old 10-21-2009 , 16:19   Re: Change Points Awarded
Reply With Quote #19

That is a very descriptive reply, thank you, but I still don’t understand. I’ve been looking through the SourceMod code but I don’t follow it. What code do I need to add to my plugin to change a player’s score?
Ajaxx is offline
pRED*
Join Date: Dec 2006
Old 10-21-2009 , 16:24   Re: Change Points Awarded
Reply With Quote #20

for tf2 it'd be:

Code:
CBaseEntity *pEntity = /* your player entity */
sm_sendprop_info_t propInfo;
if (g_HalfLife2.FindSendPropInfo("CTFPlayer", "m_iScore", &propInfo))
{
	/* Use the offset and our CBaseEntity as a base to find the prop pointer */
	int *m_iScore = (int *)(((unsigned char *)pEntity) + propInfo.offset);
	/* Add 1 to score */
	*m_iScore++;

}
CTFPlayer would obviously need to be changed to your player class which is listed on the sendprop dump I linked earlier.
pRED* 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:36.


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