Advertisement
Guest User

gm

a guest
Mar 21st, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 25.70 KB | None | 0 0
  1. // BoF - Beginning of File
  2.  
  3. #include <a_samp>
  4. #include <a_mysql>
  5. #include <sscanf2>
  6. #include <foreach>
  7. #include <zcmd>
  8. #include <YSI\y_timers>
  9.  
  10. native WP_Hash(buffer[], len, const str[]); // Whirlpool is not an include, it is a plugin. This is all we need in order to use it in the script!
  11.  
  12. #define COLOR_RED           0xE7000000
  13. #define COLOR_GREEN         0x80FF00B9
  14. #define COLOR_WHITE         0xFFFFFFFF
  15. #define COLOR_ORANGE        0xFF800000
  16. #define COLOR_YELLOW        0xFFFF09C8
  17. #define COLOR_LIGHTBLUE     0x379BFFC8
  18. #define COLOR_LIGHTRED      0xFF6464C8
  19. #define COLOR_GREY          0xC0C0C0C8
  20.  
  21. #define COLOR_DGREY1        0xE6E6E6E6
  22. #define COLOR_DGREY2        0xC8C8C8C8
  23. #define COLOR_DGREY3        0xAAAAAAAA
  24. #define COLOR_DGREY4        0x8C8C8C8C
  25. #define COLOR_DGREY5        0x6E6E6E6E
  26.  
  27. #define COL_EMB_RED         "{E70000}"
  28. #define COL_EMB_GREEN       "{80FF00}"
  29. #define COL_EMB_WHITE       "{FFFFFF}"
  30. #define COL_EMB_ORANGE      "{FF8000}"
  31. #define COL_EMB_YELLOW      "{FFFF09}"
  32. #define COL_EMB_LIGHTBLUE   "{379BFF}"
  33. #define COL_EMB_LIGHTRED    "{FF6464}"
  34. #define COL_EMB_GREY        "{C0C0C0}"
  35.  
  36. new
  37.     g_szFormatString[128]; // this global string is necessary for the defines below
  38.  
  39. #define fSendClientMessage(%1,%2,%3) \
  40.     SendClientMessage(%1, %2, (format(g_szFormatString, sizeof(g_szFormatString), %3), g_szFormatString)) // you can use this define to prevent having to format a string inline; you can do it in a single function now
  41.  
  42. #define fSendClientMessageToAll(%1,%2) \
  43.     sendGlobalMessage(%1, (format(g_szFormatString, sizeof(g_szFormatString), %2), g_szFormatString)) // you can use this define to prevent having to format a string inline; you can do it in a single function now
  44.  
  45. #define fSendAdminMessage(%1,%2) \
  46.     sendAdminMessage(%1, (format(g_szFormatString, sizeof(g_szFormatString), %2), g_szFormatString)) // you can use this define to prevent having to format a string inline; you can do it in a single function now
  47.  
  48. #define fSendAreaMessage(%1,%2,%3,%4,%5,%6,%7) \
  49.     sendAreaMessage(%1, %2, %3, %4, %5, %6, (format(g_szFormatString, sizeof(g_szFormatString), %7), g_szFormatString)) // you can use this define to prevent having to format a string inline; you can do it in a single function now
  50.  
  51. // -------------------- Server Definitions -------------------- //
  52.  
  53. #define SCRIPT_VERSION "rev. 0.0.1"
  54.  
  55. #define DEFAULT_CASH 1000 // set this to the amount of money player's should start with
  56. #define DEFAULT_LEVEL 1 // set this to the score/level player's should start with
  57.  
  58.     // ---------- MySQL Information ---------- //
  59.  
  60.         #define SQL_DEBUG 1 // enable MySQL debugging by keeping this as "1"; otherwise, use "0"
  61.         #define connectionHandle 1 // change this only if you absolutely have to
  62.  
  63.         #define SQL_HOST "localhost"
  64.         #define SQL_USER "root"
  65.         #define SQL_DATA "rpsql"
  66.         #define SQL_PASS ""
  67.  
  68.     // --------------------------------------- //
  69.  
  70. // ------------------------------------------------------------ //
  71.  
  72. enum // this is easier than handling a bunch of "#define" lines; you can just put a new line in the enum to make a new dialog definition
  73. {
  74.     DIALOG_REGISTER,
  75.     DIALOG_SETGENDER,
  76.     DIALOG_SETAGE,
  77.     DIALOG_AUTHENTICATION
  78. }
  79.  
  80. enum PLAYER_VARIABLES
  81. {
  82.     pDataID, // we use database ID's (data ID) as it's easier to handle than a username and provides easy table linking
  83.     pPassword[129], // passwords are hashed, the hash is 128 + 1 for the null terminator, equaling 129
  84.     pCash,
  85.     pSavings,
  86.     pBankAccount,
  87.     pLevel,
  88.     pKills,
  89.     pDeaths,
  90.     pRegTime, // registration time/date; saved as a timestamp
  91.     pLastOn, // last time/date online; saved as a timestamp
  92.     Float:pHealth,
  93.     Float:pArmour,
  94.     Float:pLastX, // on the last disconnect, this was the X position of the player
  95.     Float:pLastY, // on the last disconnect, this was the Y position of the player
  96.     Float:pLastZ, // on the last disconnect, this was the Z position of the player
  97.     pSkin,
  98.     pGender[7],
  99.     pAge
  100. };
  101.  
  102. new pInfo[MAX_PLAYERS][PLAYER_VARIABLES]; // this allows usage of the "pInfo" variable with the "PLAYER_VARIABLES" enumerator
  103.  
  104. // -------------------- Global Player Variables -------------------- //
  105.  
  106. new // begins global bool vars
  107.     bool:tAuthenticated[MAX_PLAYERS] = false
  108. ;
  109.  
  110. new // begins numerical global vars
  111.     iLoginAttempts[MAX_PLAYERS] = 0
  112. ;
  113.  
  114. // ----------------------------------------------------------------- //
  115.  
  116. main(){}
  117.  
  118. public OnGameModeInit()
  119. {
  120.     mysql_debug(SQL_DEBUG);
  121.     new Connection = mysql_connect(SQL_HOST, SQL_USER, SQL_DATA, SQL_PASS);
  122.     if(Connection) //checks if the database is successfully connected
  123.     {
  124.         new dest[200];
  125.         mysql_stat(dest); // display the mysql database statistics.
  126.         printf(dest);
  127.         printf(">> MySQL connection successfully initialized"); // if it is connected it will display this line, if not then it wont display anything.
  128.     }
  129.     SetGameModeText(SCRIPT_VERSION);
  130.     return 1;
  131. }
  132.  
  133. public OnGameModeExit()
  134. {
  135.     mysql_close();
  136.     return 1;
  137. }
  138. forward ConnectMySQL();
  139. public ConnectMySQL()
  140. {
  141.     if(mysql_connect(SQL_HOST,SQL_USER,SQL_DATA,SQL_PASS))
  142.     {
  143.         mysql_debug(1);
  144.         printf("[MYSQL]: Connection to `%s` succesful!",SQL_DATA);
  145.     }
  146.     else
  147.     {
  148.       printf("[MYSQL]: [ERROR]: Connection to `%s` failed!",SQL_DATA);
  149.     }
  150.     return 1;
  151. }
  152. public OnPlayerRequestClass(playerid, classid)
  153. {
  154.     return 1;
  155. }
  156.  
  157. public OnPlayerConnect(playerid)
  158. {
  159.     if(!IsRolePlayName(playerid))
  160.     {
  161.         SendClientMessage(playerid, COLOR_WHITE, "Unfortunately, your name is not in the proper format! Please use the format of "#COL_EMB_LIGHTBLUE"\"Firstname_Lastname\""#COL_EMB_WHITE".");
  162.         defer delayedKick(playerid);
  163.     }
  164.  
  165.     TogglePlayerSpectating(playerid, true);
  166.     new rows = mysql_num_rows(); //We get how many rows the query returned.
  167.     if(!rows)
  168.     {
  169.     ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""#COL_EMB_WHITE"Account Registration", ""#COL_EMB_WHITE"This account has "#COL_EMB_RED"not been registered"#COL_EMB_WHITE"!\n\nEnter your desired password below to register this account.", "Submit", "Leave");
  170.     }
  171.     if(rows == 1)
  172.     {
  173.     ShowPlayerDialog(playerid, DIALOG_AUTHENTICATION, DIALOG_STYLE_PASSWORD, ""#COL_EMB_WHITE"Account Authentication", ""#COL_EMB_WHITE"This account has "#COL_EMB_GREEN"been registered"#COL_EMB_WHITE"!\n\nEnter the account password below to proceed.", "Submit", "Leave");
  174.     }
  175.     new szQuery[500];
  176.     format(szQuery, sizeof(szQuery), "SELECT * FROM `Bans` WHERE `Username` = '%s'", getEscName(playerid));
  177.     mysql_function_query(connectionHandle, szQuery, true, "thread_checkBans", "d", playerid);
  178.     return 1;
  179. }
  180.  
  181. public OnPlayerDisconnect(playerid, reason)
  182. {
  183.     saveVariables(playerid);
  184.  
  185.     new
  186.         Float:fPos[3]
  187.     ;
  188.  
  189.     GetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
  190.     foreach(new i : Player)
  191.         if(IsPlayerInRangeOfPoint(i, 7.0, fPos[0], fPos[1], fPos[2])) fSendClientMessage(i, COLOR_YELLOW, "* %s has disconnected from the server.", getName(playerid));
  192.  
  193.     return 1;
  194. }
  195.  
  196. public OnPlayerSpawn(playerid)
  197. {
  198.     return 1;
  199. }
  200.  
  201. public OnPlayerDeath(playerid, killerid, reason)
  202. {
  203.     return 1;
  204. }
  205.  
  206. public OnVehicleSpawn(vehicleid)
  207. {
  208.     return 1;
  209. }
  210.  
  211. public OnVehicleDeath(vehicleid, killerid)
  212. {
  213.     return 1;
  214. }
  215.  
  216. public OnPlayerText(playerid, text[])
  217. {
  218.     if(strlen(text) > 2)
  219.         fSendAreaMessage(playerid, COLOR_DGREY1, COLOR_DGREY1, COLOR_DGREY2, COLOR_DGREY3, COLOR_DGREY4, "%s says: %s", getRolePlayName(playerid), text);
  220.  
  221.     return 0;
  222. }
  223.  
  224. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  225. {
  226.     return 1;
  227. }
  228.  
  229. public OnPlayerExitVehicle(playerid, vehicleid)
  230. {
  231.     return 1;
  232. }
  233.  
  234. public OnPlayerStateChange(playerid, newstate, oldstate)
  235. {
  236.     return 1;
  237. }
  238.  
  239. public OnPlayerEnterDynamicCP(playerid)
  240. {
  241.     return 1;
  242. }
  243.  
  244. public OnPlayerLeaveDynamicCP(playerid)
  245. {
  246.     return 1;
  247. }
  248.  
  249. public OnPlayerEnterDynamicRaceCP(playerid)
  250. {
  251.     return 1;
  252. }
  253.  
  254. public OnPlayerLeaveDynamicRaceCP(playerid)
  255. {
  256.     return 1;
  257. }
  258.  
  259. public OnRconCommand(cmd[])
  260. {
  261.     return 1;
  262. }
  263.  
  264. public OnPlayerRequestSpawn(playerid)
  265. {
  266.     return 1;
  267. }
  268.  
  269. public OnObjectMoved(objectid)
  270. {
  271.     return 1;
  272. }
  273.  
  274. public OnPlayerObjectMoved(playerid, objectid)
  275. {
  276.     return 1;
  277. }
  278.  
  279. public OnPlayerPickUpDynamicPickup(playerid, pickupid)
  280. {
  281.     return 1;
  282. }
  283.  
  284. public OnVehicleMod(playerid, vehicleid, componentid)
  285. {
  286.     return 1;
  287. }
  288.  
  289. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  290. {
  291.     return 1;
  292. }
  293.  
  294. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  295. {
  296.     return 1;
  297. }
  298.  
  299. public OnPlayerSelectedMenuRow(playerid, row)
  300. {
  301.     return 1;
  302. }
  303.  
  304. public OnPlayerExitedMenu(playerid)
  305. {
  306.     return 1;
  307. }
  308.  
  309. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  310. {
  311.     return 1;
  312. }
  313.  
  314. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  315. {
  316.     return 1;
  317. }
  318.  
  319. public OnRconLoginAttempt(ip[], password[], success)
  320. {
  321.     return 1;
  322. }
  323.  
  324. public OnPlayerUpdate(playerid)
  325. {
  326.     return 1;
  327. }
  328.  
  329. public OnPlayerStreamIn(playerid, forplayerid)
  330. {
  331.     return 1;
  332. }
  333.  
  334. public OnPlayerStreamOut(playerid, forplayerid)
  335. {
  336.     return 1;
  337. }
  338.  
  339. public OnVehicleStreamIn(vehicleid, forplayerid)
  340. {
  341.     return 1;
  342. }
  343.  
  344. public OnVehicleStreamOut(vehicleid, forplayerid)
  345. {
  346.     return 1;
  347. }
  348.  
  349. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  350. {
  351.     switch(dialogid)
  352.     {
  353.         case DIALOG_REGISTER:
  354.         {
  355.             if(!response || isnull(inputtext))
  356.                 return clearPlayerChat(playerid), Kick(playerid);
  357.             if(strlen(inputtext) < 4 || strlen(inputtext) > 50)
  358.                 return SendClientMessage(playerid, COLOR_RED, "ERROR: Your password cannot be shorter than 4 characters, or more than 50 characters."), SPD(playerid, DIALOG_REGISTER);
  359.  
  360.             new
  361.                 szBuffer[129];
  362.  
  363.             WP_Hash(szBuffer, sizeof(szBuffer), inputtext);
  364.             pInfo[playerid][pPassword] = szBuffer;
  365.  
  366.             SendClientMessage(playerid, COLOR_WHITE, "Okay, now let's set up your character.");
  367.             SPD(playerid, DIALOG_SETGENDER);
  368.         }
  369.         case DIALOG_SETGENDER:
  370.         {
  371.             if(!response)
  372.             {
  373.                 format(pInfo[playerid][pGender], 7, "female");
  374.                 SendClientMessage(playerid, COLOR_WHITE, "You have selected female.");
  375.             }
  376.             else
  377.             {
  378.                 format(pInfo[playerid][pGender], 7, "male");
  379.                 SendClientMessage(playerid, COLOR_WHITE, "You have selected male.");
  380.             }
  381.  
  382.             SPD(playerid, DIALOG_SETAGE);
  383.         }
  384.         case DIALOG_SETAGE:
  385.         {
  386.             if(!response)
  387.             {
  388.                 clearPlayerChat(playerid);
  389.                 SendClientMessage(playerid, COLOR_RED, "You failed to complete the registration process. Goodbye.");
  390.                 Kick(playerid);
  391.             }
  392.  
  393.             new iTemp = strval(inputtext);
  394.             if(iTemp < 10 || iTemp > 80)
  395.                 return SendClientMessage(playerid, COLOR_RED, "Character ages cannot be less than 10, or greater than 80."), SPD(playerid, DIALOG_SETAGE);
  396.  
  397.             pInfo[playerid][pAge] = iTemp;
  398.  
  399.             new
  400.                 szQuery[300];
  401.  
  402.             format(szQuery, sizeof(szQuery), "INSERT INTO `users` (`Username`, `Password`, `Level`, `Cash`, `RegTime`, `Gender`, `Age`) VALUES('%s', '%s', %d, %d, %d, '%s', %d)", getEscName(playerid), pInfo[playerid][pPassword], DEFAULT_LEVEL, DEFAULT_CASH, gettime(), pInfo[playerid][pGender], pInfo[playerid][pAge]);
  403.             mysql_function_query(connectionHandle, szQuery, false, "thread_defaultCallback", "");
  404.  
  405.             clearPlayerChat(playerid);
  406.             fSendClientMessage(playerid, COLOR_WHITE, "You have set your character's age to %d.", iTemp);
  407.             SendClientMessage(playerid, -1, "");
  408.             SendClientMessage(playerid, COLOR_WHITE, "You have completed the registration process! You will spawn momentarily...");
  409.             TogglePlayerSpectating(playerid, false);
  410.             tAuthenticated[playerid] = true;
  411.  
  412.             SetSpawnInfo(playerid, -1, 120, 131.5488, -69.1912, 1.5781, 0.0, 0, 0, 0, 0, 0, 0); // change 131.5488, -69.1912, 1.5781 to your desired spawn point X Y Z coordinates
  413.             SpawnPlayer(playerid);
  414.  
  415.             pInfo[playerid][pCash] = DEFAULT_CASH;
  416.             pInfo[playerid][pLevel] = DEFAULT_LEVEL;
  417.  
  418.             real_GivePlayerCash(playerid, DEFAULT_CASH);
  419.             SetPlayerScore(playerid, pInfo[playerid][pLevel]);
  420.         }
  421.         case DIALOG_AUTHENTICATION:
  422.         {
  423.             if(!response || isnull(inputtext))
  424.                 return clearPlayerChat(playerid), Kick(playerid);
  425.  
  426.             new
  427.                 szBuffer[129];
  428.  
  429.             WP_Hash(szBuffer, sizeof(szBuffer), inputtext);
  430.             if(!strcmp(szBuffer, pInfo[playerid][pPassword], false))
  431.             {
  432.                 clearPlayerChat(playerid);
  433.                 fSendClientMessage(playerid, COLOR_WHITE, "Welcome back, "#COL_EMB_LIGHTBLUE"%s"#COL_EMB_WHITE"! Last online: "#COL_EMB_ORANGE"%s", getRolePlayName(playerid), date(pInfo[playerid][pLastOn], 2));
  434.                 TogglePlayerSpectating(playerid, false);
  435.                 tAuthenticated[playerid] = true;
  436.  
  437.                 SetSpawnInfo(playerid, -1, pInfo[playerid][pSkin], pInfo[playerid][pLastX], pInfo[playerid][pLastY], pInfo[playerid][pLastZ], 0.0, 0, 0, 0, 0, 0, 0);
  438.                 SpawnPlayer(playerid);
  439.             }
  440.             else
  441.             {
  442.                 iLoginAttempts[playerid]++;
  443.                 if(iLoginAttempts[playerid] > 3)
  444.                 {
  445.                     iLoginAttempts[playerid] = 0;
  446.  
  447.                     clearPlayerChat(playerid);
  448.                     SendClientMessage(playerid, COLOR_RED, "You have failed to provide the password three times. Goodbye!");
  449.                     Kick(playerid);
  450.                 }
  451.                 else SendClientMessage(playerid, COLOR_RED, "Incorrect password! Please try again..."), SPD(playerid, DIALOG_AUTHENTICATION);
  452.             }
  453.         }
  454.     }
  455.     return 1;
  456. }
  457.  
  458. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  459. {
  460.     return 1;
  461. }
  462.  
  463. // ----- Threaded Callbacks [go below this line] ----- //
  464.  
  465. forward thread_checkBans(playerid);
  466. public thread_checkBans(playerid)
  467. {
  468.     new
  469.         szUsername[MAX_PLAYER_NAME],
  470.         szAdminName[MAX_PLAYER_NAME],
  471.         szReason[60],
  472.     temp[30];
  473.  
  474.     cache_get_row(0, 0, temp);
  475.     new iBanID = strval(temp);
  476.     cache_get_row(0, 2, szUsername);
  477.     cache_get_row(0, 3, szAdminName);
  478.     cache_get_row(0, 4, szReason);
  479.     cache_get_row(0, 5, temp);
  480.     new iBannedTimestamp = strval(temp);
  481.     cache_get_row(0, 6, temp);
  482.     new iUnbannedTimestamp = strval(temp);
  483.     cache_get_row(0, 7, temp);
  484.     new iPerm = strval(temp);
  485.  
  486.     if(gettime() >= iUnbannedTimestamp)
  487.     {
  488.         new szQuery[128];
  489.         format(szQuery, sizeof(szQuery), "DELETE FROM `Bans` WHERE `banID` = %d", iBanID);
  490.         mysql_function_query(connectionHandle, szQuery, false, "thread_defaultCallback", "");
  491.  
  492.         format(szQuery, sizeof(szQuery), "SELECT * FROM `users` WHERE `Username` = '%s'", getEscName(playerid));
  493.         mysql_function_query(connectionHandle, szQuery, true, "thread_loadVariables", "d", playerid);
  494.     }
  495.     else
  496.     {
  497.         clearPlayerChat(playerid);
  498.  
  499.         SendClientMessage(playerid, COLOR_RED, "You are banned from this server.");
  500.         SendClientMessage(playerid, -1, " ");
  501.         fSendClientMessage(playerid, COLOR_WHITE, "You were banned by {E70000}%s {FFFFFF}on %s.", szAdminName, date(iBannedTimestamp, 2));
  502.         fSendClientMessage(playerid, COLOR_WHITE, "Reason: %s", szReason);
  503.         SendClientMessage(playerid, -1, " ");
  504.         if(iPerm == 0) fSendClientMessage(playerid, COLOR_WHITE, "You will be automatically unbanned on %s.", date(iUnbannedTimestamp, 2));
  505.         else if(iPerm == 1) SendClientMessage(playerid, COLOR_WHITE, "This is a permanent ban and it will not expire.");
  506.         Kick(playerid);
  507.     }
  508.     return 1;
  509. }
  510.  
  511. forward thread_loadVariables(playerid);
  512. public thread_loadVariables(playerid)
  513. {
  514.     new
  515.         rows,
  516.         fields;
  517.  
  518.     cache_get_data(rows, fields);
  519.     if(rows == 1)
  520.     {
  521.         new temp[50];
  522.         cache_get_row(0, 0, temp);
  523.         pInfo[playerid][pDataID] = strval(temp);
  524.         cache_get_row(0, 2, pInfo[playerid][pPassword]);
  525.         cache_get_row(0, 3, temp);
  526.         pInfo[playerid][pCash] = strval(temp);
  527.         cache_get_row(0, 4, temp);
  528.         pInfo[playerid][pSavings] = strval(temp);
  529.         cache_get_row(0, 5, temp);
  530.         pInfo[playerid][pBankAccount] = strval(temp);
  531.         cache_get_row(0, 6, temp);
  532.         pInfo[playerid][pLevel] = strval(temp);
  533.         cache_get_row(0, 7, temp);
  534.         pInfo[playerid][pKills] = strval(temp);
  535.         cache_get_row(0, 8, temp);
  536.         pInfo[playerid][pDeaths] = strval(temp);
  537.         cache_get_row(0, 9, temp);
  538.         pInfo[playerid][pRegTime] = strval(temp);
  539.         cache_get_row(0, 10, temp);
  540.         pInfo[playerid][pLastOn] = strval(temp);
  541.         cache_get_row(0, 11, temp);
  542.         pInfo[playerid][pHealth] = floatstr(temp);
  543.         cache_get_row(0, 12, temp);
  544.         pInfo[playerid][pArmour] = floatstr(temp);
  545.         cache_get_row(0, 13, temp);
  546.         pInfo[playerid][pLastX] = floatstr(temp);
  547.         cache_get_row(0, 14, temp);
  548.         pInfo[playerid][pLastY] = floatstr(temp);
  549.         cache_get_row(0, 15, temp);
  550.         pInfo[playerid][pLastY] = floatstr(temp);
  551.         cache_get_row(0, 16, temp);
  552.         pInfo[playerid][pSkin] = strval(temp);
  553.         cache_get_row(0, 17, pInfo[playerid][pGender]);
  554.         cache_get_row(0, 18, temp);
  555.         pInfo[playerid][pAge] = strval(temp);
  556.  
  557.         clearPlayerChat(playerid);
  558.         SendClientMessage(playerid, COLOR_WHITE, "SERVER: This account "#COL_EMB_GREEN"has been registered."#COL_EMB_WHITE" Please authenticate in order to proceed.");
  559.         SPD(playerid, DIALOG_AUTHENTICATION);
  560.     }
  561.     else if(rows == 0)
  562.     {
  563.         clearPlayerChat(playerid);
  564.         SendClientMessage(playerid, COLOR_WHITE, "SERVER: This account has "#COL_EMB_RED"not been registered"#COL_EMB_WHITE".");
  565.         SPD(playerid, DIALOG_REGISTER);
  566.     }
  567.     else
  568.     {
  569.         clearPlayerChat(playerid);
  570.         SendClientMessage(playerid, COLOR_WHITE, "There was a "#COL_EMB_RED"fatal error "#COL_EMB_WHITE"during registration! Please contact a developer.");
  571.         Kick(playerid);
  572.     }
  573.     return 1;
  574. }
  575.  
  576. forward thread_defaultCallback(playerid);
  577. public thread_defaultCallback(playerid)
  578. {
  579.     return 1;
  580. }
  581.  
  582. // --------------- Timers [go below this line] -------------- //
  583.  
  584. timer delayedKick[500](playerid) Kick(playerid);
  585.  
  586. // ---------- Stock Functions [go below this line] ---------- //
  587.  
  588. stock saveVariables(playerid)
  589. {
  590.     if(tAuthenticated[playerid])
  591.     {
  592.         new
  593.             szQuery[1000],
  594.             Float:pFloatValue[5];
  595.  
  596.         GetPlayerHealth(playerid, pFloatValue[0]);
  597.         GetPlayerArmour(playerid, pFloatValue[1]);
  598.         GetPlayerPos(playerid, pFloatValue[2], pFloatValue[3], pFloatValue[4]);
  599.  
  600.         format(szQuery, sizeof(szQuery), "UPDATE `users` SET `Cash` = %d, `Savings` = %d, `BankAccount` = %d, `Level` = %d, `Kills` = %d, `Deaths` = %d, `LastOn` = %d, `Health` = %f, `Armour` = %f, `LastX` = %f, `LastY` = %f, `LastZ` = %f, `Gender` = '%s' AND `Age` = %d WHERE `Username` = '%s'",
  601.             real_GetPlayerCash(playerid),
  602.             pInfo[playerid][pSavings],
  603.             pInfo[playerid][pBankAccount],
  604.             pInfo[playerid][pLevel],
  605.             pInfo[playerid][pKills],
  606.             pInfo[playerid][pDeaths],
  607.             gettime(),
  608.             pFloatValue[0],
  609.             pFloatValue[1],
  610.             pFloatValue[2],
  611.             pFloatValue[3],
  612.             pFloatValue[4],
  613.             pInfo[playerid][pGender],
  614.             pInfo[playerid][pAge],
  615.             getEscName(playerid));
  616.  
  617.         mysql_function_query(connectionHandle, szQuery, false, "thread_defaultCallback", "");
  618.     }
  619.     return 1;
  620. }
  621.  
  622. stock sendAreaMessage(playerid, color, color1, color2, color3, color4, string[])
  623. {
  624.     new
  625.         Float:fPos[3]
  626.     ;
  627.  
  628.     GetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
  629.     foreach(new i : Player)
  630.     {
  631.         if(IsPlayerInRangeOfPoint(i, 7.0, fPos[0], fPos[1], fPos[2])) SendClientMessage(i, color, string);
  632.         else if(IsPlayerInRangeOfPoint(i, 10.0, fPos[0], fPos[1], fPos[2])) SendClientMessage(i, color1, string);
  633.         else if(IsPlayerInRangeOfPoint(i, 15.0, fPos[0], fPos[1], fPos[2])) SendClientMessage(i, color2, string);
  634.         else if(IsPlayerInRangeOfPoint(i, 20.0, fPos[0], fPos[1], fPos[2])) SendClientMessage(i, color3, string);
  635.         else if(IsPlayerInRangeOfPoint(i, 25.0, fPos[0], fPos[1], fPos[2])) SendClientMessage(i, color4, string);
  636.     }
  637. }
  638.  
  639. stock SPD(playerid, dialogid) // a shortened custom function for ShowPlayerDialog; you don't have to handle all of the ShowPlayerDialog lines, just know the playerid and the dialogid you want to show
  640. {
  641.     switch(dialogid)
  642.     {
  643.         case DIALOG_REGISTER: ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""#COL_EMB_WHITE"Account Registration", ""#COL_EMB_WHITE"This account has "#COL_EMB_RED"not been registered"#COL_EMB_WHITE"!\n\nEnter your desired password below to register this account.", "Submit", "Leave");
  644.         case DIALOG_AUTHENTICATION: ShowPlayerDialog(playerid, DIALOG_AUTHENTICATION, DIALOG_STYLE_PASSWORD, ""#COL_EMB_WHITE"Account Authentication", ""#COL_EMB_WHITE"This account has "#COL_EMB_GREEN"been registered"#COL_EMB_WHITE"!\n\nEnter the account password below to proceed.", "Submit", "Leave");
  645.         case DIALOG_SETGENDER: ShowPlayerDialog(playerid, DIALOG_SETGENDER, DIALOG_STYLE_MSGBOX, ""#COL_EMB_WHITE"Gender Selection", ""#COL_EMB_WHITE"What is your character's gender?", "Male", "Female");
  646.         case DIALOG_SETAGE: ShowPlayerDialog(playerid, DIALOG_SETAGE, DIALOG_STYLE_INPUT, ""#COL_EMB_WHITE" Age Selection", ""#COL_EMB_WHITE"How old is your character going to be?\n\nValid ages are between between 10 and 80.", "Submit", "Leave");
  647.     }
  648.     return -1;
  649. }
  650.  
  651. stock clearPlayerChat(playerid, lines = 20)
  652. {
  653.     for(new i; i < lines; i++) SendClientMessage(playerid, -1, " ");
  654.     return -1;
  655. }
  656.  
  657. stock getName(playerid)
  658. {
  659.     new
  660.         szName[MAX_PLAYER_NAME];
  661.  
  662.     GetPlayerName(playerid, szName, sizeof(szName));
  663.     return szName;
  664. }
  665.  
  666. stock getRolePlayName(playerid)
  667. {
  668.     new
  669.         szName[MAX_PLAYER_NAME],
  670.         stringPos;
  671.  
  672.     GetPlayerName(playerid, szName, sizeof(szName));
  673.     stringPos = strfind(szName, "_");
  674.     szName[stringPos] = ' ';
  675.     return szName;
  676. }
  677.  
  678. stock getEscName(playerid)
  679. {
  680.     new szUsername[25], szEscName[26];
  681.     GetPlayerName(playerid, szUsername, sizeof(szUsername));
  682.     mysql_real_escape_string(szUsername, szEscName);
  683.     return szEscName;
  684. }
  685.  
  686. stock IsRolePlayName(playerid)
  687. {
  688.     new trpn[MAX_PLAYER_NAME];
  689.     GetPlayerName(playerid, trpn, sizeof(trpn));
  690.     new strd = strfind(trpn, "_", false);
  691.     if(strfind(trpn,"_",false,strd+1) == -1)
  692.     {
  693.         if(strd > 0)
  694.         {
  695.             if(trpn[strd-1] && trpn[strd+1])
  696.             {
  697.                 for(new a = 0, l = strlen(trpn); a < l; a++)
  698.                 {
  699.                     switch(trpn[a])
  700.                     {
  701.                         case '0' .. '9': return 0;
  702.                         case 'a' .. 'z': continue;
  703.                         case 'A' .. 'Z': continue;
  704.                         case '_': continue;
  705.                         default: return 0;
  706.                     }
  707.                 }
  708.                 return 1;
  709.             }
  710.         }
  711.     }
  712.     return 0;
  713. }
  714.  
  715. stock returnTime()
  716. {
  717.     new hr, minute, sec;
  718.     gettime(hr, minute, sec);
  719.  
  720.     new szString[30];
  721.     format(szString, sizeof(szString), "%d:%d:%d", hr, minute, sec);
  722.     return szString;
  723. }
  724.  
  725. stock returnDate()
  726. {
  727.     new day, mon, year;
  728.     gettime(year, mon, day);
  729.  
  730.     new szString[30];
  731.     format(szString, sizeof(szString), "%d/%d/%d", mon, day, year);
  732.     return szString;
  733. }
  734.  
  735. stock date(timestamp, _form = 0) // credits to whoever made this function
  736. {
  737.     /*  date( 1247182451 )  will print >> 09.07.2009-23:34:11
  738.         date( 1247182451, 1) will print >> 09/07/2009
  739.         date( 1247182451, 2) will print >> July 09, 2009 at 23:34:11
  740.         date( 1247182451, 3) will print >> 9 Jul 2009, 23:34
  741.         date( 1247182451, 4) will print >> 23:34
  742.     */
  743.  
  744.     new year=1970, day=0, month=0, hours=0, mins=0, sec=0;
  745.  
  746.     new days_of_month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
  747.     new names_of_month[12][10] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
  748.     new returnstring[32];
  749.  
  750.     while(timestamp>31622400)
  751.     {
  752.         timestamp -= 31536000;
  753.         if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) timestamp -= 86400;
  754.         year++;
  755.     }
  756.  
  757.     if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )
  758.         days_of_month[1] = 29;
  759.     else
  760.         days_of_month[1] = 28;
  761.  
  762.     while(timestamp>86400)
  763.     {
  764.         timestamp -= 86400, day++;
  765.         if(day==days_of_month[month]) day=0, month++;
  766.     }
  767.     while(timestamp>60)
  768.     {
  769.         timestamp -= 60, mins++;
  770.         if( mins == 60) mins=0, hours++;
  771.     }
  772.     sec=timestamp;
  773.     switch( _form )
  774.     {
  775.         case 1: format(returnstring, 31, "%02d/%02d/%d - %02d:%02d", day+1, month+1, year, hours, mins);
  776.         case 2: format(returnstring, 31, "%s %02d, %d at %02d:%02d", names_of_month[month], day+1, year, hours, mins);
  777.         case 3: format(returnstring, 31, "%d %c%c%c %d, %02d:%02d", day+1, names_of_month[month][0], names_of_month[month][1], names_of_month[month][2], year, hours, mins);
  778.         case 4: format(returnstring, 31, "%02d:%02d:%02d", hours, mins, sec);
  779.         default: format(returnstring, 31, "%02d.%02d.%d-%02d:%02d:%02d", day+1, month+1, year, hours, mins, sec);
  780.     }
  781.  
  782.     return returnstring;
  783. }
  784.  
  785. stock mktime(hour, minute, second, day, month, year) // credits to Y_Less
  786. {
  787.     static days_of_month[12] =
  788.     { 31,   29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
  789.     lMinute, lHour, lDay, lMonth, lYear, lMinuteS, lHourS, lDayS, lMonthS, lYearS;
  790.  
  791.     if (year != lYear)
  792.     {
  793.         lYearS = 0;
  794.         for (new j = 1970; j < year; j++)
  795.         {
  796.             lYearS += 31536000;
  797.             if ((!(j % 4) && (j % 100)) || !(j % 400)) lYearS += 86400;
  798.         }
  799.         lYear = year;
  800.     }
  801.     if (month != lMonth)
  802.     {
  803.         lMonthS = 0;
  804.         month--;
  805.         for (new i = 0; i < month; i++)
  806.         {
  807.             lMonthS += days_of_month[i] * 86400;
  808.             if ((i == 1) && ((!(year % 4) && (year % 100)) || !(year % 400))) lMonthS += 86400;
  809.         }
  810.         lMonth = month;
  811.     }
  812.     if (day != lDay)
  813.     {
  814.         lDayS = day * 86400;
  815.         lDay = day;
  816.     }
  817.     if (hour != lHour)
  818.     {
  819.         lHourS = hour * 3600;
  820.         lHour = hour;
  821.     }
  822.     if (minute != lMinute)
  823.     {
  824.         lMinuteS = minute * 60;
  825.         lMinute = minute;
  826.     }
  827.     return lYearS + lMonthS + lDayS + lHourS + lMinuteS + second;
  828. }
  829.  
  830. // ---------- Server-Side Money System [functions begin] ---------- //
  831.  
  832. stock real_GivePlayerCash(playerid, value)
  833. {
  834.     pInfo[playerid][pCash] += value;
  835.  
  836.     ResetPlayerMoney(playerid);
  837.     GivePlayerMoney(playerid, pInfo[playerid][pCash]);
  838.     return 1;
  839. }
  840.  
  841. stock real_TakePlayerCash(playerid, value)
  842. {
  843.     pInfo[playerid][pCash] -= value;
  844.  
  845.     ResetPlayerMoney(playerid);
  846.     GivePlayerMoney(playerid, pInfo[playerid][pCash]);
  847.     return 1;
  848. }
  849.  
  850. stock real_SetPlayerCash(playerid, value)
  851. {
  852.     pInfo[playerid][pCash] = value;
  853.  
  854.     ResetPlayerMoney(playerid);
  855.     GivePlayerMoney(playerid, value);
  856.     return 1;
  857. }
  858.  
  859. stock real_ResetPlayerCash(playerid)
  860. {
  861.     pInfo[playerid][pCash] = 0;
  862.     ResetPlayerMoney(playerid);
  863.     return 1;
  864. }
  865.  
  866. stock real_GetPlayerCash(playerid)
  867.     return pInfo[playerid][pCash];
  868.  
  869. // ---------------------------------------------- //
  870.  
  871.  
  872.  
  873. // EoF - End of File
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement