f0cus

Gamemode:R39 ORM empty by f0cus

Aug 24th, 2014
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.73 KB | None | 0 0
  1. /*
  2.  
  3.  
  4.                                 mySQL r39_2 gamemode, su prisijungimo/registracijos sistema.
  5.  
  6.     #autorius
  7.         f0cus
  8.     #kreditai
  9.         BlueG
  10.     #data
  11.         2014-08-23
  12.  
  13.  
  14. */
  15.  
  16. #include <a_samp>
  17. #include <a_mysql>
  18. #include <easyDialog>
  19.  
  20. #define SQL_HOST "localhost"
  21. #define SQL_USER "root"
  22. #define SQL_PASS ""
  23. #define SQL_DATA "server-sql"
  24.  
  25. #define BALTA 0xFFFFFFFF
  26. #define RAUDONA 0xFF0000FF
  27.  
  28. #undef MAX_PLAYERS
  29. #define MAX_PLAYERS 100
  30. #define MAX_PLAYER_PASSWORD 30
  31. #define MIN_PLAYER_PASSWORD 6
  32.  
  33. new sql = -1,
  34.     playerSelectCheck[MAX_PLAYERS];
  35. forward OnPlayerAccountChecked(playerid, select_check);
  36. forward OnPlayerRegistered(playerid);
  37. enum p_DATA
  38. {
  39.     ORM:ORM_ID,
  40.     ID,
  41.     Vardas,
  42.     Slaptazodis,
  43.     Skin,
  44.     Float:Float[3]
  45. };
  46. new pInfo[MAX_PLAYERS][p_DATA];
  47.  
  48. main()
  49. {
  50.     print("\n\n\n\t--\nf0cus R39 gamemode\n\t--\n\n");
  51. }
  52.  
  53. public OnGameModeInit()
  54. {
  55.     SetGameModeText("f0cus_gm 0.0.1");
  56.     mysql_log(LOG_ALL, LOG_TYPE_HTML);
  57.     sql = mysql_connect(SQL_HOST, SQL_USER, SQL_DATA, SQL_PASS);
  58.     AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  59.     return 1;
  60. }
  61.  
  62. public OnGameModeExit()
  63. {
  64.     return 1;
  65. }
  66.  
  67. public OnPlayerRequestClass(playerid, classid)
  68. {
  69.     SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  70.     SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  71.     SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  72.     return 1;
  73. }
  74.  
  75. public OnPlayerConnect(playerid)
  76. {
  77.     new ORM:ormid = pInfo[playerid][ORM_ID] = orm_create("players", sql);
  78.     playerSelectCheck[playerid]++;
  79.     orm_addvar_int(ormid, pInfo[playerid][ID], "id");
  80.     orm_addvar_int(ormid, pInfo[playerid][Skin], "skin");
  81.     orm_addvar_float(ormid, pInfo[playerid][Float][0], "x");
  82.     orm_addvar_float(ormid, pInfo[playerid][Float][1], "y");
  83.     orm_addvar_float(ormid, pInfo[playerid][Float][2], "z");
  84.     orm_addvar_string(ormid, pInfo[playerid][Vardas], MAX_PLAYER_NAME, "vardas");
  85.     orm_addvar_string(ormid, pInfo[playerid][Slaptazodis], MAX_PLAYER_PASSWORD, "slaptazodis");
  86.     orm_setkey(ormid, "vardas");
  87.     orm_load(ormid, "OnPlayerAccountChecked", "dd", playerid, playerSelectCheck[playerid]);
  88.     return 1;
  89. }
  90. public OnPlayerAccountChecked(playerid, select_check)
  91. {
  92.     /*      Kas tas select_check ?
  93.         Zaidejas A prisijungia, SELECT funkcija pradeda veikti, ji uztrunka.
  94.         Kuomet tai vis dar vyksta, zaidejas A su id 2 atsijungia, zaidejas B
  95.         prisijungia su id 2. Galiausiai SELECT funkcija baigiasi, bet blogam zaidejui.
  96.         Mes ta zaideja iskickiname.
  97.             Autorius BlueG
  98.     */
  99.     if(select_check != playerSelectCheck[playerid])
  100.         return Kick(playerid);
  101.     orm_setkey(pInfo[playerid][ORM_ID], "id");
  102.     switch(orm_errno(pInfo[playerid][ORM_ID]))
  103.     {
  104.         case ERROR_OK:  // Jei randame zaideja
  105.         {
  106.             Dialog_Show(playerid, Login, DIALOG_STYLE_PASSWORD, "Prisijungimas", "Sveiki! Prasome ivesti savo slaptazodi, norint prisijungti!", "Testi", "Atsaukti");
  107.             SetPVarInt(playerid, "registruotas", 1);
  108.         }
  109.         case ERROR_NO_DATA: // Jei ne
  110.         {
  111.             Dialog_Show(playerid, Register, DIALOG_STYLE_PASSWORD, "Registracija", "Sveiki atvyke i musu serveri! Prasome ivesti\nsavo sugalvota slaptazodi!", "Testi", "Atsaukti");
  112.             SetPVarInt(playerid, "registruota", 0);
  113.         }
  114.     }
  115.     return 1;
  116. }
  117. Dialog:Login(playerid, response, listitem, inputtext[])
  118. {
  119.     if(response)
  120.     {
  121.         if(strcmp(inputtext, pInfo[playerid][Slaptazodis]) == 0)
  122.         {
  123.             SetPVarInt(playerid, "spawned", 1); // Žaidėjas prisijungęs
  124.             SetPVarInt(playerid, "status", 0);  // Nustatome, jog zaidejas po prisijungimo
  125.             SetSpawnInfo(playerid, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  126.             SpawnPlayer(playerid);
  127.         }
  128.         else
  129.         {
  130.             if(GetPVarInt(playerid, "trylog") < 3)
  131.                 return SetPVarInt(playerid, "trylog", GetPVarInt(playerid, "trylog")) , Dialog_Show(playerid, Login, DIALOG_STYLE_PASSWORD, "Prisijungimas", "Slaptazodis neteisingas! Slaptazodi turite ivesti per 3 kartus!", "Testi", "Atsaukti");
  132.             else
  133.                 return Kick(playerid);
  134.         }
  135.     }
  136.     else
  137.         return Kick(playerid);
  138.     return 1;
  139. }
  140. Dialog:Register(playerid, response, listitem, inputtext[])
  141. {
  142.     if(response)
  143.     {
  144.         if(strlen(inputtext) < MIN_PLAYER_PASSWORD || strlen(inputtext) > MAX_PLAYER_PASSWORD)
  145.             return Dialog_Show(playerid, Register, DIALOG_STYLE_PASSWORD, "Registracija", "Slaptazodi turi sudaryti nuo 5 iki 30 simboliu!", "Testi", "Atsaukti");
  146.         orm_save(pInfo[playerid][ORM_ID], "OnPlayerRegistered", "d", playerid);
  147.     }
  148.     else
  149.         return Kick(playerid);
  150.     return 1;
  151. }
  152. public OnPlayerRegistered(playerid)
  153. {
  154.     SendClientMessage(playerid, BALTA, "Sekmingai uzsiregistravote!");
  155.     SetPVarInt(playerid, "status", 1);
  156.     SetPVarInt(playerid, "spawned", 1);
  157.     SetSpawnInfo(playerid, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  158.     SpawnPlayer(playerid);
  159. }
  160. public OnPlayerDisconnect(playerid, reason)
  161. {
  162.     if(GetPVarInt(playerid, "spawned") > 0) // Jei zaidejas prisijunges,
  163.         orm_save(pInfo[playerid][ORM_ID]); // tuomet issaugome ji.
  164.     return 1;
  165. }
  166.  
  167. public OnPlayerSpawn(playerid)
  168. {
  169.     switch(GetPVarInt(playerid, "status"))
  170.     {
  171.         case 0: // Prisijungus
  172.         {
  173.             ResetPlayerMoney(playerid);
  174.             SetPlayerPos(playerid, pInfo[playerid][Float][0], pInfo[playerid][Float][1], pInfo[playerid][Float][2]);
  175.             SetPlayerSkin(playerid, pInfo[playerid][Skin]);
  176.         }
  177.         case 1: // Uzsiregistravus
  178.         {
  179.             SetPlayerSkin(playerid, 281);
  180.             SetPlayerPos(playerid, 2695.6880, -1704.6300, 11.8438);
  181.         }
  182.     }
  183.     return 1;
  184. }
  185.  
  186. public OnPlayerDeath(playerid, killerid, reason)
  187. {
  188.     return 1;
  189. }
  190.  
  191. public OnVehicleSpawn(vehicleid)
  192. {
  193.     return 1;
  194. }
  195.  
  196. public OnVehicleDeath(vehicleid, killerid)
  197. {
  198.     return 1;
  199. }
  200.  
  201. public OnPlayerText(playerid, text[])
  202. {
  203.     return 1;
  204. }
  205.  
  206. public OnPlayerCommandText(playerid, cmdtext[])
  207. {
  208.     if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  209.     {
  210.         // Do something here
  211.         return 1;
  212.     }
  213.     return 0;
  214. }
  215.  
  216. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  217. {
  218.     return 1;
  219. }
  220.  
  221. public OnPlayerExitVehicle(playerid, vehicleid)
  222. {
  223.     return 1;
  224. }
  225.  
  226. public OnPlayerStateChange(playerid, newstate, oldstate)
  227. {
  228.     return 1;
  229. }
  230.  
  231. public OnPlayerEnterCheckpoint(playerid)
  232. {
  233.     return 1;
  234. }
  235.  
  236. public OnPlayerLeaveCheckpoint(playerid)
  237. {
  238.     return 1;
  239. }
  240.  
  241. public OnPlayerEnterRaceCheckpoint(playerid)
  242. {
  243.     return 1;
  244. }
  245.  
  246. public OnPlayerLeaveRaceCheckpoint(playerid)
  247. {
  248.     return 1;
  249. }
  250.  
  251. public OnRconCommand(cmd[])
  252. {
  253.     return 1;
  254. }
  255.  
  256. public OnPlayerRequestSpawn(playerid)
  257. {
  258.     return 1;
  259. }
  260.  
  261. public OnObjectMoved(objectid)
  262. {
  263.     return 1;
  264. }
  265.  
  266. public OnPlayerObjectMoved(playerid, objectid)
  267. {
  268.     return 1;
  269. }
  270.  
  271. public OnPlayerPickUpPickup(playerid, pickupid)
  272. {
  273.     return 1;
  274. }
  275.  
  276. public OnVehicleMod(playerid, vehicleid, componentid)
  277. {
  278.     return 1;
  279. }
  280.  
  281. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  282. {
  283.     return 1;
  284. }
  285.  
  286. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  287. {
  288.     return 1;
  289. }
  290.  
  291. public OnPlayerSelectedMenuRow(playerid, row)
  292. {
  293.     return 1;
  294. }
  295.  
  296. public OnPlayerExitedMenu(playerid)
  297. {
  298.     return 1;
  299. }
  300.  
  301. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  302. {
  303.     return 1;
  304. }
  305.  
  306. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  307. {
  308.     return 1;
  309. }
  310.  
  311. public OnRconLoginAttempt(ip[], password[], success)
  312. {
  313.     return 1;
  314. }
  315.  
  316. public OnPlayerUpdate(playerid)
  317. {
  318.     return 1;
  319. }
  320.  
  321. public OnPlayerStreamIn(playerid, forplayerid)
  322. {
  323.     return 1;
  324. }
  325.  
  326. public OnPlayerStreamOut(playerid, forplayerid)
  327. {
  328.     return 1;
  329. }
  330.  
  331. public OnVehicleStreamIn(vehicleid, forplayerid)
  332. {
  333.     return 1;
  334. }
  335.  
  336. public OnVehicleStreamOut(vehicleid, forplayerid)
  337. {
  338.     return 1;
  339. }
  340.  
  341. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  342. {
  343.     return 1;
  344. }
  345.  
  346. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  347. {
  348.     return 1;
  349. }
  350. stock GetPlayerNameEx(playerid)
  351. {
  352.     new returnname[MAX_PLAYER_NAME+1];
  353.     GetPlayerName(playerid, returnname, sizeof(returnname));
  354.     return returnname;
  355. }
Advertisement
Add Comment
Please, Sign In to add comment