/
revolver_round.sp
169 lines (142 loc) · 3.89 KB
/
revolver_round.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
/* SM Revolver Round
*
* Copyright (C) 2017 Francisco 'Franc1sco' García
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/.
*/
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <sdkhooks>
new bool:revolver;
public Plugin:myinfo =
{
name = "SM Revolver Round",
author = "Franc1sco Steam: franug",
description = "",
version = "1.0",
url = "http://steamcommunity.com/id/franug"
};
new Handle:timers[MAXPLAYERS+1];
public OnPluginStart()
{
HookEvent("round_prestart", Restart);
HookEvent("player_spawn", Event_PlayerSpawn);
RegAdminCmd("sm_revolver", Rondas, ADMFLAG_GENERIC);
for(new i = 1; i <= MaxClients; i++)
if(IsClientInGame(i))
{
OnClientPutInServer(i);
}
}
public Action:Restart(Handle:event, const String:name[], bool:dontBroadcast)
{
for(new i = 1; i <= MaxClients; i++)
if(IsClientInGame(i)) OnClientDisconnect(i);
revolver = false;
SetBuyZones("Enable");
}
public OnClientPutInServer(client)
{
SDKHook(client, SDKHook_WeaponCanUse, OnWeaponCanUse);
}
public Action:OnWeaponCanUse(client, weapon)
{
if(revolver)
{
new index = GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex");
decl String:classname[64];
if(index == 64 || (GetEdictClassname(weapon, classname, 64) && (StrContains(classname, "weapon_knife") != -1 || StrContains(classname, "weapon_bayonet") != -1))) return Plugin_Continue;
else return Plugin_Handled;
}
return Plugin_Continue;
}
public Action:Rondas(client, args)
{
SetBuyZones("Disable");
revolver = true;
for(new i = 1; i <= MaxClients; i++)
if(IsClientInGame(i) && GetClientTeam(i) > 1)
{
CS_RespawnPlayer(i);
}
return Plugin_Handled;
}
public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if(revolver) DoRound(client);
}
public Action:CS_OnCSWeaponDrop(client, weaponindex)
{
if(revolver) return Plugin_Handled;
return Plugin_Continue;
}
SetBuyZones(const String:status[])
{
new maxEntities = GetMaxEntities();
decl String:class[24];
for (new i = MaxClients + 1; i < maxEntities; i++)
{
if (IsValidEdict(i))
{
GetEdictClassname(i, class, sizeof(class));
if (StrEqual(class, "func_buyzone"))
AcceptEntityInput(i, status);
}
}
}
DoRound(client)
{
if(timers[client] != INVALID_HANDLE) KillTimer(timers[client]);
timers[client] = CreateTimer(3.0, Darm, client, TIMER_REPEAT);
StripAllWeapons(client);
GivePlayerItem(client, "weapon_knife");
GivePlayerItem(client, "weapon_revolver");
}
stock StripAllWeapons(iClient)
{
new iEnt;
for (new i = 0; i <= 4; i++)
{
while ((iEnt = GetPlayerWeaponSlot(iClient, i)) != -1)
{
RemovePlayerItem(iClient, iEnt);
AcceptEntityInput(iEnt, "Kill");
}
}
}
public OnClientPostAdminCheck(client)
{
timers[client] = CreateTimer(3.0, Darm, client, TIMER_REPEAT);
}
public OnClientDisconnect(client)
{
if(timers[client] != INVALID_HANDLE)
{
KillTimer(timers[client]);
timers[client] = INVALID_HANDLE;
}
}
public Action:Darm(Handle:timer, any:client)
{
if(IsPlayerAlive(client))
{
new weapon = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon");
if(weapon > 0 && GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex") == 64)
{
SetEntProp(weapon, Prop_Send, "m_iPrimaryReserveAmmoCount", 8);
}
}
}