Advertisement
Guest User

Please help

a guest
Jul 12th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.29 KB | None | 0 0
  1. /*
  2.     CeSuX Andreas 0.2
  3.     made by CeSuX
  4.  
  5.     -=Commands=-
  6.    
  7.     Player Commands:
  8.         /PM /CMDS
  9.         /STATS
  10.     Admin Level 1 Commands:
  11.         /KICK /MUTE /UNMUTE
  12.     Admin Level 2 Commands:
  13.         /BAN /SLAP
  14. */
  15.  
  16. // INCLUDES ===============================
  17. #include <a_samp>
  18. #include <izcmd>
  19. #include <sscanf2>
  20. #include <a_mysql>
  21. native WP_Hash(buffer[], len, const str[]);
  22. // ========================================
  23.  
  24. // COLORS =====================
  25. #define COLOR_RED    0xFF0000FF
  26. #define COLOR_YELLOW 0xFFFF00FF
  27. #define COLOR_GREEN  0x33AA33FF
  28. // ============================
  29.  
  30. // COMMANDS =========================================
  31. #define CMDS "\t   {FFFF00}*Player Commands*\
  32.                       \n/CMDS /PM /R /STATS\
  33.             \n\t{FFFF00}*Admin Level 1 Commands*\
  34.                       \n/KICK /MUTE /UNMUTE\
  35.             \n\t{FFFF00}*Admin Level 2 Commands*\
  36.                         /BAN /SLAP"
  37. // ==================================================
  38.  
  39. // SETTINGS ======================
  40. #define MYSQL_HOST     "localhost"
  41. #define MYSQL_USER     "root"
  42. #define MYSQL_DATABASE "users"
  43. #define MYSQL_PASSWORD ""
  44. #define GamemodeText   "Build 0.2"
  45. // ===============================
  46.  
  47. // DIALOGS =====
  48. enum
  49. {
  50.     DIALOG_CMDS,
  51.     DIALOG_STATS,
  52.     DIALOG_REGISTER,
  53.     DIALOG_LOGIN
  54. };
  55. // =================
  56.  
  57. // PLAYER DATA ====================================
  58. enum PlayerData
  59. {
  60.     RepliedPlayer[MAX_PLAYERS],      // Doesn't save
  61.     bool:PlayerIsMuted[MAX_PLAYERS], // Doesn't save
  62.     ID,
  63.     Name[MAX_PLAYER_NAME],
  64.     Password[129],
  65.     IP[16],
  66.     Money,
  67.     Score,
  68.     AdminLevel,
  69. };
  70. new pData[MAX_PLAYERS][PlayerData];
  71. // ================================================
  72.  
  73. // TIMERS =============
  74. forward KickTimer(pID);
  75. public KickTimer(pID)
  76. {Kick(pID);}
  77.  
  78. forward BanTimer(pID);
  79. public BanTimer(pID)
  80. {Ban(pID);}
  81. // ====================
  82.  
  83. // MYSQL =========================================================================
  84. new mysql;
  85. ConnectToMySQL()
  86. {
  87.     mysql_log(LOG_ALL);
  88.    mysql = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
  89.    if(mysql_errno() != 0) print("[MySQL] The connection has failed.");
  90.    else printf("[MySQL] The connection was successful.");
  91. }
  92.  
  93. forward OnAccountCheck(playerid);
  94. public OnAccountCheck(playerid)
  95. {
  96.     new rows, fields;
  97.     cache_get_data(rows, fields, mysql);
  98.     if(rows)
  99.     {
  100.         cache_get_field_content(0, "Password", pData[playerid][Password], 129);
  101.         pData[playerid][ID] = cache_get_field_content_int(0, "ID");
  102.         ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,
  103.             "{FFFF00}Login/Register Window",
  104.             "This account has been already registered.\
  105.             \nPlease login to continue.",
  106.            "{33AA33}Login", "{FF0000}Quit");
  107.     }
  108.     else ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,
  109.         "{FFFF00}Login/Register Window",
  110.         "This account has been already registered.\
  111.        \nPlease register to continue.",
  112.         "{33AA33}Login", "{FF0000}Quit");
  113.     return 1;
  114. }
  115.  
  116. forward OnAccountLoad(playerid);
  117. public OnAccountLoad(playerid)
  118. {
  119.     pData[playerid][AdminLevel] = cache_get_field_content_int(0, "Admin Level");
  120.     pData[playerid][Money] = cache_get_field_content_int(0, "Money");
  121.     pData[playerid][Score] = cache_get_field_content_int(0, "Score");
  122.     TogglePlayerSpectating(playerid, false);
  123.     GivePlayerMoney(playerid, pData[playerid][Money]);
  124.     SetPlayerScore(playerid, pData[playerid][Score]);
  125.     return 1;
  126. }
  127.  
  128. forward OnAccountRegister(playerid);
  129. public OnAccountRegister(playerid)
  130. {
  131.    pData[playerid][ID] = cache_insert_id();
  132.    printf("[Registration] New account registered. Database ID: [%d]", pData[playerid][ID]);
  133.    TogglePlayerSpectating(playerid, false);
  134.    return 1;
  135. }  
  136. //================================================================================
  137.  
  138. // FUNCTIONS =====================================================================================================
  139. Pm(senderid, receiverid, const Message[128])
  140. {
  141.     new pName[MAX_PLAYER_NAME]; GetPlayerName(receiverid, pName, sizeof(pName));
  142.     new String[128]; format(String, sizeof(String), "To: %s: %s", pName, Message);
  143.     SendClientMessage(senderid, COLOR_YELLOW, String);
  144.     GetPlayerName(senderid, pName, sizeof(pName)); format(String, sizeof(String), "From: %s: %s", pName, Message);
  145.     SendClientMessage(receiverid, COLOR_YELLOW, String);
  146. }
  147.  
  148. KickEx(adminid, playerid, const Reason[50])
  149. {
  150.     new aName[MAX_PLAYER_NAME]; GetPlayerName(adminid, aName, sizeof(aName));
  151.     new pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, sizeof(pName));
  152.     new String[128]; format(String, sizeof(String), "Player %s got kicked by %s (%s).", pName, aName, Reason);
  153.     SendClientMessageToAll(COLOR_YELLOW, String);
  154.     SetTimerEx("KickTimer", 2000, false, "i", playerid);
  155. }
  156.  
  157. BanEx(adminid, playerid, const Reason[50])
  158. {
  159.     new aName[MAX_PLAYER_NAME]; GetPlayerName(adminid, aName, sizeof(aName));
  160.     new pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, sizeof(pName));
  161.     new String[128]; format(String, sizeof(String), "Player %s got banned by %s (%s).", pName, aName, Reason);
  162.     SendClientMessageToAll(COLOR_YELLOW, String);
  163.     SetTimerEx("BanTimer", 2000, false, "i", playerid);
  164. }
  165.  
  166. Mute(adminid, playerid, const Reason[50])
  167. {
  168.     new pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, sizeof(pName));
  169.     new String[128]; format(String, sizeof(String), "You freezed player %s(%s)", pName, Reason);
  170.     SendClientMessage(adminid, COLOR_YELLOW, String);
  171.     GetPlayerName(adminid, pName, sizeof(pName)); format(String, sizeof(String), "You got frozen by admin %s (%s)", pName, Reason);
  172.     SendClientMessage(playerid, COLOR_YELLOW, String);
  173. }
  174.  
  175. UnMute(adminid, playerid, const Reason[50])
  176. {
  177.     new pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, sizeof(pName));
  178.     new String[128]; format(String, sizeof(String), "You unfreezed player %s(%s)", pName, Reason);
  179.     SendClientMessage(adminid, COLOR_YELLOW, String);
  180.     GetPlayerName(adminid, pName, sizeof(pName)); format(String, sizeof(String), "You got unfrozen by admin %s (%s)", pName, Reason);
  181.     SendClientMessage(playerid, COLOR_YELLOW, String);
  182. }
  183.  
  184. Slap(adminid, playerid)
  185. {
  186.     new pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, sizeof(pName));
  187.     new String[128]; format(String, sizeof(String), "You slapped %s", pName);
  188.     SendClientMessage(adminid, COLOR_RED, String);
  189.     new Float:X, Float:Y, Float:Z;
  190.     GetPlayerPos(playerid, X, Y, Z); SetPlayerPos(playerid, X, Y, Z + 5);
  191. }
  192. // ==================================================================================================================================
  193.  
  194. main()
  195. {
  196.     print("\n");
  197.     print("\t -=CeSuX Andreas=-");
  198.     print("\tStarted successfully");
  199.     print("\n");
  200. }
  201.  
  202. public OnGameModeInit()
  203. {
  204.     ConnectToMySQL();
  205.     SetGameModeText(GamemodeText);
  206.     return 1;
  207. }
  208.  
  209. public OnGameModeExit()
  210. {return 1;}
  211.  
  212. public OnPlayerConnect(playerid)
  213. {
  214.     TogglePlayerSpectating(playerid, true);
  215.     new query[128], pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, sizeof(pName));
  216.     mysql_format(mysql, query, sizeof(query), "SELECT `Password`, `ID` FROM `players` WHERE `Name` = '%e' LIMIT 1", pName);
  217.     mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
  218.  
  219.     pData[playerid][PlayerIsMuted] = false;
  220.     pData[playerid][RepliedPlayer] = INVALID_PLAYER_ID;
  221.    
  222.     new Message[90]; format(Message, sizeof(Message), "Player %s has joined the game!", pName);
  223.     SendClientMessageToAll(COLOR_YELLOW, Message);
  224.     return 1;
  225. }
  226.  
  227. public OnPlayerDisconnect(playerid, reason)
  228. {
  229.     new query[128];
  230.     mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET `Money` = %d, `Score` = %d WHERE `ID` = %d",
  231.     GetPlayerMoney(playerid), GetPlayerScore(playerid), pData[playerid][ID]);
  232.     mysql_tquery(mysql, query, "", "");
  233.  
  234.     pData[playerid][PlayerIsMuted] = false;
  235.     pData[playerid][RepliedPlayer] = INVALID_PLAYER_ID;
  236.  
  237.     new DisconnectReason[3][] =
  238.     {
  239.         "Timeout/Crashed",
  240.         "Quited",
  241.         "Kicked/Banned"
  242.     };
  243.     new pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, sizeof(pName));
  244.     new Message[128]; format(Message, sizeof(Message), "Player %s left the server (%s).", pName, DisconnectReason[reason]);
  245.     return 1;
  246. }
  247.  
  248. public OnPlayerSpawn(playerid)
  249. {return 1;}
  250.  
  251. public OnPlayerText(playerid, text[])
  252. {
  253.     if(pData[playerid][PlayerIsMuted])
  254.     {
  255.         SendClientMessage(playerid, COLOR_RED, "You are muted, you cannot chat.");
  256.         return 0;
  257.     }
  258.     new String[50]; format(String, sizeof(String), "(%i) %s", playerid, text);
  259.     SendPlayerMessageToAll(playerid, String);
  260.     return 0;
  261. }
  262.  
  263. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  264. {
  265.     switch(dialogid)
  266.     {
  267.         case DIALOG_LOGIN:
  268.         {
  269.             if(!response) Kick(playerid);
  270.             new hashpass[129], query[100], pName[MAX_PLAYER_NAME];
  271.             GetPlayerName(playerid, pName, sizeof(pName));
  272.             WP_Hash(hashpass, sizeof(hashpass), pData[playerid][Password]);
  273.             if(!strcmp(hashpass, pData[playerid][Password]))
  274.             {
  275.                 mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `Name` = '%e' LIMIT 1", pName);
  276.                 mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
  277.             }
  278.             else
  279.             {
  280.                 SendClientMessage(playerid, COLOR_RED, "Incorrect password, try again.");
  281.                 ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,
  282.                     "{FFFF00}Login/Register Window",
  283.                     "This account has been already registered.\
  284.                     \nPlease login to continue.",
  285.                      "{33AA33}Login", "{FF0000}Quit");
  286.             }
  287.         }
  288.         case DIALOG_REGISTER:
  289.         {
  290.             if(!response) Kick(playerid);
  291.             if(strlen(inputtext) < 5)
  292.             {
  293.                 SendClientMessage(playerid, COLOR_RED, "Your password has to contain atleast 4 characters.");
  294.                 return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,
  295.                     "{FFFF00}Login/Register Window",
  296.                     "This account has been already registered.\
  297.                    \nPlease register to continue.",
  298.                     "{33AA33}Login", "{FF0000}Quit");
  299.             }
  300.             new query[512], pName[MAX_PLAYER_NAME], pIP[16];
  301.             GetPlayerName(playerid, pName, sizeof(pName));
  302.             GetPlayerIp(playerid, pIP, sizeof(pIP));
  303.             WP_Hash(pData[playerid][Password], 129, inputtext);
  304.             mysql_format(mysql, query, sizeof(query), "INSERT INTO `players` (`Name`, `Password`, `IP`, `Admin Level`, `Money`, `Score`) VALUES ('%e', '%e', '%e', 0, 0, 0)",
  305.             pName, pData[playerid][Password], pIP);
  306.             mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
  307.         }
  308.     }
  309.     return 1;
  310. }
  311.  
  312. // COMMANDS ==========================================================================================
  313. public OnPlayerCommandReceived(playerid, cmdtext[])
  314. {
  315.     return 1;
  316. }
  317.  
  318. CMD:cmds(playerid, params[]) // Player command
  319. {
  320.     ShowPlayerDialog(playerid, DIALOG_CMDS, DIALOG_STYLE_MSGBOX, "{FFFF00}CeSuX Andreas - Commands", CMDS, "{33AA33}Okay", "");
  321.     return 1;
  322. }
  323.  
  324. CMD:commands(playerid, params[]) // Player command
  325. {
  326.     return cmd_cmds(playerid, params);
  327. }
  328.  
  329. CMD:stats(playerid, params[]) // Player command
  330. {
  331.     new pID;
  332.     if(sscanf(params, "u", pID)) return SendClientMessage(playerid, COLOR_RED, "Usage: /Stats ID.");
  333.     if(!IsPlayerConnected(playerid)) return SendClientMessage(pID, COLOR_RED, "Player is not connected.");
  334.     new pName[MAX_PLAYER_NAME]; GetPlayerName(pID, pName, sizeof(pName));
  335.     new Caption[50]; format(Caption, sizeof(Caption), "{FFFF00}Player - %s", pName);
  336.     new Stats[128]; format(Stats, sizeof(Stats), "\n\n\
  337.                                                   \nAdmin Level: %d\
  338.                                                   \nScore:       %d\
  339.                                                   \nMoney:       %d\
  340.                                                   \nID:          %d\
  341.                                                   \n\n",
  342.                                                   0, GetPlayerScore(pID), GetPlayerMoney(pID), pID);
  343.     ShowPlayerDialog(playerid, DIALOG_STATS, DIALOG_STYLE_MSGBOX, Caption, Stats, "{33AA33}Okay", "");
  344.     return 1;
  345. }
  346.  
  347. CMD:pm(playerid, params[]) // Player command
  348. {
  349.     new pID, Message[128];
  350.     if(sscanf(params, "us[128]", pID, Message)) return SendClientMessage(playerid, COLOR_RED, "Usage: /Pm ID Message.");
  351.     if(!IsPlayerConnected(pID)) return SendClientMessage(pID, COLOR_RED, "Player is not connected.");
  352.     Pm(playerid, pID, Message);
  353.     pData[playerid][RepliedPlayer] = playerid;
  354.     return 1;
  355. }
  356.  
  357. CMD:r(playerid, params[]) // Player command
  358. {
  359.     new Message[128];
  360.     if(sscanf(params, "s[128]", Message)) return SendClientMessage(playerid, COLOR_RED, "Usage: /r Message.");
  361.     if(!IsPlayerConnected(pData[playerid][RepliedPlayer])) return SendClientMessage(playerid, COLOR_RED, "You don't have a person to reply to.");
  362.     Pm(playerid, pData[playerid][RepliedPlayer], Message);
  363.     return 1;
  364. }
  365.  
  366. CMD:reply(playerid, params[]) // Player command
  367. {return cmd_r(playerid, params);}
  368.  
  369. CMD:kick(playerid, params[]) // Admin level 1 command
  370. {
  371.     new pID, Reason[50];
  372.     if(sscanf(params, "us[50]", pID, Reason)) return SendClientMessage(playerid, COLOR_RED, "Usage: /Kick ID Reason.");
  373.     if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, COLOR_RED, "Player is not connected.");
  374.     KickEx(playerid, pID, Reason);
  375.     return 1;
  376. }
  377.  
  378. CMD:ban(playerid, params[]) // Admin level 2 command
  379. {
  380.     new pID, Reason[50];
  381.     if(sscanf(params, "us[50]", pID, Reason)) return SendClientMessage(playerid, COLOR_RED, "Usage: /Kick ID Reason.");
  382.     if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, COLOR_RED, "Player is not connected.");
  383.     BanEx(playerid, pID, Reason);
  384.     return 1;
  385. }
  386.  
  387. CMD:mute(playerid, params[]) // Admin level 1 command
  388. {
  389.     new pID, Reason[50];
  390.     if(sscanf(params, "us[50]", pID, Reason)) return SendClientMessage(playerid, COLOR_RED, "Usage: /Mute ID Reason.");
  391.     if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, COLOR_RED, "Player is not connected.");
  392.     Mute(playerid, pID, Reason);
  393.     pData[pID][PlayerIsMuted] = true;
  394.     return 1;
  395. }
  396.  
  397. CMD:unmute(playerid, params[]) // Admin level 1 command
  398. {
  399.     new pID, Reason[50];
  400.     if(sscanf(params, "us[50]", pID, Reason)) return SendClientMessage(playerid, COLOR_RED, "Usage: /Mute ID Reason.");
  401.     if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, COLOR_RED, "Player is not connected.");
  402.     UnMute(playerid, pID, Reason);
  403.     pData[playerid][PlayerIsMuted] = false;
  404.     return 1;
  405. }
  406.  
  407. CMD:slap(playerid, params[]) // Admin level 2 command
  408. {
  409.     new pID;
  410.     if(sscanf(params, "u", pID)) return SendClientMessage(playerid, COLOR_RED, "Usage: /Slap ID.");
  411.     if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, COLOR_RED, "Player is not connected.");
  412.     Slap(playerid, pID);
  413.     return 1;
  414. }
  415.  
  416. public OnPlayerCommandPerformed(playerid, cmdtext[], success)
  417. {
  418.     if(!success)
  419.         return SendClientMessage(playerid, COLOR_RED, "Unknown command, use /cmds for all commands.");
  420.     return 1;
  421. }
  422. // ====================================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement