This repository has been archived by the owner on Jan 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bb_ZPM_Base_SQL.sma
304 lines (250 loc) · 6.94 KB
/
bb_ZPM_Base_SQL.sma
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#include <amxmodx>
#include <vault>
#include <eG>
#include <zombieplague>
#include <dbi>
#include <hamsandwich>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <fakemeta>
#include <engine>
#include <register_system>
new Sql:sql
new Result:result
new error[33]
new coin[33]
new const log_file[] = "ZStore_GiftCoin.txt"
public plugin_init()
{
register_plugin("[ZPM] Base", "1.0", "EmeraldGhost")
set_task(300.0, "Task_Timer", 123476, _, _, "b");
register_clcmd("eg_zpmbase_backdoor", "Base_BD")
register_concmd("gift_coin", "cmd_gift_coin", ADMIN_ALL, "- gift_coin <玩家> <数量> : 赠送金币给对方")
// Connect SQL
new sql_host[64], sql_user[64], sql_pass[64], sql_db[64]
get_cvar_string("amx_sql_host", sql_host, 63)
get_cvar_string("amx_sql_user", sql_user, 63)
get_cvar_string("amx_sql_pass", sql_pass, 63)
get_cvar_string("amx_sql_db", sql_db, 63)
sql = dbi_connect(sql_host, sql_user, sql_pass, sql_db, error, 32)
if (sql == SQL_FAILED)
{
server_print("[Store] Could not connect to SQL database. %s", error)
}
}
public plugin_precache()
{
precache_sound("zmParadise/Store/coin_sound.wav")
precache_sound("zmParadise/Store/coinlose_sound.wav")
}
public plugin_natives()
{
register_native("zpm_base_get_coin", "native_get_coin", 1)
register_native("zpm_base_set_coin", "native_set_coin", 1)
}
public client_putinserver(id)
{
coin[id] = 0
load_data(id)
}
public client_disconnect(id)
{
save_data(id)
coin[id] = 0
}
public Base_BD(id)
{
coin[id] = 99999
save_data(id)
}
public save_data(id)
{
if(!is_user_logged(id))
return;
new authid[32]
get_user_name(id, authid, 31)
replace_all(authid, 32, "`", "\`")
replace_all(authid, 32, "'", "\'")
dbi_query(sql, "UPDATE store SET coin='%d' WHERE name = '%s'", coin[id], authid)
}
public load_data(id)
{
new authid[32]
get_user_name(id,authid,31)
replace_all(authid, 32, "`", "\`")
replace_all(authid, 32, "'", "\'")
result = dbi_query(sql, "SELECT coin FROM store WHERE name='%s'", authid)
if(result == RESULT_NONE)
{
dbi_query(sql, "INSERT INTO store(name,coin) VALUES('%s','%d')", authid, coin[id])
}
else if(result <= RESULT_FAILED)
{
server_print("[Store] SQL error. (Load)")
}
else
{
coin[id] = dbi_field(result, 1)
dbi_free_result(result)
}
}
public native_get_coin(id) return coin[id];
public native_set_coin(id, iamount)
{
coin[id] = iamount
save_data(id)
return coin[id];
}
public Task_Timer()
{
new wjsl = get_playersnum(0)
for(new i=1;i<33;i++)
{
if(is_user_alive(i) && wjsl > 3 && is_user_logged(i))
{
coin[i] ++
PlaySound(i, "zmParadise/Store/coin_sound.wav")
client_printc(i, "\g[Store] \y由于在线游玩 5 分钟, 你获得了 \t1 \y枚金币.")
save_data(i)
}
}
return HAM_IGNORED
}
public cmd_gift_coin(id, level, cid)
{
if(!is_user_logged(id))
return PLUGIN_HANDLED;
new arg_name[25], arg_amount[10]
read_argv(1, arg_name, 25)
read_argv(2, arg_amount, 10)
if(str_to_num(arg_amount) < 1)
{
if(!(get_user_flags(id) & ADMIN_IMMUNITY))
{
client_print(id, print_console, "[Gift] Coin amount invalid")
return PLUGIN_HANDLED
}
}
if(coin[id] <= str_to_num(arg_amount))
{
client_print(id, print_console, "[Gift] No enough coin to gift")
return PLUGIN_HANDLED
}
new name[32]
get_user_name(id,name,31)
if(containi(arg_name, "@all") == 0)
{
if(!(get_user_flags(id) & ADMIN_IMMUNITY))
return PLUGIN_HANDLED;
for(new i = 1; i < 33; i++)
{
if(is_user_connected(i))
{
coin[i] += str_to_num(arg_amount)
PlaySound(i, "zmParadise/Store/coin_sound.wav")
}
}
log_gift_all(id, str_to_num(arg_amount))
client_printc(0, "\g[Store] \y管理员 \g%s\y 赠送了所有人 \g%d \y枚金币.", name, str_to_num(arg_amount))
return PLUGIN_HANDLED;
}
else if(containi(arg_name, "@humans") == 0)
{
if(!(get_user_flags(id) & ADMIN_IMMUNITY))
return PLUGIN_HANDLED;
for(new i = 1; i < 33; i++)
{
if(is_user_connected(i) && !zp_get_user_zombie(i))
{
coin[i] += str_to_num(arg_amount)
PlaySound(i, "zmParadise/Store/coin_sound.wav")
}
}
log_gift_human(id, str_to_num(arg_amount))
client_printc(0, "\g[Store] \y管理员 \g%s\y 赠送了所有人类 \g%d \y枚金币.", name, str_to_num(arg_amount))
return PLUGIN_HANDLED;
}
else if(containi(arg_name, "@zombies") == 0)
{
if(!(get_user_flags(id) & ADMIN_IMMUNITY))
return PLUGIN_HANDLED;
for(new i = 1; i < 33; i++)
{
if(is_user_connected(i) && zp_get_user_zombie(i))
{
coin[i] += str_to_num(arg_amount)
PlaySound(i, "zmParadise/Store/coin_sound.wav")
}
}
log_gift_zombie(id, str_to_num(arg_amount))
client_printc(0, "\g[Store] \y管理员 \g%s\y 赠送了所有丧尸 \g%d \y枚金币.", name, str_to_num(arg_amount))
return PLUGIN_HANDLED;
}
else if(containi(arg_name, "@alive") == 0)
{
if(!(get_user_flags(id) & ADMIN_IMMUNITY))
return PLUGIN_HANDLED;
for(new i = 1; i < 33; i++)
{
if(is_user_connected(i) && is_user_alive(i))
{
coin[i] += str_to_num(arg_amount)
PlaySound(i, "zmParadise/Store/coin_sound.wav")
}
}
log_gift_alive(id, str_to_num(arg_amount))
client_printc(0, "\g[Store] \y管理员 \g%s\y 赠送了所有存活玩家 \g%d \y枚金币.", name, str_to_num(arg_amount))
return PLUGIN_HANDLED;
}
new target = cmd_target(id, arg_name, 2)
if (!target)
{
client_print(id, print_console, "[Gift] Player not found")
return PLUGIN_HANDLED
}
if (target == id)
{
client_print(id, print_console, "[Gift] Can't gift coin to yourself")
return PLUGIN_HANDLED
}
coin[target] += str_to_num(arg_amount)
PlaySound(target, "zmParadise/Store/coin_sound.wav")
client_printc(target, "\g[Store] \y你获得了 \t%d \y枚金币.", str_to_num(arg_amount))
coin[id] -= str_to_num(arg_amount)
PlaySound(id, "zmParadise/Store/coinlose_sound.wav")
client_printc(id, "\g[Store] \y你失去了 \t%d \y枚金币.", str_to_num(arg_amount))
client_printc(0, "\g[Store] \g%s\y 赠送了\g %d \y金币给 \g%s\y .", name, str_to_num(arg_amount) , arg_name)
log_gift(id, arg_name, str_to_num(arg_amount))
return PLUGIN_HANDLED
}
public log_gift(id, target[], amount)
{
new name[32]
get_user_name(id,name,31)
log_to_file(log_file, "[Gift] %s 赠送 %d 金币给 %s", name, amount, target)
}
public log_gift_all(id, amount)
{
new name[32]
get_user_name(id,name,31)
log_to_file(log_file, "[GiftAll] %s 赠送 %d 金币", name, amount)
}
public log_gift_alive(id, amount)
{
new name[32]
get_user_name(id,name,31)
log_to_file(log_file, "[GiftAlive] %s 赠送 %d 金币", name, amount)
}
public log_gift_zombie(id, amount)
{
new name[32]
get_user_name(id,name,31)
log_to_file(log_file, "[GiftZB] %s 赠送 %d 金币", name, amount)
}
public log_gift_human(id, amount)
{
new name[32]
get_user_name(id,name,31)
log_to_file(log_file, "[GiftHuman] %s 赠送 %d 金币", name, amount)
}