Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions addons/sourcemod/scripting/TopInfectors.sp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Handle g_hSpawnTimer[MAXPLAYERS + 1];
bool g_bNemesis = false;
bool g_bDynamicChannels = false;

public Plugin myinfo =
public Plugin myinfo =
{
name = "Top Infectors",
author = "Nano, maxime1907, .Rushaway",
Expand Down Expand Up @@ -246,7 +246,7 @@ public Action Command_OnToggleStatus(int client, int args)
// Purpose: Hooks
//---------------------------------------

public Action ZR_OnClientInfect(int &client, int &attacker, bool &motherInfect, bool &respawnOverride, bool &respawn)
public Action ZR_OnClientInfect(int &client, int &attacker, bool &motherInfect, bool &respawnOverride, bool &respawn)
{
if (!IsValidZombie(attacker))
{
Expand Down Expand Up @@ -282,24 +282,24 @@ public void Event_OnClientDeath(Event hEvent, const char[] sEvent, bool bDontBro
}
}

public void Event_OnRoundStart(Event event, char[] name, bool dontBroadcast)
public void Event_OnRoundStart(Event event, char[] name, bool dontBroadcast)
{
RemoveAllHats();
Cleanup();
}

public void Event_OnPlayerSpawn(Event event, const char[] name, bool dontbroadcast)
public void Event_OnPlayerSpawn(Event event, const char[] name, bool dontbroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));

if (!IsValidClient(client) || !IsPlayerAlive(client) || !ZR_IsClientHuman(client) || g_iTopInfector[client] <= -1)
return;

delete g_hSpawnTimer[client];
g_hSpawnTimer[client] = CreateTimer(7.0, Timer_OnClientSpawnPost, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
}

public void Event_OnRoundEnd(Event event, char[] name, bool dontBroadcast)
public void Event_OnRoundEnd(Event event, char[] name, bool dontBroadcast)
{
// ZombieReloaded always fire a team win event before the draw event
// So we can ignore the draw event - Prevent duplicate execution
Expand Down Expand Up @@ -576,13 +576,13 @@ stock void RemoveAllHats()
}
}

void CreateHat(int client)
{
void CreateHat(int client)
{
RemoveHat(client);

if ((g_iSkullEntities[client] = EntIndexToEntRef(CreateEntityByName("prop_dynamic"))) == INVALID_ENT_REFERENCE)
return;

int iSkullEntity = EntRefToEntIndex(g_iSkullEntities[client]);
SetEntityModel(iSkullEntity, SKULL_MODEL);

Expand Down Expand Up @@ -618,7 +618,6 @@ void CreateHat(int client)
stock void GiveGrenadesToClient(int client, int iAmount, WeaponAmmoGrenadeType type)
{
char sWeapon[32];
int iAmmo = GetClientGrenades(client, type);
switch(type)
{
case GrenadeType_HEGrenade:
Expand All @@ -631,7 +630,7 @@ stock void GiveGrenadesToClient(int client, int iAmount, WeaponAmmoGrenadeType t
return;
}

if (iAmmo > 0)
if (HasPlayerItem(client, sWeapon))
{
int offsNades = FindDataMapInfo(client, "m_iAmmo") + (view_as<int>(type) * 4);
int count = GetEntData(client, offsNades);
Expand All @@ -650,10 +649,22 @@ stock void GiveGrenadesToClient(int client, int iAmount, WeaponAmmoGrenadeType t
}
}

stock int GetClientGrenades(int client, WeaponAmmoGrenadeType type)
stock bool HasPlayerItem(int client, const char[] weapon)
{
int offsNades = FindDataMapInfo(client, "m_iAmmo") + (view_as<int>(type) * 4);
return GetEntData(client, offsNades);
int max = GetEntPropArraySize(client, Prop_Send, "m_hMyWeapons");
for (int i = 0; i < max; i++)
{
int ent = GetEntPropEnt(client, Prop_Send, "m_hMyWeapons", i);
if (ent == -1 || !IsValidEntity(ent))
continue;

char className[32];
GetEntityClassname(ent, className, sizeof(className));
if (strcmp(className, weapon, false) == 0)
return true;
}

return false;
}

stock int GetClientRank(int client)
Expand Down Expand Up @@ -692,7 +703,7 @@ public int SortInfectorsList(int[] elem1, int[] elem2, const int[][] array, Hand
return 0;
}

bool IsValidZombie(int attacker)
bool IsValidZombie(int attacker)
{
return (0 < attacker <= MaxClients && IsValidEntity(attacker) && IsClientInGame(attacker) && IsPlayerAlive(attacker));
}
Expand Down Expand Up @@ -728,3 +739,4 @@ public void Nemesis_OnConfigVerified(bool configExists)
g_bNemesis = configExists;
}
#endif

2 changes: 1 addition & 1 deletion addons/sourcemod/scripting/include/TopInfectors.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#define TopInfectors_V_MAJOR "1"
#define TopInfectors_V_MINOR "5"
#define TopInfectors_V_PATCH "9"
#define TopInfectors_V_PATCH "10"

#define TopInfectors_VERSION TopInfectors_V_MAJOR..."."...TopInfectors_V_MINOR..."."...TopInfectors_V_PATCH

Expand Down