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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#define PLUGIN_VERSION "1.0.11"
#define MAX_FILE_LEN 80
public Plugin:myinfo =
{
name = "Halftime teamswitch",
author = "[30+]Gemeni",
description = "Moves all players to the opposite team at halftime",
version = PLUGIN_VERSION,
url = "http://30plus.ownit.se/"
};
// Global variables
new mapTime;
new g_maxrounds;
new g_roundCount;
new bool:halftime;
new Handle:g_h_moneyReset = INVALID_HANDLE;
new Handle:g_h_mp_startmoney = INVALID_HANDLE;
new Handle:g_h_mp_maxrounds = INVALID_HANDLE;
new g_mp_startmoney;
new bool:g_resetMoney;
new bool:g_halftime_do_resetMoney = false;
new Handle:g_CvarHalfTimeType = INVALID_HANDLE;
new String:g_HalfTimeType[MAX_FILE_LEN];
new g_CtScore, g_TScore;
/* forwards */
new Handle:g_f_on_ht = INVALID_HANDLE;
// Offsets
new g_iAccount = -1;
// Setting halftime to false
public OnMapStart(){
//LogToGame(">>>>>Setting halftime to false, OnMapStart<<<<<");
halftime = false;
g_roundCount = 0;
GetConVarString(g_CvarHalfTimeType, g_HalfTimeType, MAX_FILE_LEN);
new tmp;
tmp = GetConVarInt(g_h_moneyReset);
if (tmp == 1) {
g_resetMoney = true;
}
else {
g_resetMoney = false;
}
g_mp_startmoney = GetConVarInt(g_h_mp_startmoney);
g_maxrounds = GetConVarInt(g_h_mp_maxrounds);
}
public OnConfigsExecuted(){
//LogToGame(">>>>>Setting halftime to false, OnConfigsExecuted<<<<<");
halftime = false;
}
// Hooking events at plugin start
public OnPluginStart(){
CreateConVar("sm_halftime_teamswitch_version", PLUGIN_VERSION, "Halftime teamswitch version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
HookEvent("round_start", Event_RoundStart);
HookEvent("round_end", Event_RoundEnd);
g_h_moneyReset = CreateConVar("sm_halftime_money_reset", "1", "If weapons should be removed and money reset to mp_startmoney");
g_h_mp_startmoney = FindConVar("mp_startmoney");
g_h_mp_maxrounds = FindConVar("mp_maxrounds");
g_CvarHalfTimeType = CreateConVar("sm_halftime_teamswitch_type", "timelimit", "timelimit|maxrounds to determin what critera halftime should be based on");
g_f_on_ht = CreateGlobalForward("gemHalftime", ET_Ignore);
// Finding offset for CS cash
g_iAccount = FindSendPropOffs("CCSPlayer", "m_iAccount");
if (g_iAccount == -1)
SetFailState("m_iAccount offset not found");
}
// RoundStart gets the maptime
// Checks to see if halftime has passed, if not then make sure halftime is 0
// Setting halftime false here as well since in some occasions when extending map
// team switch can occur again.
public Event_RoundStart (Handle:event, const String:name[], bool:dontBroadcast)
{
new wepIdx;
new playerTeam;
GetMapTimeLimit(mapTime);
mapTime=mapTime*60;
g_CtScore = GetTeamScore(CS_TEAM_CT);
g_TScore = GetTeamScore(CS_TEAM_T);
g_roundCount = g_CtScore + g_TScore + 1;
if (g_halftime_do_resetMoney) {
for (new client=1; client<=GetMaxClients(); client++)
{
if (IsClientInGame (client) && IsClientConnected(client)) {
for (new w = 0; w < 6; w++)
{
if (w != 2 && w != 4 )
while((wepIdx = GetPlayerWeaponSlot(client, w)) != -1)
RemovePlayerItem(client, wepIdx);
}
playerTeam = GetClientTeam(client);
if (playerTeam == CS_TEAM_T) {
GivePlayerItem(client, "weapon_glock");
}
else if (playerTeam == CS_TEAM_CT) {
GivePlayerItem(client, "weapon_usp");
if ((wepIdx = GetPlayerWeaponSlot(client, 6)) != -1)
RemovePlayerItem(client, wepIdx);
}
SetEntProp(client, Prop_Send, "m_ArmorValue", 0, 1);
SetEntProp(client, Prop_Send, "m_bHasHelmet", 0, 1);
SetEntData(client, g_iAccount, g_mp_startmoney, 4, true);
}
}
}
g_halftime_do_resetMoney = false;
}
public Event_RoundEnd (Handle:event, const String:name[], bool:dontBroadcast)
{
new mapTimeLeft;
new bool:doSwap = false;
new reason = GetEventInt(event, "reason");
new winner = GetEventInt(event, "winner");
g_mp_startmoney = GetConVarInt(g_h_mp_startmoney);
g_maxrounds = GetConVarInt(g_h_mp_maxrounds);
// Make sure that we have a normal round end
// reason 16 is game commencing
// other reasons are real round ends
if(reason == 15) {
g_CtScore = 0;
g_TScore = 0;
g_roundCount = 0;
return;
}
if (winner==CS_TEAM_T)
g_TScore++;
if (winner==CS_TEAM_CT)
g_CtScore++;
GetMapTimeLeft(mapTimeLeft);
LogMessage( "roundEnd: ct: %d t: %d rounds: %d max: %d", g_CtScore, g_TScore, g_roundCount, g_maxrounds/2 );
if ((g_roundCount>=g_maxrounds/2)) {
//LogMessage(">>> Halftime, Swap maxrounds %d %d<<<", g_roundCount, g_maxrounds);
doSwap = true;
}
else {
doSwap = false;
}
if( g_TScore > g_maxrounds/2 || g_CtScore > g_maxrounds/2 ) {
SetConVarInt( g_h_mp_maxrounds, 1, true, false );
PrintToChatAll("\x04============[ game end ]============");
if( g_TScore > g_CtScore ) {
PrintToChatAll("\x04Winner: T");
}
else {
PrintToChatAll("\x04Winner: CT");
}
}
if(doSwap && (halftime == false)) {
new playerTeam;
Call_StartForward(g_f_on_ht);
Call_Finish();
halftime = true;
for (new i=1; i<=GetMaxClients(); i++)
{
if (IsClientInGame (i) && IsClientConnected(i)) {
if (IsClientInGame (i) && IsClientConnected(i) && IsFakeClient(i)) {
ForcePlayerSuicide(i);
}
g_halftime_do_resetMoney = true;
//LogMessage("Player %d is InGame", i);
playerTeam = GetClientTeam(i);
if (playerTeam == CS_TEAM_T) {
//LogMessage("Before switch of %d to CT", i);
CS_SwitchTeam(i, CS_TEAM_CT);
//LogMessage("After switch of %d to CT", i);
}
else if (playerTeam == CS_TEAM_CT) {
//LogMessage("Before switch of %d to T", i);
CS_SwitchTeam(i, CS_TEAM_T);
//LogMessage("After switch of %d to T", i);
}
else {
//LogMessage("No switch, not CT not T");
}
}
else {
//LogMessage("Player %d is *NOT* InGame", i);
}
}
new tmp;
tmp = g_CtScore;
g_CtScore = g_TScore;
g_TScore = tmp;
//LogMessage(">>>>>halftime switch completed<<<<<");
PrintToChatAll("\x04==========[ halftime switch ]==========");
}
// Else just advertise that teamswitch will occur at half time
else if ((mapTimeLeft>mapTime/2) && (halftime == false)) {
//PrintToChatAll(">>> Players will switch teams at halftime <<<");
}
SetTeamScore(CS_TEAM_CT, g_CtScore);
SetTeamScore(CS_TEAM_T, g_TScore);
}
|