Cubie_

Scripting 101 #4

May 13th, 2018
6,331
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.39 KB | None | 1 0
  1. #include <a_samp>
  2. #include <a_mysql>
  3. #include <zcmd>
  4. #include <sscanf2>
  5. #include <mSelection>
  6.  
  7. #define COLOR_WHITE (0xffffffFF)
  8. #define COLOR_RED (0xdb1a1aFF)
  9. #define COLOR_BLUE (0x2265d8FF)
  10. #define COLOR_YELLOW (0xf6ff00FF)
  11.  
  12. #define SCM SendClientMessage
  13. #define function:%0(%1) forward %0(%1); public %0(%1)
  14. #define SCMex SendClientMessageEx
  15.  
  16. //Dialogs:
  17.  
  18. #define DIALOG_REGISTER (0)
  19. #define DIALOG_LOGIN (1)
  20.  
  21. //Database establisher:
  22. new ourConnection;
  23.  
  24. #define SCRIPT_VERSION "Script Adventure 1.0.1.1"
  25.  
  26. //================MySQL Connection:=========================
  27.  
  28. #define SQL_HOSTNAME "{Fill in}"
  29. #define SQL_USERNAME "{Fill in}"
  30. #define SQL_DATABASE "{Fill in}"
  31. #define SQL_PASSWORD "{Fill in}"
  32.  
  33. //==========================================================
  34.  
  35. enum P_ACCOUNT_DATA
  36. {
  37. pDBID,
  38. pAccName[60],
  39. pSkin,
  40. bool:pLoggedin
  41. }
  42.  
  43. new PlayerInfo[MAX_PLAYERS][P_ACCOUNT_DATA];
  44. new playerLogin[MAX_PLAYERS];
  45. new joinskin = mS_INVALID_LISTID;
  46.  
  47. static stock g_arrVehicleNames[][] = {
  48. "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "Sentinel", "Dumper", "Firetruck", "Trashmaster",
  49. "Stretch", "Manana", "Infernus", "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam",
  50. "Esperanto", "Taxi", "Washington", "Bobcat", "Whoopee", "BF Injection", "Hunter", "Premier", "Enforcer",
  51. "Securicar", "Banshee", "Predator", "Bus", "Rhino", "Barracks", "Hotknife", "Trailer", "Previon", "Coach",
  52. "Cabbie", "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral", "Squalo", "Seasparrow",
  53. "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder", "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy", "Solair",
  54. "Berkley's RC Van", "Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale", "Oceanic",
  55. "Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy", "Hermes", "Sabre", "Rustler", "ZR-350", "Walton",
  56. "Regina", "Comet", "BMX", "Burrito", "Camper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper", "Rancher",
  57. "FBI Rancher", "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking", "Blista Compact", "Police Maverick",
  58. "Boxville", "Benson", "Mesa", "RC Goblin", "Hotring Racer A", "Hotring Racer B", "Bloodring Banger", "Rancher",
  59. "Super GT", "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropduster", "Stunt", "Tanker", "Roadtrain",
  60. "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra", "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck",
  61. "Fortune", "Cadrona", "SWAT Truck", "Willard", "Forklift", "Tractor", "Combine", "Feltzer", "Remington", "Slamvan",
  62. "Blade", "Streak", "Freight", "Vortex", "Vincent", "Bullet", "Clover", "Sadler", "Firetruck", "Hustler", "Intruder",
  63. "Primo", "Cargobob", "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite", "Windsor", "Monster", "Monster",
  64. "Uranus", "Jester", "Sultan", "Stratum", "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna", "Bandito",
  65. "Freight Flat", "Streak Carriage", "Kart", "Mower", "Dune", "Sweeper", "Broadway", "Tornado", "AT-400", "DFT-30",
  66. "Huntley", "Stafford", "BF-400", "News Van", "Tug", "Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club",
  67. "Freight Box", "Trailer", "Andromada", "Dodo", "RC Cam", "Launch", "LSPD Cruiser", "SFPD Cruiser", "LVPD Cruiser",
  68. "Police Rancher", "Picador", "S.W.A.T", "Alpha", "Phoenix", "Glendale", "Sadler", "Luggage", "Luggage", "Stairs",
  69. "Boxville", "Tiller", "Utility Trailer"
  70. };
  71.  
  72. main()
  73. {
  74. print("\n-------------------------------------");
  75. print("This is the sick script we are making");
  76. print("---------------------------------------\n");
  77. }
  78.  
  79. public OnGameModeInit()
  80. {
  81. ourConnection = mysql_connect(SQL_HOSTNAME, SQL_USERNAME, SQL_DATABASE, SQL_PASSWORD);
  82.  
  83. SetGameModeText(SCRIPT_VERSION);
  84. if(mysql_errno() != 0)
  85. printf ("[DATABASE]: Connection failed to '%s'...", SQL_DATABASE);
  86. else printf ("[DATABASE]: Connection established to '%s'...", SQL_DATABASE);
  87.  
  88. joinskin = LoadModelSelectionMenu("skins.txt");
  89. return 1;
  90. }
  91. public OnGameModeExit()
  92. {
  93. mysql_close(ourConnection);
  94. return 1;
  95. }
  96.  
  97. public OnPlayerRequestClass(playerid, classid)
  98. {
  99. if(PlayerInfo[playerid][pLoggedin] == false)
  100. {
  101. SetSpawnInfo( playerid, 0, 0, 563.3157, 3315.2559, 0, 269.15, 0, 0, 0, 0, 0, 0 );
  102. TogglePlayerSpectating(playerid, true);
  103. TogglePlayerSpectating(playerid, false);
  104. SetPlayerCamera(playerid);
  105. return 1;
  106. }
  107. SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin], 2098.5088,1159.1156,11.6484, 65.2418, 0, 0, 0, 0, 0, 0 );
  108. SpawnPlayer(playerid);
  109. return 0;
  110. }
  111.  
  112. public OnPlayerConnect(playerid)
  113. {
  114. SetPlayerCamera(playerid);
  115. ResetPlayer(playerid);
  116.  
  117. new existCheck[248];
  118.  
  119. mysql_format(ourConnection, existCheck, sizeof(existCheck), "SELECT * FROM accounts WHERE acc_name = '%e'", ReturnName(playerid));
  120. mysql_tquery(ourConnection, existCheck, "LogPlayerIn", "i", playerid);
  121.  
  122. return 1;
  123. }
  124.  
  125. public OnPlayerDisconnect(playerid, reason)
  126. {
  127. return 1;
  128. }
  129.  
  130. public OnPlayerSpawn(playerid)
  131. {
  132. return 1;
  133. }
  134.  
  135. public OnPlayerDeath(playerid, killerid, reason)
  136. {
  137. return 1;
  138. }
  139.  
  140. public OnVehicleSpawn(vehicleid)
  141. {
  142. return 1;
  143. }
  144.  
  145. public OnVehicleDeath(vehicleid, killerid)
  146. {
  147. return 1;
  148. }
  149.  
  150. public OnPlayerText(playerid, text[])
  151. {
  152. return 1;
  153. }
  154.  
  155. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  156. {
  157. return 1;
  158. }
  159.  
  160. public OnPlayerExitVehicle(playerid, vehicleid)
  161. {
  162. return 1;
  163. }
  164.  
  165. public OnPlayerStateChange(playerid, newstate, oldstate)
  166. {
  167. return 1;
  168. }
  169.  
  170. public OnPlayerEnterCheckpoint(playerid)
  171. {
  172. return 1;
  173. }
  174.  
  175. public OnPlayerLeaveCheckpoint(playerid)
  176. {
  177. return 1;
  178. }
  179.  
  180. public OnPlayerEnterRaceCheckpoint(playerid)
  181. {
  182. return 1;
  183. }
  184.  
  185. public OnPlayerLeaveRaceCheckpoint(playerid)
  186. {
  187. return 1;
  188. }
  189.  
  190. public OnRconCommand(cmd[])
  191. {
  192. return 1;
  193. }
  194.  
  195. public OnPlayerRequestSpawn(playerid)
  196. {
  197. return 1;
  198. }
  199.  
  200. public OnObjectMoved(objectid)
  201. {
  202. return 1;
  203. }
  204.  
  205. public OnPlayerObjectMoved(playerid, objectid)
  206. {
  207. return 1;
  208. }
  209.  
  210. public OnPlayerPickUpPickup(playerid, pickupid)
  211. {
  212. return 1;
  213. }
  214.  
  215. public OnVehicleMod(playerid, vehicleid, componentid)
  216. {
  217. return 1;
  218. }
  219.  
  220. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  221. {
  222. return 1;
  223. }
  224.  
  225. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  226. {
  227. return 1;
  228. }
  229.  
  230. public OnPlayerSelectedMenuRow(playerid, row)
  231. {
  232. return 1;
  233. }
  234.  
  235. public OnPlayerExitedMenu(playerid)
  236. {
  237. return 1;
  238. }
  239.  
  240. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  241. {
  242. return 1;
  243. }
  244.  
  245. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  246. {
  247. return 1;
  248. }
  249.  
  250. public OnRconLoginAttempt(ip[], password[], success)
  251. {
  252. return 1;
  253. }
  254.  
  255. public OnPlayerUpdate(playerid)
  256. {
  257. return 1;
  258. }
  259.  
  260. public OnPlayerStreamIn(playerid, forplayerid)
  261. {
  262. return 1;
  263. }
  264.  
  265. public OnPlayerStreamOut(playerid, forplayerid)
  266. {
  267. return 1;
  268. }
  269.  
  270. public OnVehicleStreamIn(vehicleid, forplayerid)
  271. {
  272. return 1;
  273. }
  274.  
  275. public OnVehicleStreamOut(vehicleid, forplayerid)
  276. {
  277. return 1;
  278. }
  279.  
  280. // NEW
  281.  
  282. public OnPlayerModelSelection(playerid, response, listid, modelid)
  283. {
  284. if(listid == joinskin)
  285. {
  286. if(!response)
  287. return ShowModelSelectionMenu(playerid, joinskin, "Pick A Skin");
  288.  
  289. SetCameraBehindPlayer(playerid);
  290. SetPlayerSkin(playerid, modelid);
  291. PlayerInfo[playerid][pSkin] = modelid;
  292. SetSpawnInfo( playerid, 0, modelid, 2098.5088,1159.1156,11.6484, 65.2418, 0, 0, 0, 0, 0, 0 );
  293. SpawnPlayer(playerid);
  294. }
  295. return 1;
  296. }
  297.  
  298. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  299. {
  300. switch (dialogid)
  301. {
  302. case DIALOG_REGISTER:
  303. {
  304. if(!response)
  305. {
  306. SendClientMessage(playerid, COLOR_RED, "You were kicked for not registering.");
  307. return KickEx(playerid);
  308. }
  309.  
  310. new insert[256];
  311.  
  312. if(strlen(inputtext) > 128 || strlen(inputtext) < 3)
  313. return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Welcome to Cubie's Scripting Adventure", "SERVER: You have can now register!\n\nYour password needs to be greater than 3 and less than 128 characters.\nTIP: Please report all bugs that you\nmay have found to development.\n\n Enter Your Password:", "Login", "Cancel");
  314.  
  315. mysql_format(ourConnection, insert, sizeof(insert), "INSERT INTO accounts (acc_name, acc_pass, register_ip, register_date) VALUES('%e', sha1('%e'), '%e', '%e')", ReturnName(playerid), inputtext, ReturnIP(playerid), ReturnDate());
  316. mysql_tquery(ourConnection, insert, "OnPlayerRegister", "i", playerid);
  317. }
  318. case DIALOG_LOGIN:
  319. {
  320. if (!response)
  321. {
  322. SendClientMessage(playerid, COLOR_RED, "You were kicked for not logging in.");
  323. return KickEx(playerid);
  324. }
  325.  
  326. new continueCheck[211];
  327.  
  328. mysql_format(ourConnection, continueCheck, sizeof(continueCheck), "SELECT acc_dbid FROM accounts WHERE acc_name = '%e' AND acc_pass = sha1('%e') LIMIT 1",
  329. ReturnName(playerid), inputtext);
  330.  
  331. mysql_tquery(ourConnection, continueCheck, "LoggingIn", "i", playerid);
  332. return 1;
  333. }
  334. }
  335. return 1;
  336. }
  337.  
  338. // NEW
  339.  
  340. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  341. {
  342. return 1;
  343. }
  344.  
  345. // Commnands
  346.  
  347. CMD:jetpack(playerid, params[])
  348. {
  349. SetPlayerSpecialAction(playerid,SPECIAL_ACTION_USEJETPACK);
  350. return 1;
  351. }
  352.  
  353. CMD:kill(playerid, params[])
  354. {
  355. SetPlayerHealth(playerid, 0);
  356. return 1;
  357. }
  358.  
  359. CMD:skin(playerid, params[])
  360. {
  361. new skinid;
  362.  
  363. if(sscanf(params, "i", skinid))
  364. return SCM(playerid, COLOR_RED, "Usage: /skin [ID]");
  365.  
  366. SetPlayerSkin(playerid, skinid);
  367. PlayerInfo[playerid][pSkin] = skinid;
  368.  
  369. return 1;
  370. }
  371.  
  372. CMD:weapon(playerid, params[])
  373. {
  374. new weaponid, ammo;
  375.  
  376. if(sscanf(params, "ii", weaponid, ammo))
  377. return SCM(playerid, COLOR_RED, "Usage: /weapon [ID], [AMMO]");
  378.  
  379. if(weaponid < 1 || weaponid > 46 || weaponid == 18)
  380. return SCM(playerid, COLOR_RED, "You have specified a invalid weapon");
  381.  
  382. if(ammo < 1)
  383. return SCM(playerid, COLOR_RED, "You have specified invalid ammo amount");
  384.  
  385. GivePlayerWeapon(playerid, weaponid, ammo);
  386.  
  387. SCM(playerid, COLOR_YELLOW, "Enjoy your Weapon, prick");
  388.  
  389. return 1;
  390. }
  391.  
  392. CMD:gotols(playerid, params[])
  393. {
  394. SetPlayerPos(playerid, 1519.6636, -1679.0535, 12.8015);
  395. return 1;
  396. }
  397. // Stock Values
  398.  
  399. stock ReturnName(playerid, underScore = 1)
  400. {
  401. new playersName[MAX_PLAYER_NAME + 2];
  402. GetPlayerName(playerid, playersName, sizeof(playersName));
  403.  
  404. if(!underScore)
  405. {
  406. {
  407. for(new i = 0, j = strlen(playersName); i < j; i ++)
  408. {
  409. if(playersName[i] == '_')
  410. {
  411. playersName[i] = ' ';
  412. }
  413. }
  414. }
  415. }
  416.  
  417. return playersName;
  418. }
  419.  
  420. stock ReturnIP(playerid)
  421. {
  422. new
  423. ipAddress[20];
  424.  
  425. GetPlayerIp(playerid, ipAddress, sizeof(ipAddress));
  426. return ipAddress;
  427. }
  428.  
  429. stock ReturnDate()
  430. {
  431. new sendString[90], MonthStr[40], month, day, year;
  432. new hour, minute, second;
  433.  
  434. gettime(hour, minute, second);
  435. getdate(year, month, day);
  436. switch(month)
  437. {
  438. case 1: MonthStr = "January";
  439. case 2: MonthStr = "February";
  440. case 3: MonthStr = "March";
  441. case 4: MonthStr = "April";
  442. case 5: MonthStr = "May";
  443. case 6: MonthStr = "June";
  444. case 7: MonthStr = "July";
  445. case 8: MonthStr = "August";
  446. case 9: MonthStr = "September";
  447. case 10: MonthStr = "October";
  448. case 11: MonthStr = "November";
  449. case 12: MonthStr = "December";
  450. }
  451.  
  452. format(sendString, 90, "%s %d, %d %02d:%02d:%02d", MonthStr, day, year, hour, minute, second);
  453. return sendString;
  454. }
  455.  
  456. stock KickEx(playerid)
  457. {
  458. return SetTimerEx("KickTimer", 100, false, "i", playerid);
  459. }
  460.  
  461. stock SendClientMessageEx(playerid, color, const str[], {Float,_}:...)
  462. {
  463. static
  464. args,
  465. start,
  466. end,
  467. string[156]
  468. ;
  469. #emit LOAD.S.pri 8
  470. #emit STOR.pri args
  471.  
  472. if (args > 12)
  473. {
  474. #emit ADDR.pri str
  475. #emit STOR.pri start
  476.  
  477. for (end = start + (args - 12); end > start; end -= 4)
  478. {
  479. #emit LREF.pri end
  480. #emit PUSH.pri
  481. }
  482. #emit PUSH.S str
  483. #emit PUSH.C 156
  484. #emit PUSH.C string
  485. #emit PUSH.C args
  486. #emit SYSREQ.C format
  487.  
  488. SendClientMessage(playerid, color, string);
  489.  
  490. #emit LCTRL 5
  491. #emit SCTRL 4
  492. #emit RETN
  493. }
  494. return SendClientMessage(playerid, color, str);
  495. }
  496.  
  497. stock ReturnVehicleName(vehicleid)
  498. {
  499. new
  500. model = GetVehicleModel(vehicleid),
  501. name[32] = "None";
  502.  
  503. if (model < 400 || model > 611)
  504. return name;
  505.  
  506. format(name, sizeof(name), g_arrVehicleNames[model - 400]);
  507. return name;
  508. }
  509.  
  510.  
  511. function:LogPlayerIn(playerid)
  512. {
  513. new rows, fields;
  514. cache_get_data(rows, fields, ourConnection);
  515. if(!rows)
  516. {
  517. for(new i = 0; i < 3; i ++) { SendClientMessage(playerid, -1, " "); }
  518.  
  519. SendClientMessageEx(playerid, COLOR_YELLOW, "The user (%s) you're connected with is not a registered.", ReturnName(playerid));
  520. SendClientMessage(playerid, -1, "You need to register to continue.");
  521.  
  522. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Welcome to Cubie's Scripting Adventure", "SERVER: You can now register!\nTIP: Please report all bugs that you\nmay have found to development.\n\n Enter Your Password:", "Register", "Cancel");
  523. return 1;
  524. }
  525.  
  526. SendClientMessageEx(playerid, COLOR_YELLOW, "Welcome to Cubie's Scripting Adventure, %s {FFFFFF}["SCRIPT_VERSION"]", ReturnName(playerid));
  527. return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Welcome to Cubie's Scripting Adventure", "SERVER: You van now login!\nTIP: Please report all bugs that you\nmay have found to development.\n\n Enter Your Password:", "Login", "Cancel");
  528. }
  529.  
  530. function:OnPlayerRegister(playerid)
  531. {
  532. PlayerInfo[playerid][pDBID] = cache_insert_id();
  533. format(PlayerInfo[playerid][pAccName], 32, "%s", ReturnName(playerid));
  534.  
  535. PlayerInfo[playerid][pLoggedin] = true;
  536. ShowModelSelectionMenu(playerid, joinskin, "Pick A Skin");
  537. }
  538.  
  539. function:LoggingIn(playerid)
  540. {
  541. if(!cache_num_rows())
  542. {
  543. playerLogin[playerid]++;
  544. if(playerLogin[playerid] == 3)
  545. {
  546. SendClientMessage(playerid, COLOR_RED, "[SERVER]: You were kicked for bad password attempts.");
  547. return KickEx(playerid);
  548. }
  549.  
  550. return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Welcome to Cubie Emergency Roleplay", "You entered the wrong password!\n\nSERVER: You can now login!\nTIP: Please report all bugs that you\nmay have found to development.\n\n Enter Your Password:", "Login", "Cancel");
  551. }
  552.  
  553. new rows, fields;
  554. cache_get_data(rows, fields, ourConnection);
  555.  
  556. PlayerInfo[playerid][pDBID] = cache_get_field_content_int(0, "acc_dbid", ourConnection);
  557.  
  558. format(PlayerInfo[playerid][pAccName], 32, "%s", ReturnName(playerid));
  559. PlayerInfo[playerid][pLoggedin] = true;
  560. ShowModelSelectionMenu(playerid, joinskin, "Pick A Skin");
  561. return 1;
  562. }
  563.  
  564. function:ResetPlayer(playerid)
  565. {
  566. PlayerInfo[playerid][pLoggedin] = false;
  567. PlayerInfo[playerid][pSkin] = 0;
  568. return 1;
  569. }
  570.  
  571. function:SetPlayerCamera(playerid)
  572. {
  573. new rand = random(3);
  574.  
  575. switch(rand)
  576. {
  577. case 0:
  578. {
  579. SetPlayerCameraPos(playerid, 2019.1145, 1202.9185, 42.3246);
  580. SetPlayerCameraLookAt(playerid, 2019.9889, 1202.4272, 42.2945);
  581. }
  582. case 1:
  583. {
  584. SetPlayerCameraPos(playerid, 1701.8396, -1572.9250, 26.6298);
  585. SetPlayerCameraLookAt(playerid, 1701.2588, -1572.1072, 27.1848);
  586. }
  587. case 2:
  588. {
  589. SetPlayerCameraPos(playerid, -2619.1006, 2202.6091, 49.9144);
  590. SetPlayerCameraLookAt(playerid, -2619.2512, 2201.6155, 50.1043);
  591. }
  592. }
  593. return 1;
  594. }
  595.  
  596.  
  597.  
  598. //Timers:
  599.  
  600. function:KickTimer(playerid) { return Kick(playerid); }
Advertisement
Add Comment
Please, Sign In to add comment