-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathberobot_tracker.sp
205 lines (164 loc) · 4.88 KB
/
berobot_tracker.sp
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <tf2>
#include <tf2_stocks>
#include <morecolors>
#include <sm_logger>
#include <berobot_constants>
#include <berobot>
char LOG_TAGS[][] = {"VERBOSE", "INFO", "ERROR"};
enum (<<= 1)
{
SML_VERBOSE = 1,
SML_INFO,
SML_ERROR,
}
#include <berobot_core>
#pragma newdecls required
#pragma semicolon 1
public Plugin myinfo =
{
name = "berobot_tracker",
author = "icebear",
description = "",
version = "0.1",
url = "https://github.com/higps/robogithub"
};
char _isRobot[MAXPLAYERS + 1][NAMELENGTH];
bool _robotIsCreated[MAXPLAYERS + 1];
StringMap _robotCount;
public void OnPluginStart()
{
SMLoggerInit(LOG_TAGS, sizeof(LOG_TAGS), SML_ERROR, SML_FILE);
SMLogTag(SML_INFO, "berobot_tracker started at %i", GetTime());
ResetMode();
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
CreateNative("TrackRobot", Native_TrackRobot);
CreateNative("TrackRobotCreation", Native_TrackRobotCreation);
CreateNative("GetRobotCount", Native_GetRobotCount);
CreateNative("IsRobot", Native_IsRobot);
CreateNative("IsRobotWhenDead", Native_IsRobotWhenDead);
CreateNative("IsAnyRobot", Native_IsAnyRobot);
CreateNative("IsBoss", Native_IsBoss);
CreateNative("GetRobot", Native_GetRobot);
return APLRes_Success;
}
public void MM_ModeResetRequested()
{
ResetMode();
}
public any Native_TrackRobot(Handle plugin, int numParams)
{
int clientId = GetNativeCell(1);
char robotname[NAMELENGTH];
GetNativeString(2, robotname, NAMELENGTH);
SMLogTag(SML_VERBOSE, "tracking %i as robot '%s'", clientId, robotname);
if (strcmp(_isRobot[clientId], robotname) == 0)
return;
_isRobot[clientId] = robotname;
if (robotname[0] == '\0')
_robotIsCreated[clientId] = false;
_robotCount.Clear();
for(int i = 0; i <= MaxClients; i++)
{
if (_isRobot[i][0] == '\0')
continue;
int value = 0;
_robotCount.GetValue(_isRobot[i], value);
_robotCount.SetValue(_isRobot[i], value + 1);
}
// if (IsLogAllowed(SML_VERBOSE))
// {
// char loggingRobotname[NAMELENGTH];
// int robotCount;
// StringMapSnapshot robotNames = _robotCount.Snapshot();
// for(int i = 0; i < robotNames.Length; i++)
// {
// robotNames.GetKey(i, loggingRobotname, NAMELENGTH);
// _robotCount.GetValue(loggingRobotname, robotCount);
// SMLogTag(SML_VERBOSE, "tracking %i players as robot '%s'", robotCount, loggingRobotname);
// }
// }
}
public any Native_TrackRobotCreation(Handle plugin, int numParams)
{
int clientId = GetNativeCell(1);
bool created = GetNativeCell(2);
SMLogTag(SML_VERBOSE, "tracking client %i robot-creation '%b'", clientId, created);
_robotIsCreated[clientId] = created;
}
public any Native_GetRobotCount(Handle plugin, int numParams)
{
char robotname[NAMELENGTH];
GetNativeString(1, robotname, NAMELENGTH);
if (_robotCount == null)
{
int value = 0;
SMLogTag(SML_VERBOSE, "returning count %i for '%s', because plugin is not yet initialized", value, robotname);
return value;
}
int value = 0;
_robotCount.GetValue(robotname, value);
SMLogTag(SML_VERBOSE, "returning count %i for '%s'", value, robotname);
return value;
}
public any Native_IsRobot(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
if (!IsValidClient(client))
return false;
if (!_robotIsCreated[client])
return false;
char name[NAMELENGTH];
GetNativeString(2, name, NAMELENGTH);
return strcmp(_isRobot[client], name) == 0;
}
public any Native_IsRobotWhenDead(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
char name[NAMELENGTH];
GetNativeString(2, name, NAMELENGTH);
return strcmp(_isRobot[client], name) == 0;
}
public any Native_IsAnyRobot(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
return _isRobot[client][0] != '\0';
}
public any Native_IsBoss(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
char robotName[NAMELENGTH];
Robot robot;
GetRobot(client, robotName, NAMELENGTH);
GetRobotDefinition(robotName, robot);
if (StrEqual(robot.role,"ZBOSS"))
{
// PrintToChatAll("Robot role from factory: %s", robot.role);
return true;
}else
{
return false;
}
}
public any Native_GetRobot(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
int maxDestLength = GetNativeCell(3);
SetNativeString(2, _isRobot[client], maxDestLength);
}
void ResetMode()
{
SMLogTag(SML_VERBOSE, "resetting mode");
if (_robotCount == null)
_robotCount = new StringMap();
_robotCount.Clear();
for(int i = 0; i <= MaxClients; i++)
{
_isRobot[i] = "";
_robotIsCreated[i] = false;
}
}