Guest User

Untitled

a guest
Dec 5th, 2013
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.91 KB | None | 0 0
  1. /*
  2. ================================================================================
  3. Credits
  4. =======
  5. Brandon_More (GiGi) >> Coder.
  6. BlueG >> MySQL Plugin.
  7. Zeex >> ZCMD Command Processor.
  8. Slick >> GetDistanceBetweenPlayers
  9. ========================
  10. Notes: This is a basic Very Basic MySQL Roleplay gamemode, It was totally
  11. scripted by me (GiGi - Brandon_More). I made this script strictly for revision
  12. work on MySQL and Pawno. This script has been tested and It does work. But if
  13. you have problems, feel free to contact me via: Brandon_More(SA-MP Forums) or
  14. Gmail: [email protected]. Thank you for reading and I hope this helps you :)
  15.  
  16. P.s I got the IRC Code stuff off the internet.. No idea who did it.
  17. But needs a few fizxes.
  18. */
  19.  
  20. #include <a_samp>
  21. #include <a_mysql>
  22. #include <zcmd>
  23. #include <string>
  24. #include <irc>
  25. #include <ircecho>
  26. //==============================================================================
  27. main( )
  28. {
  29.  
  30. }
  31. //==============================================================================
  32. #define MYSQL_HOST "localhost" // DB Host / Supplier
  33. #define MYSQL_USER "root" // DB User
  34. #define MYSQL_DB "mysql_test" //DB
  35. #define MYSQL_PASS "password" //DB Password
  36. //==============================================================================
  37. #undef MAX_PLAYERS
  38. #define MAX_PLAYERS 25
  39. #define COLOR_GREY 0xAFAFAFAA
  40. //==============================================================================
  41. #define ALTCOMMAND:%1->%2; \
  42. COMMAND:%1(playerid, params[]) \
  43. return cmd_%2(playerid, params);
  44. //==============================================================================
  45. #define PlayerLoop(%1) for(new %1 = 0; %1 < MAX_PLAYERS; %1++) if(IsPlayerConnected(%1) && !IsPlayerNPC(%1))
  46.  
  47. #include "irc.pwn" // All your IRC Defines / Chanel information will be inside here!
  48. //==============================================================================
  49. enum pInfo
  50. {
  51. Password[126],
  52. money,
  53. age,
  54. accent[12],
  55. }
  56. new PlayerInfo[MAX_PLAYERS][pInfo];
  57. //==============================================================================
  58. new PlayerLOGGED[MAX_PLAYERS];
  59. //==============================================================================
  60. new globalstring[250]; //Global String
  61. //==============================================================================
  62. new iBots[ MAX_PLAYERS ];
  63. //==============================================================================
  64. public OnGameModeInit()
  65. {
  66. mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_DB,MYSQL_PASS);
  67. mysql_debug(1);
  68. SetGameModeText("MySQL Basic | GiGi");
  69. echo_Init();
  70.  
  71. mysql_query("CREATE TABLE IF NOT EXISTS PlayerAccounts (\
  72. user VARCHAR(24) NOT NULL, \
  73. password VARCHAR(40) NOT NULL, \
  74. money INT(225) UNSIGNED NOT NULL DEFAULT 1000, \
  75. age SMALLINT(12) UNSIGNED NOT NULL DEFAULT 25, \
  76. accent VARCHAR(24) NOT NULL DEFAULT 'None')");
  77. return 1;
  78. }
  79. //==============================================================================
  80. public OnGameModeExit()
  81. {
  82. for(new i; i < MAX_PLAYERS; i++)
  83. {
  84. SavePlayer(i);
  85. IRC_Quit(iBots[i], "Server restart");
  86. }
  87. mysql_close();
  88. return 1;
  89. }
  90. //==============================================================================
  91. public OnPlayerConnect(playerid)
  92. {
  93. PlayerLOGGED[playerid]=false;
  94. SetTimerEx("ConnectIRC", 200, false, "d", playerid);
  95. new query[126], pName[MAX_PLAYER_NAME];
  96. GetPlayerName(playerid, pName, sizeof(pName));
  97. format(query,sizeof(query), "SELECT `user` FROM `PlayerAccounts` WHERE `user` = '%s' LIMIT 1", pName);
  98. mysql_query(query);
  99. mysql_store_result();
  100. new rows = mysql_num_rows();
  101. if(rows == 1)
  102. {
  103. ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT, "MySQL Basic || Login", "Please Login with your password", "Login", "Cancel");
  104. }
  105. if(!rows)
  106. {
  107. ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "MySQL Basic || Register", "Please Register with a password", "Register", "Cancel");
  108. }
  109. mysql_free_result();
  110. return 1;
  111. }
  112. //==============================================================================
  113. public OnPlayerDisconnect(playerid, reason)
  114. {
  115. SavePlayer(playerid);
  116. if(PlayerLOGGED[playerid])
  117. {
  118. PlayerInfo[playerid][money]=1000;
  119. PlayerInfo[playerid][age]=25;
  120. myStrcpy(PlayerInfo[playerid][accent],"None");
  121. }
  122. return 1;
  123. }
  124. //==============================================================================
  125. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  126. {
  127. switch(dialogid)
  128. {
  129. case 0:
  130. {
  131. if(response)
  132. {
  133. new query[126], pName[MAX_PLAYER_NAME];
  134. GetPlayerName(playerid, pName, sizeof(pName));
  135. format(query,sizeof(query), "SELECT * FROM PlayerAccounts WHERE user='%s' AND password = '%s'", pName, inputtext);
  136. mysql_query(query);
  137. mysql_store_result();
  138. if(mysql_num_rows() == 1)
  139. {
  140. LoginPlayer(playerid);
  141. PlayerLOGGED[playerid]=true;
  142. }
  143. else
  144. {
  145. ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT, "MySQL Basic || Login", "Incorrect password!\nPlease Login with your password", "Login", "Cancel");
  146. }
  147. }
  148. }
  149. case 1:
  150. {
  151. if(response)
  152. {
  153. new query[126], pName[MAX_PLAYER_NAME];
  154. GetPlayerName(playerid, pName, sizeof(pName));
  155. format(query,sizeof(query), "INSERT INTO PlayerAccounts (user,password) VALUES ('%s','%s')", pName, inputtext);
  156. mysql_query(query);
  157. SpawnPlayer(playerid);
  158. }
  159. }
  160. }
  161. return 1;
  162. }
  163. //==============================================================================
  164. public OnPlayerText(playerid, text[])
  165. {
  166. new stringa[256];
  167. new Float:px,Float:py,Float:pz;
  168. GetPlayerPos(playerid,px,py,pz);
  169. if(text[0]== '(')
  170. {
  171. new mid[250];
  172. strmid(mid,text,1,256,sizeof(mid));
  173. format(stringa,sizeof(stringa),"%s says: (( %s ))",PlayerName(playerid),mid);
  174. }
  175. else
  176. {
  177. if(!strcmp(PlayerInfo[playerid][accent],"None"))
  178. {
  179. format(globalstring, sizeof(globalstring),": ");
  180. }
  181. else
  182. {
  183. format(globalstring,sizeof(globalstring)," [%s accent]: ",PlayerInfo[playerid][accent]);
  184. }
  185. toupper(text[0]);
  186. format(stringa,sizeof(stringa),"%s says%s%s",PlayerName(playerid),globalstring,text);
  187. }
  188. PlayerLoop(i)
  189. {
  190. if(!IsPlayerConnected(i)) continue;
  191. if(!IsPlayerInRangeOfPoint(i, 60.0, px,py,pz)) continue;
  192. if(GetPlayerVirtualWorld(i) != GetPlayerVirtualWorld(playerid) || GetPlayerInterior(i) != GetPlayerInterior(playerid)) continue;
  193. new Float:dis;
  194. dis = GetDistanceBetweenPlayers(playerid,i);
  195. if(dis<=10) SendClientMessage(i,COLOR_GREY,stringa);
  196. }
  197. return 0;
  198. }
  199. public OnPlayerSpawn(playerid)
  200. {
  201. if(PlayerLOGGED[playerid])
  202. {
  203. SetPlayerPos(playerid, 1743.1909,-1862.8228,13.5758);
  204. }
  205. else
  206. {
  207. switch(random(2))
  208. {
  209. case 0:
  210. {
  211. SetPlayerCameraPos(playerid,967.4384,2559.5483,10.7003);
  212. SetPlayerCameraLookAt(playerid,982.4874,2561.6409,22.5239);
  213. SetPlayerPos(playerid,967.4384,2559.5483,5.7003);
  214. }
  215. case 1:
  216. {
  217. SetPlayerCameraPos(playerid,2058.8811,971.7955,54.5982);
  218. SetPlayerCameraLookAt(playerid,2057.1230,1189.4883,39.5329);
  219. SetPlayerPos(playerid,2058.8811,971.7955,47.5982);
  220. }
  221. case 2:
  222. {
  223. SetPlayerCameraPos(playerid,2372.1680,2141.8135,31.8135);
  224. SetPlayerCameraLookAt(playerid,2299.5005,2142.6213,28.8228);
  225. SetPlayerPos(playerid,2372.1680,2141.8135,27.8135);
  226. }
  227. }
  228. SetPlayerInterior(playerid,0);
  229. SetPlayerColor(playerid, COLOR_GREY);
  230. TogglePlayerControllable(playerid,false);
  231. }
  232. return 0;
  233. }
  234. //==============================================================================
  235. stock LoginPlayer(playerid)
  236. {
  237. new query[300], pname[24], AccountCarry[20];
  238. GetPlayerName(playerid, pname, 24);
  239. format(query, sizeof(query), "SELECT * FROM PlayerAccounts WHERE user = '%s'", pname);
  240. mysql_query(query);
  241. mysql_store_result();
  242. while(mysql_fetch_row_format(query,"|"))
  243. {
  244. mysql_fetch_field_row(AccountCarry, "money"); PlayerInfo[playerid][money] = strval(AccountCarry);
  245. GivePlayerMoney(playerid, strval(AccountCarry));
  246. //===============
  247. mysql_fetch_field_row(AccountCarry, "accent"); strmid(PlayerInfo[playerid][accent], AccountCarry, 0, strlen(AccountCarry), 50);
  248. //===============
  249. mysql_fetch_field_row(AccountCarry, "age"); PlayerInfo[playerid][age] = strval(AccountCarry);
  250. }
  251. mysql_free_result();
  252. SpawnPlayer(playerid);
  253. return 1;
  254. }
  255. //==============================================================================
  256. stock SavePlayer(playerid)
  257. {
  258. new pname[24];
  259. GetPlayerName(playerid, pname, sizeof(pname));
  260. new query[750];
  261. format(query, sizeof(query), "UPDATE PlayerAccounts SET money=%d WHERE user='%s'", PlayerInfo[playerid][money], pname);
  262. mysql_query(query);
  263. format(query, sizeof(query), "UPDATE PlayerAccounts SET accent='%s' WHERE user='%s'", PlayerInfo[playerid][accent], pname);
  264. mysql_query(query);
  265. format(query, sizeof(query), "UPDATE PlayerAccounts SET age=%d WHERE user='%s'", PlayerInfo[playerid][age], pname);
  266. mysql_query(query);
  267. return 1;
  268. }
  269. //==============================================================================
  270. stock myStrcpy(dest[], src[])
  271. {
  272. new i = 0;
  273. while ((dest[i] = src[i])) i++;
  274. }
  275. //==============================================================================
  276. stock PlayerName(playerid)
  277. {
  278. new name[MAX_PLAYER_NAME];
  279. GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  280. return name;
  281. }
  282. //==============================================================================
  283. stock GetDistanceBetweenPlayers(playerid,playerid2) //By Slick
  284. {
  285. new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
  286. new Float:tmpdis;
  287. GetPlayerPos(playerid,x1,y1,z1);
  288. GetPlayerPos(playerid2,x2,y2,z2);
  289. tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
  290. return floatround(tmpdis);
  291. }
  292. //==============================================================================
  293. COMMAND:age(playerid, params[]) // Made this for example of loading / saving integer
  294. {
  295. new iAge;
  296. if(sscanf(params, "d", iAge)) return SendClientMessage(playerid, COLOR_GREY, "/Age [Age]");
  297. PlayerInfo[playerid][age]=iAge;
  298. format(globalstring, sizeof(globalstring),"[Age] Your characters age has been set to %d",iAge);
  299. SendClientMessage(playerid,COLOR_GREY,globalstring);
  300. return 1;
  301. }
  302. //==============================================================================
  303. COMMAND:accent(playerid, params[]) // Example of loading / saving strings
  304. {
  305. new iAccent[12];
  306. if(sscanf(params, "s", iAccent)) return SendClientMessage(playerid, COLOR_GREY, "/accent [accent]");
  307. myStrcpy(PlayerInfo[playerid][accent],iAccent);
  308. format(globalstring, sizeof(globalstring),"[Age] Your characters accent is now: %s",iAccent);
  309. SendClientMessage(playerid,COLOR_GREY,globalstring);
  310. return 1;
  311. }
  312. //==============================================================================
  313. COMMAND:commands(playerid,params[])
  314. {
  315. SendClientMessage(playerid,COLOR_GREY,"MySQL >> Basic GameMode Command selection");
  316. SendClientMessage(playerid,COLOR_GREY,"[COMMANDS] - /age - /acccent - /o - /irc - /stats");
  317. return 1;
  318. }
  319. //==============================================================================
  320. COMMAND:irc(playerid, params[]) // Made this command to test the ECHO Chanel
  321. {
  322. new iReason[ 128 ];
  323. if( sscanf ( params, "s", iReason)) return SendClientMessage(playerid, COLOR_GREY, "/irc [message]");
  324. format(globalstring, sizeof(globalstring), "10(ToIRC): %s [%d]: %s",PlayerName(playerid), playerid, iReason);
  325. iEcho(globalstring);
  326. return 1;
  327. }
  328. //==============================================================================
  329. COMMAND:o(playerid, params[])
  330. {
  331. new iText[ 128 ];
  332. if(sscanf(params, "s", iText)) return SendClientMessage(playerid, COLOR_GREY, "/o [message]");
  333. if(IsPlayerAdmin(playerid)) {
  334. format(globalstring,sizeof(globalstring),"{8bbc8b}(( [Global OOC] {CCFFCC}RCON Admin %s: %s {8bbc8b}))", PlayerName(playerid),iText);
  335. } else {
  336. format(globalstring,sizeof(globalstring),"{8bbc8b}(( [Global OOC] {CCFFCC}%s: %s {8bbc8b}))",PlayerName(playerid),iText);
  337. }
  338. SendClientMessageToAll(0xCCFFCC00, globalstring);
  339. format(globalstring, sizeof(globalstring), "10(( [Global OOC]: %s: %s ))",PlayerName(playerid), iText);
  340. iEcho(globalstring);
  341. return 1;
  342. }
  343. //==============================================================================
  344. COMMAND:stats(playerid,params[])
  345. {
  346. new iAge, iAccent, iMoney;
  347. iAge = PlayerInfo[playerid][age];
  348. iMoney = PlayerInfo[playerid][money];
  349. iAccent = PlayerInfo[playerid][accent];
  350. SendClientMessage(playerid, COLOR_GREY,"=========================================================");
  351. format(globalstring, sizeof(globalstring),"Money: [%d] - Age: [%d] - Accent: [%s]",iMoney, iAge, iAccent);
  352. SendClientMessage(playerid, COLOR_GREY, globalstring);
  353. SendClientMessage(playerid, COLOR_GREY,"=========================================================");
  354. return 1;
  355. }
Advertisement
Add Comment
Please, Sign In to add comment