Here's my modification on your plugin to make sure that people can't just type 'retry' in console to avoid the same thing. I seem to recall seeing this somewhere already but in case you find it worthwhile too: (untested yet)
PHP Code:
/* Plugin Template generated by Pawn Studio */
#pragma semicolon 1
#include <sourcemod>
#define SPEC_VERSION "1.0"
#define BUILDD __DATE__
#define BULLDT __TIME__
public Plugin:myinfo =
{
name = "No Spec Hop Cash",
author = "TnTSCS modified by databomb",
description = "Prevents players from receiving mp_startmoney by spectate hopping",
version = SPEC_VERSION,
url = "http://forums.alliedmods.net/showthread.php?t=157593"
}
new g_MoneyOffset;
new Handle:g_hStartMoney = INVALID_HANDLE;
new Handle:gH_SteamList = INVALID_HANDLE;
new g_hPlayersMoney[MAXPLAYERS+1];
new g_hPlayersDiffMoney[MAXPLAYERS+1];
new bool:FirstJoined[MAXPLAYERS+1];
new bool:PlayerSpec[MAXPLAYERS+1];
public OnPluginStart()
{
CreateConVar("sm_nospeccash_buildversion",SOURCEMOD_VERSION, "This version of 'No Spec Hop Cash' was built on ", FCVAR_PLUGIN);
CreateConVar("sm_nospeccash_version", SPEC_VERSION, "This version of 'No Spec Hop Cash' ", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
g_hStartMoney = FindConVar("mp_startmoney");
g_MoneyOffset = FindSendPropInfo("CCSPlayer", "m_iAccount");
if (g_MoneyOffset != -1)
{
HookEvent("player_team", TeamChanged);
}
else
{
SetFailState("* FATAL ERROR: Failed to obtain offset for CCSPlayer::m_iAccount");
}
gH_SteamList = CreateArray(22);
}
public OnClientDisconnect(client)
{
if (IsClientInGame(client))
{
decl String:authString[20];
GetClientAuthString(client, authString, 20);
if (FindStringInArray(gH_SteamList, authString) == -1)
{
PushArrayString(gH_SteamList, authString);
PushArrayCell(gH_SteamList, GetPlayerCash(client));
}
}
}
public TeamChanged(Handle:event, const String:name[], bool:dontBroadcast)
{
if(GetEventBool(event,"disconnect"))
{
return;
}
else
{
new client = GetClientOfUserId(GetEventInt(event,"userid"));
new clientteam = GetEventInt(event,"team"); //get the TeamID of the player
if(FirstJoined[client]) //Check to see if a player is joining the game and picking their first team
{
FirstJoined[client] = false; //After a player joins for the first time and picks a team, they are marked as NOT FirstJoined
return;
}
else //if FirstJoined = false
{
if(clientteam != 0) //ensure team is spectate, t, or ct
{
g_hPlayersMoney[client] = GetPlayerCash(client); //find out what the player's current cash is
if(g_hPlayersMoney[client] < GetConVarInt(g_hStartMoney)) //if player's cash is less than mp_startmoney
{
g_hPlayersDiffMoney[client] = GetConVarInt(g_hStartMoney) - g_hPlayersMoney[client]; //figure out the difference between player's cash and mp_startmoney
}
else
{
g_hPlayersDiffMoney[client] = 0; //set to 0 since player's money is greater than mp_startmoney
}
if(clientteam == 1) //if player is on team 1 for spectate
{
PlayerSpec[client] = true; //Set player as being in spectate
//PrintToChat(client,"\x04[\x03SpecHopCash\x04]\x01 When you join your team again, your cash will be restored to %i",g_hPlayersMoney[client]);
return;
}
if(clientteam != 1) //player joined t or ct
{
if(PlayerSpec[client]) //if player is marked as spectate
{
if(g_hPlayersDiffMoney[client] != 0) //check if there is a PlayersDiffMoney value, if so, we will subtract that amount from the player's cash
{
//PrintToChat(client,"\x04[\x03SpecHopCash\x04]\x01 When you spawn, you will be fined for spectate hopping in the amount of %i",g_hPlayersDiffMoney[client]);
SetPlayerCash(client,g_hPlayersMoney[client] - g_hPlayersDiffMoney[client]); //subtract the difference from the player's cash to preserve the cash amount when they went into spectate
}
PlayerSpec[client] = false; //player joined a team, mark as not in spectate
}
}
}
}
}
}
public OnMapEnd()
{
for(new i = 0; i < MAXPLAYERS + 1; i++)
{
FirstJoined[i] = true;
PlayerSpec[i] = false;
g_hPlayersDiffMoney[i] = 0;
}
}
public OnMapStart()
{
for(new i = 0; i < MAXPLAYERS + 1; i++)
{
FirstJoined[i] = true;
PlayerSpec[i] = false;
g_hPlayersDiffMoney[i] = 0;
}
ClearArray(gH_SteamList);
}
public OnClientAuthorized(client,const String:auth[])
{
new indexNum = FindStringInArray(gH_SteamList, auth);
if (indexNum == -1)
{
FirstJoined[client] = true;
g_hPlayersDiffMoney[client] = 0;
PlayerSpec[client] = false;
}
else
{
FirstJoined[client] = false;
PlayerSpec[client] = true;
new playerCash = GetArrayCell(gH_SteamList, indexNum, 20);
g_hPlayersDiffMoney[client] = GetConVarInt(g_hStartMoney) - playerCash;
}
}
public GetPlayerCash(entity)
{
return GetEntData(entity, g_MoneyOffset);
}
public SetPlayerCash(entity, amount)
{
SetEntData(entity, g_MoneyOffset, amount, 4, true);
}
__________________