· 6 years ago · Jul 11, 2019, 02:32 PM
1#include <a_samp>
2#include <core>
3#include <float>
4
5// command libraries
6#include <smartcmd>
7#include <sscanf2>
8
9// basic privileged commands
10#include "admin/tempobject.pwn"
11
12#pragma tabsize 0
13
14
15
16// player interaction
17#define PLAYER_KILL_MONEY_REWARD 250
18#define PLAYER_KILL_XP_REWARD 5
19
20// colors
21#define COLOR_DEFAULT 0xAAAAAAFF
22#define COLOR_FAILURE 0xD62B20FF
23#define COLOR_ERROR 0xEA9888FF
24#define COLOR_ADMINCHAT 0x2A74D6FF
25#define COLOR_STATS 0xFCE68FFF
26#define COLOR_WHISPER 0xFFF64CFF
27#define COLOR_PRIVILEGE_LOWMODERATOR "E0914C"
28#define COLOR_PRIVILEGE_MIDMODERATOR "E67E22"
29#define COLOR_PRIVILEGE_HIGHMODERATOR "C96A16"
30#define COLOR_PRIVILEGE_ADMINISTRATOR "E74C3C"
31#define COLOR_PRIVILEGE_FOUNDER "CC392A"
32
33// strings
34#define SHOOT_TEXTDRAW_URL "www.~Y~p~W~hoenix~Y~n~W~etwork.net"
35#define SHOOT_COMMANDS_ERR_UNAVAILABLE "You can not input commands right now."
36#define SHOOT_COMMANDS_ERR_DENIED "You do not met the requirements to execute this command."
37#define SHOOT_COMMANDS_ERR_NOTFOUND "Command %s not found."
38#define SHOOT_COMMANDS_ERR_NOPARAMS "No parameters required."
39#define SHOOT_COMMANDS_ERR_PLAYERNOTFOUND "Player not found."
40
41
42// enums
43#include "core/enums/dialogs.pwn"
44#include "core/enums/playerdata.pwn"
45#include "core/enums/privileges.pwn"
46#include "core/enums/memberships.pwn"
47#include "core/enums/disconnects.pwn"
48
49new DB: Database;
50new gPData[MAX_PLAYERS][playerdata];
51new Text:websiteUrlTextDraw, PlayerText:playerLevelTextDraw[MAX_PLAYERS];
52
53stock getPname(playerid)
54{
55 new pname[24];
56 GetPlayerName(playerid, pname, sizeof(pname));
57 return pname;
58}
59
60stock calcRequiredXP(lvl)
61{
62 new value = 25*lvl*(1+lvl);
63 return value;
64}
65
66public increaseLevel(playerid)
67{
68 new string[128];
69 gPData[playerid][level] += 1;
70
71 PlayerTextDrawDestroy(playerid, playerLevelTextDraw[playerid]);
72 format(string, sizeof(string), "Level %d", gPData[playerid][level])
73 playerLevelTextDraw[playerid] = CreatePlayerTextDraw(playerid, 553.000000, 101.000000, string);
74 PlayerTextDrawAlignment(playerid, playerLevelTextDraw[playerid], 2);
75 PlayerTextDrawBackgroundColor(playerid, playerLevelTextDraw[playerid], 0x000000ff);
76 PlayerTextDrawFont(playerid, playerLevelTextDraw[playerid], 2);
77 PlayerTextDrawLetterSize(playerid, playerLevelTextDraw[playerid], 0.299999, 1.300000);
78 PlayerTextDrawColor(playerid, playerLevelTextDraw[playerid], 0xffffffff);
79 PlayerTextDrawSetProportional(playerid, playerLevelTextDraw[playerid], 1);
80 PlayerTextDrawSetShadow(playerid, playerLevelTextDraw[playerid], 1);
81 PlayerTextDrawShow(playerid, playerLevelTextDraw[playerid]);
82
83 SetPlayerScore(playerid,gPData[playerid][level]);
84
85 SendClientMessage(playerid,COLOR_DEFAULT,"Congratulations, you have leveled up!");
86}
87
88public pullData(playerid)
89{
90 new DBResult: Result, buf[129];
91
92 format(buf, sizeof buf, "SELECT * FROM playerdata WHERE name = '%q' LIMIT 1", gPData[playerid][name]);
93 Result = db_query(Database, buf);
94
95 if (db_num_rows(Result))
96 {
97 gPData[playerid][id] = db_get_field_assoc_int(Result, "id");
98 gPData[playerid][privilege] = db_get_field_assoc_int(Result, "privilege");
99 gPData[playerid][membership] = db_get_field_assoc_int(Result, "membership");
100 gPData[playerid][level] = db_get_field_assoc_int(Result, "level");
101 gPData[playerid][xp] = db_get_field_assoc_int(Result, "xp");
102 gPData[playerid][balance] = db_get_field_assoc_int(Result, "balance");
103 gPData[playerid][skinid] = db_get_field_assoc_int(Result, "skinid");
104 gPData[playerid][dr] = db_get_field_assoc_int(Result, "dr");
105 gPData[playerid][pposx] = db_get_field_assoc_int(Result, "pposx");
106 gPData[playerid][pposy] = db_get_field_assoc_int(Result, "pposy");
107 gPData[playerid][pposz] = db_get_field_assoc_int(Result, "pposz");
108 gPData[playerid][pposa] = db_get_field_assoc_int(Result, "pposa");
109 }
110 db_free_result(Result);
111}
112
113public submitData(playerid)
114{
115 new Query[320];
116
117 GetPlayerPos(playerid, gPData[playerid][pposx], gPData[playerid][pposy], gPData[playerid][pposz]);
118 GetPlayerFacingAngle(playerid, gPData[playerid][pposa]);
119 format(Query, sizeof Query, "UPDATE playerdata SET level=%d, xp=%d, balance=%d, dr=%d, pposx=%f, pposy=%f, pposz=%f, pposa=%f, skinid=%d WHERE id = %d", gPData[playerid][level], gPData[playerid][xp], gPData[playerid][balance], gPData[playerid][dr], gPData[playerid][pposx], gPData[playerid][pposy], gPData[playerid][pposz], gPData[playerid][pposa], gPData[playerid][skinid], gPData[playerid][id]);
120 db_query(Database, Query);
121}
122
123public sendToAdminChat(playerid, msg[])
124{
125 new pname[MAX_PLAYER_NAME], string[128];
126 GetPlayerName(playerid, pname, sizeof(pname));
127 for(new i; i < MAX_PLAYERS; i++)
128 {
129 if(isStaff(i))
130 {
131 format(string, sizeof string, "Administration: %s: %s", pname, msg);
132 SendClientMessage(i,COLOR_ADMINCHAT,string);
133 }
134 }
135}
136
137public isStaff(playerid)
138{
139 if(gPData[playerid][privilege] >= PRIVILEGE_LOWMODERATOR)
140 {
141 return 1;
142 }
143 return 0;
144}
145
146public isCash(playerid)
147{
148 if(gPData[playerid][membership] >= MEMBERSHIP_CASH)
149 {
150 return 1;
151 }
152 return 0;
153}
154
155stock getPrivilegeName(playerid)
156{
157 new prname[64];
158 switch(gPData[playerid][privilege])
159 {
160 case PRIVILEGE_LOWMODERATOR:{prname = "Novice Staff";}
161 case PRIVILEGE_MIDMODERATOR:{prname = "Staff";}
162 case PRIVILEGE_HIGHMODERATOR:{prname = "High Staff";}
163 case PRIVILEGE_ADMINISTRATOR:{prname = "Administrator";}
164 case PRIVILEGE_FOUNDER:{prname = "Founder";}
165 default:{prname = "None";}
166 }
167 return prname;
168}
169
170stock getPrivilegeColor(playerid)
171{
172 new prcolor[64];
173 switch(gPData[playerid][privilege])
174 {
175 case PRIVILEGE_LOWMODERATOR:{prcolor = COLOR_PRIVILEGE_LOWMODERATOR;}
176 case PRIVILEGE_MIDMODERATOR:{prcolor = COLOR_PRIVILEGE_MIDMODERATOR;}
177 case PRIVILEGE_HIGHMODERATOR:{prcolor = COLOR_PRIVILEGE_HIGHMODERATOR;}
178 case PRIVILEGE_ADMINISTRATOR:{prcolor = COLOR_PRIVILEGE_ADMINISTRATOR;}
179 case PRIVILEGE_FOUNDER:{prcolor = COLOR_PRIVILEGE_FOUNDER;}
180 default:{prcolor = "";}
181 }
182 return prcolor;
183}
184
185stock getMembershipName(playerid)
186{
187 new mbname[64];
188 switch(gPData[playerid][membership])
189 {
190 case MEMBERSHIP_CASH:{mbname = "VIP";}
191 case MEMBERSHIP_BIGCASH:{mbname = "VIP+";}
192 default:{mbname = "None";}
193 }
194 return mbname;
195}
196
197public getDisconnectReason(pname)
198{
199 new DBResult: Result, buf[129], dcr;
200 format(buf, sizeof buf, "SELECT * FROM playerdata WHERE name = '%q' LIMIT 1", pname);
201 Result = db_query(Database, buf);
202 dcr = db_get_field_assoc_int(Result, "dr");
203 if(dcr >= 0)
204 {
205 db_free_result(Result);
206 return dcr;
207 }
208 else
209 {
210 db_free_result(Result);
211 return 8;
212 }
213}
214
215forward increaseLevel(playerid);
216forward pullData(playerid);
217forward submitData(playerid);
218forward sendToAdminChat(playerid, msg[]);
219forward isStaff(playerid);
220forward isCash(playerid);
221forward getPrivilegeName(playerid);
222forward getMembershipName(playerid);
223forward getDisconnectReason(pname);
224native WP_Hash(buffer[], len, const str[]); // required to work with WP hashes on register/login.
225
226main()
227{
228 aAbB();
229 print("Initializing project-shoot...\n");
230}
231
232public OnGameModeInit()
233{
234 SetGameModeText("Deathmatch/Freeroam");
235 ShowPlayerMarkers(PLAYER_MARKERS_MODE_GLOBAL);
236 ShowNameTags(1);
237 SetNameTagDrawDistance(40.0);
238 EnableStuntBonusForAll(0);
239 DisableInteriorEnterExits();
240 SetWeather(2);
241 SetWorldTime(11);
242 UsePlayerPedAnims();
243
244 websiteUrlTextDraw = TextDrawCreate(70.000000,432.000000,SHOOT_TEXTDRAW_URL);
245 TextDrawAlignment(websiteUrlTextDraw,2);
246 TextDrawBackgroundColor(websiteUrlTextDraw,0x000000ff);
247 TextDrawFont(websiteUrlTextDraw,2);
248 TextDrawLetterSize(websiteUrlTextDraw,0.199999,1.300000);
249 TextDrawColor(websiteUrlTextDraw,0xffffffff);
250 TextDrawSetOutline(websiteUrlTextDraw,1);
251 TextDrawSetProportional(websiteUrlTextDraw,1);
252 TextDrawSetShadow(websiteUrlTextDraw,1);
253
254 if ((Database = db_open("players.db")) == DB: 0)
255 {
256 print("Failed to open a connection to playerdata database.");
257 }
258 else
259 {
260 db_query(Database, "PRAGMA synchronous = OFF");
261 new createTable[620] = "CREATE TABLE IF NOT EXISTS playerdata (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(24) COLLATE NOCASE, password VARCHAR(129), privilege INTEGER DEFAULT 0 NOT NULL, membership INTEGER DEFAULT 0 NOT NULL, level INTEGER DEFAULT 1 NOT NULL, xp INTEGER DEFAULT 0 NOT NULL,";
262 strcat(createTable, " balance INTEGER DEFAULT 2500 NOT NULL, skinid INTEGER DEFAULT 73 NOT NULL, dr INTEGER DEFAULT 0 NOT NULL, pposx REAL DEFAULT 0.0 NOT NULL, pposy REAL DEFAULT 0.0 NOT NULL, pposz REAL DEFAULT 0.0 NOT NULL, pposa REAL DEFAULT 0.0 NOT NULL)");
263 db_query(Database, createTable);
264 }
265 return 1;
266}
267
268public OnGameModeExit()
269{
270 for(new i; i < MAX_PLAYERS; i++)
271 {
272 submitData(i);
273 }
274 db_close(Database);
275 return 1;
276}
277
278public OnPlayerConnect(playerid)
279{
280 new tmp[playerdata];
281
282 gPData[playerid] = tmp;
283 gPData[playerid][loggedin] = 0;
284 gPData[playerid][statsSet] = 0;
285 TogglePlayerSpectating(playerid,true);
286
287 new Query[82], DBResult: Result;
288
289 GetPlayerName(playerid, gPData[playerid][name], MAX_PLAYER_NAME);
290 format(Query, sizeof Query, "SELECT password FROM playerdata WHERE name = '%q' LIMIT 1", gPData[playerid][name]);
291 Result = db_query(Database, Query);
292
293 if (db_num_rows(Result))
294 {
295 db_get_field_assoc(Result, "password", gPData[playerid][password], 129);
296 ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "It seems you're already registered, please type in your password:", "Login", "Exit");
297 }
298 else
299 {
300 ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "It appears to be your first time around, welcome! Please type in a password for your account below.", "Register", "Exit");
301 }
302 db_free_result(Result);
303 TextDrawShowForPlayer(playerid, websiteUrlTextDraw);
304 return 1;
305}
306
307public OnPlayerDisconnect(playerid, reason)
308{
309 switch(reason)
310 {
311 case 0:{gPData[playerid][dr] = DISCONNECT_CONN_LOST_OR_CRASH;}
312 case 1:{gPData[playerid][dr] = DISCONNECT_VOLUNTARILY;}
313 case 2:{gPData[playerid][dr] = DISCONNECT_KICKBAN;}
314 }
315 submitData(playerid);
316
317 new tmp[playerdata];
318 gPData[playerid] = tmp;
319 return 1;
320}
321
322public OnPlayerSpawn(playerid)
323{
324 if(IsPlayerNPC(playerid)) return 1;
325
326 if(gPData[playerid][statsSet] < 1)
327 {
328 SetPlayerPos(playerid, gPData[playerid][pposx], gPData[playerid][pposy], gPData[playerid][pposz]);
329 SetPlayerFacingAngle(playerid, gPData[playerid][pposa]);
330 SetPlayerScore(playerid,gPData[playerid][level]);
331 ResetPlayerMoney(playerid);
332 GivePlayerMoney(playerid, gPData[playerid][balance]);
333
334 new string[128];
335 format(string, sizeof(string), "Level %d", gPData[playerid][level])
336 playerLevelTextDraw[playerid] = CreatePlayerTextDraw(playerid, 553.000000, 101.000000, string);
337 PlayerTextDrawAlignment(playerid, playerLevelTextDraw[playerid], 2);
338 PlayerTextDrawBackgroundColor(playerid, playerLevelTextDraw[playerid], 0x000000ff);
339 PlayerTextDrawFont(playerid, playerLevelTextDraw[playerid], 2);
340 PlayerTextDrawLetterSize(playerid, playerLevelTextDraw[playerid], 0.299999, 1.300000);
341 PlayerTextDrawColor(playerid, playerLevelTextDraw[playerid], 0xffffffff);
342 PlayerTextDrawSetProportional(playerid, playerLevelTextDraw[playerid], 1);
343 PlayerTextDrawSetShadow(playerid, playerLevelTextDraw[playerid], 1);
344 PlayerTextDrawShow(playerid, playerLevelTextDraw[playerid]);
345
346 gPData[playerid][statsSet] = 1;
347 }
348 else
349 {
350 SetPlayerPos(playerid, 2493.9133, -1682.3986, 13.3382);
351 }
352
353 SetPlayerInterior(playerid,0);
354 TogglePlayerClock(playerid,0);
355 SetPlayerSkin(playerid, gPData[playerid][skinid]);
356 GivePlayerWeapon(playerid,WEAPON_MP5,9999);
357 GivePlayerWeapon(playerid,WEAPON_SILENCED,9999);
358 GivePlayerWeapon(playerid,WEAPON_AK47,9999);
359 GivePlayerWeapon(playerid,WEAPON_SPRAYCAN,9999);
360
361 return 1;
362}
363
364public OnPlayerDeath(playerid, killerid, reason)
365{
366 SendDeathMessage(killerid, playerid, reason);
367 gPData[playerid][skinid] = GetPlayerSkin(playerid);
368
369 GivePlayerMoney(playerid, 100); // GTA automatically deducts $100 on death.
370
371 if(killerid != INVALID_PLAYER_ID)
372 {
373 gPData[killerid][balance] += PLAYER_KILL_MONEY_REWARD;
374 GivePlayerMoney(killerid, PLAYER_KILL_MONEY_REWARD);
375 gPData[killerid][xp] += PLAYER_KILL_XP_REWARD;
376
377 new string[128], pname[MAX_PLAYER_NAME];
378 GetPlayerName(playerid, pname, sizeof pname);
379 format(string, sizeof string, "+$%d and +%d XP awarded for killing %s.", PLAYER_KILL_MONEY_REWARD, PLAYER_KILL_XP_REWARD, pname)
380 SendClientMessage(killerid, COLOR_DEFAULT, string)
381
382 new requiredXP = calcRequiredXP(gPData[killerid][level]);
383 if(gPData[killerid][xp] >= requiredXP)
384 {
385 increaseLevel(killerid);
386 }
387 }
388 return 1;
389}
390
391public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
392{
393 switch(dialogid){
394 case DIALOG_REGISTER:
395 {
396 if(!response) return Kick(playerid);
397 if(!(5 <= strlen(inputtext) <= 20))
398 {
399 ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "It appears to be your first time around, welcome! Please type in a password for your account below.\n{D62B20}Password must at least have 5 characters, and it can not exceed 20.", "Register", "Exit");
400 return 1;
401 }
402
403 new Query[208];
404
405 WP_Hash(gPData[playerid][password], 129, inputtext);
406 format(Query, sizeof Query, "INSERT INTO playerdata (name, password) VALUES ('%q', '%s')", gPData[playerid][name], gPData[playerid][password]);
407 db_query(Database, Query);
408
409 new DBResult: Result;
410
411 Result = db_query(Database, "SELECT last_insert_rowid()");
412 gPData[playerid][id] = db_get_field_int(Result);
413
414 db_free_result(Result);
415
416 pullData(playerid);
417 gPData[playerid][loggedin] = 1;
418 TogglePlayerSpectating(playerid,false);
419 }
420 case DIALOG_LOGIN:
421 {
422 if(!response) return Kick(playerid);
423
424 new buf[129];
425
426 WP_Hash(buf, 129, inputtext);
427 if (strcmp(buf, gPData[playerid][password]))
428 {
429 ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "It seems you're already registered, please type in your password:\n{D62B20}Password did not match, try again.", "Login", "Exit");
430 return 1;
431 }
432 pullData(playerid);
433 gPData[playerid][loggedin] = 1;
434 TogglePlayerSpectating(playerid,false);
435 }
436 default: return 0;
437 }
438 return 1;
439}
440
441public OnPlayerUpdate(playerid)
442{
443 if(!IsPlayerConnected(playerid)) return 0;
444 if(IsPlayerNPC(playerid)) return 1;
445
446 // minecraft good, minigun bad
447 if(GetPlayerWeapon(playerid) == WEAPON_MINIGUN && gPData[playerid][privilege] < PRIVILEGE_ADMINISTRATOR) {
448 Kick(playerid);
449 return 0;
450 }
451
452 return 1;
453}
454
455public OnPlayerText(playerid, text[])
456{
457 SetPlayerChatBubble(playerid, text, 0xFFFFFFFF, 40.0, 10000);
458 return 1;
459}
460
461public OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid, bodypart)
462{
463
464 if(gPData[damagedid][adminEnabled])
465 {
466 return 0;
467 }
468 else
469 {
470 if (bodypart == 9)
471 {
472 new Float:hp;
473 GetPlayerHealth(damagedid, hp);
474 SetPlayerHealth(damagedid, hp-95);
475 }
476 return 1;
477 }
478}
479
480// ~-------------~
481// C O M M A N D S
482// ~-------------~
483
484
485
486// ~--------------~
487// Command handlers
488// ~--------------~
489
490
491
492public OnPlayerCommandReceived(cmdid, playerid, cmdtext[])
493{
494 new playerState = GetPlayerState(playerid);
495 if (playerState != PLAYER_STATE_SPECTATING && playerState != PLAYER_STATE_WASTED)
496 {
497 if(GetCommandFlags(cmdid) <= gPData[playerid][privilege] || GetCommandFlags(cmdid) <= gPData[playerid][membership])
498 {
499 return 1;
500 }
501 else
502 {
503 SendClientMessage(playerid, COLOR_FAILURE, SHOOT_COMMANDS_ERR_DENIED);
504 return 0;
505 }
506 }
507 SendClientMessage(playerid, COLOR_FAILURE, SHOOT_COMMANDS_ERR_UNAVAILABLE);
508 return 0;
509}
510
511public OnPlayerCommandPerformed(cmdid, playerid, cmdtext[], success) {
512 if (!success)
513 {
514 new string[128];
515 format(string, sizeof(string), SHOOT_COMMANDS_ERR_NOTFOUND, cmdtext);
516 SendClientMessage(playerid, COLOR_FAILURE, string);
517 }
518 return 1;
519}
520
521
522
523// ~-----------------~
524// Privileged commands
525// ~-----------------~
526
527
528
529/*
530 Command: /restart
531 Description: Restarts gamemode.
532 Notes: N/A.
533*/
534COMMAND<PRIVILEGE_FOUNDER>:restart(cmdid, params[])
535{
536 for(new i; i < MAX_PLAYERS; i++)
537 {
538 submitData(i);
539 }
540 SendClientMessageToAll(COLOR_DEFAULT, "Server: Stats saved. Restarting server...");
541 SendRconCommand("gmx");
542 return CMD_SUCCESS;
543}
544
545
546
547/*
548 Command: /a [message]
549 Description: Sends a message to administration private chat.
550 Notes: N/A.
551*/
552COMMAND<PRIVILEGE_LOWMODERATOR>:a(cmdid, playerid, params[])
553{
554 sendToAdminChat(playerid, params);
555 return CMD_SUCCESS;
556}
557
558
559
560/*
561 Command: /adminmode
562 Description: Enables admin mode on command invoker,
563 granting godmode along other moderation benefits.
564 Notes: N/A.
565*/
566COMMAND<PRIVILEGE_LOWMODERATOR>:adminmode(cmdid, playerid, params[])
567{
568 if(gPData[playerid][adminEnabled])
569 {
570 SetPlayerHealth(playerid, 100);
571 SendClientMessage(playerid,COLOR_DEFAULT,"Administration: Admin mode toggled OFF.");
572 SetPlayerColor(playerid, COLOR_DEFAULT);
573 gPData[playerid][adminEnabled] = 0;
574 }
575 else
576 {
577 SetPlayerHealth(playerid, Float:0x7F800000);
578 SendClientMessage(playerid,COLOR_DEFAULT,"Administration: Admin mode toggled ON.");
579 SetPlayerColor(playerid, COLOR_FAILURE);
580 gPData[playerid][adminEnabled] = 1;
581 }
582 return CMD_SUCCESS;
583}
584
585/* Shortcuts for /adminmode */
586ALT:am = CMD:adminmode;
587
588
589
590/*
591 Command: /setprivilege [player id] [value]
592 Description: Sets a player's privilege to a specific value.
593 Notes: N/A.
594*/
595COMMAND<PRIVILEGE_ADMINISTRATOR>:setprivilege(cmdid, playerid, params[])
596{
597 new pid, priv;
598 if (sscanf(params, "ud", pid, priv)) SendClientMessage(playerid, COLOR_ERROR, "Usage: /setprivilege [player id] [privilege]");
599 {
600 if(pid == INVALID_PLAYER_ID)
601 {
602 SendClientMessage(playerid, COLOR_ERROR, SHOOT_COMMANDS_ERR_PLAYERNOTFOUND);
603 return CMD_SUCCESS;
604 }
605 new Query[128], string[128], pname[MAX_PLAYER_NAME], tname[MAX_PLAYER_NAME];
606 gPData[pid][privilege] = priv;
607 format(Query, sizeof Query, "UPDATE playerdata SET privilege=%d WHERE id = %d", gPData[pid][privilege], gPData[pid][id]);
608 db_query(Database, Query);
609 GetPlayerName(pid, pname, sizeof(pname));
610 GetPlayerName(playerid, tname, sizeof(tname));
611 format(string, sizeof string, "Administration: %s has set your rank to %s.", tname, getPrivilegeName(pid));
612 SendClientMessage(pid, COLOR_DEFAULT, string);
613 format(string, sizeof string, "Administration: You have set %s rank to %s.", pname, getPrivilegeName(pid));
614 SendClientMessage(playerid, COLOR_DEFAULT, string);
615 }
616 return CMD_SUCCESS;
617}
618
619
620
621/*
622 Command: /staffpromote [player id]
623 Description: Increases a player's privilege by 1.
624 Notes: N/A.
625*/
626COMMAND<PRIVILEGE_ADMINISTRATOR>:staffpromote(cmdid, playerid, params[])
627{
628 new pid;
629 if (sscanf(params, "u", pid)) SendClientMessage(playerid, COLOR_ERROR, "Usage: /staffpromote [player id]");
630 {
631 if(pid == INVALID_PLAYER_ID)
632 {
633 SendClientMessage(playerid, COLOR_ERROR, SHOOT_COMMANDS_ERR_PLAYERNOTFOUND);
634 return CMD_SUCCESS;
635 }
636 new Query[128], string[128], pname[MAX_PLAYER_NAME], tname[MAX_PLAYER_NAME];
637 gPData[pid][privilege] += 1;
638 format(Query, sizeof Query, "UPDATE playerdata SET privilege=%d WHERE id = %d", gPData[pid][privilege], gPData[pid][id]);
639 db_query(Database, Query);
640 GetPlayerName(pid, pname, sizeof(pname));
641 GetPlayerName(playerid, tname, sizeof(tname));
642 format(string, sizeof string, "Administration: %s has promoted you to %s.", tname, getPrivilegeName(pid));
643 SendClientMessage(pid, COLOR_DEFAULT, string);
644 format(string, sizeof string, "Administration: You have promoted %s to %s.", pname, getPrivilegeName(pid));
645 SendClientMessage(playerid, COLOR_DEFAULT, string);
646 }
647 return CMD_SUCCESS;
648}
649
650
651
652/*
653 Command: /staffadd [player id]
654 Description: Uppers a player's privilege up to minimum required to appear as staff.
655 Notes: N/A.
656*/
657COMMAND<PRIVILEGE_ADMINISTRATOR>:staffadd(cmdid, playerid, params[])
658{
659 new pid;
660 if (sscanf(params, "u", pid)) SendClientMessage(playerid, COLOR_ERROR, "Usage: /staffadd [player id]");
661 {
662 if(pid == INVALID_PLAYER_ID)
663 {
664 SendClientMessage(playerid, COLOR_ERROR, SHOOT_COMMANDS_ERR_PLAYERNOTFOUND);
665 return CMD_SUCCESS;
666 }
667 new Query[128], string[128], pname[MAX_PLAYER_NAME], tname[MAX_PLAYER_NAME];
668 gPData[pid][privilege] = 4;
669 format(Query, sizeof Query, "UPDATE playerdata SET privilege=%d WHERE id = %d", gPData[pid][privilege], gPData[pid][id]);
670 db_query(Database, Query);
671 GetPlayerName(pid, pname, sizeof(pname));
672 GetPlayerName(playerid, tname, sizeof(tname));
673 format(string, sizeof string, "Administration: %s has added you to the Staff team, welcome! (/help admin)", tname);
674 SendClientMessage(pid, COLOR_DEFAULT, string);
675 format(string, sizeof string, "Administration: You have added %s to the Staff team.", pname);
676 SendClientMessage(playerid, COLOR_DEFAULT, string);
677 }
678 return CMD_SUCCESS;
679}
680
681
682
683/*
684 Command: /tp [player name]
685 Description: Teleports to a player.
686 Notes: N/A.
687*/
688COMMAND<PRIVILEGE_LOWMODERATOR>:tp(cmdid, playerid, params[])
689{
690 if(isnull(params))
691 {
692 return SendClientMessage(playerid, COLOR_ERROR, "Usage: /tp [player name]");
693 }
694
695 new found, result, target[MAX_PLAYER_NAME], invoker[MAX_PLAYER_NAME], string[128], Float:x, Float:y, Float:z;
696 for(new i; i < MAX_PLAYERS; i++)
697 {
698 new pname[MAX_PLAYER_NAME];
699 GetPlayerName(i, pname, sizeof(pname));
700 if(strfind(pname, params, true) != -1) {
701 result = i;
702 found++;
703 }
704 }
705 if(found == 0)
706 {
707 SendClientMessage(playerid, COLOR_ERROR, "No players found.");
708 return CMD_SUCCESS;
709 }
710 if(found > 1)
711 {
712 SendClientMessage(playerid, COLOR_ERROR, "More than one player was found with that input, please be specific.");
713 return CMD_SUCCESS;
714 }
715 if(found == 1)
716 {
717 GetPlayerPos(result, x, y, z);
718 if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == 2)
719 {
720 SetVehiclePos(GetPlayerVehicleID(playerid), x+2, y, z+2);
721 }
722 else
723 {
724 SetPlayerPos(playerid, x+2, y, z+2);
725 }
726 GetPlayerName(result, target, sizeof(target));
727 GetPlayerName(playerid, invoker, sizeof(invoker));
728 format(string, sizeof string, "Administration: You were teleported to %s.", target);
729 SendClientMessage(playerid,COLOR_DEFAULT,string);
730 format(string, sizeof string, "Administration: %s has teleported to your position.", invoker);
731 SendClientMessage(result,COLOR_DEFAULT,string);
732 return CMD_SUCCESS;
733 }
734 return CMD_SUCCESS;
735}
736
737
738
739/*
740 Command: /bring [player name]
741 Description: Brings a player to your position.
742 Notes: N/A.
743*/
744COMMAND<PRIVILEGE_LOWMODERATOR>:bring(cmdid, playerid, params[])
745{
746 if(isnull(params))
747 {
748 return SendClientMessage(playerid, COLOR_ERROR, "Usage: /bring [player name]");
749 }
750
751 new found, result, target[MAX_PLAYER_NAME], invoker[MAX_PLAYER_NAME], string[128], Float:x, Float:y, Float:z;
752 for(new i; i < MAX_PLAYERS; i++)
753 {
754 new pname[MAX_PLAYER_NAME];
755 GetPlayerName(i, pname, sizeof(pname));
756 if(strfind(pname, params, true) != -1)
757 {
758 result = i;
759 found++;
760 }
761 }
762 if(found == 0)
763 {
764 SendClientMessage(playerid, COLOR_ERROR, "No players found.");
765 return CMD_SUCCESS;
766 }
767 if(found > 1)
768 {
769 SendClientMessage(playerid, COLOR_ERROR, "More than one player was found with that input, please be specific.");
770 return CMD_SUCCESS;
771 }
772 if(found == 1)
773 {
774 GetPlayerPos(playerid, x, y, z);
775 if(IsPlayerInAnyVehicle(result) && GetPlayerState(result) == 2)
776 {
777 SetVehiclePos(GetPlayerVehicleID(result), x+2, y, z+2);
778 }
779 else
780 {
781 SetPlayerPos(result, x+2, y, z+2);
782 }
783 GetPlayerName(result, target, sizeof(target));
784 GetPlayerName(playerid, invoker, sizeof(invoker));
785 format(string, sizeof string, "Administration: You brought %s to your position.", target);
786 SendClientMessage(playerid,COLOR_DEFAULT,string);
787 format(string, sizeof string, "Administration: %s brought you to his position.", invoker);
788 SendClientMessage(result,COLOR_DEFAULT,string);
789 return CMD_SUCCESS;
790 }
791 return CMD_SUCCESS;
792}
793
794
795
796/*
797 Command: /otp [player id]
798 Description: Teleports to a player.
799 Notes: Legacy command.
800*/
801COMMAND<PRIVILEGE_LOWMODERATOR>:otp(cmdid, playerid, params[])
802{
803 new pid, target[MAX_PLAYER_NAME], invoker[MAX_PLAYER_NAME], string[128], Float:x, Float:y, Float:z;
804
805 if(pid == INVALID_PLAYER_ID)
806 {
807 SendClientMessage(playerid, COLOR_ERROR, "Player not found.");
808 return CMD_SUCCESS;
809 }
810
811 if(sscanf(params,"i",pid)) return SendClientMessage(playerid, COLOR_ERROR, "Usage: /otp [player id]");
812 GetPlayerPos(pid, x, y, z);
813 SetPlayerPos(playerid, x+2, y, z+2);
814 GetPlayerName(pid, target, sizeof(target));
815 GetPlayerName(playerid, invoker, sizeof(invoker));
816 format(string, sizeof string, "Administration: You were teleported to %s.", target);
817 SendClientMessage(playerid,COLOR_DEFAULT,string);
818 format(string, sizeof string, "Administration: %s has teleported to your position.", invoker);
819 SendClientMessage(pid,COLOR_DEFAULT,string);
820 return CMD_SUCCESS;
821}
822
823
824
825/*
826 Command: /obring [player id]
827 Description: Brings a player to your position.
828 Notes: Legacy command.
829*/
830COMMAND<PRIVILEGE_LOWMODERATOR>:obring(cmdid, playerid, params[])
831{
832 new pid, target[MAX_PLAYER_NAME], invoker[MAX_PLAYER_NAME], string[128], Float:x, Float:y, Float:z;
833
834 if(pid == INVALID_PLAYER_ID)
835 {
836 SendClientMessage(playerid, COLOR_ERROR, "Player not found.");
837 return CMD_SUCCESS;
838 }
839
840 if(sscanf(params,"i",pid)) return SendClientMessage(playerid, COLOR_ERROR, "Usage: /obring [player id]");
841 GetPlayerPos(playerid, x, y, z);
842 SetPlayerPos(pid, x+2, y, z+2);
843 GetPlayerName(pid, target, sizeof(target));
844 GetPlayerName(playerid, invoker, sizeof(invoker));
845 format(string, sizeof string, "Administration: You brought %s to your position.", target);
846 SendClientMessage(playerid,COLOR_DEFAULT,string);
847 format(string, sizeof string, "Administration: %s brought you to his position.", invoker);
848 SendClientMessage(pid,COLOR_DEFAULT,string);
849 return CMD_SUCCESS;
850}
851
852
853
854/*
855 Command: /bringveh [vehicle id]
856 Description: Brings a vehicle to your position.
857 Notes: N/A.
858*/
859COMMAND<PRIVILEGE_LOWMODERATOR>:bringveh(cmdid, playerid, params[])
860{
861 new vid, distance, string[128], Float:x, Float:y, Float:z, Float:a;
862 if(sscanf(params,"i",vid)) return SendClientMessage(playerid, COLOR_ERROR, "Usage: /bringveh [vehicle id]");
863
864 distance = 5;
865
866 GetPlayerPos(playerid, x, y, z);
867 GetPlayerFacingAngle(playerid, a);
868 if (GetPlayerVehicleID(playerid))
869 {
870 distance += 2;
871 GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
872 }
873
874 x += (distance * floatsin(-a, degrees));
875 y += (distance * floatcos(-a, degrees));
876
877 SetVehiclePos(vid, x, y, z);
878
879 format(string, sizeof string, "Administration: You brought vehicle ID %d to your position.", vid);
880 SendClientMessage(playerid,COLOR_DEFAULT,string);
881 return CMD_SUCCESS;
882}
883
884
885
886/*
887 Command: /kill [player id]
888 Description: Kills a player.
889 Notes: N/A.
890*/
891COMMAND<PRIVILEGE_ADMINISTRATOR>:kill(cmdid, playerid, params[])
892{
893 new pid;
894 if(sscanf(params,"i",pid)) return SendClientMessage(playerid, COLOR_ERROR, "Usage: /kill [player id]");
895
896 if(pid == INVALID_PLAYER_ID)
897 {
898 SendClientMessage(playerid, COLOR_ERROR, "Player not found.");
899 return CMD_SUCCESS;
900 }
901
902 else SetPlayerHealth(pid,0.0);
903 return CMD_SUCCESS;
904}
905
906
907
908/*
909 Command: /timeset [time id]
910 Description: Sets world time.
911 Notes: N/A.
912*/
913COMMAND<PRIVILEGE_ADMINISTRATOR>:timeset(cmdid, playerid, params[])
914{
915 new timeid;
916 if(sscanf(params,"i",timeid)) return SendClientMessage(playerid, COLOR_ERROR, "Usage: /timeset [time id]");
917 else SetWorldTime(timeid);
918 return CMD_SUCCESS;
919}
920
921
922
923/*
924 Command: /weatherset [weather id]
925 Description: Sets world weather.
926 Notes: N/A.
927*/
928COMMAND<PRIVILEGE_ADMINISTRATOR>:weatherset(cmdid, playerid, params[])
929{
930 new weatherid;
931 if(sscanf(params,"i",weatherid)) return SendClientMessage(playerid, COLOR_ERROR, "Usage: /weatherset [weather id]");
932 else SetWeather(weatherid);
933 return CMD_SUCCESS;
934}
935
936
937
938/*
939 Command: /dr [player name]
940 Description: Checks player disconnect reason.
941 Notes: N/A.
942*/
943COMMAND<PRIVILEGE_LOWMODERATOR>:dr(cmdid, playerid, params[])
944{
945 new dcr, reason[64];
946 dcr = getDisconnectReason(params[0]);
947 if(dcr < 8)
948 {
949 switch(dcr)
950 {
951 case DISCONNECT_VOLUNTARILY:{reason = "Voluntarily";}
952 case DISCONNECT_CONN_LOST_OR_CRASH:{reason = "Connection Lost or Crash";}
953 case DISCONNECT_ANTICHEAT:{reason = "Kicked by Anticheat";}
954 case DISCONNECT_KICKBAN:{reason = "Kicked/Banned by Admin";}
955 default:{reason = "Unknown";}
956 }
957 new string[128];
958 format(string, sizeof string, "Administration: %s DR: %s.", params[0], reason);
959 SendClientMessage(playerid, COLOR_DEFAULT, string);
960 }
961 else
962 {
963 SendClientMessage(playerid, COLOR_ERROR, SHOOT_COMMANDS_ERR_PLAYERNOTFOUND);
964 return CMD_SUCCESS;
965 }
966 return CMD_SUCCESS;
967}
968
969
970
971// ~-------------~
972// Player commands
973// ~-------------~
974
975
976
977/*
978 Command: /veh [vehicle id]
979 Description: Spawns a vehicle.
980 Notes: N/A.
981*/
982COMMAND:veh(cmdid, playerid, params[])
983{
984 new vid, distance, string[128], Float:x, Float:y, Float:z, Float:a;
985 distance = 5;
986
987 GetPlayerPos(playerid, x, y, z);
988 GetPlayerFacingAngle(playerid, a);
989
990 if (GetPlayerVehicleID(playerid))
991 {
992 distance += 2;
993 GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
994 }
995
996 x += (distance * floatsin(-a, degrees));
997 y += (distance * floatcos(-a, degrees));
998
999 if(sscanf(params,"i",vid)) return SendClientMessage(playerid, COLOR_ERROR, "Usage: /veh [vehicle id]");
1000 {
1001 CreateVehicle(vid, x, y, z, a, -1, -1, 60);
1002 new str_vid[24];
1003 valstr(str_vid, vid);
1004 format(string, sizeof string, "You have spawned a vehicle with ID %s.", str_vid);
1005 SendClientMessage(playerid,COLOR_DEFAULT,string);
1006 }
1007 return CMD_SUCCESS;
1008}
1009
1010
1011
1012/*
1013 Command: /skin [skin id]
1014 Description: Sets your skin.
1015 Notes: N/A.
1016*/
1017COMMAND:skin(cmdid, playerid, params[])
1018{
1019 new sid, string[128];
1020 if(sscanf(params,"i",sid)) return SendClientMessage(playerid, COLOR_ERROR, "Usage: /skin [skin id]");
1021 SetPlayerSkin(playerid, sid);
1022 new str_sid[24];
1023 valstr(str_sid, sid);
1024 format(string, sizeof string, "You have changed your skin to ID %s.", str_sid);
1025 SendClientMessage(playerid,COLOR_DEFAULT,string);
1026 return CMD_SUCCESS;
1027}
1028
1029
1030
1031/*
1032 Command: /wep [weapon id]
1033 Description: Gives yourself a weapon.
1034 Notes: N/A.
1035*/
1036COMMAND:wep(cmdid, playerid, params[])
1037{
1038 new wid, string[128];
1039 if(sscanf(params,"i",wid)) return SendClientMessage(playerid, COLOR_ERROR, "Usage: /wep [weapon id]");
1040 GivePlayerWeapon(playerid,wid,9999);
1041 new str_wid[24];
1042 valstr(str_wid, wid);
1043 format(string, sizeof string, "You have given yourself weapon ID %s.", str_wid);
1044 SendClientMessage(playerid, COLOR_DEFAULT, string);
1045 return CMD_SUCCESS;
1046}
1047
1048
1049
1050/*
1051 Command: /repair
1052 Description: Repairs your current vehicle.
1053 Requires you to be in the driver seat.
1054 on command input.
1055 Notes: N/A.
1056*/
1057COMMAND:repair(cmdid, playerid, params[])
1058{
1059 if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_ERROR, "You are not in a vehicle.");
1060 if(GetPlayerState(playerid) != 2) return SendClientMessage(playerid, COLOR_ERROR, "You are not in the driver seat.");
1061 RepairVehicle(GetPlayerVehicleID(playerid));
1062 SendClientMessage(playerid, COLOR_DEFAULT, "Your vehicle has been successfully repaired.");
1063 PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
1064 return 1;
1065}
1066
1067
1068
1069/*
1070 Command: /nitro
1071 Description: Attaches x10 nitro to your current vehicle (if applicable).
1072 Requires you to be in the driver seat.
1073 Notes: N/A.
1074*/
1075COMMAND:nitro(cmdid, playerid, params[])
1076{
1077 if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_ERROR, "You are not in a vehicle.");
1078 if(GetPlayerState(playerid) != 2) return SendClientMessage(playerid, COLOR_ERROR, "You are not in the driver seat.");
1079 AddVehicleComponent(GetPlayerVehicleID(playerid), 1010);
1080 SendClientMessage(playerid, COLOR_DEFAULT, "Your vehicle now has x10 nitro.");
1081 PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
1082 return 1;
1083}
1084
1085
1086
1087/*
1088 Command: /id [input]
1089 Description: Searches for any matching online players based
1090 on command input.
1091 Notes: N/A.
1092*/
1093COMMAND:id(cmdid, playerid, params[])
1094{
1095 if(isnull(params))
1096 {
1097 return SendClientMessage(playerid,COLOR_FAILURE,"Usage: /id [player name]");
1098 }
1099
1100 new string[128], found;
1101
1102 for(new i; i < MAX_PLAYERS; i++)
1103 {
1104 new pname[MAX_PLAYER_NAME];
1105 GetPlayerName(i, pname, sizeof(pname));
1106 if(strfind(pname, params, true) != -1)
1107 {
1108 format(string, sizeof(string), "%s (ID %d) (Level: %d)", pname, i, gPData[i][level]);
1109 SendClientMessage(playerid,COLOR_DEFAULT,string);
1110 found++;
1111 }
1112 }
1113 if(found == 0)
1114 {
1115 SendClientMessage(playerid, COLOR_DEFAULT, SHOOT_COMMANDS_ERR_PLAYERNOTFOUND);
1116 }
1117 return CMD_SUCCESS;
1118}
1119
1120
1121
1122/*
1123 Command: /w [player/staff id] [message]
1124 Description: Privately whispers some message to a certain player.
1125 Regular users can only whisper staff members with this command.
1126 Notes: N/A.
1127*/
1128COMMAND:w(cmdid, playerid, params[])
1129{
1130 new pid, msg[128];
1131 if(sscanf(params, "us", pid, msg)) SendClientMessage(playerid, COLOR_FAILURE, "Usage: /w [staff id] [message]");
1132 {
1133 if(pid == INVALID_PLAYER_ID)
1134 {
1135 SendClientMessage(playerid, COLOR_FAILURE, SHOOT_COMMANDS_ERR_PLAYERNOTFOUND);
1136 return CMD_SUCCESS;
1137 }
1138 if(isStaff(pid) || isStaff(playerid))
1139 {
1140 new string[128], pname[MAX_PLAYER_NAME];
1141 GetPlayerName(playerid, pname, sizeof(pname));
1142 format(string, sizeof string, "Administration: %s (ID %d) whispers: %s", pname, playerid, msg);
1143 SendClientMessage(pid, COLOR_WHISPER, string);
1144 GetPlayerName(pid, pname, sizeof(pname));
1145 format(string, sizeof string, "Administration: you whispered %s (ID %d): %s", pname, pid, msg);
1146 SendClientMessage(playerid, COLOR_WHISPER, string);
1147 }
1148 else
1149 {
1150 SendClientMessage(playerid, COLOR_ERROR, "You can only whisper staff members. (/staff)");
1151 }
1152 }
1153 return CMD_SUCCESS;
1154}
1155
1156
1157
1158/*
1159 Command: /staff
1160 Description: Displays current online staff members.
1161 Notes: N/A.
1162*/
1163COMMAND:staff(cmdid, playerid, params[])
1164{
1165 if(!isnull(params))
1166 {
1167 return SendClientMessage(playerid, COLOR_ERROR, SHOOT_COMMANDS_ERR_NOPARAMS);
1168 }
1169
1170 new string[128], found;
1171 format(string, sizeof(string), "* Online Staff:");
1172 SendClientMessage(playerid,COLOR_DEFAULT,string);
1173
1174 for(new i; i < MAX_PLAYERS; i++)
1175 {
1176 if(gPData[i][privilege] >= PRIVILEGE_LOWMODERATOR)
1177 {
1178 new pname[MAX_PLAYER_NAME];
1179 GetPlayerName(i, pname, sizeof(pname));
1180 format(string, sizeof(string), "{%s}** %s %s (ID %d)", getPrivilegeColor(i), getPrivilegeName(i), pname, i);
1181 SendClientMessage(playerid,COLOR_DEFAULT,string);
1182 found++;
1183 }
1184 }
1185 if(found == 0)
1186 {
1187 SendClientMessage(playerid, COLOR_DEFAULT, "There are no staff members online.");
1188 }
1189 return CMD_SUCCESS;
1190}
1191
1192
1193
1194/*
1195 Command: /stats
1196 Description: Displays your account stats.
1197 Notes: N/A.
1198*/
1199COMMAND:stats(cmdid, playerid, params[])
1200{
1201 new string[128];
1202 SendClientMessage(playerid, COLOR_STATS, "* Your stats:");
1203 format(string, sizeof(string), "ID DB: %d | Rank: %s | Membership: %s | Level: %d | Experience: %d/%d | Balance: %d | Skin ID: %d", gPData[playerid][id], getPrivilegeName(playerid), getMembershipName(playerid), gPData[playerid][level], gPData[playerid][xp], calcRequiredXP(gPData[playerid][level]), gPData[playerid][balance], gPData[playerid][skinid]);
1204 SendClientMessage(playerid, COLOR_STATS, string);
1205 return CMD_SUCCESS;
1206}
1207
1208aAbB()
1209{
1210 new a[][] =
1211 {
1212 "Unarmed (Fist)",
1213 "Brass K"
1214 };
1215 #pragma unused a
1216}