Phanto90

PRaceSystem v1.2.1

Apr 27th, 2011
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 45.50 KB | None | 0 0
  1. /*
  2. ================================================================================
  3.                                Phanto's Script
  4. ________________________________________________________________________________
  5. •Script: PRaceSystem         •Scripter: Phanto90
  6. •Type: FS                    •File size: 46 Kb(.pwn) / 57 Kb(.amx)
  7. •Lines: 1021                 •Version: 1.2.1v
  8. ________________________________________________________________________________
  9.                               * Description *
  10.                              
  11. Tired of your server modes? No problem! Here it is a nice FS that allows you to
  12. play races on your server! Added also a in-game race editor!
  13. In the version 1.2 it has been added the new race type "Chase"
  14.  
  15. System:
  16. •3 types of races: Circuit, Sprint & Chase.
  17. •You can build your own race in few minutes thanks to the powerful editor.
  18. •Different players can race on different tracks at the same time.
  19. •Functional & nice system
  20.  
  21. Fixed bug & updates:
  22. -Version 1.1
  23. •Fixed a bug /quitrace when race isn't started yet.
  24. •Added a nice ingame race editor
  25. -Version 1.2
  26. •Added new race type "Chase"
  27. •Modified the Race Edior to build also Chase Races.
  28. -Version 1.2.1
  29. •Fixed a serious bug in OnDialogResponse callback.
  30.  
  31. Note: Old race.txt are no longer compatible. Change the races in scriptfiles
  32.       with the new one instead.
  33.  
  34.  
  35.                      Thanks for choosing Pawnoscripter!
  36.                      http://pawnoscripter.forumfree.it
  37.      
  38.                                                                       Phanto90
  39. ________________________________________________________________________________
  40. Do not remove credits.
  41. ================================================================================
  42. */
  43. #include <a_samp>
  44. //===============MODIFICABILI
  45. #define TELETRASPORTO_INIZIAGARA // Comment to disable teleport to the starting checkpoint
  46. #define MAX_GARE 20
  47. #define MAX_CHECKPOINT 40
  48. //===============COLORI
  49. #define ROSSO    0xFF3233FF
  50. #define BIANCO   0xFFFFFFFF
  51. #define VERDE    0x00FF00FF
  52. #define TURCHESE 0x3C93FFFF
  53. //================DIALOG
  54. #define DIALOGGARE            10016
  55. #define DIALOGINFO            10017
  56. #define DIALOGINFOCOSTRUTTORE 10018
  57. #define DIALOGNOMEGARA        10019
  58. #define DIALOGGIRIGARA        10020
  59. #define DIALOGCOSTOGARA       10021
  60. #define DIALOGINFOGARA2       10022
  61. #define DIALOGINSEGUIMENTO    10023
  62. //=========================FORWARD
  63. forward Tre(playerid);
  64. forward Due(playerid);
  65. forward Uno(playerid);
  66. forward Via(playerid);
  67. forward Secondo(playerid);
  68. forward Cronometro(playerid);
  69. //=========================VARIABILIGIOCATORE
  70. enum InfoGiocatore{IdGara,Tempo,Giro,Checkpoint,Pronto,Costruttore,GaraEditorId,AttivaCheck,Inseguitore,Punti};
  71. new Giocatore[MAX_PLAYERS][InfoGiocatore];
  72. new Float:XPosizione,Float:YPosizione,Float:ZPosizione;
  73. new nome[25];
  74. //==============VARIABILIGARE
  75. enum InfoGara{Nome[50],Giri,NumeroCheckpoint,Inseguimento,Costo,Partecipanti,PartecipantiPronti,Avviata,Record,GiocatoreRecord[25],Produttore[25],Podio};
  76. new Gara[MAX_GARE][InfoGara];
  77. enum CheckInfo{Float:CXPos,Float:CYPos,Float:CZPos};
  78. new CheckpointGara[MAX_GARE][MAX_CHECKPOINT][CheckInfo];
  79. new TimerPlayers[MAX_PLAYERS];
  80. new GareCaricate,GareEditor;
  81. //=============VARIABILI
  82. new stringa[1000],stringa2[1000];
  83. new InfoSplit[7][250];
  84. new InfoCheck1[MAX_CHECKPOINT][256];
  85. new InfoCheck2[3][256];
  86. //============TEXTDRAW
  87. new Text:sfondo,Text:sfondorosso,Text:sfondogiallo,Text:sfondoverde,Text:rossoacceso,Text:gialloacceso,Text:verdeacceso; //Textdraw semaforo
  88. new Text:TimerSfondo,Text:TimerText[MAX_PLAYERS]; //Timer textdraw
  89. new Text:TextGiriSfondo,Text:TextGiriContatore[MAX_PLAYERS]; //Textdraw laps
  90. new Text:TextSfondoInseguimento,Text:SfondoInseguimentoRosso,Text:SfondoInseguimentoGiallo,Text:SfondoInseguimentoVerde,Text:SfondoInseguimentoAzzurro,Text:TextInseguimento,Text:TextPessimo,Text:TextMediocre,Text:TextBuono,Text:TextOttimo,Text:TextPunti[MAX_PLAYERS];
  91. //====================================================================CARICAGARE
  92. stock CaricaGare()
  93. {
  94.    new stringagara[1000];
  95.    for(new i=0;i<MAX_GARE;i++)
  96.    {
  97.    //==============CARICAMENTOINFOGARA
  98.    format(stringa,sizeof(stringa),"Races/Race%d.txt",i);
  99.    format(stringa2,sizeof(stringa2),"Race %d not found. Failed to load this race.",i);
  100.    if(!fexist(stringa)) return printf(stringa2);
  101.    new File:nomegara=fopen(stringa, io_read);
  102.    fread(nomegara,stringagara);
  103.    fclose(nomegara);
  104.    split(stringagara,InfoSplit,',');
  105.    format(Gara[i][Nome],50,InfoSplit[0]); //Nome,Giri,Costo,Record,GiocatoreRecord,Produttore,Inseguimento
  106.    Gara[i][Giri]=strval(InfoSplit[1]);
  107.    Gara[i][Costo]=strval(InfoSplit[2]);
  108.    Gara[i][Record]=strval(InfoSplit[3]);
  109.    format(Gara[i][GiocatoreRecord],25,InfoSplit[4]);
  110.    format(Gara[i][Produttore],300,InfoSplit[5]);
  111.    Gara[i][Inseguimento]=strval(InfoSplit[6]);
  112.    Gara[i][NumeroCheckpoint]=-1;
  113.    format(stringa,sizeof(stringa),"%s,%d,%d$,%s,%s",Gara[i][Nome],Gara[i][Giri],Gara[i][Costo],Gara[i][GiocatoreRecord],Gara[i][Produttore]);
  114.    printf(stringa);
  115.    //================CARICAMENTOCHECKPOINT
  116.    format(stringagara,sizeof(stringagara),"");
  117.    format(stringa,sizeof(stringa),"Races/Check%d.txt",i);
  118.    format(stringa2,sizeof(stringa2),"Checkpoint list for Race %d not found. Failed to load this race.",i);
  119.    if(!fexist(stringa)) return printf(stringa2);
  120.    nomegara=fopen(stringa, io_read);
  121.    fread(nomegara,stringagara);
  122.    fclose(nomegara);
  123.    split(stringagara,InfoCheck1,'|');
  124.    print("____________________________________");
  125.    for(new j=0;j<MAX_CHECKPOINT;j++)
  126.     {
  127.     split(InfoCheck1[j],InfoCheck2,',');
  128.     if(floatstr(InfoCheck2[0])==0) {printf("%d checkpoints loaded for Race %d.",Gara[i][NumeroCheckpoint]+1,i);break;}
  129.     CheckpointGara[i][j][CXPos]=floatstr(InfoCheck2[0]);
  130.     CheckpointGara[i][j][CYPos]=floatstr(InfoCheck2[1]);
  131.     CheckpointGara[i][j][CZPos]=floatstr(InfoCheck2[2]);
  132.     Gara[i][NumeroCheckpoint]++;
  133.     }
  134.    GareCaricate=i;
  135.    GareEditor=i;
  136.    print("____________________________________");
  137.    }
  138.    return 1;
  139. }
  140. //====================================================================SALVAGARE
  141. stock SalvaGare()
  142. {
  143.    for(new i=0;i<GareCaricate;i++)
  144.    {
  145.    format(stringa,sizeof(stringa),"Races/Race%d.txt",i);
  146.    format(stringa2,sizeof(stringa2),"Race %d not found. Failed to save this race.",i);
  147.    if(!fexist(stringa)) return printf(stringa2);
  148.    new File:nomegara=fopen(stringa, io_write);
  149.    new stringagara[700];  
  150.    format(stringagara,sizeof(stringagara),"%s,%d,%d,%d,%s,%s,%d",Gara[i][Nome],Gara[i][Giri],Gara[i][Costo],Gara[i][Record],Gara[i][GiocatoreRecord],Gara[i][Produttore],Gara[i][Inseguimento]);
  151.    fwrite(nomegara,stringagara);
  152.    fclose(nomegara);
  153.    }
  154.    return 1;
  155. }
  156. //=====================================================================AVVIAGARA
  157. stock AvviaGara(idGara)
  158. {
  159.   format(stringa,sizeof(stringa),"[RACE:] Race {446ED1}%s{FFFFFF} starts!",Gara[idGara][Nome]);
  160.   SendClientMessageToAll(BIANCO,stringa);
  161.   Gara[idGara][Avviata]=1;
  162.   for(new i=0;i<MAX_PLAYERS;i++)
  163.   {
  164.   if(Giocatore[i][IdGara]==idGara)
  165.    {
  166.    TogglePlayerControllable(i,0);
  167.    TextDrawShowForPlayer(i,sfondo);
  168.    TextDrawShowForPlayer(i,sfondorosso);
  169.    TextDrawShowForPlayer(i,sfondogiallo);
  170.    TextDrawShowForPlayer(i,sfondoverde);
  171.    TextDrawShowForPlayer(i,rossoacceso);
  172.    if(Gara[Giocatore[i][IdGara]][Inseguimento])
  173.    {
  174.     TextDrawShowForPlayer(i,TextSfondoInseguimento);
  175.     TextDrawShowForPlayer(i,SfondoInseguimentoRosso);
  176.     TextDrawShowForPlayer(i,SfondoInseguimentoGiallo);
  177.     TextDrawShowForPlayer(i,SfondoInseguimentoVerde);
  178.     TextDrawShowForPlayer(i,SfondoInseguimentoAzzurro);
  179.     TextDrawShowForPlayer(i,TextInseguimento);
  180.     TextDrawShowForPlayer(i,TextPessimo);
  181.     TextDrawShowForPlayer(i,TextMediocre);
  182.     TextDrawShowForPlayer(i,TextBuono);
  183.     TextDrawShowForPlayer(i,TextOttimo);
  184.     TextDrawSetString(TextPunti[i],"Points: 0000");
  185.     TextDrawShowForPlayer(i,TextPunti[i]);
  186.    }
  187.    SetTimerEx("Tre",1000,false,"idx",i);
  188.    }
  189.   }
  190.   return 1;
  191. }
  192. //===========================================================================TRE
  193. public Tre(playerid)
  194. {
  195.  GameTextForPlayer(playerid,"~r~3",1000,3);
  196.  SuonoGiocatore(playerid,1056);
  197.  Giocatore[playerid][Tempo]=0;
  198.  Giocatore[playerid][Giro]=1;
  199.  format(stringa,sizeof(stringa),"Laps: 1/%d",Gara[Giocatore[playerid][IdGara]][Giri]);
  200.  TextDrawSetString(TextGiriContatore[playerid],stringa);
  201.  TextDrawSetString(TimerText[playerid],"00:00");
  202.  GetPlayerPos(playerid,XPosizione,YPosizione,ZPosizione);
  203.  SetPlayerCameraPos(playerid,XPosizione+4,YPosizione+2,ZPosizione+3);
  204.  SetPlayerCameraLookAt(playerid,XPosizione,YPosizione,ZPosizione);
  205.  TextDrawShowForPlayer(playerid,TimerSfondo);
  206.  TextDrawShowForPlayer(playerid,TimerText[playerid]);
  207.  TextDrawShowForPlayer(playerid,TextGiriSfondo);
  208.  TextDrawShowForPlayer(playerid,TextGiriContatore[playerid]);
  209.  SetTimerEx("Due",1000,false,"idx",playerid);
  210. }
  211. //===========================================================================DUE
  212. public Due(playerid)
  213. {
  214.  GameTextForPlayer(playerid,"~r~3~n~~y~2",1000,3);
  215.  SuonoGiocatore(playerid,1056);
  216.  GetPlayerPos(playerid,XPosizione,YPosizione,ZPosizione);
  217.  SetPlayerCameraPos(playerid,XPosizione-4,YPosizione-2,ZPosizione+3);
  218.  SetPlayerCameraLookAt(playerid,XPosizione,YPosizione,ZPosizione);
  219.  SetTimerEx("Uno",1000,false,"idx",playerid);
  220. }
  221. //===========================================================================UNO
  222. public Uno(playerid)
  223. {
  224.  GameTextForPlayer(playerid,"~r~3~n~~y~2~n~~g~~h~1",1000,3);
  225.  SuonoGiocatore(playerid,1056);
  226.  GetPlayerPos(playerid,XPosizione,YPosizione,ZPosizione);
  227.  SetPlayerCameraPos(playerid,XPosizione+4,YPosizione-2,ZPosizione+3);
  228.  SetPlayerCameraLookAt(playerid,XPosizione,YPosizione,ZPosizione);
  229.  TextDrawShowForPlayer(playerid,gialloacceso);
  230.  TextDrawHideForPlayer(playerid,rossoacceso);
  231.  SetTimerEx("Via",1000,false,"idx",playerid);
  232. }
  233. //===========================================================================VIA
  234. public Via(playerid)
  235. {
  236.  SetCameraBehindPlayer(playerid);
  237.  GameTextForPlayer(playerid,"~w~Go!",3000,3);
  238.  SuonoGiocatore(playerid,1057);
  239.  TogglePlayerControllable(playerid,1);
  240.  TextDrawShowForPlayer(playerid,verdeacceso);
  241.  TextDrawHideForPlayer(playerid,gialloacceso);
  242.  SetTimerEx("Secondo",1000,false,"idx",playerid);
  243.  TimerPlayers[playerid]=SetTimerEx("Cronometro",1000,true,"idx",playerid);
  244. }
  245. //=======================================================================SECONDO
  246. public Secondo(playerid)
  247. {
  248.  TextDrawHideForPlayer(playerid,sfondo);
  249.  TextDrawHideForPlayer(playerid,sfondorosso);
  250.  TextDrawHideForPlayer(playerid,sfondogiallo);
  251.  TextDrawHideForPlayer(playerid,sfondoverde);
  252.  TextDrawHideForPlayer(playerid,verdeacceso);
  253.  return 1;
  254. }
  255. //===================================================================CONTROMETRO
  256. public Cronometro(playerid)
  257. {
  258.  
  259.  Giocatore[playerid][Tempo]++;
  260.  new Minuti=floatround(Giocatore[playerid][Tempo]/60);
  261.  new Secondi=Giocatore[playerid][Tempo]-(Minuti*60);
  262.  if(Minuti>20)
  263.  {
  264.  SendClientMessage(playerid,ROSSO,"[RACE:] {FFFFFF}You quit automatically the race for excessive time (20 minutes)");
  265.  LasciaGara(playerid);
  266.  return 1;
  267.  }
  268.  new stringatempo[10];
  269.  format(stringatempo,sizeof(stringatempo),"%02d:%02d",Minuti,Secondi);
  270.  TextDrawSetString(TimerText[playerid],stringatempo);
  271.  if(Gara[Giocatore[playerid][IdGara]][Inseguimento]==1)
  272.  {
  273.  for(new i=0;i<MAX_PLAYERS;i++)
  274.   {
  275.   if(Giocatore[i][IdGara]==Giocatore[playerid][IdGara] && i!=playerid)
  276.    {
  277.    GetPlayerPos(i,XPosizione,YPosizione,ZPosizione);
  278.    break;
  279.    }
  280.   }
  281.  TextDrawHideForPlayer(playerid,SfondoInseguimentoRosso);
  282.  TextDrawHideForPlayer(playerid,SfondoInseguimentoGiallo);
  283.  TextDrawHideForPlayer(playerid,SfondoInseguimentoVerde);
  284.  TextDrawHideForPlayer(playerid,SfondoInseguimentoAzzurro);
  285.  if(!Giocatore[playerid][Inseguitore])
  286.   {
  287.   if(IsPlayerInRangeOfPoint(playerid,15,XPosizione,YPosizione,ZPosizione)){
  288.   Giocatore[playerid][Punti]+=3; TextDrawShowForPlayer(playerid,SfondoInseguimentoRosso);}
  289.   else if (IsPlayerInRangeOfPoint(playerid,30,XPosizione,YPosizione,ZPosizione)){
  290.   Giocatore[playerid][Punti]+=5; TextDrawShowForPlayer(playerid,SfondoInseguimentoGiallo);}
  291.   else if(IsPlayerInRangeOfPoint(playerid,40,XPosizione,YPosizione,ZPosizione)){
  292.   Giocatore[playerid][Punti]+=7; TextDrawShowForPlayer(playerid,SfondoInseguimentoVerde);}
  293.   else{
  294.   Giocatore[playerid][Punti]+=8; TextDrawShowForPlayer(playerid,SfondoInseguimentoAzzurro);}
  295.   }
  296.  else
  297.   {
  298.   if(IsPlayerInRangeOfPoint(playerid,15,XPosizione,YPosizione,ZPosizione)){
  299.   Giocatore[playerid][Punti]+=8; TextDrawShowForPlayer(playerid,SfondoInseguimentoAzzurro);}
  300.   else if (IsPlayerInRangeOfPoint(playerid,30,XPosizione,YPosizione,ZPosizione)){
  301.   Giocatore[playerid][Punti]+=7; TextDrawShowForPlayer(playerid,SfondoInseguimentoVerde);}
  302.   else if(IsPlayerInRangeOfPoint(playerid,40,XPosizione,YPosizione,ZPosizione)){
  303.   Giocatore[playerid][Punti]+=5; TextDrawShowForPlayer(playerid,SfondoInseguimentoGiallo);}
  304.   else{
  305.   Giocatore[playerid][Punti]+=3; TextDrawShowForPlayer(playerid,SfondoInseguimentoRosso);}
  306.   }
  307.  format(stringa,sizeof(stringa),"Points: %d",Giocatore[playerid][Punti]);
  308.  TextDrawSetString(TextPunti[playerid],stringa);
  309.  }
  310.  return 1;
  311. }
  312. //====================================================================LASCIAGARA
  313. stock LasciaGara(playerid)
  314. {
  315.     if(Giocatore[playerid][IdGara]==-1) return 1;
  316.     if(Gara[Giocatore[playerid][IdGara]][Avviata]==0)
  317.     {
  318.     if(Giocatore[playerid][Pronto]==1)
  319.     Gara[Giocatore[playerid][IdGara]][PartecipantiPronti]--;
  320.     }
  321.     KillTimer(TimerPlayers[playerid]);
  322.     Giocatore[playerid][Tempo]=0;
  323.     GetPlayerName(playerid,nome,sizeof(nome));
  324.     format(stringa,sizeof(stringa),"[RACE:] {8CE46C}%s {FFFFFF}quit the race.", nome);
  325.     MandaMessaggioPartecipanti(Giocatore[playerid][IdGara],stringa);
  326.     //==========TEXTBASE
  327.     TextDrawHideForPlayer(playerid,sfondo);
  328.     TextDrawHideForPlayer(playerid,TimerText[playerid]);
  329.     TextDrawHideForPlayer(playerid,TimerSfondo);
  330.     TextDrawHideForPlayer(playerid,sfondorosso);
  331.     TextDrawHideForPlayer(playerid,sfondogiallo);
  332.     TextDrawHideForPlayer(playerid,sfondoverde);
  333.     TextDrawHideForPlayer(playerid,rossoacceso);
  334.     TextDrawHideForPlayer(playerid,gialloacceso);
  335.     TextDrawHideForPlayer(playerid,verdeacceso);
  336.     TextDrawHideForPlayer(playerid,TextGiriSfondo);
  337.     //==========TEXTINSEGUIMENTO
  338.     TextDrawHideForPlayer(playerid,TextSfondoInseguimento);
  339.     TextDrawHideForPlayer(playerid,SfondoInseguimentoRosso);
  340.     TextDrawHideForPlayer(playerid,SfondoInseguimentoGiallo);
  341.     TextDrawHideForPlayer(playerid,SfondoInseguimentoVerde);
  342.     TextDrawHideForPlayer(playerid,SfondoInseguimentoAzzurro);
  343.     TextDrawHideForPlayer(playerid,TextInseguimento);
  344.     TextDrawHideForPlayer(playerid,TextPessimo);
  345.     TextDrawHideForPlayer(playerid,TextMediocre);
  346.     TextDrawHideForPlayer(playerid,TextBuono);
  347.     TextDrawHideForPlayer(playerid,TextOttimo);
  348.     TextDrawHideForPlayer(playerid,TextPunti[playerid]);
  349.    
  350.     TextDrawHideForPlayer(playerid,TextGiriContatore[playerid]);
  351.     TextDrawSetString(TimerText[playerid],"00:00");
  352.     Giocatore[playerid][Checkpoint]=0;
  353.     Gara[Giocatore[playerid][IdGara]][Partecipanti]--;
  354.     if(Gara[Giocatore[playerid][IdGara]][PartecipantiPronti]==Gara[Giocatore[playerid][IdGara]][Partecipanti] && Gara[Giocatore[playerid][IdGara]][Partecipanti]!=0 && Gara[Giocatore[playerid][IdGara]][Avviata]==0)
  355.     AvviaGara(Giocatore[playerid][IdGara]);
  356.     ChiudiGara(Giocatore[playerid][IdGara]);
  357.     Giocatore[playerid][IdGara]=-1;
  358.     Giocatore[playerid][Pronto]=0;
  359.     Giocatore[playerid][Giro]=1;
  360.     Giocatore[playerid][Inseguitore]=0;
  361.     Giocatore[playerid][Punti]=0;
  362.     DisablePlayerRaceCheckpoint(playerid);
  363.     return 1;
  364. }
  365. //====================================================================CHIUDIGARA
  366. stock ChiudiGara(idGara)
  367. {
  368.  if(Gara[idGara][Partecipanti]==0 && idGara!=-1)
  369.  {
  370.  format(stringa,sizeof(stringa),"[RACE:] {FFFFFF}Race {446ED1}%s{FFFFFF} finish.",Gara[idGara][Nome]);
  371.  SendClientMessageToAll(BIANCO,stringa);
  372.  Gara[idGara][Podio]=0;
  373.  Gara[idGara][Avviata]=0;
  374.  Gara[idGara][Partecipanti]=0;
  375.  Gara[idGara][PartecipantiPronti]=0;
  376.  }
  377. }
  378. //============================================================ONFILTERSCRIPTINIT
  379. public OnFilterScriptInit()
  380.   {
  381.   print("_______________________________________________");
  382.   print("       PRaceSystem by Phanto90 loaded ");
  383.   print("_______________________________________________");
  384.   CaricaGare();
  385.   TextGiriSfondo = TextDrawCreate(541.000000, 189.000000, "1");
  386.   TextDrawBackgroundColor(TextGiriSfondo, 0);
  387.   TextDrawFont(TextGiriSfondo, 1);
  388.   TextDrawLetterSize(TextGiriSfondo, 0.579999, 1.700000);
  389.   TextDrawColor(TextGiriSfondo, 0);
  390.   TextDrawSetOutline(TextGiriSfondo, 0);
  391.   TextDrawSetProportional(TextGiriSfondo, 1);
  392.   TextDrawSetShadow(TextGiriSfondo, 1);
  393.   TextDrawUseBox(TextGiriSfondo, 1);
  394.   TextDrawBoxColor(TextGiriSfondo, 1010580600);
  395.   TextDrawTextSize(TextGiriSfondo, 613.000000, 0.000000);
  396.  
  397.   TimerSfondo = TextDrawCreate(620.000000, 160.000000, ".sfo");
  398.   TextDrawBackgroundColor(TimerSfondo, 0);
  399.   TextDrawFont(TimerSfondo, 1);
  400.   TextDrawLetterSize(TimerSfondo, 0.500000, 2.499999);
  401.   TextDrawColor(TimerSfondo, 0);
  402.   TextDrawSetOutline(TimerSfondo, 0);
  403.   TextDrawSetProportional(TimerSfondo, 1);
  404.   TextDrawSetShadow(TimerSfondo, 1);
  405.   TextDrawUseBox(TimerSfondo, 1);
  406.   TextDrawBoxColor(TimerSfondo, 1010580580);
  407.   TextDrawTextSize(TimerSfondo, 535.000000, 0.000000);
  408.  
  409.   sfondo = TextDrawCreate(265.000000, 40.000000, "sfondo");
  410.   TextDrawBackgroundColor(sfondo, 0);
  411.   TextDrawFont(sfondo, 1);
  412.   TextDrawLetterSize(sfondo, 0.500000, 3.500000);
  413.   TextDrawColor(sfondo, 0);
  414.   TextDrawSetOutline(sfondo, 0);
  415.   TextDrawSetProportional(sfondo, 1);
  416.   TextDrawSetShadow(sfondo, 1);
  417.   TextDrawUseBox(sfondo, 1);
  418.   TextDrawBoxColor(sfondo, 338826495);
  419.   TextDrawTextSize(sfondo, 384.000000, 0.000000);
  420.  
  421.   sfondorosso = TextDrawCreate(278.000000, 48.000000, "sfondorosso");
  422.   TextDrawBackgroundColor(sfondorosso, 0);
  423.   TextDrawFont(sfondorosso, 1);
  424.   TextDrawLetterSize(sfondorosso, 0.500000, 1.800001);
  425.   TextDrawColor(sfondorosso, 0);
  426.   TextDrawSetOutline(sfondorosso, 0);
  427.   TextDrawSetProportional(sfondorosso, 1);
  428.   TextDrawSetShadow(sfondorosso, 1);
  429.   TextDrawUseBox(sfondorosso, 1);
  430.   TextDrawBoxColor(sfondorosso, 840176895);
  431.   TextDrawTextSize(sfondorosso, 293.000000, 0.000000);
  432.  
  433.   sfondogiallo = TextDrawCreate(320.000000, 48.000000, "sfondoarancione");
  434.   TextDrawBackgroundColor(sfondogiallo, 0);
  435.   TextDrawFont(sfondogiallo, 1);
  436.   TextDrawLetterSize(sfondogiallo, 0.500000, 1.800001);
  437.   TextDrawColor(sfondogiallo, 0);
  438.   TextDrawSetOutline(sfondogiallo, 0);
  439.   TextDrawSetProportional(sfondogiallo, 1);
  440.   TextDrawSetShadow(sfondogiallo, 1);
  441.   TextDrawUseBox(sfondogiallo, 1);
  442.   TextDrawBoxColor(sfondogiallo, 842142975);
  443.   TextDrawTextSize(sfondogiallo, 334.000000, 0.000000);
  444.  
  445.   sfondoverde = TextDrawCreate(359.000000, 48.000000, "sfondoverde");
  446.   TextDrawBackgroundColor(sfondoverde, 0);
  447.   TextDrawFont(sfondoverde, 1);
  448.   TextDrawLetterSize(sfondoverde, 0.500000, 1.800001);
  449.   TextDrawColor(sfondoverde, 0);
  450.   TextDrawSetOutline(sfondoverde, 0);
  451.   TextDrawSetProportional(sfondoverde, 1);
  452.   TextDrawSetShadow(sfondoverde, 1);
  453.   TextDrawUseBox(sfondoverde, 1);
  454.   TextDrawBoxColor(sfondoverde, 337515775);
  455.   TextDrawTextSize(sfondoverde, 373.000000, 0.000000);
  456.  
  457.   rossoacceso = TextDrawCreate(281.000000, 51.000000, "sfondorossoacceso");
  458.   TextDrawBackgroundColor(rossoacceso, 0);
  459.   TextDrawFont(rossoacceso, 1);
  460.   TextDrawLetterSize(rossoacceso, 0.500000, 1.100001);
  461.   TextDrawColor(rossoacceso, 0);
  462.   TextDrawSetOutline(rossoacceso, 0);
  463.   TextDrawSetProportional(rossoacceso, 1);
  464.   TextDrawSetShadow(rossoacceso, 1);
  465.   TextDrawUseBox(rossoacceso, 1);
  466.   TextDrawBoxColor(rossoacceso, -938208001);
  467.   TextDrawTextSize(rossoacceso, 291.000000, 0.000000);
  468.  
  469.   gialloacceso = TextDrawCreate(322.000000, 51.000000, "sfondoarancioneacceso");
  470.   TextDrawBackgroundColor(gialloacceso, 0);
  471.   TextDrawFont(gialloacceso, 1);
  472.   TextDrawLetterSize(gialloacceso, 0.500000, 1.100001);
  473.   TextDrawColor(gialloacceso, 0);
  474.   TextDrawSetOutline(gialloacceso, 0);
  475.   TextDrawSetProportional(gialloacceso, 1);
  476.   TextDrawSetShadow(gialloacceso, 1);
  477.   TextDrawUseBox(gialloacceso, 1);
  478.   TextDrawBoxColor(gialloacceso, -926411521);
  479.   TextDrawTextSize(gialloacceso, 332.000000, 0.000000);
  480.  
  481.   verdeacceso = TextDrawCreate(362.000000, 51.000000, "sfondoverdeacceso");
  482.   TextDrawBackgroundColor(verdeacceso, 0);
  483.   TextDrawFont(verdeacceso, 1);
  484.   TextDrawLetterSize(verdeacceso, 0.500000, 1.100001);
  485.   TextDrawColor(verdeacceso, 0);
  486.   TextDrawSetOutline(verdeacceso, 0);
  487.   TextDrawSetProportional(verdeacceso, 1);
  488.   TextDrawSetShadow(verdeacceso, 1);
  489.   TextDrawUseBox(verdeacceso, 1);
  490.   TextDrawBoxColor(verdeacceso, 348656895);
  491.   TextDrawTextSize(verdeacceso, 370.000000, 0.000000);
  492.  
  493.   TextSfondoInseguimento = TextDrawCreate(170.000000, 362.000000, "box");
  494.   TextDrawBackgroundColor(TextSfondoInseguimento, 0);
  495.   TextDrawFont(TextSfondoInseguimento, 1);
  496.   TextDrawLetterSize(TextSfondoInseguimento, 0.460000, 2.700011);
  497.   TextDrawColor(TextSfondoInseguimento, 0);
  498.   TextDrawSetOutline(TextSfondoInseguimento, 0);
  499.   TextDrawSetProportional(TextSfondoInseguimento, 1);
  500.   TextDrawSetShadow(TextSfondoInseguimento, 1);
  501.   TextDrawUseBox(TextSfondoInseguimento, 1);
  502.   TextDrawBoxColor(TextSfondoInseguimento, 505290340);
  503.   TextDrawTextSize(TextSfondoInseguimento, 467.000000, 0.000000);
  504.  
  505.   SfondoInseguimentoRosso = TextDrawCreate(174.000000, 366.000000, "boxrosso");
  506.   TextDrawBackgroundColor(SfondoInseguimentoRosso, 0);
  507.   TextDrawFont(SfondoInseguimentoRosso, 1);
  508.   TextDrawLetterSize(SfondoInseguimentoRosso, 0.460000, 1.600010);
  509.   TextDrawColor(SfondoInseguimentoRosso, 0);
  510.   TextDrawSetOutline(SfondoInseguimentoRosso, 0);
  511.   TextDrawSetProportional(SfondoInseguimentoRosso, 1);
  512.   TextDrawSetShadow(SfondoInseguimentoRosso, 1);
  513.   TextDrawUseBox(SfondoInseguimentoRosso, 1);
  514.   TextDrawBoxColor(SfondoInseguimentoRosso, -1776410956);
  515.   TextDrawTextSize(SfondoInseguimentoRosso, 243.000000, 0.000000);
  516.  
  517.   SfondoInseguimentoGiallo = TextDrawCreate(249.000000, 366.000000, "boxgiallo");
  518.   TextDrawBackgroundColor(SfondoInseguimentoGiallo, 0);
  519.   TextDrawFont(SfondoInseguimentoGiallo, 1);
  520.   TextDrawLetterSize(SfondoInseguimentoGiallo, 0.460000, 1.600010);
  521.   TextDrawColor(SfondoInseguimentoGiallo, 0);
  522.   TextDrawSetOutline(SfondoInseguimentoGiallo, 0);
  523.   TextDrawSetProportional(SfondoInseguimentoGiallo, 1);
  524.   TextDrawSetShadow(SfondoInseguimentoGiallo, 1);
  525.   TextDrawUseBox(SfondoInseguimentoGiallo, 1);
  526.   TextDrawBoxColor(SfondoInseguimentoGiallo, -1768546636);
  527.   TextDrawTextSize(SfondoInseguimentoGiallo, 319.000000, 0.000000);
  528.  
  529.   SfondoInseguimentoVerde = TextDrawCreate(325.000000, 366.000000, "boxverde");
  530.   TextDrawBackgroundColor(SfondoInseguimentoVerde, 0);
  531.   TextDrawFont(SfondoInseguimentoVerde, 1);
  532.   TextDrawLetterSize(SfondoInseguimentoVerde, 0.460000, 1.600010);
  533.   TextDrawColor(SfondoInseguimentoVerde, 0);
  534.   TextDrawSetOutline(SfondoInseguimentoVerde, 0);
  535.   TextDrawSetProportional(SfondoInseguimentoVerde, 1);
  536.   TextDrawSetShadow(SfondoInseguimentoVerde, 1);
  537.   TextDrawUseBox(SfondoInseguimentoVerde, 1);
  538.   TextDrawBoxColor(SfondoInseguimentoVerde, 513154740);
  539.   TextDrawTextSize(SfondoInseguimentoVerde, 394.000000, 0.000000);
  540.  
  541.   SfondoInseguimentoAzzurro = TextDrawCreate(400.000000, 366.000000, "boxazzurro");
  542.   TextDrawBackgroundColor(SfondoInseguimentoAzzurro, 0);
  543.   TextDrawFont(SfondoInseguimentoAzzurro, 1);
  544.   TextDrawLetterSize(SfondoInseguimentoAzzurro, 0.460000, 1.600010);
  545.   TextDrawColor(SfondoInseguimentoAzzurro, 0);
  546.   TextDrawSetOutline(SfondoInseguimentoAzzurro, 0);
  547.   TextDrawSetProportional(SfondoInseguimentoAzzurro, 1);
  548.   TextDrawSetShadow(SfondoInseguimentoAzzurro, 1);
  549.   TextDrawUseBox(SfondoInseguimentoAzzurro, 1);
  550.   TextDrawBoxColor(SfondoInseguimentoAzzurro, 513198260);
  551.   TextDrawTextSize(SfondoInseguimentoAzzurro, 463.000000, 0.000000);
  552.  
  553.   TextInseguimento = TextDrawCreate(274.000000, 339.000000, "   Chase");
  554.   TextDrawBackgroundColor(TextInseguimento, 255);
  555.   TextDrawFont(TextInseguimento, 0);
  556.   TextDrawLetterSize(TextInseguimento, 0.629999, 2.599999);
  557.   TextDrawColor(TextInseguimento, -1);
  558.   TextDrawSetOutline(TextInseguimento, 0);
  559.   TextDrawSetProportional(TextInseguimento, 1);
  560.   TextDrawSetShadow(TextInseguimento, 1);
  561.  
  562.   TextPessimo = TextDrawCreate(188.000000, 363.000000, "  Bad");
  563.   TextDrawBackgroundColor(TextPessimo, 255);
  564.   TextDrawFont(TextPessimo, 1);
  565.   TextDrawLetterSize(TextPessimo, 0.339999, 2.000000);
  566.   TextDrawColor(TextPessimo, -1);
  567.   TextDrawSetOutline(TextPessimo, 0);
  568.   TextDrawSetProportional(TextPessimo, 1);
  569.   TextDrawSetShadow(TextPessimo, 1);
  570.  
  571.   TextMediocre = TextDrawCreate(258.000000, 363.000000, "Average");
  572.   TextDrawBackgroundColor(TextMediocre, 255);
  573.   TextDrawFont(TextMediocre, 1);
  574.   TextDrawLetterSize(TextMediocre, 0.339999, 2.000000);
  575.   TextDrawColor(TextMediocre, -1);
  576.   TextDrawSetOutline(TextMediocre, 0);
  577.   TextDrawSetProportional(TextMediocre, 1);
  578.   TextDrawSetShadow(TextMediocre, 1);
  579.  
  580.   TextBuono = TextDrawCreate(344.000000, 363.000000, "Good");
  581.   TextDrawBackgroundColor(TextBuono, 255);
  582.   TextDrawFont(TextBuono, 1);
  583.   TextDrawLetterSize(TextBuono, 0.339999, 2.000000);
  584.   TextDrawColor(TextBuono, -1);
  585.   TextDrawSetOutline(TextBuono, 0);
  586.   TextDrawSetProportional(TextBuono, 1);
  587.   TextDrawSetShadow(TextBuono, 1);
  588.  
  589.   TextOttimo = TextDrawCreate(410.000000, 363.000000, "Excellent");
  590.   TextDrawBackgroundColor(TextOttimo, 255);
  591.   TextDrawFont(TextOttimo, 1);
  592.   TextDrawLetterSize(TextOttimo, 0.339999, 2.000000);
  593.   TextDrawColor(TextOttimo, -1);
  594.   TextDrawSetOutline(TextOttimo, 0);
  595.   TextDrawSetProportional(TextOttimo, 1);
  596.   TextDrawSetShadow(TextOttimo, 1);
  597.  
  598.   for(new i=0;i<MAX_PLAYERS;i++)
  599.   {
  600.     Giocatore[i][IdGara]=-1;
  601.  
  602.     TextPunti[i] = TextDrawCreate(288.000000, 386.000000, "Points: 0000");
  603.     TextDrawBackgroundColor(TextPunti[i], 255);
  604.     TextDrawFont(TextPunti[i], 1);
  605.     TextDrawLetterSize(TextPunti[i], 0.339999, 2.000000);
  606.     TextDrawColor(TextPunti[i], -1);
  607.     TextDrawSetOutline(TextPunti[i], 0);
  608.     TextDrawSetProportional(TextPunti[i], 1);
  609.     TextDrawSetShadow(TextPunti[i], 1);
  610.  
  611.     TimerText[i] = TextDrawCreate(542.000000, 150.000000, "00:00");
  612.     TextDrawBackgroundColor(TimerText[i], 255);
  613.     TextDrawFont(TimerText[i], 2);
  614.     TextDrawLetterSize(TimerText[i], 0.610000, 4.099999);
  615.     TextDrawColor(TimerText[i], TURCHESE);
  616.     TextDrawSetOutline(TimerText[i], 0);
  617.     TextDrawSetProportional(TimerText[i], 1);
  618.     TextDrawSetShadow(TimerText[i], 1);
  619.    
  620.     TextGiriContatore[i] = TextDrawCreate(542.000000, 192.000000, "Laps: 1/3");
  621.     TextDrawBackgroundColor(TextGiriContatore[i], 255);
  622.     TextDrawFont(TextGiriContatore[i], 1);
  623.     TextDrawLetterSize(TextGiriContatore[i], 0.460000, 1.000000);
  624.     TextDrawColor(TextGiriContatore[i], -1);
  625.     TextDrawSetOutline(TextGiriContatore[i], 0);
  626.     TextDrawSetProportional(TextGiriContatore[i], 1);
  627.     TextDrawSetShadow(TextGiriContatore[i], 1);
  628.   }
  629.   return 1;
  630. }
  631. //============================================================ONFILTERSCRIPTEXIT
  632. public OnFilterScriptExit()
  633. {
  634.  SalvaGare();
  635.  return 1;
  636. }
  637. //===============================================================ONPLAYERCONNECT
  638. public OnPlayerConnect(playerid)
  639. {
  640.   return 1;
  641. }
  642. //============================================================ONPLAYERDISCONNECT
  643. public OnPlayerDisconnect(playerid, reason)
  644. {
  645.     if(Gara[Giocatore[playerid][IdGara]][Inseguimento] && Gara[Giocatore[playerid][IdGara]][Avviata]==1)
  646.     {
  647.     for(new i=0;i<MAX_PLAYERS;i++)
  648.      {
  649.      if(Giocatore[i][IdGara]==Giocatore[playerid][IdGara] && i!=playerid)
  650.       {
  651.       GetPlayerName(i,nome,sizeof(nome));
  652.       format(stringa,sizeof(stringa),"[RACE:] {8ECE46}%s{FFFFFF} wons the race because the opponent disconnected.",nome);
  653.       SendClientMessageToAll(BIANCO,stringa);
  654.       GivePlayerMoney(i,Gara[Giocatore[i][IdGara]][Costo]*2);
  655.       LasciaGara(i);
  656.       }
  657.      }
  658.     }
  659.     LasciaGara(playerid);
  660.     Giocatore[playerid][Costruttore]=0;
  661.     return 1;
  662. }
  663. //===========================================================ONPLAYERCOMMANDTEXT
  664. public OnPlayerCommandText(playerid, cmdtext[])
  665. {
  666. //=====================================PROVVISORIO
  667.     if(!strcmp(cmdtext,"/car",true))
  668.     {
  669.     GetPlayerPos(playerid,XPosizione,YPosizione,ZPosizione);
  670.     CreateVehicle(400,XPosizione,YPosizione,ZPosizione,0,1,1,0);
  671.     return 1;
  672.     }
  673. //=====================================GARE
  674.     if(!strcmp(cmdtext,"/race",true))
  675.     {
  676.     if(Giocatore[playerid][Costruttore]==1) return SendClientMessage(playerid,ROSSO,"[ERROR:] {FFFFFF}You are in builder mode.");
  677.     format(stringa,sizeof(stringa),"");
  678.     for(new i=0;i<=GareCaricate; i++)
  679.      {
  680.      if(Gara[i][Giri]>1 && Gara[i][Inseguimento]==0)
  681.      format(stringa2,sizeof(stringa2),"{F58C5B}Circuit-{FFFFFF}%s (%d laps)",Gara[i][Nome],Gara[i][Giri]);
  682.      if(Gara[i][Giri]==1 && Gara[i][Inseguimento]==0)
  683.      format(stringa2,sizeof(stringa2),"{97EA68}Sprint-{FFFFFF}%s",Gara[i][Nome]);
  684.      if(Gara[i][Giri]>1 && Gara[i][Inseguimento]==1)
  685.      format(stringa2,sizeof(stringa2),"{446ED1}Chase-{FFFFFF}%s (%d laps)",Gara[i][Nome],Gara[i][Giri]);
  686.      if(Gara[i][Giri]==1 && Gara[i][Inseguimento]==1)
  687.      format(stringa2,sizeof(stringa2),"{446ED1}Chase-{FFFFFF}%s",Gara[i][Nome]);
  688.      strins(stringa,stringa2,strlen(stringa),sizeof(stringa));
  689.      if(i!=GareCaricate)
  690.      strins(stringa,"\n",strlen(stringa),sizeof(stringa));
  691.      }
  692.     ShowPlayerDialog(playerid,DIALOGGARE,DIALOG_STYLE_LIST,"Avaible races",stringa,"Join","Exit");
  693.     return 1;
  694.     }
  695. //=====================================LASCIAGARA
  696.     if(!strcmp(cmdtext,"/quitrace",true))
  697.     {
  698.     if(Giocatore[playerid][IdGara]==-1) return SendClientMessage(playerid,ROSSO,"[ERROR:] {FFFFFF}You did not join any race.");
  699.     if(Gara[Giocatore[playerid][IdGara]][Inseguimento] && Gara[Giocatore[playerid][IdGara]][Avviata]==1)
  700.     {
  701.     for(new i=0;i<MAX_PLAYERS;i++)
  702.      {
  703.      if(Giocatore[i][IdGara]==Giocatore[playerid][IdGara] && i!=playerid)
  704.       {
  705.       GetPlayerName(i,nome,sizeof(nome));
  706.       format(stringa,sizeof(stringa),"[RACE:] {8ECE46}%s{FFFFFF} wons the race because the opponent quitted.",nome);
  707.       SendClientMessageToAll(BIANCO,stringa);
  708.       GivePlayerMoney(i,Gara[Giocatore[i][IdGara]][Costo]*2);
  709.       LasciaGara(i);
  710.       }
  711.      }
  712.     }
  713.     LasciaGara(playerid);
  714.     return 1;
  715.     }
  716. //=====================================PRONTO
  717.     if(!strcmp(cmdtext,"/ready",true))
  718.     {
  719.     if(Giocatore[playerid][IdGara]==-1) return SendClientMessage(playerid,ROSSO,"[ERROR:] {FFFFFF}You did not join any race.");
  720.     if(Giocatore[playerid][Pronto]==1) return SendClientMessage(playerid,ROSSO,"[ERROR:] {FFFFFF} You are yet ready, wait opponents to be.");
  721.     SendClientMessage(playerid,BIANCO,"[PRONTO:] Now you are ready, wait other players to be.");
  722.     Gara[Giocatore[playerid][IdGara]][PartecipantiPronti]++;
  723.     Giocatore[playerid][Pronto]=1;
  724.     if(Gara[Giocatore[playerid][IdGara]][Partecipanti]==Gara[Giocatore[playerid][IdGara]][PartecipantiPronti] && Gara[Giocatore[playerid][IdGara]][Inseguimento]==0)
  725.     AvviaGara(Giocatore[playerid][IdGara]);
  726.     if(Gara[Giocatore[playerid][IdGara]][PartecipantiPronti]==2 && Gara[Giocatore[playerid][IdGara]][Inseguimento]==1)
  727.     AvviaGara(Giocatore[playerid][IdGara]);
  728.     return 1;
  729.     }
  730. //=====================================COSTRUISCIGARA
  731.     if(!strcmp(cmdtext,"/builder",true))
  732.     {
  733.     if(!IsPlayerAdmin(playerid)) return 1;
  734.     if(Giocatore[playerid][IdGara]!=-1) return SendClientMessage(playerid,ROSSO,"[ERROR:]{FFFFFF} You cannot build races while racing.");
  735.     ShowPlayerDialog(playerid,DIALOGINFOCOSTRUTTORE,0,"Info Builder","{FFFFFF}Welcome in the builder mode of {C14124}PRaceSystem{FFFFFF}.\nNow you have to inserit some race informations:\n•Race's Name\n•Laps\n•Cost\n•Creation of a checkpoint list\n\nNote: During the builder mode you cannot join races.","Proceed","");
  736.     GareEditor++;
  737.     Giocatore[playerid][GaraEditorId]=GareEditor;
  738.     Giocatore[playerid][Costruttore]=1;
  739.     format(stringa,sizeof(stringa),"Races/Race%d.txt",GareEditor);
  740.     new File:nomegara=fopen(stringa, io_write);
  741.     fwrite(nomegara,"Name,1,50,1000,Nobody,0");
  742.     fclose(nomegara);
  743.     return 1;
  744.     }
  745. //======================================CHECK
  746.     if (!strcmp("/check", cmdtext, true))
  747.     {
  748.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,ROSSO,"[ERROR:] {FFFFFF}You are not logged as RCON Admin");
  749.     if(Giocatore[playerid][Costruttore]==0) return SendClientMessage(playerid,ROSSO,"[ERROR:]{FFFFFF} You are not in builder mode.");
  750.     if(Giocatore[playerid][AttivaCheck]==0) return SendClientMessage(playerid,ROSSO,"[ERROR:]{FFFFFF} Finish to inserit race information before creating a checkpoint list.");
  751.     SendClientMessage(playerid,VERDE,"[CHECKPOINT:] {FFFFFF}Checkpoint saved.");
  752.     format(stringa,sizeof(stringa),"Races/Check%d.txt",Giocatore[playerid][GaraEditorId]);
  753.     new File:nomegara=fopen(stringa, io_append);
  754.     new stringagara[150];
  755.     GetPlayerPos(playerid,XPosizione,YPosizione,ZPosizione);
  756.     format(stringagara,sizeof(stringagara),"%f,%f,%f|",XPosizione,YPosizione,ZPosizione);
  757.     SetPlayerCheckpoint(playerid,XPosizione,YPosizione,ZPosizione,9);
  758.     fwrite(nomegara,stringagara);
  759.     fclose(nomegara);
  760.     return 1;
  761.     }
  762. //====================================FINECHECK
  763.     if(!strcmp("/endcheck", cmdtext, true))
  764.     {
  765.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,ROSSO,"[ERROR:] {FFFFFF}You are not logged as RCON Admin");
  766.     if(Giocatore[playerid][Costruttore]==0) return SendClientMessage(playerid,ROSSO,"[ERROR:]{FFFFFF} You are not in builder mode.");
  767.     if(Giocatore[playerid][AttivaCheck]==0) return SendClientMessage(playerid,ROSSO,"[ERROR:]{FFFFFF} To finish, create first a checkpoint list with /check");
  768.     Giocatore[playerid][Costruttore]=0;
  769.     Giocatore[playerid][AttivaCheck]=0;
  770.     SendClientMessage(playerid,BIANCO,"[EDITOR:] You completed the race.");
  771.     DisablePlayerCheckpoint(playerid);
  772.     SalvaGare();
  773.     for(new i=0;i<MAX_PLAYERS;i++){
  774.     LasciaGara(i);}
  775.     SendClientMessageToAll(BIANCO,"[ANNOUNCE:] Administrator has build a new race. In order to load all the other races have been forced to finish.");
  776.     CaricaGare();
  777.     return 1;
  778.     }
  779.     return 0;
  780. }
  781. //===================================================ONPLAYERENTERRACECHECKPOINT
  782. public OnPlayerEnterRaceCheckpoint(playerid)
  783. {
  784.  if(Giocatore[playerid][IdGara]==-1) return 1;
  785.  new g=Giocatore[playerid][IdGara];
  786.  new c=Giocatore[playerid][Checkpoint];
  787.  if(Gara[Giocatore[playerid][IdGara]][Avviata]==0) return 1;
  788.  SuonoGiocatore(playerid,1138);
  789.  //==============SECHECKPOINT==ULTIMO
  790.  if(Giocatore[playerid][Checkpoint]==Gara[Giocatore[playerid][IdGara]][NumeroCheckpoint])
  791.   {
  792.   //===========SEGIRO=ULTIMO
  793.   if(Giocatore[playerid][Giro]==Gara[Giocatore[playerid][IdGara]][Giri])
  794.     {
  795.     GetPlayerName(playerid,nome,sizeof(nome));
  796.     Gara[Giocatore[playerid][IdGara]][Podio]++;
  797.     if(Giocatore[playerid][Tempo]<Gara[Giocatore[playerid][IdGara]][Record])
  798.     {
  799.     new Minuti=floatround(Giocatore[playerid][Tempo]/60);
  800.     new Secondi=Giocatore[playerid][Tempo]-(Minuti*60);
  801.     format(stringa,sizeof(stringa),"[RECORD:] Player:{8ECE46}%s{FFFFFF} Track: {446ED1}%s{FFFFFF} Record: {C14124}%02d:%02d",nome,Gara[Giocatore[playerid][IdGara]][Nome],Minuti,Secondi);
  802.     SendClientMessageToAll(BIANCO,stringa);
  803.     Gara[Giocatore[playerid][IdGara]][Record]=Giocatore[playerid][Tempo];
  804.     format(Gara[Giocatore[playerid][IdGara]][GiocatoreRecord],25,nome);
  805.     }
  806.     if(!Gara[Giocatore[playerid][IdGara]][Inseguimento])
  807.     {
  808.     format(stringa,sizeof(stringa),"[RACE:] {8ECE46}%s{FFFFFF} finish the race. Position: {C14124}%d",nome,Gara[Giocatore[playerid][IdGara]][Podio]);
  809.     GivePlayerMoney(playerid,floatround(Gara[Giocatore[playerid][IdGara]][Costo]*Gara[Giocatore[playerid][IdGara]][PartecipantiPronti]/Gara[Giocatore[playerid][IdGara]][Podio]));
  810.     SendClientMessageToAll(BIANCO,stringa);
  811.     }
  812.     if(Gara[Giocatore[playerid][IdGara]][Inseguimento])
  813.     {
  814.     for(new i=0;i<MAX_PLAYERS;i++)
  815.      {
  816.      if(Giocatore[i][IdGara]==Giocatore[playerid][IdGara] && i!=playerid)
  817.       {
  818.       if(Giocatore[playerid][Punti]>=Giocatore[i][Punti])
  819.         {
  820.         GetPlayerName(playerid,nome,sizeof(nome));
  821.         format(stringa,sizeof(stringa),"[RACE:] {8ECE46}%s{FFFFFF} wons the chase race with {C14124}%d{FFFFFF} points.",nome,Giocatore[playerid][Punti]);
  822.         SendClientMessageToAll(BIANCO,stringa);
  823.         GivePlayerMoney(playerid,Gara[Giocatore[playerid][IdGara]][Costo]*2);
  824.         }
  825.       if(Giocatore[playerid][Punti]<Giocatore[i][Punti])
  826.         {
  827.         GetPlayerName(i,nome,sizeof(nome));
  828.         format(stringa,sizeof(stringa),"[RACE:] {8ECE46}%s{FFFFFF} wons the chase race with {C14124}%d{FFFFFF} points.",nome,Giocatore[i][Punti]);
  829.         SendClientMessageToAll(BIANCO,stringa);
  830.         GivePlayerMoney(i,Gara[Giocatore[playerid][IdGara]][Costo]*2);
  831.         }
  832.       LasciaGara(i);
  833.       }
  834.      }
  835.     }
  836.     DisablePlayerRaceCheckpoint(playerid);
  837.     LasciaGara(playerid);
  838.     return 1;
  839.     }
  840.   //========SEGIRO!=ULTIMO
  841.   else
  842.     {
  843.     Giocatore[playerid][Giro]++;
  844.     SetPlayerRaceCheckpoint(playerid,0,CheckpointGara[g][0][CXPos],CheckpointGara[g][0][CYPos],CheckpointGara[g][0][CZPos],CheckpointGara[g][1][CXPos],CheckpointGara[g][1][CYPos],CheckpointGara[g][1][CZPos],9);
  845.     Giocatore[playerid][Checkpoint]=0;
  846.     format(stringa,sizeof(stringa),"Laps: %d/%d",Giocatore[playerid][Giro],Gara[Giocatore[playerid][IdGara]][Giri]);
  847.     TextDrawSetString(TextGiriContatore[playerid],stringa);
  848.     return 1;
  849.     }
  850.   }
  851.   //=========SECHECKPOINTNORMALE
  852.  if(Giocatore[playerid][Checkpoint]<Gara[Giocatore[playerid][IdGara]][NumeroCheckpoint]-1)
  853.   {
  854.   Giocatore[playerid][Checkpoint]++;
  855.   c=Giocatore[playerid][Checkpoint];
  856.   SetPlayerRaceCheckpoint(playerid,0,CheckpointGara[g][c][CXPos],CheckpointGara[g][c][CYPos],CheckpointGara[g][c][CZPos],CheckpointGara[g][c+1][CXPos],CheckpointGara[g][c+1][CYPos],CheckpointGara[g][c+1][CZPos],9);
  857.   return 1;
  858.   }
  859.  //=========SECHECKPOINTFINALE
  860.  else if(Giocatore[playerid][Checkpoint]==Gara[Giocatore[playerid][IdGara]][NumeroCheckpoint]-1)
  861.   {
  862.   Giocatore[playerid][Checkpoint]++;
  863.   c=Giocatore[playerid][Checkpoint];
  864.   SetPlayerRaceCheckpoint(playerid,1,CheckpointGara[g][c][CXPos],CheckpointGara[g][c][CYPos],CheckpointGara[g][c][CZPos],CheckpointGara[g][c+1][CXPos],CheckpointGara[g][c+1][CYPos],CheckpointGara[g][c+1][CZPos],9);
  865.   return 1;
  866.   }
  867.  return 1;
  868. }
  869. //===================================================ONPLAYERLEAVERACECHECKPOINT
  870. public OnPlayerLeaveRaceCheckpoint(playerid)
  871. {
  872.     OnPlayerEnterRaceCheckpoint(playerid);
  873.     return 1;
  874. }
  875. //==============================================================ONDIALOGRESPONSE
  876. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  877. {
  878.     if(dialogid==DIALOGINFOGARA2)
  879.       {
  880.       Giocatore[playerid][AttivaCheck]=1;
  881.       return 1;
  882.       }
  883.     if(dialogid==DIALOGINSEGUIMENTO)
  884.       {
  885.       if(strcmp(inputtext,"Yes",true) && strcmp(inputtext,"No",true)) return ShowPlayerDialog(playerid,DIALOGINSEGUIMENTO,DIALOG_STYLE_INPUT,"Chase option","{FFFFFF}ERROR:\nType Yes or No\nDo you want this race to be a Chase type?\n(Type Yes or No)","Continue","");
  886.       format(stringa,sizeof(stringa),"Races/Race%d.txt",Giocatore[playerid][GaraEditorId]);
  887.       new File:nomegara=fopen(stringa, io_append);
  888.       if(!strcmp(inputtext,"Yes",true))
  889.       fwrite(nomegara,",1");
  890.       if(!strcmp(inputtext,"No",true))
  891.       fwrite(nomegara,",0");
  892.       fclose(nomegara);
  893.       ShowPlayerDialog(playerid,DIALOGINFOGARA2,0,"Race Info Menu","{FFFFFF}You created the race's info file.\nNow you need a checkpoint list.\nUse the command \"{C14124}/check{FFFFFF}\" to create checkpoint for your race.\nOnce you've finished, type \"{C14124}/endcheck{FFFFFF}\" to exit builder mode and load the new race.","Go","");
  894.       return 1;
  895.       }
  896.     if(dialogid==DIALOGCOSTOGARA)
  897.       {
  898.       if(!strlen(inputtext) || !isNumeric(inputtext) || strval(inputtext)<=0) return ShowPlayerDialog(playerid,DIALOGCOSTOGARA,DIALOG_STYLE_INPUT,"Race's Cost","{FFFFFF}Type the cost to join your race (min 1):","Continue","");
  899.       format(stringa,sizeof(stringa),"Races/Race%d.txt",Giocatore[playerid][GaraEditorId]);
  900.       new File:nomegara=fopen(stringa, io_append);
  901.       GetPlayerName(playerid,nome,sizeof(nome));
  902.       format(stringa,sizeof(stringa),"%d,1000,Nobody,%s",strval(inputtext),nome);
  903.       fwrite(nomegara,stringa);
  904.       fclose(nomegara);
  905.       ShowPlayerDialog(playerid,DIALOGINSEGUIMENTO,DIALOG_STYLE_INPUT,"Chase option","{FFFFFF}Do you want this race to be a Chase type?\n(Type Yes or No)","Continue","");
  906.       return 1;
  907.       }
  908.     if(dialogid==DIALOGGIRIGARA)
  909.       {
  910.       if(!strlen(inputtext) || !isNumeric(inputtext) || strval(inputtext)<=0) return ShowPlayerDialog(playerid,DIALOGGIRIGARA,DIALOG_STYLE_INPUT,"Race's Laps","{FFFFFF}ERROR:\nType the number of laps for your races (1:sprint 2-more:circuit)","Continue","");
  911.       format(stringa,sizeof(stringa),"Races/Race%d.txt",Giocatore[playerid][GaraEditorId]);
  912.       new File:nomegara=fopen(stringa, io_append);
  913.       format(stringa,sizeof(stringa),"%d,",strval(inputtext));
  914.       fwrite(nomegara,stringa);
  915.       fclose(nomegara);
  916.       ShowPlayerDialog(playerid,DIALOGCOSTOGARA,DIALOG_STYLE_INPUT,"Race's Cost","{FFFFFF}Type the cost to join your race (min 1):","Continue","");
  917.       return 1;
  918.       }
  919.     if(dialogid==DIALOGNOMEGARA)
  920.       {
  921.       if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOGNOMEGARA,DIALOG_STYLE_INPUT,"Race's Name","{FFFFFF}ERROR:\nType the name of your race:","Continua","");
  922.       format(stringa,sizeof(stringa),"Races/Race%d.txt",Giocatore[playerid][GaraEditorId]);
  923.       new File:nomegara=fopen(stringa, io_write);
  924.       format(stringa,sizeof(stringa),"%s,",inputtext);
  925.       fwrite(nomegara,stringa);
  926.       fclose(nomegara);
  927.       ShowPlayerDialog(playerid,DIALOGGIRIGARA,DIALOG_STYLE_INPUT,"Race's Laps","{FFFFFF}Type the number of laps for your races (1:sprint 2-more:circuit)","Continue","");
  928.       return 1;
  929.       }
  930.     if(dialogid==DIALOGINFOCOSTRUTTORE)
  931.       {
  932.       ShowPlayerDialog(playerid,DIALOGNOMEGARA,DIALOG_STYLE_INPUT,"Race's Name","{FFFFFF}Type the name of you race:","Continue","");
  933.       return 1;
  934.       }
  935.     if(dialogid==DIALOGINFO) return 1;
  936.     if(dialogid==DIALOGGARE && response)
  937.     {
  938.     if(Giocatore[playerid][IdGara]!=-1) return SendClientMessage(playerid,ROSSO,"[ERROR:] {FFFFFF}You already joined another race.");
  939.     if(Gara[listitem][Avviata]==1) return SendClientMessage(playerid,ROSSO,"[ERROR:] {FFFFFF}This race is already started. Wait its ending before joining.");
  940.     if(Gara[listitem][Inseguimento]==1)
  941.     {
  942.     if(Gara[listitem][Partecipanti]==2) return SendClientMessage(playerid,ROSSO,"[ERROR:] {FFFFFF}There are already two player in this race (chase race limit)");
  943.     if(Gara[listitem][Partecipanti]==0)
  944.      {
  945.      SendClientMessage(playerid,BIANCO,"[RACE:] You are the hunted. When the race starts, stay in front of your opponent and try to escape.");
  946.      }
  947.     if(Gara[listitem][Partecipanti]==1)
  948.      {
  949.      SendClientMessage(playerid,BIANCO,"[RACE:] You are the hunter. When the race starts, stay behind your opponent and chase him.");
  950.      Giocatore[playerid][Inseguitore]=1;
  951.      }
  952.     }
  953.     Giocatore[playerid][IdGara]=listitem;
  954.     GetPlayerName(playerid,nome,sizeof(nome));
  955.     format(stringa,sizeof(stringa),"{8CE46C}%s {FFFFFF}join the race.",nome);
  956.     GivePlayerMoney(playerid,-Gara[listitem][Costo]);
  957.     MandaMessaggioPartecipanti(listitem,stringa);
  958.     #if defined TELETRASPORTO_INIZIAGARA
  959.     SetPlayerPos(playerid,CheckpointGara[listitem][0][CXPos],CheckpointGara[listitem][0][CYPos],CheckpointGara[listitem][0][CZPos]);
  960.     SendClientMessage(playerid,BIANCO,"[RACE:] You join the race. Type \"{C14124}/Ready{FFFFFF}\" when you are ready.");
  961.     #else
  962.     SendClientMessage(playerid,BIANCO,"[RACE:] You join the race. Go to the checkpoint and type \"{C14124}/Ready{FFFFFF}\" when you are ready");
  963.     #endif
  964.     Gara[listitem][Partecipanti]++;
  965.     SetPlayerRaceCheckpoint(playerid,0,CheckpointGara[listitem][0][CXPos],CheckpointGara[listitem][0][CYPos],CheckpointGara[listitem][0][CZPos],CheckpointGara[listitem][1][CXPos],CheckpointGara[listitem][1][CYPos],CheckpointGara[listitem][1][CZPos],9);
  966.     new minuti=floatround(Gara[listitem][Record]/60);
  967.     new secondi=Gara[listitem][Record]-(minuti*60);
  968.     format(stringa,sizeof(stringa),"{FFFFFF}Track: {8CE46C}%s\n{FFFFFF}Laps: {8CE46C}%d\n{FFFFFF}Cost: {8CE46C}%d$\n{FFFFFF}Record: {8CE46C}%02d:%02d\n{FFFFFF}Player's Record: {8CE46C}%s\n{FFFFFF}Builder: {8CE46C}%s",Gara[listitem][Nome],Gara[listitem][Giri],Gara[listitem][Costo],minuti,secondi,Gara[listitem][GiocatoreRecord],Gara[listitem][Produttore]);
  969.     ShowPlayerDialog(playerid,DIALOGINFO,0,"Race Info",stringa,"Quit","");
  970.     return 1;
  971.     }
  972.     return 1;
  973. }
  974. //====================================================MANDAMESSAGGIOPARTECIPANTI
  975. stock MandaMessaggioPartecipanti(idGara,Messaggio[])
  976. {
  977.  for(new i=0;i<MAX_PLAYERS;i++)
  978.  {
  979.  if(Giocatore[i][IdGara]==idGara)
  980.  SendClientMessage(i,BIANCO,Messaggio);
  981.  }
  982. }
  983. //================================================================SUONOGIOCATORE
  984. stock SuonoGiocatore(playerid,idsuono)
  985. {
  986.  new Float:SPosX,Float:SPosY,Float:SPosZ;
  987.  GetPlayerPos(playerid,SPosX,SPosY,SPosZ);
  988.  PlayerPlaySound(playerid,idsuono,SPosX,SPosY,SPosZ);
  989.  return 1;
  990. }
  991. //=========================================================================SPLIT
  992. stock split(const strsrc[], strdest[][], delimiter)
  993. {
  994.     new i, li,aNum,len;
  995.     while(i <= strlen(strsrc))
  996.     {
  997.         if(strsrc[i]==delimiter || i==strlen(strsrc))
  998.         {
  999.             len = strmid(strdest[aNum], strsrc, li, i, 128);
  1000.             strdest[aNum][len] = 0;
  1001.             li = i+1;
  1002.             aNum++;
  1003.         }
  1004.         i++;
  1005.     }
  1006.     return 1;
  1007. }
  1008. //=====================================================================ISNUMERIC
  1009. stock isNumeric(const string[]) {
  1010.     new length=strlen(string);
  1011.     if (length==0) return false;
  1012.     for (new i = 0; i < length; i++) {
  1013.         if (
  1014.         (string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+')
  1015.         || (string[i]=='-' && i!=0)                                            
  1016.         || (string[i]=='+' && i!=0)                                            
  1017.         ) return false;
  1018.     }
  1019.     if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
  1020.     return true;
  1021. }
Advertisement
Add Comment
Please, Sign In to add comment