-
Notifications
You must be signed in to change notification settings - Fork 7
/
berobot_dynamicRobotCount.sp
184 lines (152 loc) · 4.58 KB
/
berobot_dynamicRobotCount.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
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <tf2>
#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_dynamicRobotCount",
author = "icebear",
description = "sets the number of allowed robots based of a ratio of humans-to-robots",
version = "0.1",
url = "https://github.com/higps/robogithub"
};
ConVar _enabledConVar;
bool _enabled;
ConVar _humansPerRobotConVar;
float _humansPerRobot;
ConVar _roboCapTeamConVar;
//bool g_timer;
public void OnPluginStart()
{
SMLoggerInit(LOG_TAGS, sizeof(LOG_TAGS), SML_ERROR, SML_FILE);
SMLogTag(SML_INFO, "berobot_dynamicRobotCount started at %i", GetTime());
_enabledConVar = CreateConVar("sm_berobot_dynamicRobotCount_enable", "1", "enables dynamically setting sm_robocap_team from the ratio of humans-to-robot");
_enabledConVar.AddChangeHook(EnabledConVarChangeHook);
_enabled = _enabledConVar.BoolValue;
_humansPerRobotConVar = CreateConVar("sm_berobot_dynamicRobotCount_humansPerRobot", "4.0", "ratio of humans-to-robot for dynamic robot count calculation");
_humansPerRobotConVar.AddChangeHook(RoboCapTeamHumansPerRobotConVarChangeHook);
_humansPerRobot = _humansPerRobotConVar.FloatValue;
HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
//g_timer = false;
}
// public void OnGameFrame()
// {
// if (!g_timer)
// {
// CreateTimer(3.0, Timer_Check_Teams);
// g_timer = true;
// }
// }
// public Action Timer_Check_Teams(Handle timer)
// {
// SetRoboCapTeam();
// g_timer = false;
// }
public void OnConfigsExecuted()
{
_roboCapTeamConVar = FindConVar(CONVAR_ROBOCAP_TEAM);
}
public void EnabledConVarChangeHook(ConVar convar, const char[] sOldValue, const char[] sNewValue)
{
_enabled = _enabledConVar.BoolValue;
}
public void RoboCapTeamHumansPerRobotConVarChangeHook(ConVar convar, const char[] sOldValue, const char[] sNewValue)
{
_humansPerRobot = StringToFloat(sNewValue);
}
// public void OnClientPutInServer(int client)
// {
// SetRoboCapTeam();
// }
// public void OnClientDisconnect_Post(int client)
// {
// SetRoboCapTeam();
// }
void SetRoboCapTeam()
{
if (!_enabled)
return;
//int count = GetClientCount();
// int Spectate = GetTeamClientCount(1);
int Red = GetTeamClientCount(2);
int Blue = GetTeamClientCount(3);
// int count = Red+Blue+Spectate;
int count = Red+Blue;
// PrintToChatAll("Red Team had: %i players", Red);
// PrintToChatAll("Blue Team had: %i players", Blue);
// PrintToChatAll("Total player count was: %i", count);
// PrintToChatAll("Spectate Team had: %i players", Spectate);
// int robotteam = GetRobotTeam();
// PrintToChatAll("Robot Team was %i", robotteam);
float ratio = _humansPerRobot;
int robotCount = RoundToCeil(count/ratio);
// PrintToChatAll("Robocount was: %i", robotCount);
if (robotCount == 0){
robotCount = 1;
}
// Code to account for low player counts
// if (robotCount < 3 && count < 7 && count >= 5)
// {
// robotCount ++;
// //PrintToChatAll("TRIGGERING LOW PLAYER CHANGE, ROBOT COUNT IS NOW %i", robotCount);
// }
// SMLogTag(SML_VERBOSE, "setting %s to %i for %i players", CONVAR_ROBOCAP_TEAM, robotCount, count);
_roboCapTeamConVar.SetInt(robotCount);
//RequestFrame(EnsureRobotCountDelay, robotCount);
EnsureRobotCount();
}
// void EnsureRobotCountDelay(int roboCount){
// EnsureRobotCount();
// }
public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
RequestFrame(SetRoboCapFrame);
}
void SetRoboCapFrame()
{
SetRoboCapTeam();
}
int Native_GetCurrentRobotCount(Handle plugin, int numParams)
{
int CurrentRobots = 0;
// int STV = 0;
for(int i = 0; i <= MaxClients+1; i++)
{
if(IsAnyRobot(i))
{
CurrentRobots++;
}
}
return CurrentRobots;
}
int Native_GetCurrentHumanCount()
{
int CurrentHumans = 0;
for(int i = 0; i <= MaxClients+1; i++)
{
if(!IsAnyRobot(i) && IsValidClient(i))
{
TFTeam iteam = GetClientTeam(i);
//Teams unassigned and spectate is below 2
if (iteam != TFTeam_Spectator || iteam != TFTeam_Unassigned)
{
CurrentHumans++;
}
}
}
return CurrentHumans;
}