Guest User

Untitled

a guest
Apr 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 17.02 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //                                                                            //
  3. //                  San Fierro RPG by Jonas ( 2011 - 2012 ).                  //                                                         //
  4. //                                                                            //
  5. ////////////////////////////////////////////////////////////////////////////////
  6.  
  7. #include < a_samp >
  8. #include < a_mysql.inc >
  9. #include < streamer >
  10. #include < sscanf2 >
  11. #include < foreach >
  12. #include < zcmd >
  13. //-----------------------------------------------------------
  14. // Mysql prisijungimo duomenys
  15. //-----------------------------------------------------------
  16. #define MySQL_HOST "localhost"
  17. #define MySQL_USER "root"
  18. #define MySQL_DATA "sanfierrorpg"
  19. #define MySQL_PASS ""
  20. //-----------------------------------------------------------
  21. // Definai
  22. //-----------------------------------------------------------
  23. #define MAX_QUERY 4000
  24. //-----------------------------------------------------------
  25. // Forwardai
  26. //-----------------------------------------------------------
  27. //-----------------------------------------------------------
  28. // Enum'ai
  29. //-----------------------------------------------------------
  30. enum PlayerInfo
  31. {
  32. bool: atsispawnines ,
  33. bool: uzsiregistraves ,
  34. }
  35. new pInfo [ MAX_PLAYERS ][ PlayerInfo ];
  36. //-----------------------------------------------------------
  37. // Spalvos
  38. //-----------------------------------------------------------
  39. #define MELYNA              0x0080FFFF
  40. #define JUODA               0x000000FF
  41. #define BALTA               0xFFFFFFFF
  42. #define ZYDRA               0xFFFF00FF
  43. #define ZALIA               0x00EA00FF
  44. #define TZALIA              0x408080FF
  45. #define RAUDONA             0xF00000FF
  46. #define PURPLE              0xFF80C0FF
  47. #define PILKA               0xC0C0C0FF
  48. #define GELTONA             0xFFFF00FF
  49. #define ORANGE              0xFF8000FF
  50. #define TORANGE             0xFF5D00FF
  51. //-----------------------------------------------------------
  52. // Serverio paleidimo ( motd )
  53. //-----------------------------------------------------------
  54. main( )
  55. {
  56.     print (  "\n---------------------------------------" ) ;
  57.     print (  "Paleistas San Fierro RPG by Jonas\n 2011 - 2012" ) ;
  58.     print (  "---------------------------------------\n" ) ;
  59. }
  60.  
  61. //-----------------------------------------------------------
  62. // OnPlayerConnect callback'as
  63. //-----------------------------------------------------------
  64.  
  65. public OnPlayerConnect ( playerid )
  66. {
  67. //-----------------------------------------------------------
  68. // Jei vartotojo vardas netaisyklingas ( Vardas_Pavarde )
  69. //-----------------------------------------------------------
  70.     if ( InvalidNickKick( playerid ) ) return 0;
  71. //-----------------------------------------------------------
  72. // Jei vartotojo vardas taisyklingas ( Vardas_Pavarde )
  73. //-----------------------------------------------------------
  74.     SendClientMessage ( playerid, BALTA, " ");
  75.     SendClientMessage ( playerid, BALTA, " ");
  76.     SendClientMessage ( playerid, BALTA, " ");
  77.     SendClientMessage ( playerid, BALTA, " ");
  78.     SendClientMessage ( playerid, BALTA, " ");
  79.     SendClientMessage ( playerid, BALTA, " ");
  80.     SendClientMessage ( playerid, ORANGE, " Sveiki atvykę į San Fierro RPG! ");
  81.     SendClientMessage ( playerid, ORANGE, " Serverio komandos - /Komandos , /Komandos2 , /Komandos3 ");
  82.     SendClientMessage ( playerid, ORANGE, " Serverio pagalba - /Pagalba ");
  83.     SendClientMessage ( playerid, BALTA, " ");
  84.     SendClientMessage ( playerid, RAUDONA," Naudoti 'cheatus' ir kitas pagalbines žaidimo priemones yra GRIEŽTAI DRAUDŽIAMA! ");
  85. //-----------------------------------------------------------
  86. // Registracija ( Dialog 0 ), Prisijungimas ( Dialog 1 )
  87. //-----------------------------------------------------------
  88.     SendClientMessage ( playerid, BALTA, " " );
  89.     new
  90.         Query[ 200 ]
  91.     ;
  92.     format ( Query,sizeof( Query ), "SELECT * FROM `Vartotojai` WHERE `Vardas` = '%s'", GetPlayerNameEx ( playerid ) );
  93.     mysql_query ( Query );
  94.     mysql_store_result( );
  95.  
  96.     if( mysql_num_rows( ) )
  97. {
  98.         ShowPlayerDialog( playerid,1,DIALOG_STYLE_PASSWORD,"Prisijungimas","Jūs jau esate užsiregistravęs, todėl jums reikia prisijungti:","Jungtis","Atšaukti" );
  99. }
  100.     else
  101. {
  102.         ShowPlayerDialog( playerid,0,DIALOG_STYLE_PASSWORD,"Registracija","Jūs neįrašytas mūsų duomenų bazėje todėl užsiregistruokite:","Registruotis","Atšaukti" );
  103. }
  104.     mysql_free_result( );
  105. //-----------------------------------------------------------
  106. //
  107. //-----------------------------------------------------------
  108.     return 1;
  109. }
  110. //-----------------------------------------------------------
  111. // OnPlayerSpawn callback'as
  112. //-----------------------------------------------------------
  113.  
  114. public OnPlayerSpawn( playerid )
  115. {
  116. SetPlayerInterior( playerid, GetPVarInt( playerid, "interior" ) );
  117. /*  print("Sekmingai atsispawnines");
  118.     if(pInfo[playerid][atsispawnines] == false)
  119. {
  120.     Krovimas( playerid );
  121.     pInfo[playerid][atsispawnines] = true;
  122. }
  123.     return 1;*/
  124. }
  125. //-----------------------------------------------------------
  126. // OnPlayerDeath callback'as
  127. //-----------------------------------------------------------
  128.  
  129. public OnPlayerDeath( playerid, killerid, reason )
  130. {
  131. }
  132.  
  133. //-----------------------------------------------------------
  134. // onPlayerRequestSpawn callback'as
  135. //-----------------------------------------------------------
  136. public OnPlayerRequestSpawn ( playerid )
  137. {
  138.     if (pInfo[playerid][uzsiregistraves] == true)
  139. {
  140.     SetPlayerSkin(playerid,98);
  141.     SetPlayerPos(playerid,-1957.3085,137.5778,27.6940);
  142.     pInfo[playerid][uzsiregistraves] = false;
  143. }
  144.     return 1;
  145. }
  146. //-----------------------------------------------------------
  147. // OnPlayerRequestClass callback'as
  148. //-----------------------------------------------------------
  149. public OnPlayerRequestClass( playerid, classid )
  150. {
  151.     if(IsPlayerNPC(playerid)) return 1;
  152.     SetPlayerFacingAngle(playerid,250.7573);
  153.     SetPlayerPos(playerid,-1980.2172,137.8874,30.4085);
  154.     SetPlayerCameraPos(playerid,-1978.7152,138.0048,28.3085);
  155.     SetPlayerCameraLookAt(playerid,-1980.2172,137.8874,30.4085);
  156.     PlayerPlaySound(playerid, 1097, 0 , 0 , 0);// Garsas
  157.     ApplyAnimation(playerid,"DANCING","DAN_Left_A",4.0,1,0,0,0,-1);// Sokis
  158.     SetPlayerInterior(playerid,0);
  159.     SetPlayerVirtualWorld(playerid, 1);
  160.     GameTextForPlayer(playerid, "~w~Spauskite ~n~~g~SHIFT ~n~~w~arba~n~~g~'Spawn'", 1000, 3);
  161.     return 1;
  162. }
  163. //-----------------------------------------------------------
  164. // OnGameModeInit callback'as
  165. //-----------------------------------------------------------
  166.  
  167. public OnGameModeInit( )
  168. {
  169. //-----------------------------------------------------------
  170. // Gamemode ( Mode ), Serverio nustatymai
  171. //-----------------------------------------------------------
  172.     SetGameModeText("San Fierro - RPG");
  173.     EnableStuntBonusForAll(false);
  174.     AllowInteriorWeapons(true);
  175.     SetNameTagDrawDistance(25);
  176.     LimitGlobalChatRadius(30);
  177.     ShowPlayerMarkers(0);
  178. //-----------------------------------------------------------
  179. // Mysql pranešimas ( Prisijungta / Neprisijungta )
  180. //-----------------------------------------------------------
  181.     mysql_debug( true );
  182.     mysql_connect( MySQL_HOST,MySQL_USER,MySQL_DATA,MySQL_PASS );
  183.     if( mysql_ping( ) >= 1 )
  184. {
  185.         print( "San Fierro - RPG: Prisijungimas prie mysql sėkmingas!" );
  186. }
  187.     else
  188. {
  189.         SendRconCommand( "exit" );
  190. }
  191.     return 1;
  192. }
  193. //-----------------------------------------------------------
  194. // OnGameModeExit callback'as
  195. //-----------------------------------------------------------
  196. public OnGameModeExit( )
  197. {
  198.     SendClientMessageToAll( -1, "~ Serveris išjungiamas, prisijunkite vėliau.");
  199.     mysql_close( );
  200.     return 1;
  201. }
  202. //-----------------------------------------------------------
  203. // OnPlayerUpdate callback'as
  204. //-----------------------------------------------------------
  205.  
  206. public OnPlayerUpdate( playerid )
  207. {
  208. }
  209. //-----------------------------------------------------------
  210. // OnPlayerCommandText callback;as
  211. //-----------------------------------------------------------
  212. public OnPlayerCommandText( playerid )
  213. {
  214. }
  215. //-----------------------------------------------------------
  216. // OnDialogResponse callback'as
  217. //-----------------------------------------------------------
  218. public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[] )
  219. {
  220. //-----------------------------------------------------------
  221. // Serverio mysql registracija
  222. //-----------------------------------------------------------
  223.     if( dialogid == 0 )
  224. {
  225.     if( response )
  226. {
  227.     if( !strlen( inputtext ) )
  228.     return SendClientMessage( playerid,-1,"Laukelis Negali būti tuščias." );
  229.     if( strlen( inputtext ) > 40 )
  230.     return SendClientMessage( playerid,-1,"Slaptažodis negali būti ilgesnis nei 40simboliū." );
  231.  
  232.     new
  233.     Query[ 150 ],string [ 68 ]
  234.     ;
  235.     format( Query,sizeof( Query ),"INSERT INTO `Vartotojai` (Vardas,Slaptazodis) VALUES ('%s','%s')",GetPlayerNameEx( playerid ),inputtext );
  236.     mysql_query( Query );
  237.     mysql_free_result();
  238.     format(string, 68, "Sveikiname! Užsiregistravote, jūsų slaptažodis - %s",inputtext);
  239.     SendClientMessage(playerid,MELYNA,string);
  240.     SendClientMessage(playerid,MELYNA,"Jūs prijungtas automatiškai, gero žaidimo!");
  241.     pInfo[playerid][uzsiregistraves] = true;
  242.  
  243. }
  244.     else
  245. {
  246.     Kick( playerid );
  247. }
  248.     return true;
  249. }
  250. //-----------------------------------------------------------
  251. // Serverio mysql prisijungimas
  252. //-----------------------------------------------------------
  253.     if( dialogid == 1 )
  254. {
  255.     if( response )
  256. {
  257.     if( !strlen( inputtext ) )
  258.     return SendClientMessage( playerid,-1,"Laukelis Negali būti tuščias." );
  259.     if( strlen( inputtext ) > 40 )
  260.     return SendClientMessage( playerid,-1,"Slaptažodis negali būti ilgesnis nei 40simbolių." );
  261.  
  262.     new
  263.     Query[ 150 ]
  264.     ;
  265.     format( Query,sizeof( Query ),"SELECT * FROM `Vartotojai` WHERE `Vardas` = '%s' AND `Slaptazodis` = '%s'",GetPlayerNameEx( playerid ),inputtext );
  266.     mysql_query( Query );
  267.     mysql_store_result( );
  268.  
  269.     if(! mysql_num_rows( ) )
  270. {
  271.     Kick( playerid );
  272. }
  273.     else
  274. {
  275.     SendClientMessage( playerid,-1,"Prisijungėte sėkmingai!" );
  276.     Krovimas( playerid );
  277. }
  278.  
  279.     if( !response )
  280. {
  281.     Kick( playerid );
  282. }
  283.     mysql_free_result( );
  284.     return true;
  285. }
  286.     return true;
  287. }
  288.     return true;
  289. }
  290. //-----------------------------------------------------------
  291. // OnPlayerDisconnect callback'as
  292. //-----------------------------------------------------------
  293. public OnPlayerDisconnect ( playerid )
  294. {
  295.     saugojimas( playerid );
  296. }
  297. //-----------------------------------------------------------
  298. // Vardo stock'as
  299. //-----------------------------------------------------------
  300. stock GetPlayerNameEx( playerid )
  301. {
  302.     new
  303.         Name[ MAX_PLAYER_NAME ]
  304.     ;
  305.     GetPlayerName( playerid,Name,MAX_PLAYER_NAME );
  306.     return Name;
  307. }
  308.  
  309. //-----------------------------------------------------------
  310. // Mysql saugojimo stock'as
  311. //-----------------------------------------------------------
  312. /*stock saugojimas( playerid )
  313. {
  314.     new query[MAX_QUERY];
  315.     new Float:x, Float:y, Float:z, Float:a;
  316.     GetPlayerPos(playerid,x,y,z);
  317.     GetPlayerFacingAngle(playerid,a);
  318.     SQLUpdateAddInt(query,"Interjeras",GetPlayerInterior(playerid));
  319.     SQLUpdateAddFloat(query,"x",x);
  320.     SQLUpdateAddFloat(query,"y",y);
  321.     SQLUpdateAddFloat(query,"z",z);
  322.     SQLUpdateAddFloat(query,"a",a);
  323.     SQLUpdateCompleteEx("Vartotojai",query,"sanfierrorpg");
  324.     mysql_query(query);
  325. }*/
  326. stock saugojimas ( playerid )
  327. {
  328. new query [MAX_QUERY];
  329. new Float:x, Float:y, Float:z, Float:a;
  330. GetPlayerPos( playerid, x, y, z );
  331. GetPlayerFacingAngle( playerid, a);
  332. format     ( query, sizeof ( query ), "UPDATE `Vartotojai` SET `Interjeras` = %d, `x` = %f, `y` = %f, `z` = %f, `a` = %f WHERE `id` = %i",GetPlayerInterior( playerid ), x, y, z, a,GetPVarInt(playerid,"id"));
  333. mysql_query( query );
  334. }
  335. //-----------------------------------------------------------
  336. // Mysql krovimo stock'as
  337. //-----------------------------------------------------------
  338. stock Krovimas ( playerid )
  339. {
  340.     new resultline [ 1024 ] , fetch[258], Float:x,Float:y,Float:z, query [ MAX_QUERY ],tmpinterior, Float:a, tmpid;
  341.     format(query,1042,"SELECT * FROM `Vartotojai` WHERE `Vardas` = '%s'",GetPlayerNameEx(playerid));
  342.     mysql_query(query);
  343.     mysql_store_result();
  344.     mysql_fetch_row(resultline);
  345.     mysql_fetch_field_row(fetch,"id");
  346.     sscanf(fetch, "i", tmpid);
  347.     SetPVarInt( playerid, "id", tmpid );
  348.     mysql_fetch_field_row(fetch,"x");
  349.     sscanf(fetch, "f", x);
  350.     mysql_fetch_field_row(fetch,"y");
  351.     sscanf(fetch, "f", y);
  352.     mysql_fetch_field_row(fetch,"z");
  353.     sscanf(fetch, "f", z);
  354.     mysql_fetch_field_row(fetch,"a");
  355.     sscanf(fetch, "f", a);
  356.     mysql_fetch_field_row(fetch,"Interjeras");
  357.     sscanf(fetch, "d", tmpinterior);
  358.     SetPVarInt( playerid, "interior", tmpinterior );
  359.     SetSpawnInfo( playerid, NO_TEAM, GetPlayerSkin( playerid ), x, y, z, a, 0, 0, 0, 0, 0, 0 );
  360. }
  361. //-----------------------------------------------------------
  362. // Neteisingo vardo stock'as
  363. //-----------------------------------------------------------
  364. stock InvalidNickKick(playerid)
  365. {
  366.     if(IsPlayerNPC(playerid))return 1;
  367.     new name[MAX_PLAYER_NAME];
  368.     GetPlayerName(playerid,name,MAX_PLAYER_NAME);
  369.     new where = strfind(name,"_",true);
  370.     new lenght = strlen(name)-1;
  371.     new invalid = strfind(name,"[",true);
  372.     if(invalid == -1) invalid = strfind(name,"]",true);
  373.     if(name[0] < 65 || name[0] > 90)
  374. {
  375.     SendClientMessage(playerid,RAUDONA,"Jūsų slapyvardis netinkamas, vardas rašosi didžiają raide!");
  376.     SendClientMessage(playerid,RAUDONA,"Teisinga slapyvardžio forma būtų:");
  377.     SendClientMessage(playerid,RAUDONA,"Vardas_Pavardė.");
  378.     Kick(playerid);
  379.     return 1;
  380. }
  381.     if(name[where+1] < 65 || name[where+1] > 90)
  382. {
  383.     SendClientMessage(playerid,RAUDONA,"Jūsų slapyvardis netinkamas, pavardė rašosi didžiaja raide!");
  384.     SendClientMessage(playerid,RAUDONA,"Teisinga slapyvardžio forma būtų:");
  385.     SendClientMessage(playerid,RAUDONA,"Vardas_Pavardė.");
  386.     Kick(playerid);
  387.     return 1;
  388. }
  389.     for(new i = 1; i < where-1; i++)
  390. {
  391.     if(name[i] < 97 || name[i] > 122)
  392. {
  393.     SendClientMessage(playerid,RAUDONA,"Jūsų slapyvardis netinkamas (didžiosios raidės arba skaičiai vardo viduryje).");
  394.     SendClientMessage(playerid,RAUDONA,"Teisinga slapyvardžio forma būtų:");
  395.     SendClientMessage(playerid,RAUDONA,"Vardas_Pavardė.");
  396.     Kick(playerid);
  397.     return 1;
  398. }
  399. }
  400.     if(where == 0 || where == lenght || where==-1)
  401. {
  402.     SendClientMessage(playerid,RAUDONA,"Jūsų slapyvardis netinkamas.");
  403.     SendClientMessage(playerid,RAUDONA,"Teisinga slapyvardžio forma būtų:");
  404.     SendClientMessage(playerid,RAUDONA,"Vardas_Pavardė.");
  405.     Kick(playerid);
  406.     return 1;
  407. }
  408.     if(strlen(name[where])<4)
  409. {
  410.     SendClientMessage(playerid,RAUDONA,"Jūsų pavardė per trumpa.");
  411.     SendClientMessage(playerid,RAUDONA,"Teisinga slapyvardžio forma būtų:");
  412.     SendClientMessage(playerid,RAUDONA,"Vardas_Pavardė.");
  413.     Kick(playerid);
  414.     return 1;
  415. }
  416.     if(where<3)
  417. {
  418.     SendClientMessage(playerid,RAUDONA,"Jūsų vardas per trumpas.");
  419.     SendClientMessage(playerid,RAUDONA,"Teisinga slapyvardžio forma būtų:");
  420.     SendClientMessage(playerid,RAUDONA,"Vardas_Pavardė.");
  421.     Kick(playerid);
  422.     return 1;
  423. }
  424.     if(invalid != -1)
  425. {
  426.     SendClientMessage(playerid,RAUDONA,"Varde rasta netinkamų raidzių.");
  427.     SendClientMessage(playerid,RAUDONA,"Teisinga slapyvardžio forma būtų:");
  428.     SendClientMessage(playerid,RAUDONA,"Vardas_Pavardė.");
  429.     Kick(playerid);
  430.     return 1;
  431. }
  432.     for(new i = where+2; i < MAX_PLAYER_NAME; i++)
  433. {
  434.     if(name[i] < 97 || name[i] > 122)
  435. {
  436.     if(name[i] == 0){i = MAX_PLAYER_NAME; return 0;}
  437.     SendClientMessage(playerid,RAUDONA,"Jūsų slapyvardis netinkamas (didžiosios raidės arba skaičiai pavardės viduryje).");
  438.     SendClientMessage(playerid,RAUDONA,"Teisinga slapyvardžio forma būtų:");
  439.     SendClientMessage(playerid,RAUDONA,"Vardas_Pavardė.");
  440.     Kick(playerid);
  441.     return 1;
  442. }
  443. }
  444.     return 0;
  445. }
  446. //-----------------------------------------------------------
  447. // Mysql užklausų generavimas
  448. //-----------------------------------------------------------
  449. stock SQLUpdateAddInt(string[],varname,var,bool:last=false)
  450. {
  451.     new epicstr[MAX_QUERY];
  452.     format(epicstr,sizeof(epicstr),"%s %s=%d",string,varname,var);
  453.     if(!last) strcat(epicstr,",");
  454.     return epicstr;
  455. }
  456.  
  457. stock SQLUpdateAddString(string[],varname,var[],bool:last=false)
  458. {
  459.     new epicstr[MAX_QUERY];
  460.     format(epicstr,sizeof(epicstr),"%s %s=\"%s\"",string,varname,var);
  461.     if(!last) strcat(epicstr,",");
  462.     return epicstr;
  463. }
  464.  
  465. stock SQLUpdateAddFloat(string[],varname,Float:var,bool:last=false)
  466. {
  467.     new epicstr[MAX_QUERY];
  468.     format(epicstr,sizeof(epicstr),"%s %s=%f",string,varname,var);
  469.     if(!last) strcat(epicstr,",");
  470.     return epicstr;
  471. }
  472.  
  473. stock SQLUpdateComplete(table[],data[],id)
  474. {
  475.     new epicstr[MAX_QUERY];
  476.     format(epicstr,sizeof(epicstr),"UPDATE %s SET %s WHERE id=%d",table,data,id);
  477.     return epicstr;
  478. }
  479.  
  480. stock SQLUpdateCompleteEx(table[],data[],where[])
  481. {
  482.     new epicstr[MAX_QUERY];
  483.     format(epicstr,sizeof(epicstr),"UPDATE %s SET %s WHERE %s",table,data,where);
  484.     return epicstr;
  485. }
  486. //-----------------------------------------------------------
  487. // Skripto pabaiga
  488. //-----------------------------------------------------------
Add Comment
Please, Sign In to add comment