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_ZStore_PlayerSkin_SQL.sma
642 lines (520 loc) · 16 KB
/
bb_ZPM_ZStore_PlayerSkin_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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
#include <amxmodx>
#include <zpm>
#include <vault>
#include <eG>
#include <zombieplague>
#include <hamsandwich>
#include <dbi>
#include <register_system>
#define COMPOSE_COST 25
// A~D出率递增
#define COMPOSE_TYPE_A 250
#define COMPOSE_TYPE_B 375
#define COMPOSE_TYPE_C 500
#define COMPOSE_TYPE_D 750
native zp_donater_get_level(id)
new const has_model[][] = { "\d", "\r" }
new const model_name[][] = { "null", "【蕾米莉亚】", "【黑白.涅普基雅】", "【五河琴里】", "【四糸乃】", "【時崎狂三】", "【SnowWhite Miku】", "(特殊笑声)【琪露诺】", "(限定)【克劳德】", "(限定)【白上吹雪】", "(置换.Lv1)【尼尔.2B】", "(置换.Lv1)【ELO-诗乃】", "(置换.Lv2)【泳装.和泉纱雾】" }
//new const model_cost[] = { 0, 500, 1000, 1500, 1500, 1500, 1500, 750, 3000, 99999, 99999 } // 非活动
//new const model_sell[] = { 0, 250, 500, 750, 750, 750, 750, 425, 1000, 1000, 1000 } // 非活动
new const model_cost[] = { 0, 500, 1000, 1500, 1500, 1500, 1000, 750, 99999, 3000, 99999, 99999, 99999 } // 活动
new const model_sell[] = { 0, 250, 500, 750, 750, 750, 500, 375, 750, 1500, 800, 800, 1500 } // 活动
new const model_code[][] = { "null", "remilia", "bwgear", "kotori", "yoshino", "kurumi", "swmiku", "cirno", "cloud", "fubuki", "nier2b", "eloshino", "sagiri" }
enum
{
MODEL_NULL,
MODEL_REMILIA,
MODEL_BWGEAR,
MODEL_KOTORI,
MODEL_YOSHINO,
MODEL_KURUMI,
MODEL_SWMIKU,
MODEL_CIRNO,
MODEL_CLOUD,
MODEL_FUBUKI,
MODEL_NIER2B,
MODEL_SHINO,
MODEL_SAGIRI
}
new pcv_debug
new iSelected[33]
new iPlayerHasSkin[33][sizeof model_code]
new const log_file[] = "ZStore_PlayerBuy.txt"
//SQL variable
new Sql:sql
new Result:result
new error[33]
public plugin_init()
{
register_plugin("[ZPM] Store - Skin", "1.0", "EmeraldGhost")
// SQL Initionlize
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("[ZStore] Could not connect to SQL database. %s", error)
}
register_clcmd("store_skin", "skin_menu")
register_clcmd("say /store", "skin_menu")
register_clcmd("say !store", "skin_menu")
register_clcmd("store_sell", "sellskin_menu")
register_clcmd("say /storesell", "sellskin_menu")
register_clcmd("say !storesell", "sellskin_menu")
register_clcmd("store_compose", "compose_skin")
register_clcmd("say /compose", "compose_skin")
register_clcmd("say !compose", "compose_skin")
}
public plugin_natives()
{
register_native("zpm_store_get_user_skin", "Native_Get_Skin", 1)
}
public client_putinserver(id)
{
for(new i=1;i<sizeof model_code;i++)
iPlayerHasSkin[id][i] = 0
load_data(id)
}
public client_disconnect(id)
{
for(new i=1;i<sizeof model_code;i++)
iPlayerHasSkin[id][i] = 0
}
public save_data(id)
{
new authid[32]
get_user_name(id, authid, 31)
replace_all(authid, 32, "`", "\`")
replace_all(authid, 32, "'", "\'")
for(new i=1;i<sizeof model_code;i++)
{
dbi_query(sql, "UPDATE skinstore SET %s='%d' WHERE name = '%s'", model_code[i], iPlayerHasSkin[id][i], 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 remilia,bwgear,kotori,yoshino,kurumi,swmiku,cirno,cloud,fubuki,nier2b,eloshino,sagiri FROM skinstore WHERE name='%s'", authid)
if(result == RESULT_NONE)
{
dbi_query(sql, "INSERT INTO skinstore(name,remilia,bwgear,kotori,yoshino,kurumi,swmiku,cirno,cloud,fubuki,nier2b,eloshino,sagiri) VALUES('%s','0','0','0','0','0','0','0','0','0','0','0','0')", authid)
}
else if(result <= RESULT_FAILED)
{
server_print("[ZStore] SQL Init error. (Skin-Load)")
}
else
{
for(new i=1;i<sizeof model_code;i++)
{
iPlayerHasSkin[id][i] = dbi_field(result, i)
}
dbi_free_result(result)
}
}
public skin_menu(id)
{
static option[64]
formatex(option, charsmax(option), "\r[喪屍樂園] - 模型商店^n您拥有金币:%d 个", zpm_base_get_coin(id))
new menu = menu_create(option, "store_skinmenu");
new szTempid[32]
for(new i = 1; i < sizeof model_code; i++)
{
new iSkin = iPlayerHasSkin[id][i]
new szItems[101]
formatex(szItems, 100, "%s%s \y| \d%d \y金币", has_model[iSkin], model_name[i], model_cost[i])
num_to_str(i, szTempid, 31)
menu_additem(menu, szItems, szTempid, 0)
}
menu_setprop(menu, MPROP_NUMBER_COLOR, "\r");
menu_setprop(menu, MPROP_BACKNAME, "返回");
menu_setprop(menu, MPROP_NEXTNAME, "更多");
menu_setprop(menu, MPROP_EXITNAME, "退出");
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_display(id, menu, 0);
return PLUGIN_HANDLED;
}
public store_skinmenu(id, menu, item)
{
new sz_Name[ 32 ];
get_user_name( id, sz_Name, 31 );
if(item==MENU_EXIT)
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[6], szName[64];
new access, callback;
menu_item_getinfo(menu, item, access, data, charsmax(data), szName, charsmax(szName), callback);
new key = str_to_num(data);
iSelected[id] = key
sure_to_buy(id, iSelected[id])
menu_destroy(menu);
return PLUGIN_HANDLED;
}
public sure_to_buy(id, skinid)
{
static option[64]
formatex(option, charsmax(option), "\r你确定要购买%s吗?", model_name[skinid])
new menu = menu_create(option, "confirm_handler");
menu_additem(menu, "\y是的,我确定买!", "1");
menu_additem(menu, "\y不是,我手抖了。", "2");
menu_setprop(menu, MPROP_NUMBER_COLOR, "\r");
menu_setprop(menu, MPROP_BACKNAME, "返回");
menu_setprop(menu, MPROP_NEXTNAME, "更多...");
menu_setprop(menu, MPROP_EXITNAME, "退出");
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_display(id, menu, 0);
return PLUGIN_HANDLED;
}
public confirm_handler(id, menu, item)
{
new sz_Name[ 32 ];
get_user_name( id, sz_Name, 31 );
if(item == MENU_EXIT)
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[6], szName[64];
new access, callback;
menu_item_getinfo(menu, item, access, data, charsmax(data), szName, charsmax(szName), callback);
new key = str_to_num(data);
switch(key)
{
case 1:
{
buy_skin(id, iSelected[id])
}
case 2:
{
return PLUGIN_HANDLED;
}
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
public buy_skin(id, skinid)
{
if(!is_user_logged(id))
return PLUGIN_HANDLED;
new IsHasModel = iPlayerHasSkin[id][skinid]
new iCoin = zpm_base_get_coin(id)
if(IsHasModel == 1)
{
client_printc(id, "\g[Store]\y 你已经拥有皮肤%s了 !", model_name[skinid]);
}
else if(iCoin >= model_cost[skinid])
{
client_printc(id, "\g[Store]\y 购买皮肤\g%s\y成功 !", model_name[skinid]);
PlaySound(id, "zmParadise/Store/coinlose_sound.wav")
zpm_base_set_coin(id, iCoin - model_cost[skinid]);
iPlayerHasSkin[id][skinid] = 1
save_data(id)
log_buy(id, skinid)
}
else client_printc(id, "\g[Store]\y 没钱还想买皮肤? 算了吧!");
return PLUGIN_HANDLED;
}
public log_buy(id, skinid)
{
new name[32]
get_user_name(id,name,31)
log_to_file(log_file, "[Buy] %s 购买皮肤 %s .", name, model_name[skinid])
}
public sellskin_menu(id)
{
static option[64]
formatex(option, charsmax(option), "\r[喪屍樂園] - 模型收购^n您拥有金币:%d 个", zpm_base_get_coin(id))
new menu = menu_create(option, "store_sellskinmenu");
new szTempid[32]
for(new i = 1; i < sizeof model_code; i++)
{
new iSkin = iPlayerHasSkin[id][i]
new szItems[101]
formatex(szItems, 100, "\y%s\r%s - %d 金币", has_model[iSkin], model_name[i], model_sell[i])
num_to_str(i, szTempid, 31)
menu_additem(menu, szItems, szTempid, 0)
}
menu_setprop(menu, MPROP_NUMBER_COLOR, "\r");
menu_setprop(menu, MPROP_BACKNAME, "返回");
menu_setprop(menu, MPROP_NEXTNAME, "更多");
menu_setprop(menu, MPROP_EXITNAME, "退出");
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_display(id, menu, 0);
return PLUGIN_HANDLED;
}
public store_sellskinmenu(id, menu, item)
{
new sz_Name[ 32 ];
get_user_name( id, sz_Name, 31 );
if(item==MENU_EXIT)
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[6], szName[64];
new access, callback;
menu_item_getinfo(menu, item, access, data, charsmax(data), szName, charsmax(szName), callback);
new key = str_to_num(data);
iSelected[id] = key
sure_to_sell(id, iSelected[id])
menu_destroy(menu);
return PLUGIN_HANDLED;
}
public sure_to_sell(id, skinid)
{
static option[64]
formatex(option, charsmax(option), "\r你确定要卖出%s吗?", model_name[skinid])
new menu = menu_create(option, "sell_confirm_handler");
menu_additem(menu, "\y是的,我确定卖!", "1");
menu_additem(menu, "\y不是,我手抖了。", "2");
menu_setprop(menu, MPROP_NUMBER_COLOR, "\r");
menu_setprop(menu, MPROP_BACKNAME, "返回");
menu_setprop(menu, MPROP_NEXTNAME, "更多...");
menu_setprop(menu, MPROP_EXITNAME, "退出");
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_display(id, menu, 0);
return PLUGIN_HANDLED;
}
public sell_confirm_handler(id, menu, item)
{
new sz_Name[ 32 ];
get_user_name( id, sz_Name, 31 );
if(item == MENU_EXIT)
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[6], szName[64];
new access, callback;
menu_item_getinfo(menu, item, access, data, charsmax(data), szName, charsmax(szName), callback);
new key = str_to_num(data);
switch(key)
{
case 1:
{
sell_skin(id, iSelected[id])
}
case 2:
{
return PLUGIN_HANDLED;
}
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
public sell_skin(id, skinid)
{
if(!is_user_logged(id))
return PLUGIN_HANDLED;
new IsHasModel = iPlayerHasSkin[id][skinid]
new iCoin = zpm_base_get_coin(id)
if(IsHasModel == 1)
{
client_printc(id, "\g[Store]\y 卖出皮肤\g%s\y成功 !", model_name[skinid]);
PlaySound(id, "zmParadise/Store/coin_sound.wav")
zpm_base_set_coin(id, iCoin + model_sell[skinid]);
iPlayerHasSkin[id][skinid] = 0
save_data(id)
log_sell(id, skinid)
}
else client_printc(id, "\g[Store]\y 没皮肤你卖什么? 洗洗睡吧!");
return PLUGIN_HANDLED;
}
public log_sell(id, skinid)
{
new name[32]
get_user_name(id,name,31)
log_to_file(log_file, "[Sell] %s 卖出皮肤 %s .", name, model_name[skinid])
}
public compose_skin(id)
{
static option[64]
formatex(option, charsmax(option), "\r[喪屍樂園] - 玄学菜单^n请选择模型:", zpm_base_get_coin(id))
new menu = menu_create(option, "compose_handler");
new szTempid[32]
for(new i = 1; i < sizeof model_code; i++)
{
new iSkin = iPlayerHasSkin[id][i]
new szItems[101]
formatex(szItems, 100, "\y%s\r%s", has_model[iSkin], model_name[i])
num_to_str(i, szTempid, 31)
menu_additem(menu, szItems, szTempid, 0)
}
menu_setprop(menu, MPROP_NUMBER_COLOR, "\r");
menu_setprop(menu, MPROP_BACKNAME, "返回");
menu_setprop(menu, MPROP_NEXTNAME, "更多");
menu_setprop(menu, MPROP_EXITNAME, "退出");
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_display(id, menu, 0);
return PLUGIN_HANDLED;
}
public compose_handler(id, menu, item)
{
new sz_Name[ 32 ];
get_user_name( id, sz_Name, 31 );
if(item == MENU_EXIT)
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[6], szName[64];
new access, callback;
menu_item_getinfo(menu, item, access, data, charsmax(data), szName, charsmax(szName), callback);
new key = str_to_num(data);
new iSkin = iPlayerHasSkin[id][key]
if(iSkin == 1)
{
iSelected[id] = key
sure_to_compose(id, key)
}
else client_printc(id, "\g[Compose] \y你没有皮肤%s !", model_name[key])
menu_destroy(menu);
return PLUGIN_HANDLED;
}
public sure_to_compose(id, skinid)
{
static option[64]
formatex(option, charsmax(option), "\r你确定要拿%s来抽奖吗?", model_name[skinid])
new menu = menu_create(option, "confirm_compose_handler");
formatex(option, charsmax(option), "\y是的,我是欧皇!(消耗 \r%d\y 金币)", COMPOSE_COST)
menu_additem(menu, option, "1");
menu_additem(menu, "\y不是,我手抖了。^n^n", "2");
menu_additem(menu, "\y提示:皮肤越贵,爆率越高哦!", "5");
menu_setprop(menu, MPROP_NUMBER_COLOR, "\r");
menu_setprop(menu, MPROP_BACKNAME, "返回");
menu_setprop(menu, MPROP_NEXTNAME, "更多...");
menu_setprop(menu, MPROP_EXITNAME, "退出");
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_display(id, menu, 0);
return PLUGIN_HANDLED;
}
public confirm_compose_handler(id, menu, item)
{
new sz_Name[ 32 ];
get_user_name( id, sz_Name, 31 );
if(item == MENU_EXIT)
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[6], szName[64];
new access, callback;
menu_item_getinfo(menu, item, access, data, charsmax(data), szName, charsmax(szName), callback);
new key = str_to_num(data);
switch(key)
{
case 1:
{
new iCoin = zpm_base_get_coin(id)
if(iCoin >= COMPOSE_COST)
{
zpm_base_set_coin(id, zpm_base_get_coin(id) - COMPOSE_COST)
try_compose_skin(id, iSelected[id])
}
else client_printc(id, "\g[Compose] \y没钱还想白嫖? 不可能的!")
}
case 2:
{
return PLUGIN_HANDLED;
}
case 5:
{
return PLUGIN_HANDLED;
}
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
public try_compose_skin(id, skinid)
{
if(!is_user_logged(id))
return PLUGIN_HANDLED;
new name[32]
get_user_name(id,name,31)
new MaxNum = 1000
if(model_cost[skinid] == COMPOSE_TYPE_A) MaxNum = 970
else if(model_cost[skinid] == COMPOSE_TYPE_B) MaxNum = 950
else if(model_cost[skinid] == COMPOSE_TYPE_C) MaxNum = 920
else if(model_cost[skinid] == COMPOSE_TYPE_D) MaxNum = 965
else if(model_cost[skinid] == 99999) MaxNum = 600
if(zp_donater_get_level(id) == 10) MaxNum -= 10
new cNum = random_num(1, MaxNum)
switch(cNum)
{
case 436..446:
{
new comNum = random_num(1, 10)
switch(comNum)
{
case 1..4:
{
if(iPlayerHasSkin[id][MODEL_NIER2B] == 0)
{
iPlayerHasSkin[id][skinid] = 0
iPlayerHasSkin[id][MODEL_NIER2B] = 1
log_compose(id, skinid, MODEL_NIER2B)
save_data(id)
client_printc(0, "\g[Compose] \t%s\y 使用了\t%s\y参与置换,成功置换\t【尼尔.2B】\y皮肤 !", name, model_name[skinid])
return PLUGIN_HANDLED;
}
else
{
client_printc(0, "\g[Compose] \t%s\y 使用了\t%s\y参与置换,本来可以置换\t【尼尔.2B】\y皮肤,可惜他有了!", name, model_name[skinid])
return PLUGIN_HANDLED;
}
}
case 5..8:
{
if(iPlayerHasSkin[id][MODEL_SHINO] == 0)
{
iPlayerHasSkin[id][skinid] = 0
iPlayerHasSkin[id][MODEL_SHINO] = 1
log_compose(id, skinid, MODEL_SHINO)
save_data(id)
client_printc(0, "\g[Compose] \t%s\y 使用了\t%s\y参与置换,成功置换\t【ELO-诗乃】\y皮肤 !", name, model_name[skinid])
return PLUGIN_HANDLED;
}
else
{
client_printc(0, "\g[Compose] \t%s\y 使用了\t%s\y参与置换,本来可以置换\t【ELO-诗乃】\y皮肤,可惜他有了!", name, model_name[skinid])
return PLUGIN_HANDLED;
}
}
case 9..10:
{
if(iPlayerHasSkin[id][MODEL_SAGIRI] == 0)
{
iPlayerHasSkin[id][skinid] = 0
iPlayerHasSkin[id][MODEL_SAGIRI] = 1
log_compose(id, skinid, MODEL_SAGIRI)
save_data(id)
client_printc(0, "\g[Compose] \t%s\y 使用了\t%s\y参与置换,成功置换\t【泳装.和泉纱雾】\y皮肤 !", name, model_name[skinid])
return PLUGIN_HANDLED;
}
else
{
client_printc(0, "\g[Compose] \t%s\y 使用了\t%s\y参与置换,本来可以置换\t【泳装.和泉纱雾】\y皮肤,可惜他有了!", name, model_name[skinid])
return PLUGIN_HANDLED;
}
}
}
}
}
client_printc(0, "\g[Compose] \t%s\y 使用了\t%s\y参与置换,可惜什么都没有获得 !", name, model_name[skinid])
return PLUGIN_HANDLED;
}
public log_compose(id, oldskin, skinid)
{
new name[32]
get_user_name(id,name,31)
log_to_file(log_file, "[Compose] %s 成功使用%s合成皮肤%s.", name, model_name[oldskin], model_name[skinid])
}
public Native_Get_Skin(id, skinid) return iPlayerHasSkin[id][skinid]