-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame-stats.sp
More file actions
118 lines (94 loc) · 3.31 KB
/
game-stats.sp
File metadata and controls
118 lines (94 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <files>
#define PLUGIN_AUTHOR "rgsilva"
#define PLUGIN_VERSION "1.4"
#pragma semicolon 1
#define MAX_PASSWORD_LENGTH 32
#define PASSWORD_FILE "plugins/game-stats.pass"
new String:pluginPassword[MAX_PASSWORD_LENGTH];
public Plugin:myinfo =
{
name = "GameStats",
author = PLUGIN_AUTHOR,
description = "Provides a password-protected command to get detailed game information",
version = PLUGIN_VERSION,
url = "https://github.com/rgsilva/sourcemod-plugins"
};
public OnPluginStart()
{
LoadPasswordFromFile();
RegConsoleCmd("sm_gamestats", Cmd_GameStats);
}
void LoadPasswordFromFile() {
new String:passFilePath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, passFilePath, sizeof(passFilePath), PASSWORD_FILE);
File passFile = OpenFile(passFilePath, "r");
if (passFile) {
passFile.ReadLine(pluginPassword, sizeof(pluginPassword));
TrimString(pluginPassword);
passFile.Close();
} else {
strcopy(pluginPassword, MAX_PASSWORD_LENGTH, "");
}
}
public Action Cmd_GameStats(int client, int args) {
if (!IsPluginConfigured()) {
ReplyToCommand(client, "[SM] Plugin is not configured: the password file (%s) is missing!", PASSWORD_FILE);
return Plugin_Handled;
}
if (args != 1) {
ReplyToCommand(client, "[SM] Usage: sm_gamestats <password>");
return Plugin_Handled;
}
new String:password[MAX_NAME_LENGTH];
GetCmdArg(1, password, sizeof(password));
if (!IsPasswordCorrect(password)) {
ReplyToCommand(client, "[SM] Nice try, but that's the wrong password.");
return Plugin_Handled;
}
PrintGameStats(client);
return Plugin_Handled;
}
void PrintGameStats(int client) {
PrintToConsole(client, "-- Game stats --");
for (new i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && !(IsClientSourceTV(i))) {
int team = GetClientTeam(i);
if (team == CS_TEAM_CT || team == CS_TEAM_T) {
// Get frags, deaths and money.
int frags = GetEntProp(i, Prop_Data, "m_iFrags");
int deaths = GetEntProp(i, Prop_Data, "m_iDeaths");
int money = GetEntProp(i, Prop_Send, "m_iAccount");
// Get health, armor and helmet, but only if the player is alive.
int health = 0;
int armor = 0;
bool has_helmet = false;
if (IsPlayerAlive(i)) {
health = GetClientHealth(i);
armor = GetClientArmor(i);
has_helmet = GetEntProp(i, Prop_Send, "m_bHasHelmet");
}
// Get the player name.
new String:name[MAX_NAME_LENGTH];
GetClientName(i, name, sizeof(name));
// Check if the player has the bomb.
bool has_bomb = (GetPlayerWeaponSlot(i, CS_SLOT_C4) != -1);
// Check if the player has a defuse kit.
bool has_defuse = (GetEntProp(i, Prop_Send, "m_bHasDefuser"));
PrintToConsole(client, "Player: %s, %d, %d, %d, %d, %d, %d, %d, %d, %d", name, team, frags, deaths, money, health, armor, has_helmet, has_bomb, has_defuse);
}
}
}
int ct_score = CS_GetTeamScore(CS_TEAM_CT);
int t_score = CS_GetTeamScore(CS_TEAM_T);
PrintToConsole(client, "Score: %d, %d", ct_score, t_score);
PrintToConsole(client, "----");
}
bool IsPluginConfigured() {
return !StrEqual(pluginPassword, "");
}
bool IsPasswordCorrect(char[] password) {
return StrEqual(password, pluginPassword);
}