Advertisement
Guest User

Race Systém by Angelus

a guest
Nov 10th, 2012
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 28.96 KB | None | 0 0
  1. /*
  2.  
  3.  
  4.  
  5. ================================================================================
  6. --------------------------------------------------------------------------------
  7. ================================================================================
  8.  
  9.                                Race System
  10.                                
  11.                                Verzia: 1.0
  12.  
  13.                             Created by Angelus
  14.  
  15.                            4.6.2012 - 6.6.2012
  16.  
  17.                             Copyright © 2012
  18.  
  19. ================================================================================
  20. --------------------------------------------------------------------------------
  21. ================================================================================
  22.  
  23.  
  24.  
  25. */
  26. //INCLUDE
  27. #include                        <a_samp>
  28. #include                        <dini>
  29. #define MAX_PLAYERS_EX          MAX_PLAYERS
  30.  
  31. //DEFINE
  32. #define MAX_RACE_CPS            30
  33. #define MAX_RACE                10
  34. #define MAX_RACERS              15
  35.  
  36. //Názvy PVarov
  37. #define CRace                   "CreatingRace"
  38. #define CID                     "CreatingID"
  39. #define CPC                     "CPCount"
  40. #define CRP                     "CarRacePlace"
  41. #define ARID                    "ActuallyRaceID"
  42. #define PJTR                    "PlayerJoinedToRace"
  43. #define PRV                     "PlayerRaceVehicle"
  44. #define PCP                     "PlayerCheckpoint"
  45.  
  46. #define QCMD:%1(%2)             \
  47.                                 forward cmd_%1(%2); \
  48.                                 public cmd_%1(%2)
  49.  
  50. #define DIALOG_ERROR            133
  51. #define DIALOG_RACES            155
  52. #define DIALOG_MANAGE_RACE      166
  53. #define DIALOG_SETWIN           177
  54.  
  55. #define SCM                     SendClientMessage
  56. #define SCMTA                   SendClientMessageToAll
  57.  
  58. #define ADMINCOL                0xFFB666FF
  59. #define RED                     0xFF0000FF
  60.  
  61. //
  62. #define RCON_Allowed
  63. //Ak chceš použiť vlastnú podmienku pre admina na vytvorenie závodu, daj "//" (bez úvodzoviek) na začiatok
  64. //riadku 63 a uprav riadky:
  65.  
  66. //ENUM
  67. enum Race_Info
  68. {
  69.     Float:RaceX,
  70.     Float:RaceY,
  71.     Float:RaceZ,
  72.     Float:Radius,
  73. };
  74.  
  75. enum Race__Info
  76. {
  77.     Name[50],
  78.     bool:RaceCreating,
  79.     bool:RaceCreated,
  80.     ModelVozu,
  81.     CPs,
  82.     Places,
  83.     Win,
  84.     Interier,
  85. };
  86.  
  87. enum Racers_Info
  88. {
  89.     Float:RposX,
  90.     Float:RposY,
  91.     Float:RposZ,
  92.     Float:RposF,
  93. };
  94.  
  95. //NEWS
  96. new RaceCPInfo[MAX_RACE][MAX_RACE_CPS][Race_Info];
  97. new RaceInfo[MAX_RACE][Race__Info];
  98. new RacersInfo[MAX_RACE][MAX_RACERS][Racers_Info];
  99. new RaceTimer;
  100. new RaceTimerCount;
  101. new RaceUcastnici;
  102. new RaceStartedID;
  103. new RaceEndPlace;
  104. new bool:RaceStarted;
  105. new bool:RaceStarting;
  106. new RaceCount=-1;
  107.  
  108. //FORWARD
  109. forward CreatingRace(playerid,name[],model);
  110. forward EndCRace(playerid,bool:MozeVytvoritRace);
  111. forward AddCheckpoint(playerid,Float:radius);
  112. forward AddRacePlace(playerid);
  113. forward EndPlayerRace(playerid,reason[]);
  114. forward Start();
  115. forward Jeden();
  116. forward Dva();
  117. forward Tri();
  118. forward Drei();
  119. forward LoadPlayersOnRacePlace();
  120. forward PredcasnyKonec();
  121. // !!! Pod týmto riadkom vložiť do módu !!!
  122. forward RaceOnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
  123. forward RaceOnPlayerDisconnect(playerid);
  124. forward RaceOnPlayerDeath(playerid);
  125. forward RaceOnPlayerExitVehicle(playerid);
  126. forward RaceOnPlayerEnterRaceCP(playerid);
  127. forward RaceOnGameModeInit();
  128.  
  129. //PUBLIC
  130. public CreatingRace(playerid,name[],model)
  131. {
  132.     if(MAX_RACE > RaceCount)
  133.     {
  134.         SCM(playerid,ADMINCOL,"Začal si vytvárať závod. Teraz vytvor závodné miesta na štarte pomocou /saveplace");
  135.         SetPVarInt(playerid,CRace,1);
  136.         SetPVarInt(playerid,CID,GetPlayerFreeRaceID());
  137.         SetPVarInt(playerid,CPC,0);
  138.         RaceInfo[GetPVarInt(playerid,CID)][RaceCreating]=true;
  139.         RaceInfo[GetPVarInt(playerid,CID)][ModelVozu]=model;
  140.         RaceInfo[GetPVarInt(playerid,CID)][Interier]=GetPlayerInterior(playerid);
  141.         format(RaceInfo[GetPVarInt(playerid,CID)][Name],50,"%s",name);
  142.     }
  143.     else
  144.         SCM(playerid,RED,"Nemôžeš vytvoriť závod, bol naplnený maximálny limit závodov!");
  145.     return 1;
  146. }
  147.  
  148. public EndCRace(playerid,bool:MozeVytvoritRace)
  149. {
  150.     if(MozeVytvoritRace)
  151.     {
  152.         if(GetPVarInt(playerid,CRP)<2)return SCM(playerid,RED,"Musíš vytvoriť aspoň 2 závodné miesta!");
  153.         if(GetPVarInt(playerid,CPC)<2)return SCM(playerid,RED,"Musíš vytvoriť aspoň 2 checkpointy!");
  154.        
  155.         new s[75],cid=GetPVarInt(playerid,CID),i;
  156.        
  157.         format(s,sizeof(s),"Races/Race%d.ini",cid);
  158.        
  159.         if(fexist(s))return SCM(playerid,RED,"ERROR: Súbor s ID tohto závodu už existuje!");
  160.        
  161.         dini_Create(s);
  162.         dini_Set(s,"Name",RaceInfo[cid][Name]);
  163.         dini_IntSet(s,"RaceModel",RaceInfo[cid][ModelVozu]);
  164.         dini_IntSet(s,"CPs",GetPVarInt(playerid,CPC));
  165.         dini_IntSet(s,"Places",GetPVarInt(playerid,CRP));
  166.         dini_IntSet(s,"Interior",RaceInfo[cid][Interier]);
  167.        
  168.         RaceInfo[cid][CPs]=GetPVarInt(playerid,CPC);
  169.         RaceInfo[cid][Places]=GetPVarInt(playerid,CRP);
  170.        
  171.         for( ;i<GetPVarInt(playerid,CPC);i++)
  172.         {
  173.             format(s,sizeof(s),"Races/Race%d CP%d.ini",cid,i);
  174.             dini_Create(s);
  175.             dini_FloatSet(s,"PosX",RaceCPInfo[cid][i][RaceX]);
  176.             dini_FloatSet(s,"PosY",RaceCPInfo[cid][i][RaceY]);
  177.             dini_FloatSet(s,"PosZ",RaceCPInfo[cid][i][RaceZ]);
  178.             dini_FloatSet(s,"Radius",RaceCPInfo[cid][i][Radius]);
  179.         }
  180.         i=0;
  181.        
  182.         for( ;i<GetPVarInt(playerid,CRP);i++)
  183.         {
  184.             format(s,sizeof(s),"Races/Race%d Place%d.ini",cid,i);
  185.             dini_Create(s);
  186.             dini_FloatSet(s,"PosX",RacersInfo[cid][i][RposX]);
  187.             dini_FloatSet(s,"PosY",RacersInfo[cid][i][RposY]);
  188.             dini_FloatSet(s,"PosZ",RacersInfo[cid][i][RposZ]);
  189.             dini_FloatSet(s,"ZAngle",RacersInfo[cid][i][RposF]);
  190.         }
  191.        
  192.         RaceInfo[GetPVarInt(playerid,CID)][RaceCreating]=false;
  193.         RaceInfo[GetPVarInt(playerid,CID)][RaceCreated]=true;
  194.        
  195.         SCM(playerid,ADMINCOL,"Ukončil si vytvárenie závodu. Teraz môžeš spustiť závod pomocou /races!");
  196.        
  197.         RaceCount++;
  198.     }
  199.     else
  200.     {
  201.         SCM(playerid,ADMINCOL,"Ukončil si vytváranie závodu, závod nebol uložený.");
  202.         RaceInfo[GetPVarInt(playerid,CID)][RaceCreating]=false;
  203.     }
  204.        
  205.     DeletePVar(playerid,CRace);
  206.     DeletePVar(playerid,CID);
  207.     DeletePVar(playerid,CPC);
  208.     DeletePVar(playerid,CRP);
  209.     return 1;
  210. }
  211.  
  212. public AddCheckpoint(playerid,Float:radius)
  213. {
  214.     new i = GetPVarInt(playerid,CPC);
  215.     if(MAX_RACE_CPS > i)
  216.     {
  217.         new Float:p1,Float:p2,Float:p3,b=GetPVarInt(playerid,CID);
  218.         GetPlayerPos(playerid,p1,p2,p3);
  219.        
  220.         RaceCPInfo[b][i][RaceX]=p1;
  221.         RaceCPInfo[b][i][RaceY]=p2;
  222.         RaceCPInfo[b][i][RaceZ]=p3;
  223.         RaceCPInfo[b][i][Radius]=radius;
  224.        
  225.         SetPVarInt(playerid,CPC,i+1);
  226.        
  227.         new s[60];
  228.         format(s,60,"* Vytvorený Checkpoint %d/%d!",i+1,MAX_RACE_CPS);
  229.         SCM(playerid,ADMINCOL,s);
  230.     }
  231.     else
  232.     {
  233.         SCM(playerid,RED,"Nemôžeš vytvoriť ďalší Checkpoint, už bol naplnený limit!");
  234.     }
  235.     return 1;
  236. }
  237.  
  238. public AddRacePlace(playerid)
  239. {
  240.     new i = GetPVarInt(playerid,CRP);
  241.     if(MAX_RACERS > i)
  242.     {
  243.         new Float:p1,Float:p2,Float:p3,Float:p4,b=GetPVarInt(playerid,CID);
  244.         GetVehiclePos(GetPlayerVehicleID(playerid),p1,p2,p3);
  245.         GetVehicleZAngle(GetPlayerVehicleID(playerid),p4);
  246.  
  247.         RacersInfo[b][i][RposX]=p1;
  248.         RacersInfo[b][i][RposY]=p2;
  249.         RacersInfo[b][i][RposZ]=p3;
  250.         RacersInfo[b][i][RposF]=p4;
  251.  
  252.         SetPVarInt(playerid,CRP,i+1);
  253.  
  254.         new s[60];
  255.         format(s,60,"* Vytvorené Závodné Miesto %d/%d!",i+1,MAX_RACERS);
  256.         SCM(playerid,ADMINCOL,s);
  257.     }
  258.     else
  259.     {
  260.         SCM(playerid,RED,"Nemôžeš vytvoriť ďalšie Závodné Miesto, už si naplnil limit (15 miest) !");
  261.     }
  262.     return 1;
  263. }
  264.  
  265. public EndPlayerRace(playerid,reason[])
  266. {
  267.     DestroyVehicle(GetPVarInt(playerid,PRV));
  268.     DeletePVar(playerid,PJTR);
  269.     DeletePVar(playerid,PRV);
  270.     DeletePVar(playerid,PCP);
  271.     DisablePlayerRaceCheckpoint(playerid);
  272.     SetPlayerInterior(playerid,0);
  273.     SpawnPlayer(playerid);
  274.     RaceUcastnici--;
  275.    
  276.     new s[128];
  277.     format(s,sizeof(s),"* Hráč %s (ID:%d) ukončil závod [ Dôvod: %s ]. V závode ostalo %d hráčov.",PlayerName(playerid),playerid,reason,RaceUcastnici);
  278.     SCMTA(ADMINCOL,s);
  279.    
  280.     if(RaceUcastnici==1)
  281.     {
  282.         for(new i;i<MAX_PLAYERS_EX;i++)
  283.         {
  284.             if(GetPVarInt(i,PJTR))
  285.             {
  286.                 DestroyVehicle(GetPVarInt(i,PRV));
  287.                 DeletePVar(i,PJTR);
  288.                 DeletePVar(i,PRV);
  289.                 DeletePVar(i,PCP);
  290.                 DisablePlayerRaceCheckpoint(i);
  291.                 SetPlayerInterior(playerid,0);
  292.                 SpawnPlayer(i);
  293.                
  294.                 format(s,sizeof(s),"* Hráč %s (ID:%d) kontumačne vyhral závod! Dostane výhru %d$",PlayerName(i),i,RaceInfo[RaceStartedID][Win]);
  295.                 SCMTA(ADMINCOL,s);
  296.                
  297.                 GivePlayerMoney(i,RaceInfo[RaceStartedID][Win]);
  298.                
  299.                 RaceStarted=false;
  300.                
  301.                 break;
  302.             }
  303.         }
  304.     }
  305. }
  306.  
  307. public Start()
  308. {
  309.     for(new i;i<MAX_PLAYERS_EX;i++)
  310.     {
  311.         if(GetPVarInt(i,PJTR))
  312.         {
  313.             GameTextForPlayer(i,"~r~start",1000,5);
  314.             TogglePlayerControllable(i,true);
  315.             SetPVarInt(i,PCP,0);
  316.             SetPlayerRaceCheckpoint(i,0,RaceCPInfo[RaceStartedID][0][RaceX],RaceCPInfo[RaceStartedID][0][RaceY],RaceCPInfo[RaceStartedID][0][RaceZ],RaceCPInfo[RaceStartedID][1][RaceX],RaceCPInfo[RaceStartedID][1][RaceY],RaceCPInfo[RaceStartedID][1][RaceZ],RaceCPInfo[RaceStartedID][0][Radius]);
  317.         }
  318.     }
  319. }
  320.  
  321. public Jeden()
  322. {
  323.     for(new i;i<MAX_PLAYERS_EX;i++)
  324.     {
  325.         if(GetPVarInt(i,PJTR))
  326.         {
  327.             GameTextForPlayer(i,"~r~1",1000,5);
  328.         }
  329.     }
  330.     SetTimer("Start",1050,false);
  331. }
  332.  
  333. public Dva()
  334. {
  335.     for(new i;i<MAX_PLAYERS_EX;i++)
  336.     {
  337.         if(GetPVarInt(i,PJTR))
  338.         {
  339.             GameTextForPlayer(i,"~r~2",1000,5);
  340.         }
  341.     }
  342.     SetTimer("Jeden",1050,false);
  343. }
  344.  
  345. public Tri()
  346. {
  347.     for(new i;i<MAX_PLAYERS_EX;i++)
  348.     {
  349.         if(GetPVarInt(i,PJTR))
  350.         {
  351.             GameTextForPlayer(i,"~r~3",1000,5);
  352.         }
  353.     }
  354.     SetTimer("Dva",1050,false);
  355. }
  356.  
  357. public Drei()
  358. {
  359.     RaceTimerCount--;
  360.    
  361.     if(RaceTimerCount == 40 || RaceTimerCount == 20 || RaceTimerCount == 10 || RaceTimerCount == 5)
  362.     {
  363.         new s[128];
  364.         format(s,128,"Bol vytvorený závod %s. Výhra: $%d. Pripojíte sa pomocou /joinrace. Ostáva %d sekúnd do štartu!",RaceInfo[RaceStartedID][Name],RaceInfo[RaceStartedID][Win],RaceTimerCount);
  365.         SCMTA(ADMINCOL,s);
  366.     }
  367.     if(RaceTimerCount==0)
  368.     {
  369.         KillTimer(RaceTimer);
  370.         if(RaceUcastnici<2)
  371.         {
  372.             SCMTA(ADMINCOL,"* Závod bol zrušený kvôli nedostatku účastníkov!");
  373.         }
  374.         else
  375.         {
  376.             RaceStarting=false;
  377.             RaceStarted=true;
  378.             LoadPlayersOnRacePlace();
  379.             SetTimer("Tri",5050,false);
  380.         }
  381.         RaceStarting=false;
  382.     }
  383. }
  384.  
  385. public LoadPlayersOnRacePlace()
  386. {
  387.     new count;
  388.     for(new i;i<MAX_PLAYERS_EX;i++)
  389.     {
  390.         if(GetPVarInt(i,PJTR))
  391.         {
  392.             SetPVarInt(i,PRV,CreateVehicle(RaceInfo[RaceStartedID][ModelVozu],RacersInfo[RaceStartedID][count][RposX],RacersInfo[RaceStartedID][count][RposY],RacersInfo[RaceStartedID][count][RposZ],RacersInfo[RaceStartedID][count][RposF],random(150),random(150),-1));
  393.             LinkVehicleToInterior(GetPVarInt(i,PRV),RaceInfo[RaceStartedID][Interier]);
  394.             SetPlayerInterior(i,RaceInfo[RaceStartedID][Interier]);
  395.             PutPlayerInVehicle(i,GetPVarInt(i,PRV),0);
  396.             SetCameraBehindPlayer(i);
  397.             TogglePlayerControllable(i,false);
  398.             SCM(i,ADMINCOL,"Bol si spawnutý na dráhu závodu! Počkaj na odštartovánie závodu!");
  399.             count++;
  400.         }
  401.     }
  402.     RaceUcastnici=count;
  403. }
  404.  
  405. public PredcasnyKonec()
  406. {
  407.     if(RaceStarted)
  408.     {
  409.         for(new a;a<MAX_PLAYERS_EX;a++)
  410.         {
  411.             if(GetPVarInt(a,PJTR))
  412.             {
  413.                 DestroyVehicle(GetPVarInt(a,PRV));
  414.                 DeletePVar(a,PJTR);
  415.                 DeletePVar(a,PRV);
  416.                 DeletePVar(a,PCP);
  417.                 DisablePlayerRaceCheckpoint(a);
  418.                 SetPlayerInterior(a,0);
  419.                 SpawnPlayer(a);
  420.             }
  421.         }
  422.         RaceStarted=false;
  423.         RaceEndPlace=0;
  424.         SCMTA(ADMINCOL,"* Závod skončil. Ďakujeme všetkým závodníkom za účasť!");
  425.     }
  426. }
  427.  
  428. public RaceOnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  429. {
  430.     if(dialogid == DIALOG_RACES && response)
  431.     {
  432.         if(!RaceInfo[listitem][RaceCreated])
  433.         {
  434.             DialogListOfRaces(playerid);
  435.         }
  436.         else
  437.         {
  438.             SetPVarInt(playerid,ARID,listitem);
  439.             new s[128];
  440.             format(s,sizeof(s),"Info: Počet Checkpointov: %d | Počet závodných miest: %d\nSpustiť\nZmazať",RaceInfo[listitem][CPs],RaceInfo[listitem][Places]);
  441.             ShowPlayerDialog(playerid,DIALOG_MANAGE_RACE,DIALOG_STYLE_LIST,RaceInfo[listitem][Name],s,"Vybrať","Koniec");
  442.         }
  443.     }
  444.     if(dialogid == DIALOG_MANAGE_RACE)
  445.     {
  446.         if(response)
  447.         {
  448.             if(listitem == 0)
  449.             {
  450.                 new s[128];
  451.                 format(s,sizeof(s),"Info: Počet Checkpointov: %d | Počet závodných miest: %d\nSpustiť\nZmazať",RaceInfo[GetPVarInt(playerid,ARID)][CPs],RaceInfo[GetPVarInt(playerid,ARID)][Places]);
  452.                 ShowPlayerDialog(playerid,DIALOG_MANAGE_RACE,DIALOG_STYLE_LIST,RaceInfo[GetPVarInt(playerid,ARID)][Name],s,"Vybrat","Konec");
  453.             }
  454.             else if(listitem == 1)
  455.             {
  456.                 if(RaceStarted || RaceStarting)return SCM(playerid,RED,"Niekto už spúšťa závod!");
  457.                 ShowPlayerDialog(playerid,DIALOG_SETWIN,DIALOG_STYLE_INPUT,RaceInfo[GetPVarInt(playerid,ARID)][Name],"Zadejte výhru závodu:","Zadat","Konec");
  458.             }
  459.             else if(listitem == 2)
  460.             {
  461.                 new s[128],cid=GetPVarInt(playerid,ARID),i;
  462.                 DeletePVar(playerid,ARID);
  463.  
  464.                 format(s,sizeof(s),"Races/Race%d.ini",cid);
  465.  
  466.                 dini_Remove(s);
  467.  
  468.                 RaceInfo[cid][RaceCreated]=false;
  469.  
  470.                 for( ;i<RaceInfo[cid][CPs];i++)
  471.                 {
  472.                     format(s,sizeof(s),"Races/Race%d CP%d.ini",cid,i);
  473.                     dini_Remove(s);
  474.                     RaceCPInfo[cid][i][RaceX]=0;
  475.                     RaceCPInfo[cid][i][RaceY]=0;
  476.                     RaceCPInfo[cid][i][RaceZ]=0;
  477.                     RaceCPInfo[cid][i][Radius]=0;
  478.                 }
  479.                 i=0;
  480.  
  481.                 for( ;i<RaceInfo[cid][Places];i++)
  482.                 {
  483.                     format(s,sizeof(s),"Races/Race%d Place%d.ini",cid,i);
  484.                     dini_Remove(s);
  485.                     RacersInfo[cid][i][RposX]=0;
  486.                     RacersInfo[cid][i][RposY]=0;
  487.                     RacersInfo[cid][i][RposZ]=0;
  488.                     RacersInfo[cid][i][RposF]=0;
  489.                 }
  490.                 format(RaceInfo[cid][Name],50," ");
  491.                 format(s,sizeof(s),"* Závod %s bol zmazaný!",RaceInfo[cid][Name]);
  492.                 SCM(playerid,ADMINCOL,s);
  493.             }
  494.         }
  495.         else
  496.         {
  497.             DeletePVar(playerid,ARID);
  498.         }
  499.     }
  500.     if(dialogid == DIALOG_SETWIN)
  501.     {
  502.         if(response)
  503.         {
  504.             if(!strlen(inputtext))return ShowPlayerDialog(playerid,DIALOG_SETWIN,DIALOG_STYLE_INPUT,RaceInfo[GetPVarInt(playerid,ARID)][Name],"Zadejte výhru závodu:","Zadat","Konec");
  505.  
  506.             new cid=GetPVarInt(playerid,ARID);
  507.  
  508.             RaceInfo[cid][Win]=strval(inputtext);
  509.  
  510.             new s[128];
  511.             format(s,sizeof(s),"* Admin %s (ID:%d) vytvoril závod %s pre %d hráčov. Výhra: %d$. Závod bude spustený o 60 sekúnd!",PlayerName(playerid),playerid,RaceInfo[cid][Name],RaceInfo[cid][Places],RaceInfo[cid][Win]);
  512.             SCMTA(ADMINCOL,s);
  513.            
  514.             format(s,128,"Bol vytvorený závod %s. Výhra: $%d. Pripojíte sa pomocou /joinrace. Ostáva 60 sekúnd do štartu!",RaceInfo[cid][Name],RaceInfo[cid][Win]);
  515.             SCMTA(ADMINCOL,s);
  516.            
  517.             RaceTimerCount=60;
  518.             RaceStarting=true;
  519.             RaceUcastnici=0;
  520.             RaceStartedID=cid;
  521.             RaceTimer=SetTimer("Drei",1000,true);
  522.         }
  523.         DeletePVar(playerid,ARID);
  524.     }
  525.     return 1;
  526. }
  527.  
  528. public RaceOnPlayerDisconnect(playerid)
  529. {
  530.     if(GetPVarInt(playerid,CRace))
  531.         EndCRace(playerid,false);
  532.     if(RaceStarting)
  533.     {
  534.         if(GetPVarInt(playerid,PJTR))
  535.         {
  536.             RaceUcastnici--;
  537.         }
  538.     }
  539.     if(RaceStarted)
  540.     {
  541.         if(GetPVarInt(playerid,PJTR))
  542.         {
  543.             EndPlayerRace(playerid,"Odišiel zo serveru");
  544.         }
  545.     }
  546. }
  547.  
  548. public RaceOnPlayerDeath(playerid)
  549. {
  550.     if(GetPVarInt(playerid,CRace))
  551.         EndCRace(playerid,false);
  552.     if(RaceStarted)
  553.     {
  554.         if(GetPVarInt(playerid,PJTR))
  555.         {
  556.             EndPlayerRace(playerid,"Smrť");
  557.         }
  558.     }
  559. }
  560.  
  561. public RaceOnPlayerExitVehicle(playerid)
  562. {
  563.     if(RaceStarted)
  564.     {
  565.         if(GetPVarInt(playerid,PJTR))
  566.         {
  567.             EndPlayerRace(playerid,"Vystúpenie z vozidla");
  568.         }
  569.     }
  570. }
  571.  
  572. public RaceOnPlayerEnterRaceCP(playerid)
  573. {
  574.     if(GetPVarInt(playerid,PJTR))
  575.     {
  576.         new i=GetPVarInt(playerid,PCP)+1;
  577.         SetPVarInt(playerid,PCP,i);
  578.        
  579.         if(i == (RaceInfo[RaceStartedID][CPs]-1))
  580.         {
  581.             SetPlayerRaceCheckpoint(playerid,1,RaceCPInfo[RaceStartedID][i][RaceX],RaceCPInfo[RaceStartedID][i][RaceY],RaceCPInfo[RaceStartedID][i][RaceZ],RaceCPInfo[RaceStartedID][i+1][RaceX],RaceCPInfo[RaceStartedID][i+1][RaceY],RaceCPInfo[RaceStartedID][i+1][RaceZ],RaceCPInfo[RaceStartedID][i][Radius]);
  582.         }
  583.         else if(i == RaceInfo[RaceStartedID][CPs])
  584.         {
  585.             RaceEndPlace++;
  586.            
  587.             new s[128];
  588.             format(s,sizeof(s),"* Hráč %s (ID:%d) skončil v závode na %d. mieste!",PlayerName(playerid),playerid,RaceEndPlace);
  589.             SCMTA(ADMINCOL,s);
  590.            
  591.             new bool:F;
  592.            
  593.             if(RaceEndPlace == 1)
  594.             {
  595.                 F=true;
  596.                 GivePlayerMoney(playerid,RaceInfo[RaceStartedID][Win]);
  597.                 SetTimer("PredcasnyKonec",60*1000,false);
  598.             }
  599.            
  600.             DestroyVehicle(GetPVarInt(playerid,PRV));
  601.             DeletePVar(playerid,PJTR);
  602.             DeletePVar(playerid,PRV);
  603.             DeletePVar(playerid,PCP);
  604.             DisablePlayerRaceCheckpoint(playerid);
  605.             SetPlayerInterior(playerid,0);
  606.             SpawnPlayer(playerid);
  607.  
  608.             new b;
  609.             for(new a;a<MAX_PLAYERS_EX;a++)
  610.             {
  611.                 if(GetPVarInt(a,PJTR))
  612.                 {
  613.                     b++;
  614.                     if(F)
  615.                     {
  616.                         SCM(a,ADMINCOL,"Máš 60 sekund než skončí závod aby si prišiel do cieľa!");
  617.                     }
  618.                 }
  619.             }
  620.  
  621.             if(b == 0)
  622.             {
  623.                 RaceStarted=false;
  624.                 RaceEndPlace=0;
  625.                 SCMTA(ADMINCOL,"* Závod skončil. Ďakujeme všetkým závodníkom za účasť!");
  626.             }
  627.         }
  628.         else if(i < (RaceInfo[RaceStartedID][CPs]-1))
  629.         {
  630.             SetPlayerRaceCheckpoint(playerid,0,RaceCPInfo[RaceStartedID][i][RaceX],RaceCPInfo[RaceStartedID][i][RaceY],RaceCPInfo[RaceStartedID][i][RaceZ],RaceCPInfo[RaceStartedID][i+1][RaceX],RaceCPInfo[RaceStartedID][i+1][RaceY],RaceCPInfo[RaceStartedID][i+1][RaceZ],RaceCPInfo[RaceStartedID][i][Radius]);
  631.         }
  632.     }
  633. }
  634.  
  635. public RaceOnGameModeInit()
  636. {
  637.     new s[60],i;
  638.     for(new cid;cid<MAX_RACE;cid++)
  639.     {
  640.         format(s,sizeof(s),"Races/Race%d.ini",cid);
  641.  
  642.         if(fexist(s))
  643.         {
  644.             format(RaceInfo[cid][Name],50,"%s",dini_Get(s,"Name"));
  645.             RaceInfo[cid][ModelVozu]=dini_Int(s,"RaceModel");
  646.             RaceInfo[cid][CPs]=dini_Int(s,"CPs");
  647.             RaceInfo[cid][Places]=dini_Int(s,"Places");
  648.             RaceInfo[cid][Interier]=dini_Int(s,"Interior");
  649.             printf("Zavod %s (%d) nacitany",RaceInfo[cid][Name],cid);
  650.            
  651.             for(i=0 ;i<RaceInfo[cid][CPs];i++)
  652.             {
  653.                 format(s,sizeof(s),"Races/Race%d CP%d.ini",cid,i);
  654.                 if(fexist(s))
  655.                 {
  656.                     RaceCPInfo[cid][i][RaceX]=dini_Float(s,"PosX");
  657.                     RaceCPInfo[cid][i][RaceY]=dini_Float(s,"PosY");
  658.                     RaceCPInfo[cid][i][RaceZ]=dini_Float(s,"PosZ");
  659.                     RaceCPInfo[cid][i][Radius]=dini_Float(s,"Radius");
  660.                     printf("Race CP (%d) nacitany",i);
  661.                 }
  662.             }
  663.  
  664.             for(i=0 ;i<RaceInfo[cid][Places];i++)
  665.             {
  666.                 format(s,sizeof(s),"Races/Race%d Place%d.ini",cid,i);
  667.                 if(fexist(s))
  668.                 {
  669.                     RacersInfo[cid][i][RposX]=dini_Float(s,"PosX");
  670.                     RacersInfo[cid][i][RposY]=dini_Float(s,"PosY");
  671.                     RacersInfo[cid][i][RposZ]=dini_Float(s,"PosZ");
  672.                     RacersInfo[cid][i][RposF]=dini_Float(s,"ZAngle");
  673.                     printf("Race Place (%d) nacitane",i);
  674.                 }
  675.             }
  676.  
  677.             RaceInfo[cid][RaceCreated]=true;
  678.            
  679.             RaceCount++;
  680.         }
  681.     }
  682. }
  683.  
  684. //STOCK
  685. stock GetPlayerFreeRaceID()
  686. {
  687.     for(new i;i<MAX_RACE;i++)
  688.     {
  689.         if(!RaceInfo[i][RaceCreated])
  690.             return i;
  691.     }
  692.     return -1;
  693. }
  694.  
  695. stock DialogListOfRaces(playerid)
  696. {
  697.     new s[256];
  698.     for(new i;i<MAX_RACE;i++)
  699.     {
  700.         if(RaceInfo[i][RaceCreated])
  701.         {
  702.             format(s,sizeof(s),"%s%s\n",s,RaceInfo[i][Name]);
  703.         }
  704.         else
  705.         {
  706.             format(s,sizeof(s),"%sNevytvorený\n",s);
  707.         }
  708.     }
  709.     ShowPlayerDialog(playerid,DIALOG_RACES,DIALOG_STYLE_LIST,"Zoznam závodov:",s,"Vybrať","Koniec");
  710.     return 1;
  711. }
  712.  
  713. stock PlayerName(playerid)
  714. {
  715.     new p[MAX_PLAYER_NAME];
  716.     GetPlayerName(playerid,p,MAX_PLAYER_NAME);
  717.     return p;
  718. }
  719.  
  720. //CMDs
  721. QCMD:createrace(playerid,params[])
  722. {
  723.     #if defined RCON_Allowed
  724.     if(!IsPlayerAdmin(playerid))return SCM(playerid,RED,"Nedostatočný level!");
  725.     #else
  726.     //if( Vasa podmienka pre admin level )return SCM(playerid,RED,"Nedostatočný level!");
  727.     #endif
  728.    
  729.     if(GetPVarInt(playerid,CRace))return SCM(playerid,RED,"Nemôžeš vytvoriť závod, keď už jeden vytváraš! (zadaj /endcreaterace pre ukončenie vytvárania závodu bez uloženia)");
  730.     if(strlen(params)>49)return SCM(playerid,RED,"Príliš dlhý názov!");
  731.     new i,s[50];
  732.     if(sscanf(params,"dz",i,s))return SCM(playerid,RED,"Použitie: /createrace [ID modelu auta v závode][názov závodu]");
  733.     CreatingRace(playerid,s,i);
  734.     return 1;
  735. }
  736.  
  737. QCMD:endcreaterace(playerid,params[])
  738. {
  739.     #if defined RCON_Allowed
  740.     if(!IsPlayerAdmin(playerid))return SCM(playerid,RED,"Nedostatočný level!");
  741.     #else
  742.     //if( Vasa podmienka pre admin level )return SCM(playerid,RED,"Nedostatočný level!");
  743.     #endif
  744.    
  745.     if(!GetPVarInt(playerid,CRace))return SCM(playerid,RED,"Žiadny závod nevytváraš!");
  746.     EndCRace(playerid,false);
  747.     return 1;
  748. }
  749.  
  750. QCMD:saverace(playerid,params[])
  751. {
  752.     #if defined RCON_Allowed
  753.     if(!IsPlayerAdmin(playerid))return SCM(playerid,RED,"Nedostatočný level!");
  754.     #else
  755.     //if( Vasa podmienka pre admin level )return SCM(playerid,RED,"Nedostatočný level!");
  756.     #endif
  757.    
  758.     if(!GetPVarInt(playerid,CRace))return SCM(playerid,RED,"Žiadny závod nevytváraš!");
  759.     EndCRace(playerid,true);
  760.     return 1;
  761. }
  762.  
  763. QCMD:savecp(playerid,params[])
  764. {
  765.     #if defined RCON_Allowed
  766.     if(!IsPlayerAdmin(playerid))return SCM(playerid,RED,"Nedostatočný level!");
  767.     #else
  768.     //if( Vasa podmienka pre admin level )return SCM(playerid,RED,"Nedostatočný level!");
  769.     #endif
  770.    
  771.     if(!GetPVarInt(playerid,CRace))return SCM(playerid,RED,"Nemôžeš uložiť checkpoint, ak si nespustil vytváranie závodu!");
  772.     new Float:radius;
  773.     if(sscanf(params,"f",radius))return SCM(playerid,RED,"Použitie: /savecp [rádius]");
  774.     AddCheckpoint(playerid,radius);
  775.     return 1;
  776. }
  777.  
  778. QCMD:saveplace(playerid,params[])
  779. {
  780.     #if defined RCON_Allowed
  781.     if(!IsPlayerAdmin(playerid))return SCM(playerid,RED,"Nedostatočný level!");
  782.     #else
  783.     //if( Vasa podmienka pre admin level )return SCM(playerid,RED,"Nedostatočný level!");
  784.     #endif
  785.    
  786.     if(!GetPVarInt(playerid,CRace))return SCM(playerid,RED,"Nemôžeš uložiť závodné miesto, ak si nespustil vytváranie závodu!");
  787.     if(GetVehicleModel(GetPlayerVehicleID(playerid))!=RaceInfo[GetPVarInt(playerid,CID)][ModelVozu])return SCM(playerid,RED,"Závodní místo musíš ukládat ve vozidle, které je určeno pro závod!");
  788.     AddRacePlace(playerid);
  789.     return 1;
  790. }
  791.  
  792. QCMD:races(playerid,params[])
  793. {
  794.     #if defined RCON_Allowed
  795.     if(!IsPlayerAdmin(playerid))return SCM(playerid,RED,"Nedostatočný level!");
  796.     #else
  797.     //if( Vasa podmienka pre admin level )return SCM(playerid,RED,"Nedostatočný level!");
  798.     #endif
  799.    
  800.     DialogListOfRaces(playerid);
  801.     return 1;
  802. }
  803.  
  804. QCMD:rhelp(playerid,params[])
  805. {
  806.     #if defined RCON_Allowed
  807.     if(!IsPlayerAdmin(playerid))return SCM(playerid,RED,"Nedostatočný level!");
  808.     #else
  809.     //if( Vasa podmienka pre admin level )return SCM(playerid,RED,"Nedostatočný level!");
  810.     #endif
  811.    
  812.     new s[1000];
  813.     strcat(s,"Vitajte v pomocníku pre Race Systém\n\n\nMaximum Checkpointov: 30\nMaximum Závodných miest: 15\nMaximum Závodov: 10\n\n\nZoznam príkazov: \n\t/createrace - spustí vytváranie závodu\n\t/endcreaterace - ukončí vytváranie závodu bez uloženia\n\t/saverace - uloží vytvorený závod\n\t/savecp - uloží Checkpoint pre závod\n\t/saveplace - uloží závodné miesto\n\t/races - zoznam vytvorených závodov",1000);
  814.     strcat(s,"\n\n\nNávod:\n\n\n1. Spustiť vytvárnie závodu pomocou /createrace\n2. Uložiť závodné miesta pomocou /saveplace\n3. Uložiť checkpointy pre závod pomocou /savecp\n( pokiaľ ste niečo zle uložili musíte zrušiť vytváranie závodu pomocou /endcreaterace a potom podľa návodu od bodu 1. pokračovať )\n4. Uložiť závod, miesta atď. pomocou /saverace",1000);
  815.     strcat(s,"\n5. Spustiť závod pomocou /races > vybraný závod podľa názvu",1000);
  816.     ShowPlayerDialog(playerid,DIALOG_ERROR,DIALOG_STYLE_MSGBOX,"Race Systém",s,"OK","");
  817.     return 1;
  818. }
  819.  
  820. QCMD:joinrace(playerid,params[])
  821. {
  822.     if(!RaceStarting && !RaceStarted)return SCM(playerid,RED,"Nebol spustený žiadny závod!");
  823.     if(!RaceStarting && RaceStarted)return SCM(playerid,RED,"Závod už začal!");
  824.     if(RaceInfo[RaceStartedID][Places]>RaceUcastnici)
  825.     {
  826.         RaceUcastnici++;
  827.         SetPVarInt(playerid,PJTR,1);
  828.         SCM(playerid,ADMINCOL,"Úspešne si sa prihlásil do závodu. Počkaj, než budeš spawnutý na závod!");
  829.     }
  830.     else
  831.         SCM(playerid,RED,"Počet účastníkov je plný!");
  832.     return 1;
  833. }
  834.  
  835. stock sscanf(string[], format[], {Float,_}:...)
  836. {
  837.     #if defined isnull
  838.         if (isnull(string))
  839.     #else
  840.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  841.     #endif
  842.         {
  843.             return format[0];
  844.         }
  845.     #pragma tabsize 4
  846.     new
  847.         formatPos = 0,
  848.         stringPos = 0,
  849.         paramPos = 2,
  850.         paramCount = numargs(),
  851.         delim = ' ';
  852.     while (string[stringPos] && string[stringPos] <= ' ')
  853.     {
  854.         stringPos++;
  855.     }
  856.     while (paramPos < paramCount && string[stringPos])
  857.     {
  858.         switch (format[formatPos++])
  859.         {
  860.             case '\0':
  861.             {
  862.                 return 0;
  863.             }
  864.             case 'i', 'd':
  865.             {
  866.                 new
  867.                     neg = 1,
  868.                     num = 0,
  869.                     ch = string[stringPos];
  870.                 if (ch == '-')
  871.                 {
  872.                     neg = -1;
  873.                     ch = string[++stringPos];
  874.                 }
  875.                 do
  876.                 {
  877.                     stringPos++;
  878.                     if ('0' <= ch <= '9')
  879.                     {
  880.                         num = (num * 10) + (ch - '0');
  881.                     }
  882.                     else
  883.                     {
  884.                         return -1;
  885.                     }
  886.                 }
  887.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  888.                 setarg(paramPos, 0, num * neg);
  889.             }
  890.             case 'h', 'x':
  891.             {
  892.                 new
  893.                     num = 0,
  894.                     ch = string[stringPos];
  895.                 do
  896.                 {
  897.                     stringPos++;
  898.                     switch (ch)
  899.                     {
  900.                         case 'x', 'X':
  901.                         {
  902.                             num = 0;
  903.                             continue;
  904.                         }
  905.                         case '0' .. '9':
  906.                         {
  907.                             num = (num << 4) | (ch - '0');
  908.                         }
  909.                         case 'a' .. 'f':
  910.                         {
  911.                             num = (num << 4) | (ch - ('a' - 10));
  912.                         }
  913.                         case 'A' .. 'F':
  914.                         {
  915.                             num = (num << 4) | (ch - ('A' - 10));
  916.                         }
  917.                         default:
  918.                         {
  919.                             return -1;
  920.                         }
  921.                     }
  922.                 }
  923.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  924.                 setarg(paramPos, 0, num);
  925.             }
  926.             case 'c':
  927.             {
  928.                 setarg(paramPos, 0, string[stringPos++]);
  929.             }
  930.             case 'f':
  931.             {
  932.  
  933.                 new changestr[16], changepos = 0, strpos = stringPos;
  934.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  935.                 {
  936.                     changestr[changepos++] = string[strpos++];
  937.                     }
  938.                 changestr[changepos] = '\0';
  939.                 setarg(paramPos,0,_:floatstr(changestr));
  940.             }
  941.             case 'p':
  942.             {
  943.                 delim = format[formatPos++];
  944.                 continue;
  945.             }
  946.             case '\'':
  947.             {
  948.                 new
  949.                     end = formatPos - 1,
  950.                     ch;
  951.                 while ((ch = format[++end]) && ch != '\'') {}
  952.                 if (!ch)
  953.                 {
  954.                     return -1;
  955.                 }
  956.                 format[end] = '\0';
  957.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  958.                 {
  959.                     if (format[end + 1])
  960.                     {
  961.                         return -1;
  962.                     }
  963.                     return 0;
  964.                 }
  965.                 format[end] = '\'';
  966.                 stringPos = ch + (end - formatPos);
  967.                 formatPos = end + 1;
  968.             }
  969.             case 'u':
  970.             {
  971.                 new
  972.                     end = stringPos - 1,
  973.                     id = 0,
  974.                     bool:num = true,
  975.                     ch;
  976.                 while ((ch = string[++end]) && ch != delim)
  977.                 {
  978.                     if (num)
  979.                     {
  980.                         if ('0' <= ch <= '9')
  981.                         {
  982.                             id = (id * 10) + (ch - '0');
  983.                         }
  984.                         else
  985.                         {
  986.                             num = false;
  987.                         }
  988.                     }
  989.                 }
  990.                 if (num && IsPlayerConnected(id))
  991.                 {
  992.                     setarg(paramPos, 0, id);
  993.                 }
  994.                 else
  995.                 {
  996.                     #if !defined foreach
  997.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS_EX; %2++) if (IsPlayerConnected(%2))
  998.                         #define __SSCANF_FOREACH__
  999.                     #endif
  1000.                     string[end] = '\0';
  1001.                     num = false;
  1002.                     new
  1003.                         name[MAX_PLAYER_NAME];
  1004.                     id = end - stringPos;
  1005.                     foreach (Player, playerid)
  1006.                     {
  1007.                         GetPlayerName(playerid, name, sizeof (name));
  1008.                         if (!strcmp(name, string[stringPos], true, id))
  1009.                         {
  1010.                             setarg(paramPos, 0, playerid);
  1011.                             num = true;
  1012.                             break;
  1013.                         }
  1014.                     }
  1015.                     if (!num)
  1016.                     {
  1017.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  1018.                     }
  1019.                     string[end] = ch;
  1020.                     #if defined __SSCANF_FOREACH__
  1021.                         #undef foreach
  1022.                         #undef __SSCANF_FOREACH__
  1023.                     #endif
  1024.                 }
  1025.                 stringPos = end;
  1026.             }
  1027.             case 's', 'z':
  1028.             {
  1029.                 new
  1030.                     i = 0,
  1031.                     ch;
  1032.                 if (format[formatPos])
  1033.                 {
  1034.                     while ((ch = string[stringPos++]) && ch != delim)
  1035.                     {
  1036.                         setarg(paramPos, i++, ch);
  1037.                     }
  1038.                     if (!i)
  1039.                     {
  1040.                         return -1;
  1041.                     }
  1042.                 }
  1043.                 else
  1044.                 {
  1045.                     while ((ch = string[stringPos++]))
  1046.                     {
  1047.                         setarg(paramPos, i++, ch);
  1048.                     }
  1049.                 }
  1050.                 stringPos--;
  1051.                 setarg(paramPos, i, '\0');
  1052.             }
  1053.             default:
  1054.             {
  1055.                 continue;
  1056.             }
  1057.         }
  1058.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  1059.         {
  1060.             stringPos++;
  1061.         }
  1062.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  1063.         {
  1064.             stringPos++;
  1065.         }
  1066.         paramPos++;
  1067.     }
  1068.     do
  1069.     {
  1070.         if ((delim = format[formatPos++]) > ' ')
  1071.         {
  1072.             if (delim == '\'')
  1073.             {
  1074.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  1075.             }
  1076.             else if (delim != 'z')
  1077.             {
  1078.                 return delim;
  1079.             }
  1080.         }
  1081.     }
  1082.     while (delim > ' ');
  1083.     return 0;
  1084. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement