PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <tf2_stocks>
#include <sdkhooks>
public Plugin:myinfo = {
name = "SetScore",
author = "bl4nk",
description = "Set a player's score to whatever you want",
version = "1.0.0",
url = "http://forums.alliedmods.net/"
};
new g_iSetScore[MAXPLAYERS+1] = { -1, ... };
public OnPluginStart() {
RegAdminCmd("sm_setscore", Command_SetScore, ADMFLAG_ROOT, "sm_setscore <#userid|name> <score> - Set a player's score (-1 to disable)");
}
public OnMapStart() {
new iIndex = FindEntityByClassname(MaxClients+1, "tf_player_manager");
if (iIndex == -1) {
SetFailState("Unable to find tf_player_manager entity");
}
SDKHook(iIndex, SDKHook_ThinkPost, Hook_OnThinkPost);
}
public OnClientPutInServer(iClient) {
g_iSetScore[iClient] = -1;
}
public Action:Command_SetScore(iClient, iArgCount) {
if (iArgCount < 2) {
ReplyToCommand(iClient, "[SM] Usage: sm_setscore <#userid|name> <score>");
return Plugin_Handled;
}
decl String:szTarget[65];
GetCmdArg(1, szTarget, sizeof(szTarget));
decl String:szTargetName[MAX_TARGET_LENGTH+1];
decl iTargetList[MAXPLAYERS+1], iTargetCount, bool:bTnIsMl;
if ((iTargetCount = ProcessTargetString(
szTarget,
iClient,
iTargetList,
MAXPLAYERS,
COMMAND_FILTER_CONNECTED,
szTargetName,
sizeof(szTargetName),
bTnIsMl)) <= 0)
{
ReplyToTargetError(iClient, iTargetCount);
return Plugin_Handled;
}
decl String:szScore[6];
GetCmdArg(2, szScore, sizeof(szScore));
new iScore = StringToInt(szScore);
ClampInt(iScore, -1, 4095);
for (new i = 0; i < iTargetCount; i++)
{
g_iSetScore[iTargetList[i]] = iScore;
}
return Plugin_Handled;
}
public Hook_OnThinkPost(iEnt) {
static iTotalScoreOffset = -1;
if (iTotalScoreOffset == -1) {
iTotalScoreOffset = FindSendPropInfo("CTFPlayerResource", "m_iTotalScore");
}
new iTotalScore[MAXPLAYERS+1];
GetEntDataArray(iEnt, iTotalScoreOffset, iTotalScore, MaxClients+1);
for (new i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && g_iSetScore[i] > -1) {
iTotalScore[i] = g_iSetScore[i];
}
}
SetEntDataArray(iEnt, iTotalScoreOffset, iTotalScore, MaxClients+1);
}
stock ClampInt(&iValue, iMin, iMax) {
if (iValue < iMin) {
iValue = iMin;
} else if (iValue > iMax) {
iValue = iMax;
}
}
Requires SDKHooks.
sm_setscore <#userid|name> <score> - Set a player's score (-1 to disable)