Advertisement
Guest User

SAMP Help

a guest
Nov 29th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.19 KB | None | 0 0
  1. native WP_Hash(buffer[],len,const str[]);
  2.  
  3. enum PlayerInfo{
  4. ID,
  5. pName[128],
  6. pPassword[130],
  7. Float: Pos[3],
  8. Skin,
  9. pAdminLevel,
  10. pBanned,
  11. pHealth,
  12. pArmour,
  13.  
  14.  
  15.  
  16. }
  17. new PlayerStats[MAX_PLAYERS][PlayerInfo];
  18.  
  19. stock GetName(playerid)
  20. {
  21. new name[MAX_PLAYER_NAME];
  22. GetPlayerName(playerid, name, sizeof(name));
  23. strreplace(name, '_', ' ');
  24. return name;
  25. }
  26.  
  27. stock LoginPlayer(playerid)
  28. {
  29. new query[500],string[256];
  30. format(query,sizeof(query),"SELECT * EVERYTHING FROM accounts WHERE name = '%s'", GetName(playerid));
  31. mysql_query(query);
  32. mysql_store_result();
  33.  
  34. while(mysql_fetch_row_format(query,"|"))
  35. {
  36. mysql_fetch_field_row(string, "id"); PlayerStats[playerid][ID] = strval(string);
  37. mysql_fetch_field_row(PlayerStats[playerid][pName],"Name");
  38. mysql_fetch_field_row(PlayerStats[playerid][pPassword],"Password");
  39. mysql_fetch_field_row(string, "PlayerPos"); sscanf(query,"fff",PlayerStats[playerid][Pos][0],PlayerStats[playerid][Pos][1],PlayerStats[playerid][Pos][2]);
  40. mysql_fetch_field_row(string, "AdminLevel"); PlayerStats[playerid][pAdminLevel] = strval(string);
  41. mysql_fetch_field_row(string, "Skin"); PlayerStats[playerid][Skin] = strval(string);
  42. mysql_fetch_field_row(string, "Health"); PlayerStats[playerid][pHealth] = floatstr(string);
  43. mysql_fetch_field_row(string, "Armour"); PlayerStats[playerid][pArmour] = floatstr(string);
  44.  
  45.  
  46. }
  47. mysql_free_result();
  48.  
  49. AddPlayerClass(PlayerStats[playerid][Skin], PlayerStats[playerid][Pos][0], PlayerStats[playerid][Pos][1], PlayerStats[playerid][Pos][2], 0, 0, 0, 0, 0, 0, 0);
  50.  
  51. SetSpawnInfo(playerid, 0, PlayerStats[playerid][Skin], PlayerStats[playerid][Pos][0], PlayerStats[playerid][Pos][1], PlayerStats[playerid][Pos][2], 90, 0, 0, 0, 0, 0, 0);
  52. SpawnPlayer(playerid);
  53.  
  54. SetPlayerPos(playerid, PlayerStats[playerid][Pos][0], PlayerStats[playerid][Pos][1], PlayerStats[playerid][Pos][2]);
  55. SetPlayerSkin(playerid, PlayerStats[playerid][Skin]);
  56.  
  57. SetCameraBehindPlayer(playerid);
  58.  
  59. SetPlayerHealth(playerid, PlayerStats[playerid][pHealth]);
  60. SetPlayerArmour(playerid, PlayerStats[playerid][pArmour]);
  61. SetPlayerInterior(playerid, 0);
  62. SetPlayerVirtualWorld(playerid, 0);
  63.  
  64.  
  65.  
  66.  
  67. }
  68.  
  69. stock SavePlayerStats(playerid)
  70. {
  71. new query[500], EncryptPass[130];
  72.  
  73. WP_Hash(EncryptPass,sizeof(EncryptPass),PlayerStats[playerid][pPassword]);
  74. GetPlayerPos(playerid,PlayerStats[playerid][Pos][0],PlayerStats[playerid][Pos][1],PlayerStats[playerid][Pos][2]);
  75. format(query,sizeof(query),"UPDATE accounts SET Name = '%s', Password = '%s', PlayerPos = '%f %f %f', AdminLevel = '%d', Skin = '%d' WHERE id = '%d'",GetName(playerid),PlayerStats[playerid][pPassword],PlayerStats[playerid][Pos][0],
  76. PlayerStats[playerid][Pos][1],PlayerStats[playerid][Pos][2],PlayerStats[playerid][pAdminLevel],PlayerStats[playerid][Skin],PlayerStats[playerid][ID]);
  77. mysql_query(query);
  78.  
  79. printf("Player %s has been saved into the mysql table",GetName(playerid));
  80.  
  81. }
  82.  
  83.  
  84. stock RegisterPlayer(playerid,registeredpassword[])
  85. {
  86. new query[256], EncryptPass[130];
  87.  
  88. WP_Hash(EncryptPass,sizeof(EncryptPass),registeredpassword);
  89.  
  90. format(query,sizeof(query),"INSERT INTO accounts (Name, Password, PlayerPos, Skin) ('%s', '%s', '1.0,2.0,3.0','299')",GetName(playerid),EncryptPass);
  91. mysql_query(query);
  92.  
  93. LoginPlayer(playerid);
  94.  
  95. return 1;
  96. }
  97.  
  98. stock CheckBan(playerid)
  99. {
  100. new query[128], playerIPAddress[128];
  101.  
  102. GetPlayerIp(playerid,playerIPAddress,sizeof(playerIPAddress));
  103.  
  104. format(query,sizeof(query),"SELECT * FROM bans WHERE (name = '%s' OR IPAddress = '%s') AND status = 1",GetName(playerid),playerIPAddress);
  105. mysql_query(query);
  106.  
  107. mysql_store_result();
  108. if(mysql_num_rows() >= 1)
  109. {
  110. new banReason[128], bannedBy[50], dialogString[128];
  111. while(mysql_fetch_row_format(query,"|"))
  112. {
  113. mysql_fetch_field_row(banReason,"Reason");
  114. mysql_fetch_field_row(bannedBy,"BannedBy");
  115. format(dialogString,sizeof(dialogString),"You are banned from this server\nReason: %s\nBanned by: %s",banReason,bannedBy);
  116. ShowPlayerDialog(playerid,dialogThreadBanned,DIALOG_STYLE_MSGBOX,"Banned",dialogString,"Close","");
  117.  
  118. }
  119. return 1;
  120. }
  121. mysql_free_result();
  122. return 0;
  123. }
  124.  
  125. public OnPlayerConnect(playerid)
  126. {
  127. new query[128];
  128.  
  129. if(CheckBan(playerid) == 0)
  130. {
  131. format(query,sizeof(query),"SELECT * FROM bans WHERE (name = '%s' OR IPAddress = '%s') AND status = 1");
  132. mysql_query(query);
  133.  
  134.  
  135.  
  136. format(query,sizeof(query),"SELECT * FROM accounts WHERE name = '%s'",GetName(playerid));
  137. mysql_query(query);
  138. mysql_store_result();
  139.  
  140. if(mysql_num_rows() == 1)
  141. {
  142. SendClientMessage(playerid,COLOUR_WHITE,"That username is registered.");
  143. ShowPlayerDialog(playerid,dialogThreadLogin,DIALOG_STYLE_INPUT, "Login", "Enter your password to login","Login", "Back");
  144. }
  145. else
  146. {
  147. SendClientMessage(playerid,COLOUR_WHITE,"That username is not registered.");
  148. ShowPlayerDialog(playerid,dialogThreadRegister,DIALOG_STYLE_INPUT, "Register", "Enter a password to register this account","Register", "Back");
  149. }
  150. }
  151.  
  152.  
  153. return 1;
  154. }
  155.  
  156. public OnPlayerDisconnect(playerid, reason)
  157. {
  158. SavePlayerStats(playerid);
  159. return 1;
  160. }
  161.  
  162. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  163. {
  164. switch(dialogid)
  165. {
  166. case dialogThreadLogin:
  167. {
  168. if(response)
  169. {
  170. new query[256], EncryptPass[130];
  171.  
  172. WP_Hash(EncryptPass,sizeof(EncryptPass),inputtext);
  173. format(query,sizeof(query),"SELECT * FROM accounts WHERE name = '%s' AND password = '%s'", GetName(playerid),EncryptPass);
  174. mysql_query(query);
  175. mysql_store_result();
  176.  
  177. if(mysql_num_rows() == 1)
  178. {
  179.  
  180.  
  181. LoginPlayer(playerid);
  182.  
  183.  
  184.  
  185. }
  186. else
  187. {
  188. SendClientMessage(playerid,COLOUR_WHITE,"You have entered an incorrect password!");
  189. ShowPlayerDialog(playerid,dialogThreadLogin,DIALOG_STYLE_INPUT, "Login", "Enter your password to login","Login", "Back");
  190. }
  191. }
  192. }
  193.  
  194. case dialogThreadRegister:
  195. {
  196. if(response)
  197. {
  198.  
  199.  
  200. RegisterPlayer(playerid,inputtext);
  201.  
  202.  
  203.  
  204. }
  205.  
  206. }
  207.  
  208. case dialogThreadBanned:
  209. {
  210. if(response)
  211. {
  212. Kick(playerid);
  213. }
  214. }
  215.  
  216. }
  217.  
  218.  
  219.  
  220.  
  221. return 1;
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement