I'm trying to write an extension that hooks the OnTakeDamage event for CS: S and gives more damage for certain weapons for certain players. I've tried to do this with a plugin but it seems that there is no other way to do it other than an extension since both the hacks extension and the hooker extension won't do it. I successfully hooked the event but when I try to write code to check the weapon I get link errors that I'm having a real problem resolving.
Code:
int MyExtension::OnTakeDamage(const CTakeDamageInfo &info)
{
int AttackerIndex = engine->IndexOfEdict(serverents->BaseEntityToEdict(info.GetAttacker()));
}
This code above compiles OK, but then doesn't link. Here's the link error:
Code:
error LNK2001: unresolved external symbol "class CBaseEntityList * g_pEntityList" (?g_pEntityList@@3PAVCBaseEntityList@@A)
Here's the other piece of code that's causing link errors:
Code:
void MyDelagate::OnDoDamage(CTakeDamageInfo& info){
int client = engine->IndexOfEdict(serverents->BaseEntityToEdict(info.GetAttacker()));
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer)
{
g_pSM->LogMessage(g_VAH.getIExtension(), "Client index %d is invalid", client);
return;
} else if (!pPlayer->IsInGame()) {
g_pSM->LogMessage(g_VAH.getIExtension(), "Client %d is not in game", client);
return;
}
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
if (!pInfo)
{
g_pSM->LogMessage(g_VAH.getIExtension(), "IPlayerInfo not supported by game");
return;
}
const char *weapon = pInfo->GetWeaponName();
g_pSM->LogMessage(g_VAH.getIExtension(), "weapon is %s", weapon);
if (strcmp(weapon, "weapon_knife") == 0){
info.SetDamage(1000);
}
}
And here are the link errors caused by the above code:
Code:
error LNK2001: unresolved external symbol "class CBaseEntityList * g_pEntityList"
error LNK2019: unresolved external symbol "public: class CPlayer * __thiscall PlayerManager::GetPlayerByIndex(int)const " (?GetPlayerByIndex@PlayerManager@@QBEPAVCPlayer@@H@Z) referenced in function "public: virtual void __thiscall MyDelegate::OnDoDamage(class CTakeDamageInfo &)"
error LNK2001: unresolved external symbol "class PlayerManager g_Players"
The thing is that I know where some of these these unresolved symbols are defined:
g_pEntityList is defined in entitylist.cpp
g_Players is defined in PlayerManager.cpp
I've done everything I can think of to get these files to be included in the build process. I went to Tools -> options -> vc++ directories and added the path to both the include files and the source files. I include the .h files for the corresponding cpp files at in the files that use the code. I even went into the project settings -> linker -> additional dependencies and added every single lib file I could find in the HL2SDK.
Note that I have #define GAME_DLL in my project so it might be looking for the definition of these symbols in a dll somewhere. However if I don't #define GAME_DLL I get literally like 1000 errors... so there's no way I can compile without that.
Can anyone give me some suggestions as to what to do?