Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ================================================================================
- --------------------------------------------------------------------------------
- ================================================================================
- Race System
- Verzia: 1.0
- Created by Angelus
- 4.6.2012 - 6.6.2012
- Copyright © 2012
- ================================================================================
- --------------------------------------------------------------------------------
- ================================================================================
- */
- //INCLUDE
- #include <a_samp>
- #include <dini>
- #define MAX_PLAYERS_EX MAX_PLAYERS
- #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
- //DEFINE
- #define MAX_RACE_CPS 30
- #define MAX_RACE 10
- #define MAX_RACERS 15
- //Názvy PVarov
- #define CRace "CreatingRace"
- #define CID "CreatingID"
- #define CPC "CPCount"
- #define CRP "CarRacePlace"
- #define ARID "ActuallyRaceID"
- #define PJTR "PlayerJoinedToRace"
- #define PRV "PlayerRaceVehicle"
- #define PCP "PlayerCheckpoint"
- #define QCMD:%1(%2) \
- forward cmd_%1(%2); \
- public cmd_%1(%2)
- #define DIALOG_ERROR 133
- #define DIALOG_RACES 155
- #define DIALOG_MANAGE_RACE 166
- #define DIALOG_SETWIN 177
- #define SCM SendClientMessage
- #define SCMTA SendClientMessageToAll
- #define ADMINCOL 0xFFB666FF
- #define RED 0xFF0000FF
- //
- #define RCON_Allowed
- //Ak chceš použiť vlastnú podmienku pre admina na vytvorenie závodu, daj "//" (bez úvodzoviek) na začiatok
- //riadku 63 a uprav riadky:
- //ENUM
- enum Race_Info
- {
- Float:RaceX,
- Float:RaceY,
- Float:RaceZ,
- Float:Radius,
- };
- enum Race__Info
- {
- Name[50],
- bool:RaceCreating,
- bool:RaceCreated,
- ModelVozu,
- CPs,
- Places,
- Win,
- Interier,
- };
- enum Racers_Info
- {
- Float:RposX,
- Float:RposY,
- Float:RposZ,
- Float:RposF,
- };
- //NEWS
- new RaceCPInfo[MAX_RACE][MAX_RACE_CPS][Race_Info];
- new RaceInfo[MAX_RACE][Race__Info];
- new RacersInfo[MAX_RACE][MAX_RACERS][Racers_Info];
- new RaceTimer;
- new RaceTimerCount;
- new RaceUcastnici;
- new RaceStartedID;
- new RaceEndPlace;
- new bool:RaceStarted;
- new bool:RaceStarting;
- new RaceCount=-1;
- //FORWARD
- forward CreatingRace(playerid,name[],model);
- forward EndCRace(playerid,bool:MozeVytvoritRace);
- forward AddCheckpoint(playerid,Float:radius);
- forward AddRacePlace(playerid);
- forward EndPlayerRace(playerid,reason[]);
- forward Start();
- forward Jeden();
- forward Dva();
- forward Tri();
- forward Drei();
- forward LoadPlayersOnRacePlace();
- forward PredcasnyKonec();
- // !!! Pod týmto riadkom vložiť do módu !!!
- forward RaceOnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
- forward RaceOnPlayerDisconnect(playerid);
- forward RaceOnPlayerDeath(playerid);
- forward RaceOnPlayerExitVehicle(playerid);
- forward RaceOnPlayerEnterRaceCP(playerid);
- forward RaceOnGameModeInit();
- //PUBLIC
- public CreatingRace(playerid,name[],model)
- {
- if(MAX_RACE > RaceCount)
- {
- SCM(playerid,ADMINCOL,"Začal si vytvárať závod. Teraz vytvor závodné miesta na štarte pomocou /saveplace");
- SetPVarInt(playerid,CRace,1);
- SetPVarInt(playerid,CID,GetPlayerFreeRaceID());
- SetPVarInt(playerid,CPC,0);
- RaceInfo[GetPVarInt(playerid,CID)][RaceCreating]=true;
- RaceInfo[GetPVarInt(playerid,CID)][ModelVozu]=model;
- RaceInfo[GetPVarInt(playerid,CID)][Interier]=GetPlayerInterior(playerid);
- format(RaceInfo[GetPVarInt(playerid,CID)][Name],50,"%s",name);
- }
- else
- SCM(playerid,RED,"Nemôžeš vytvoriť závod, bol naplnený maximálny limit závodov!");
- return 1;
- }
- public EndCRace(playerid,bool:MozeVytvoritRace)
- {
- if(MozeVytvoritRace)
- {
- if(GetPVarInt(playerid,CRP)<2)return SCM(playerid,RED,"Musíš vytvoriť aspoň 2 závodné miesta!");
- if(GetPVarInt(playerid,CPC)<2)return SCM(playerid,RED,"Musíš vytvoriť aspoň 2 checkpointy!");
- new s[75],cid=GetPVarInt(playerid,CID),i;
- format(s,sizeof(s),"Races/Race%d.ini",cid);
- if(fexist(s))return SCM(playerid,RED,"ERROR: Súbor s ID tohto závodu už existuje!");
- dini_Create(s);
- dini_Set(s,"Name",RaceInfo[cid][Name]);
- dini_IntSet(s,"RaceModel",RaceInfo[cid][ModelVozu]);
- dini_IntSet(s,"CPs",GetPVarInt(playerid,CPC));
- dini_IntSet(s,"Places",GetPVarInt(playerid,CRP));
- dini_IntSet(s,"Interior",RaceInfo[cid][Interier]);
- RaceInfo[cid][CPs]=GetPVarInt(playerid,CPC);
- RaceInfo[cid][Places]=GetPVarInt(playerid,CRP);
- for( ;i<GetPVarInt(playerid,CPC);i++)
- {
- format(s,sizeof(s),"Races/Race%d CP%d.ini",cid,i);
- dini_Create(s);
- dini_FloatSet(s,"PosX",RaceCPInfo[cid][i][RaceX]);
- dini_FloatSet(s,"PosY",RaceCPInfo[cid][i][RaceY]);
- dini_FloatSet(s,"PosZ",RaceCPInfo[cid][i][RaceZ]);
- dini_FloatSet(s,"Radius",RaceCPInfo[cid][i][Radius]);
- }
- i=0;
- for( ;i<GetPVarInt(playerid,CRP);i++)
- {
- format(s,sizeof(s),"Races/Race%d Place%d.ini",cid,i);
- dini_Create(s);
- dini_FloatSet(s,"PosX",RacersInfo[cid][i][RposX]);
- dini_FloatSet(s,"PosY",RacersInfo[cid][i][RposY]);
- dini_FloatSet(s,"PosZ",RacersInfo[cid][i][RposZ]);
- dini_FloatSet(s,"ZAngle",RacersInfo[cid][i][RposF]);
- }
- RaceInfo[GetPVarInt(playerid,CID)][RaceCreating]=false;
- RaceInfo[GetPVarInt(playerid,CID)][RaceCreated]=true;
- SCM(playerid,ADMINCOL,"Ukončil si vytvárenie závodu. Teraz môžeš spustiť závod pomocou /races!");
- RaceCount++;
- }
- else
- {
- SCM(playerid,ADMINCOL,"Ukončil si vytváranie závodu, závod nebol uložený.");
- RaceInfo[GetPVarInt(playerid,CID)][RaceCreating]=false;
- }
- DeletePVar(playerid,CRace);
- DeletePVar(playerid,CID);
- DeletePVar(playerid,CPC);
- DeletePVar(playerid,CRP);
- return 1;
- }
- public AddCheckpoint(playerid,Float:radius)
- {
- new i = GetPVarInt(playerid,CPC);
- if(MAX_RACE_CPS > i)
- {
- new Float:p1,Float:p2,Float:p3,b=GetPVarInt(playerid,CID);
- GetPlayerPos(playerid,p1,p2,p3);
- RaceCPInfo[b][i][RaceX]=p1;
- RaceCPInfo[b][i][RaceY]=p2;
- RaceCPInfo[b][i][RaceZ]=p3;
- RaceCPInfo[b][i][Radius]=radius;
- SetPVarInt(playerid,CPC,i+1);
- new s[60];
- format(s,60,"* Vytvorený Checkpoint %d/%d!",i+1,MAX_RACE_CPS);
- SCM(playerid,ADMINCOL,s);
- }
- else
- {
- SCM(playerid,RED,"Nemôžeš vytvoriť ďalší Checkpoint, už bol naplnený limit!");
- }
- return 1;
- }
- public AddRacePlace(playerid)
- {
- new i = GetPVarInt(playerid,CRP);
- if(MAX_RACERS > i)
- {
- new Float:p1,Float:p2,Float:p3,Float:p4,b=GetPVarInt(playerid,CID);
- GetVehiclePos(GetPlayerVehicleID(playerid),p1,p2,p3);
- GetVehicleZAngle(GetPlayerVehicleID(playerid),p4);
- RacersInfo[b][i][RposX]=p1;
- RacersInfo[b][i][RposY]=p2;
- RacersInfo[b][i][RposZ]=p3;
- RacersInfo[b][i][RposF]=p4;
- SetPVarInt(playerid,CRP,i+1);
- new s[60];
- format(s,60,"* Vytvorené Závodné Miesto %d/%d!",i+1,MAX_RACERS);
- SCM(playerid,ADMINCOL,s);
- }
- else
- {
- SCM(playerid,RED,"Nemôžeš vytvoriť ďalšie Závodné Miesto, už si naplnil limit (15 miest) !");
- }
- return 1;
- }
- public EndPlayerRace(playerid,reason[])
- {
- DestroyVehicle(GetPVarInt(playerid,PRV));
- DeletePVar(playerid,PJTR);
- DeletePVar(playerid,PRV);
- DeletePVar(playerid,PCP);
- DisablePlayerRaceCheckpoint(playerid);
- SetPlayerInterior(playerid,0);
- SpawnPlayer(playerid);
- RaceUcastnici--;
- new s[128];
- 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);
- SCMTA(ADMINCOL,s);
- if(RaceUcastnici==1)
- {
- for(new i;i<MAX_PLAYERS_EX;i++)
- {
- if(GetPVarInt(i,PJTR))
- {
- DestroyVehicle(GetPVarInt(i,PRV));
- DeletePVar(i,PJTR);
- DeletePVar(i,PRV);
- DeletePVar(i,PCP);
- DisablePlayerRaceCheckpoint(i);
- SetPlayerInterior(playerid,0);
- SpawnPlayer(i);
- format(s,sizeof(s),"* Hráč %s (ID:%d) kontumačne vyhral závod! Dostane výhru %d$",PlayerName(i),i,RaceInfo[RaceStartedID][Win]);
- SCMTA(ADMINCOL,s);
- GivePlayerMoney(i,RaceInfo[RaceStartedID][Win]);
- RaceStarted=false;
- break;
- }
- }
- }
- }
- public Start()
- {
- for(new i;i<MAX_PLAYERS_EX;i++)
- {
- if(GetPVarInt(i,PJTR))
- {
- GameTextForPlayer(i,"~r~start",1000,5);
- TogglePlayerControllable(i,true);
- SetPVarInt(i,PCP,0);
- 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]);
- }
- }
- }
- public Jeden()
- {
- for(new i;i<MAX_PLAYERS_EX;i++)
- {
- if(GetPVarInt(i,PJTR))
- {
- GameTextForPlayer(i,"~r~1",1000,5);
- }
- }
- SetTimer("Start",1050,false);
- }
- public Dva()
- {
- for(new i;i<MAX_PLAYERS_EX;i++)
- {
- if(GetPVarInt(i,PJTR))
- {
- GameTextForPlayer(i,"~r~2",1000,5);
- }
- }
- SetTimer("Jeden",1050,false);
- }
- public Tri()
- {
- for(new i;i<MAX_PLAYERS_EX;i++)
- {
- if(GetPVarInt(i,PJTR))
- {
- GameTextForPlayer(i,"~r~3",1000,5);
- }
- }
- SetTimer("Dva",1050,false);
- }
- public Drei()
- {
- RaceTimerCount--;
- if(RaceTimerCount == 40 || RaceTimerCount == 20 || RaceTimerCount == 10 || RaceTimerCount == 5)
- {
- new s[128];
- 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);
- SCMTA(ADMINCOL,s);
- }
- if(RaceTimerCount==0)
- {
- KillTimer(RaceTimer);
- if(RaceUcastnici<2)
- {
- SCMTA(ADMINCOL,"* Závod bol zrušený kvôli nedostatku účastníkov!");
- }
- else
- {
- RaceStarting=false;
- RaceStarted=true;
- LoadPlayersOnRacePlace();
- SetTimer("Tri",5050,false);
- }
- RaceStarting=false;
- }
- }
- public LoadPlayersOnRacePlace()
- {
- new count;
- for(new i;i<MAX_PLAYERS_EX;i++)
- {
- if(GetPVarInt(i,PJTR))
- {
- 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));
- LinkVehicleToInterior(GetPVarInt(i,PRV),RaceInfo[RaceStartedID][Interier]);
- SetPlayerInterior(i,RaceInfo[RaceStartedID][Interier]);
- PutPlayerInVehicle(i,GetPVarInt(i,PRV),0);
- SetCameraBehindPlayer(i);
- TogglePlayerControllable(i,false);
- SCM(i,ADMINCOL,"Bol si spawnutý na dráhu závodu! Počkaj na odštartovánie závodu!");
- count++;
- }
- }
- RaceUcastnici=count;
- }
- public PredcasnyKonec()
- {
- if(RaceStarted)
- {
- for(new a;a<MAX_PLAYERS_EX;a++)
- {
- if(GetPVarInt(a,PJTR))
- {
- DestroyVehicle(GetPVarInt(a,PRV));
- DeletePVar(a,PJTR);
- DeletePVar(a,PRV);
- DeletePVar(a,PCP);
- DisablePlayerRaceCheckpoint(a);
- SetPlayerInterior(a,0);
- SpawnPlayer(a);
- }
- }
- RaceStarted=false;
- RaceEndPlace=0;
- SCMTA(ADMINCOL,"* Závod skončil. Ďakujeme všetkým závodníkom za účasť!");
- }
- }
- public RaceOnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == DIALOG_RACES && response)
- {
- if(!RaceInfo[listitem][RaceCreated])
- {
- DialogListOfRaces(playerid);
- }
- else
- {
- SetPVarInt(playerid,ARID,listitem);
- new s[128];
- format(s,sizeof(s),"Info: Počet Checkpointov: %d | Počet závodných miest: %d\nSpustiť\nZmazať",RaceInfo[listitem][CPs],RaceInfo[listitem][Places]);
- ShowPlayerDialog(playerid,DIALOG_MANAGE_RACE,DIALOG_STYLE_LIST,RaceInfo[listitem][Name],s,"Vybrať","Koniec");
- }
- }
- if(dialogid == DIALOG_MANAGE_RACE)
- {
- if(response)
- {
- if(listitem == 0)
- {
- new s[128];
- 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]);
- ShowPlayerDialog(playerid,DIALOG_MANAGE_RACE,DIALOG_STYLE_LIST,RaceInfo[GetPVarInt(playerid,ARID)][Name],s,"Vybrat","Konec");
- }
- else if(listitem == 1)
- {
- if(RaceStarted || RaceStarting)return SCM(playerid,RED,"Niekto už spúšťa závod!");
- ShowPlayerDialog(playerid,DIALOG_SETWIN,DIALOG_STYLE_INPUT,RaceInfo[GetPVarInt(playerid,ARID)][Name],"Zadejte výhru závodu:","Zadat","Konec");
- }
- else if(listitem == 2)
- {
- new s[128],cid=GetPVarInt(playerid,ARID),i;
- DeletePVar(playerid,ARID);
- format(s,sizeof(s),"Races/Race%d.ini",cid);
- dini_Remove(s);
- RaceInfo[cid][RaceCreated]=false;
- for( ;i<RaceInfo[cid][CPs];i++)
- {
- format(s,sizeof(s),"Races/Race%d CP%d.ini",cid,i);
- dini_Remove(s);
- RaceCPInfo[cid][i][RaceX]=0;
- RaceCPInfo[cid][i][RaceY]=0;
- RaceCPInfo[cid][i][RaceZ]=0;
- RaceCPInfo[cid][i][Radius]=0;
- }
- i=0;
- for( ;i<RaceInfo[cid][Places];i++)
- {
- format(s,sizeof(s),"Races/Race%d Place%d.ini",cid,i);
- dini_Remove(s);
- RacersInfo[cid][i][RposX]=0;
- RacersInfo[cid][i][RposY]=0;
- RacersInfo[cid][i][RposZ]=0;
- RacersInfo[cid][i][RposF]=0;
- }
- format(RaceInfo[cid][Name],50," ");
- format(s,sizeof(s),"* Závod %s bol zmazaný!",RaceInfo[cid][Name]);
- SCM(playerid,ADMINCOL,s);
- }
- }
- else
- {
- DeletePVar(playerid,ARID);
- }
- }
- if(dialogid == DIALOG_SETWIN)
- {
- if(response)
- {
- if(!strlen(inputtext))return ShowPlayerDialog(playerid,DIALOG_SETWIN,DIALOG_STYLE_INPUT,RaceInfo[GetPVarInt(playerid,ARID)][Name],"Zadejte výhru závodu:","Zadat","Konec");
- new cid=GetPVarInt(playerid,ARID);
- RaceInfo[cid][Win]=strval(inputtext);
- new s[128];
- 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]);
- SCMTA(ADMINCOL,s);
- 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]);
- SCMTA(ADMINCOL,s);
- RaceTimerCount=60;
- RaceStarting=true;
- RaceUcastnici=0;
- RaceStartedID=cid;
- RaceTimer=SetTimer("Drei",1000,true);
- }
- DeletePVar(playerid,ARID);
- }
- return 1;
- }
- public RaceOnPlayerDisconnect(playerid)
- {
- if(GetPVarInt(playerid,CRace))
- EndCRace(playerid,false);
- if(RaceStarting)
- {
- if(GetPVarInt(playerid,PJTR))
- {
- RaceUcastnici--;
- }
- }
- if(RaceStarted)
- {
- if(GetPVarInt(playerid,PJTR))
- {
- EndPlayerRace(playerid,"Odišiel zo serveru");
- }
- }
- }
- public RaceOnPlayerDeath(playerid)
- {
- if(GetPVarInt(playerid,CRace))
- EndCRace(playerid,false);
- if(RaceStarted)
- {
- if(GetPVarInt(playerid,PJTR))
- {
- EndPlayerRace(playerid,"Smrť");
- }
- }
- }
- public RaceOnPlayerExitVehicle(playerid)
- {
- if(RaceStarted)
- {
- if(GetPVarInt(playerid,PJTR))
- {
- EndPlayerRace(playerid,"Vystúpenie z vozidla");
- }
- }
- }
- public RaceOnPlayerEnterRaceCP(playerid)
- {
- if(GetPVarInt(playerid,PJTR))
- {
- new i=GetPVarInt(playerid,PCP)+1;
- SetPVarInt(playerid,PCP,i);
- if(i == (RaceInfo[RaceStartedID][CPs]-1))
- {
- 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]);
- }
- else if(i == RaceInfo[RaceStartedID][CPs])
- {
- RaceEndPlace++;
- new s[128];
- format(s,sizeof(s),"* Hráč %s (ID:%d) skončil v závode na %d. mieste!",PlayerName(playerid),playerid,RaceEndPlace);
- SCMTA(ADMINCOL,s);
- new bool:F;
- if(RaceEndPlace == 1)
- {
- F=true;
- GivePlayerMoney(playerid,RaceInfo[RaceStartedID][Win]);
- SetTimer("PredcasnyKonec",60*1000,false);
- }
- DestroyVehicle(GetPVarInt(playerid,PRV));
- DeletePVar(playerid,PJTR);
- DeletePVar(playerid,PRV);
- DeletePVar(playerid,PCP);
- DisablePlayerRaceCheckpoint(playerid);
- SetPlayerInterior(playerid,0);
- SpawnPlayer(playerid);
- new b;
- for(new a;a<MAX_PLAYERS_EX;a++)
- {
- if(GetPVarInt(a,PJTR))
- {
- b++;
- if(F)
- {
- SCM(a,ADMINCOL,"Máš 60 sekund než skončí závod aby si prišiel do cieľa!");
- }
- }
- }
- if(b == 0)
- {
- RaceStarted=false;
- RaceEndPlace=0;
- SCMTA(ADMINCOL,"* Závod skončil. Ďakujeme všetkým závodníkom za účasť!");
- }
- }
- else if(i < (RaceInfo[RaceStartedID][CPs]-1))
- {
- 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]);
- }
- }
- }
- public RaceOnGameModeInit()
- {
- new s[60],i;
- for(new cid;cid<MAX_RACE;cid++)
- {
- format(s,sizeof(s),"Races/Race%d.ini",cid);
- if(fexist(s))
- {
- format(RaceInfo[cid][Name],50,"%s",dini_Get(s,"Name"));
- RaceInfo[cid][ModelVozu]=dini_Int(s,"RaceModel");
- RaceInfo[cid][CPs]=dini_Int(s,"CPs");
- RaceInfo[cid][Places]=dini_Int(s,"Places");
- RaceInfo[cid][Interier]=dini_Int(s,"Interior");
- printf("Zavod %s (%d) nacitany",RaceInfo[cid][Name],cid);
- for(i=0 ;i<RaceInfo[cid][CPs];i++)
- {
- format(s,sizeof(s),"Races/Race%d CP%d.ini",cid,i);
- if(fexist(s))
- {
- RaceCPInfo[cid][i][RaceX]=dini_Float(s,"PosX");
- RaceCPInfo[cid][i][RaceY]=dini_Float(s,"PosY");
- RaceCPInfo[cid][i][RaceZ]=dini_Float(s,"PosZ");
- RaceCPInfo[cid][i][Radius]=dini_Float(s,"Radius");
- printf("Race CP (%d) nacitany",i);
- }
- }
- for(i=0 ;i<RaceInfo[cid][Places];i++)
- {
- format(s,sizeof(s),"Races/Race%d Place%d.ini",cid,i);
- if(fexist(s))
- {
- RacersInfo[cid][i][RposX]=dini_Float(s,"PosX");
- RacersInfo[cid][i][RposY]=dini_Float(s,"PosY");
- RacersInfo[cid][i][RposZ]=dini_Float(s,"PosZ");
- RacersInfo[cid][i][RposF]=dini_Float(s,"ZAngle");
- printf("Race Place (%d) nacitane",i);
- }
- }
- RaceInfo[cid][RaceCreated]=true;
- RaceCount++;
- }
- }
- }
- //STOCK
- stock GetPlayerFreeRaceID()
- {
- for(new i;i<MAX_RACE;i++)
- {
- if(!RaceInfo[i][RaceCreated])
- return i;
- }
- return -1;
- }
- stock DialogListOfRaces(playerid)
- {
- new s[256];
- for(new i;i<MAX_RACE;i++)
- {
- if(RaceInfo[i][RaceCreated])
- {
- format(s,sizeof(s),"%s%s\n",s,RaceInfo[i][Name]);
- }
- else
- {
- format(s,sizeof(s),"%sNevytvorený\n",s);
- }
- }
- ShowPlayerDialog(playerid,DIALOG_RACES,DIALOG_STYLE_LIST,"Zoznam závodov:",s,"Vybrať","Koniec");
- return 1;
- }
- stock PlayerName(playerid)
- {
- new p[MAX_PLAYER_NAME];
- GetPlayerName(playerid,p,MAX_PLAYER_NAME);
- return p;
- }
- //CMDs
- dcmd_createrace(playerid,params[])
- {
- #if defined RCON_Allowed
- if(!IsPlayerAdmin(playerid))return SCM(playerid,RED,"Nedostatočný level!");
- #else
- //if( Vasa podmienka pre admin level )return SCM(playerid,RED,"Nedostatočný level!");
- #endif
- 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)");
- if(strlen(params)>49)return SCM(playerid,RED,"Príliš dlhý názov!");
- new i,s[50];
- if(sscanf(params,"dz",i,s))return SCM(playerid,RED,"Použitie: /createrace [ID modelu auta v závode][názov závodu]");
- CreatingRace(playerid,s,i);
- return 1;
- }
- dcmd_endcreaterace(playerid,params[])
- {
- #if defined RCON_Allowed
- if(!IsPlayerAdmin(playerid))return SCM(playerid,RED,"Nedostatočný level!");
- #else
- //if( Vasa podmienka pre admin level )return SCM(playerid,RED,"Nedostatočný level!");
- #endif
- if(!GetPVarInt(playerid,CRace))return SCM(playerid,RED,"Žiadny závod nevytváraš!");
- EndCRace(playerid,false);
- return 1;
- }
- dcmd_saverace(playerid,params[])
- {
- #if defined RCON_Allowed
- if(!IsPlayerAdmin(playerid))return SCM(playerid,RED,"Nedostatočný level!");
- #else
- //if( Vasa podmienka pre admin level )return SCM(playerid,RED,"Nedostatočný level!");
- #endif
- if(!GetPVarInt(playerid,CRace))return SCM(playerid,RED,"Žiadny závod nevytváraš!");
- EndCRace(playerid,true);
- return 1;
- }
- dcmd_savecp(playerid,params[])
- {
- #if defined RCON_Allowed
- if(!IsPlayerAdmin(playerid))return SCM(playerid,RED,"Nedostatočný level!");
- #else
- //if( Vasa podmienka pre admin level )return SCM(playerid,RED,"Nedostatočný level!");
- #endif
- if(!GetPVarInt(playerid,CRace))return SCM(playerid,RED,"Nemôžeš uložiť checkpoint, ak si nespustil vytváranie závodu!");
- new Float:radius;
- if(sscanf(params,"f",radius))return SCM(playerid,RED,"Použitie: /savecp [rádius]");
- AddCheckpoint(playerid,radius);
- return 1;
- }
- dcmd_saveplace(playerid,params[])
- {
- #if defined RCON_Allowed
- if(!IsPlayerAdmin(playerid))return SCM(playerid,RED,"Nedostatočný level!");
- #else
- //if( Vasa podmienka pre admin level )return SCM(playerid,RED,"Nedostatočný level!");
- #endif
- if(!GetPVarInt(playerid,CRace))return SCM(playerid,RED,"Nemôžeš uložiť závodné miesto, ak si nespustil vytváranie závodu!");
- 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!");
- AddRacePlace(playerid);
- return 1;
- }
- dcmd_races(playerid,params[])
- {
- #if defined RCON_Allowed
- if(!IsPlayerAdmin(playerid))return SCM(playerid,RED,"Nedostatočný level!");
- #else
- //if( Vasa podmienka pre admin level )return SCM(playerid,RED,"Nedostatočný level!");
- #endif
- DialogListOfRaces(playerid);
- return 1;
- }
- dcmd_rhelp(playerid,params[])
- {
- #if defined RCON_Allowed
- if(!IsPlayerAdmin(playerid))return SCM(playerid,RED,"Nedostatočný level!");
- #else
- //if( Vasa podmienka pre admin level )return SCM(playerid,RED,"Nedostatočný level!");
- #endif
- new s[1000];
- 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);
- 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);
- strcat(s,"\n5. Spustiť závod pomocou /races > vybraný závod podľa názvu",1000);
- ShowPlayerDialog(playerid,DIALOG_ERROR,DIALOG_STYLE_MSGBOX,"Race Systém",s,"OK","");
- return 1;
- }
- dcmd_joinrace(playerid,params[])
- {
- if(!RaceStarting && !RaceStarted)return SCM(playerid,RED,"Nebol spustený žiadny závod!");
- if(!RaceStarting && RaceStarted)return SCM(playerid,RED,"Závod už začal!");
- if(RaceInfo[RaceStartedID][Places]>RaceUcastnici)
- {
- RaceUcastnici++;
- SetPVarInt(playerid,PJTR,1);
- SCM(playerid,ADMINCOL,"Úspešne si sa prihlásil do závodu. Počkaj, než budeš spawnutý na závod!");
- }
- else
- SCM(playerid,RED,"Počet účastníkov je plný!");
- return 1;
- }
- stock sscanf(string[], format[], {Float,_}:...)
- {
- #if defined isnull
- if (isnull(string))
- #else
- if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
- #endif
- {
- return format[0];
- }
- #pragma tabsize 4
- new
- formatPos = 0,
- stringPos = 0,
- paramPos = 2,
- paramCount = numargs(),
- delim = ' ';
- while (string[stringPos] && string[stringPos] <= ' ')
- {
- stringPos++;
- }
- while (paramPos < paramCount && string[stringPos])
- {
- switch (format[formatPos++])
- {
- case '\0':
- {
- return 0;
- }
- case 'i', 'd':
- {
- new
- neg = 1,
- num = 0,
- ch = string[stringPos];
- if (ch == '-')
- {
- neg = -1;
- ch = string[++stringPos];
- }
- do
- {
- stringPos++;
- if ('0' <= ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return -1;
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num * neg);
- }
- case 'h', 'x':
- {
- new
- num = 0,
- ch = string[stringPos];
- do
- {
- stringPos++;
- switch (ch)
- {
- case 'x', 'X':
- {
- num = 0;
- continue;
- }
- case '0' .. '9':
- {
- num = (num << 4) | (ch - '0');
- }
- case 'a' .. 'f':
- {
- num = (num << 4) | (ch - ('a' - 10));
- }
- case 'A' .. 'F':
- {
- num = (num << 4) | (ch - ('A' - 10));
- }
- default:
- {
- return -1;
- }
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num);
- }
- case 'c':
- {
- setarg(paramPos, 0, string[stringPos++]);
- }
- case 'f':
- {
- new changestr[16], changepos = 0, strpos = stringPos;
- while(changepos < 16 && string[strpos] && string[strpos] != delim)
- {
- changestr[changepos++] = string[strpos++];
- }
- changestr[changepos] = '\0';
- setarg(paramPos,0,_:floatstr(changestr));
- }
- case 'p':
- {
- delim = format[formatPos++];
- continue;
- }
- case '\'':
- {
- new
- end = formatPos - 1,
- ch;
- while ((ch = format[++end]) && ch != '\'') {}
- if (!ch)
- {
- return -1;
- }
- format[end] = '\0';
- if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
- {
- if (format[end + 1])
- {
- return -1;
- }
- return 0;
- }
- format[end] = '\'';
- stringPos = ch + (end - formatPos);
- formatPos = end + 1;
- }
- case 'u':
- {
- new
- end = stringPos - 1,
- id = 0,
- bool:num = true,
- ch;
- while ((ch = string[++end]) && ch != delim)
- {
- if (num)
- {
- if ('0' <= ch <= '9')
- {
- id = (id * 10) + (ch - '0');
- }
- else
- {
- num = false;
- }
- }
- }
- if (num && IsPlayerConnected(id))
- {
- setarg(paramPos, 0, id);
- }
- else
- {
- #if !defined foreach
- #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS_EX; %2++) if (IsPlayerConnected(%2))
- #define __SSCANF_FOREACH__
- #endif
- string[end] = '\0';
- num = false;
- new
- name[MAX_PLAYER_NAME];
- id = end - stringPos;
- foreach (Player, playerid)
- {
- GetPlayerName(playerid, name, sizeof (name));
- if (!strcmp(name, string[stringPos], true, id))
- {
- setarg(paramPos, 0, playerid);
- num = true;
- break;
- }
- }
- if (!num)
- {
- setarg(paramPos, 0, INVALID_PLAYER_ID);
- }
- string[end] = ch;
- #if defined __SSCANF_FOREACH__
- #undef foreach
- #undef __SSCANF_FOREACH__
- #endif
- }
- stringPos = end;
- }
- case 's', 'z':
- {
- new
- i = 0,
- ch;
- if (format[formatPos])
- {
- while ((ch = string[stringPos++]) && ch != delim)
- {
- setarg(paramPos, i++, ch);
- }
- if (!i)
- {
- return -1;
- }
- }
- else
- {
- while ((ch = string[stringPos++]))
- {
- setarg(paramPos, i++, ch);
- }
- }
- stringPos--;
- setarg(paramPos, i, '\0');
- }
- default:
- {
- continue;
- }
- }
- while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
- {
- stringPos++;
- }
- while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
- {
- stringPos++;
- }
- paramPos++;
- }
- do
- {
- if ((delim = format[formatPos++]) > ' ')
- {
- if (delim == '\'')
- {
- while ((delim = format[formatPos++]) && delim != '\'') {}
- }
- else if (delim != 'z')
- {
- return delim;
- }
- }
- }
- while (delim > ' ');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement