/
buy_commands.sp
220 lines (179 loc) · 5.63 KB
/
buy_commands.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/* SM Buy weapons by commands
*
* 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 <sdkhooks>
#undef REQUIRE_PLUGIN
#include <zombiereloaded>
#pragma newdecls required
#define DATA "2.2"
char sConfig[PLATFORM_MAX_PATH];
Handle kv, trie_weapons[MAXPLAYERS + 1];
public Plugin myinfo =
{
name = "SM Buy weapons by commands",
description = "",
author = "Franc1sco franug",
version = DATA,
url = "http://steamcommunity.com/id/franug"
};
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
MarkNativeAsOptional("ZR_IsClientZombie");
return APLRes_Success;
}
public void OnPluginStart()
{
CreateConVar("sm_buybycommands_version", DATA, "", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
AddCommandListener(SayC, "say");
AddCommandListener(SayC, "say_team");
HookEvent("player_spawn", PlayerSpawn);
for(int client = 1; client <= MaxClients; client++)
{
if(IsClientInGame(client))
{
OnClientConnected(client);
}
}
}
public Action PlayerSpawn(Handle event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));
ClearTrie(trie_weapons[client]);
}
public void OnClientConnected(int client)
{
trie_weapons[client] = CreateTrie();
}
public void OnClientDisconnect(int client)
{
if(trie_weapons[client] != INVALID_HANDLE) CloseHandle(trie_weapons[client]);
}
public void OnMapStart()
{
RefreshKV();
}
public void RefreshKV()
{
BuildPath(Path_SM, sConfig, PLATFORM_MAX_PATH, "configs/franug_buybycommands.txt");
if(kv != INVALID_HANDLE) CloseHandle(kv);
kv = CreateKeyValues("BuyCommands");
FileToKeyValues(kv, sConfig);
}
public Action SayC(int client, const char[] command, int args)
{
if (!IsValidClient(client))return;
char buffer[255];
GetCmdArgString(buffer,sizeof(buffer));
StripQuotes(buffer);
if (strlen(buffer) < 1)return;
if (kv == INVALID_HANDLE)RefreshKV();
KvRewind(kv);
if (!KvJumpToKey(kv, buffer))return;
char flags[24];
KvGetString(kv, "flags", flags, sizeof(flags), "public");
if(!StrEqual(flags, "public", false) && !CheckAdminFlagsByString(client, flags))
{
PrintToChat(client, " \x04You dont have access to buy this weapon");
return;
}
int money = GetEntProp(client, Prop_Send, "m_iAccount");
int cost = KvGetNum(kv, "price");
if(money >= cost)
{
if(GetClientTeam(client) < 2)
{
PrintToChat(client, " \x04You need to be in a team for buy weapons");
return;
}
if(!IsPlayerAlive(client))
{
PrintToChat(client, " \x04You need to be alive for buy weapons");
return;
}
if ((GetFeatureStatus(FeatureType_Native, "ZR_IsClientZombie") == FeatureStatus_Available) && ZR_IsClientZombie(client))
{
PrintToChat(client, " \x04You need to be human for buy weapons");
return;
}
char weapons[64];
KvGetString(kv, "weapon", weapons, 64);
int times = KvGetNum(kv, "times");
int current;
if(times == 0)
{
int drop = KvGetNum(kv, "slot", -1);
if(drop != -1)
{
int weapon = GetPlayerWeaponSlot(client, drop);
if(weapon != -1) SDKHooks_DropWeapon(client, weapon);
}
GivePlayerItem(client, weapons);
SetEntProp(client, Prop_Send, "m_iAccount", money-cost);
ReplaceString(weapons, sizeof(weapons), "weapon_", "");
PrintToChat(client, " \x04You have bought a %s", weapons);
return;
}
if (!GetTrieValue(trie_weapons[client], weapons, current))current = 0;
if(times <= current)
{
PrintToChat(client, " \x04You cant buy more %s this round", weapons);
return;
}
SetTrieValue(trie_weapons[client], weapons, ++current);
int drop = KvGetNum(kv, "slot", -1);
if(drop != -1)
{
int weapon = GetPlayerWeaponSlot(client, drop);
if(weapon != -1) SDKHooks_DropWeapon(client, weapon);
}
GivePlayerItem(client, weapons);
SetEntProp(client, Prop_Send, "m_iAccount", money-cost);
ReplaceString(weapons, sizeof(weapons), "weapon_", "");
PrintToChat(client, " \x04You have bought a %s %i/%i", weapons, current, times);
}
else PrintToChat(client, " \x04You dont have enought money. You need %i", cost);
}
stock bool IsValidClient(int client, bool bAllowBots = false, bool bAllowDead = true)
{
if (!(1 <= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
{
return false;
}
return true;
}
stock bool CheckAdminFlagsByString(int client, const char[] flagString)
{
AdminId admin = view_as<AdminId>(GetUserAdmin(client));
if (admin != INVALID_ADMIN_ID){
int count, found, flags = ReadFlagString(flagString);
for (int i = 0; i <= 20; i++){
if (flags & (1<<i))
{
count++;
if(GetAdminFlag(admin, view_as<AdminFlag>(i))){
found++;
}
}
}
if (count == found || GetUserFlagBits(client) & ADMFLAG_ROOT){
return true;
}
}
return false;
}