#1

Код:
public UnlockRacers()
{
	for(new i;i<GetMaxPlayers();i++)
	{
		if(RaceParticipant[i]>0)
		{
			TogglePlayerControllable(i,1);
			if(PlayerVehicles[i] != 0)
			{
			    PutPlayerInVehicle(i,PlayerVehicles[i],0);
				PlayerVehicles[i]=0;
			}
		}
	}
}

public LockRacers()
{
	for(new i;i<GetMaxPlayers();i++)
	{
		if(RaceParticipant[i] != 0)
		{
			TogglePlayerControllable(i,0);
			if(IsPlayerInAnyVehicle(i)) PlayerVehicles[i]=GetPlayerVehicleID(i);
			else PlayerVehicles[i]=0;
		}
	}
}

public Racecountdown() {
	if(RaceStart == 1)  // Locking players, setting the reward and
      {
        RaceStart=0;
		LockRacers();
		new tmpprize, OPot;
		OPot=Pot;
		if(PrizeMode == 1 || PrizeMode == 4)
		{
			if(Racemode == 0 || Racemode == 3) tmpprize = floatround(RLenght);
			else if(Racemode == 1) tmpprize = floatround(LLenght * Racelaps);
			else if(Racemode == 2) tmpprize = floatround(RLenght * 2 * Racelaps);
		}
		tmpprize *= DynaMP;
		if(PrizeMode == 0 || PrizeMode == 3) Pot += Prize;
		else if(PrizeMode == 1 || PrizeMode == 4) Pot += tmpprize;
		if(Participants == 1) Pot=OPot; // Only 1 racer, force reward to entrance fees.
	}
	if(cd>0)
	{
		format(ystring, sizeof(ystring), "%d...",cd);
		for(new i=0;i<GetMaxPlayers();i++)
		{
			if(RaceParticipant[i]>1)
			{
				RaceSound(i,1056);
				GameTextForPlayer(i,ystring,1000,3);
			}
		}
	}
	else if(cd == 0)
	{
		format(ystring, sizeof(ystring), "~g~GO!",cd);
		KillTimer(Countdown);
		for(new i=0;i<GetMaxPlayers();i++)
		{
			if(RaceParticipant[i]>1)
			{
				RaceSound(i,1057);
				GameTextForPlayer(i,ystring,3000,3);
				RaceParticipant[i]=4;
				CurrentLap[i]=1;
				if(Racemode == 3) SetRaceCheckpoint(i,LCurrentCheckpoint,LCurrentCheckpoint-1);
				else SetRaceCheckpoint(i,0,1);
			}
		}
		UnlockRacers();
		RaceTick=tickcount();
	}
	cd--;
}

public SetNextCheckpoint(playerid)
{
	if(Racemode == 0) // Default Mode
	{
		CurrentCheckpoint[playerid]++;
		if(CurrentCheckpoint[playerid] == LCurrentCheckpoint)
		{
			SetRaceCheckpoint(playerid,CurrentCheckpoint[playerid],-1);
			RaceParticipant[playerid]=6;
		}
		else SetRaceCheckpoint(playerid,CurrentCheckpoint[playerid],CurrentCheckpoint[playerid]+1);
	}
	else if(Racemode == 1) // Ring Mode
	{
		CurrentCheckpoint[playerid]++;
		if(CurrentCheckpoint[playerid] == LCurrentCheckpoint+1 && CurrentLap[playerid] == Racelaps)
		{
			SetRaceCheckpoint(playerid,0,-1);
			RaceParticipant[playerid]=6;
		}
		else if (CurrentCheckpoint[playerid] == LCurrentCheckpoint+1 && CurrentLap[playerid] != Racelaps)
		{
			CurrentCheckpoint[playerid]=0;
			SetRaceCheckpoint(playerid,0,1);
			RaceParticipant[playerid]=5;
		}
		else if(CurrentCheckpoint[playerid] == 1 && RaceParticipant[playerid]==5)
		{
			ChangeLap(playerid);
			if(LCurrentCheckpoint==1)
			{
				SetRaceCheckpoint(playerid,CurrentCheckpoint[playerid],0);
			}
			else
			{
				SetRaceCheckpoint(playerid,CurrentCheckpoint[playerid],2);
			}
  			RaceParticipant[playerid]=4;
		}
		else
		{
			if(LCurrentCheckpoint==1 || CurrentCheckpoint[playerid] == LCurrentCheckpoint) SetRaceCheckpoint(playerid,CurrentCheckpoint[playerid],0);
			else SetRaceCheckpoint(playerid,CurrentCheckpoint[playerid],CurrentCheckpoint[playerid]+1);
		}
	}
	else if(Racemode == 2) // Yoyo-mode
	{
		if(RaceParticipant[playerid]==4)
		{
			if(CurrentCheckpoint[playerid] == LCurrentCheckpoint) // @ Last CP, trigger last-1
			{
				RaceParticipant[playerid]=5;
				CurrentCheckpoint[playerid]=LCurrentCheckpoint-1;
				SetRaceCheckpoint(playerid,CurrentCheckpoint[playerid],CurrentCheckpoint[playerid]-1);
			}
			else if(CurrentCheckpoint[playerid] == LCurrentCheckpoint-1) // Second last CP, set next accordingly
			{
				CurrentCheckpoint[playerid]++;
				SetRaceCheckpoint(playerid,CurrentCheckpoint[playerid],CurrentCheckpoint[playerid]-1);
			}
			else
			{
				CurrentCheckpoint[playerid]++;
				SetRaceCheckpoint(playerid,CurrentCheckpoint[playerid],CurrentCheckpoint[playerid]+1);
			}
		}
		else if(RaceParticipant[playerid]==5)
		{
			if(CurrentCheckpoint[playerid] == 1 && CurrentLap[playerid] == Racelaps) //Set the finish line
			{
				SetRaceCheckpoint(playerid,0,-1);
				RaceParticipant[playerid]=6;
			}
			else if(CurrentCheckpoint[playerid] == 0) //At finish line, change lap.
			{
				ChangeLap(playerid);
				if(LCurrentCheckpoint==1)
				{
					SetRaceCheckpoint(playerid,1,0);
				}
				else
				{
					SetRaceCheckpoint(playerid,1,2);
				}
	  			RaceParticipant[playerid]=4;
			}
			else if(CurrentCheckpoint[playerid] == 1)
			{
				CurrentCheckpoint[playerid]--;
				SetRaceCheckpoint(playerid,0,1);
			}
			else
			{
				CurrentCheckpoint[playerid]--;
				SetRaceCheckpoint(playerid,CurrentCheckpoint[playerid],CurrentCheckpoint[playerid]-1);
			}
		}
	}
	else if(Racemode == 3) // Mirror Mode
	{
		CurrentCheckpoint[playerid]--;
		if(CurrentCheckpoint[playerid] == 0)
		{
			SetRaceCheckpoint(playerid,CurrentCheckpoint[playerid],-1);
			RaceParticipant[playerid]=6;
		}
		else
		{
			 SetRaceCheckpoint(playerid,CurrentCheckpoint[playerid],CurrentCheckpoint[playerid]-1);
		}
	}
}

public SetRaceCheckpoint(playerid,target,next)
{
	if(next == -1 && Airrace == 0) SetPlayerRaceCheckpoint(playerid,1,RaceCheckpoints[target][0],RaceCheckpoints[target][1],RaceCheckpoints[target][2],0.0,0.0,0.0,CPsize);
	else if(next == -1 && Airrace == 1) SetPlayerRaceCheckpoint(playerid,4,RaceCheckpoints[target][0],RaceCheckpoints[target][1],RaceCheckpoints[target][2],0.0,0.0,0.0,CPsize);
	else if(Airrace == 1) SetPlayerRaceCheckpoint(playerid,3,RaceCheckpoints[target][0],RaceCheckpoints[target][1],RaceCheckpoints[target][2],RaceCheckpoints[next][0],
							RaceCheckpoints[next][1],RaceCheckpoints[next][2],CPsize);
	else SetPlayerRaceCheckpoint(playerid,0,RaceCheckpoints[target][0],RaceCheckpoints[target][1],RaceCheckpoints[target][2],RaceCheckpoints[next][0],RaceCheckpoints[next][1],
							RaceCheckpoints[next][2],CPsize);
}
public SetBRaceCheckpoint(playerid,target,next)
{
	new ar = BAirrace[b(playerid)];
	if(next == -1 && ar == 0) SetPlayerRaceCheckpoint(playerid,1,BRaceCheckpoints[b(playerid)][target][0],BRaceCheckpoints[b(playerid)][target][1],
								BRaceCheckpoints[b(playerid)][target][2],0.0,0.0,0.0,BCPsize[b(playerid)]);
	else if(next == -1 && ar == 1) SetPlayerRaceCheckpoint(playerid,4,BRaceCheckpoints[b(playerid)][target][0],
				BRaceCheckpoints[b(playerid)][target][1],BRaceCheckpoints[b(playerid)][target][2],0.0,0.0,0.0,
				BCPsize[b(playerid)]);
	else if(ar == 1) SetPlayerRaceCheckpoint(playerid,3,BRaceCheckpoints[b(playerid)][target][0],BRaceCheckpoints[b(playerid)][target][1],BRaceCheckpoints[b(playerid)][target][2],
						BRaceCheckpoints[b(playerid)][next][0],BRaceCheckpoints[b(playerid)][next][1],BRaceCheckpoints[b(playerid)][next][2],BCPsize[b(playerid)]);
	else SetPlayerRaceCheckpoint(playerid,0,BRaceCheckpoints[b(playerid)][target][0],BRaceCheckpoints[b(playerid)][target][1],BRaceCheckpoints[b(playerid)][target][2],
			BRaceCheckpoints[b(playerid)][next][0],BRaceCheckpoints[b(playerid)][next][1],BRaceCheckpoints[b(playerid)][next][2],BCPsize[b(playerid)]);
}

public GetLapTick(playerid)
{
	new tick, lap;
	tick=tickcount();
	if(CurrentLap[playerid]==1)
	{
		lap=tick-RaceTick;
		LastLapTick[playerid]=tick;
	}
	else
	{
		lap=tick-LastLapTick[playerid];
		LastLapTick[playerid]=tick;
	}
	return lap;
}

public GetRaceTick(playerid)
{
	new tick, race;
	tick=tickcount();
	race=tick-RaceTick;
	return race;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
	if(RaceParticipant[playerid]>=1) // See if the player is participating in a race, allows race builders to do their stuff in peace.
	{
		if(RaceParticipant[playerid] == 6) // Player reaches the checkered flag.
		{
			new rname[MAX_PLAYER_NAME], LapTime, RaceTime;
			LapTime=GetLapTick(playerid);
			RaceTime=GetRaceTick(playerid);
			GetPlayerName(playerid, rname, MAX_PLAYER_NAME);
			RaceParticipant[playerid]=0;
			RaceSound(playerid,1139);
			format(ystring,sizeof(ystring),"%s has finished the race, position: %d",rname,Ranking);
			if (Ranking < 4) SendClientMessageToAll(COLOR_GREEN,ystring);
			else SendClientMessage(playerid,COLOR_GREEN,ystring);
			if(Racemode == ORacemode && ORacelaps == Racelaps)
			{
				new	LapString[10],RaceString[10], laprank, racerank;
				LapString=BeHuman(LapTime);
				RaceString=BeHuman(RaceTime);
				format(ystring,sizeof(ystring),"~w~Racetime: %s",RaceString);
				if(ORacemode!=0) format(ystring,sizeof(ystring),"%s~n~Laptime: %s",ystring,LapString);
				laprank=CheckBestLap(playerid,LapTime);
				if(laprank == 1)
				{
					format(ystring,sizeof(ystring),"%s~n~~y~LAP RECORD!",ystring);
				}
				racerank=CheckBestRace(playerid,RaceTime);
				if(racerank == 1)
				{
					format(ystring,sizeof(ystring),"%s~n~~y~TRACK RECORD!",ystring);
				}
				GameTextForPlayer(playerid,ystring,13000,3);
			}
			if(Ranking<4)
			{
				new winrar;
				if(Ranking == 1 && Participants == 1) winrar=Pot; // If the player was only participant, give the whole pot.
				else if(Ranking == 1 && Participants == 2) winrar=Pot/6*4; // If only 2 participants, give 4/6ths of the pot.
				else winrar=Pot/6*PrizeMP;  // Otherwise 3/6ths, 2/6ths and 1/6th.
				GivePlayerMoney(playerid,winrar);
				format(ystring,sizeof(ystring),"You have earned $%d from the race!",winrar);
				PrizeMP--;
				SendClientMessage(playerid,COLOR_GREEN,ystring);
			}
			Ranking++;
			Participants--;
			DisablePlayerRaceCheckpoint(playerid);
			if(Participants == 0)
			{
				endrace();
			}
		}
		else if (RaceStart == 0 && RaceParticipant[playerid]==1) // Player arrives to the start CP for 1st time
		{
			SendClientMessage(playerid,COLOR_YELLOW,"Type /ready when you are ready to start.");
			SendClientMessage(playerid,COLOR_YELLOW,"NOTE: Your controls will be locked once the countdown starts.");
			RaceParticipant[playerid]=2;
		}
		else if (RaceStart==1) // Otherwise switch to the next race CP.
		{
			RaceSound(playerid,1138);
			SetNextCheckpoint(playerid);
		}
	}
	return 1;
}

public endrace()
{
	SaveScores(); //If the race had already started, and mode & laps are as originally, save the lapscores and racescores.
	for(new i=0;i<LCurrentCheckpoint;i++)
	{
		RaceCheckpoints[i][0]=0.0;
		RaceCheckpoints[i][1]=0.0;
		RaceCheckpoints[i][2]=0.0;
	}
	LCurrentCheckpoint=0;
	for(new i=0;i<GetMaxPlayers();i++)
	{
		LastLapTick[i]=0;
		DisablePlayerRaceCheckpoint(i);
		if(RaceParticipant[i]==3) //Player was still /ready-locked, unlocking.
		{
				TogglePlayerControllable(i,1);
				if(PlayerVehicles[i] != 0)
				{
					PutPlayerInVehicle(i,PlayerVehicles[i],0);
					PlayerVehicles[i]=0;
				}
		}
		RaceParticipant[i]=0;
	}
	RaceActive=0;
	RaceStart=0;
	Participants=0;
	Pot = 0;
	PrizeMP = 3;
	SendClientMessageToAll(COLOR_YELLOW, "The current race has been finished.");
}

public BActiveCP(playerid,sele)
{
	if(BCurrentCheckpoints[b(playerid)]-1 == sele) SetBRaceCheckpoint(playerid,sele,-1);
	else SetBRaceCheckpoint(playerid,sele,sele+1);
}

public RaceSound(playerid,sound)
{
	new Float:x,Float:y,Float:z;
	GetPlayerPos(playerid,x,y,z);
	PlayerPlaySound(playerid,sound,x,y,z);
}

public ReadyRefresh(playerid)
{
	if(RaceActive==1) //No countdown if no race is active (could occur with /leave)
	{
		new Waiting=0, Ready=0;
		for(new i=0;i<GetMaxPlayers();i++)
		{
			if(RaceParticipant[i] == 1 || RaceParticipant[i] == 2) Waiting++;
			else if(RaceParticipant[i] == 3) Ready++;
		}
		if(Waiting==0)
		{
			SendClientMessageToAll(COLOR_GREEN,"Everyone is ready, the race begins!");
			cd=5;
			Countdown = SetTimer("Racecountdown",1000,1);
		}
		else if(Ready >= Waiting && MajorityDelay > 0 && MajStart == 0)
		{
			MajStart=1;
			format(ystring,sizeof(ystring),"Half of the racers are ready, race starts in %d seconds!", MajorityDelay);
			SendClientMessageToAll(COLOR_GREEN,ystring);
			MajStartTimer = SetTimer("mscountdown",10000,1);
			mscd= MajorityDelay;
		}
	}
}

public mscountdown()
{
	if(RaceStart == 1 || MajStart == 0)
	{
		MajStart=0;
		KillTimer(MajStartTimer);
	}
	else
	{
		mscd-=10;
		if(mscd <= 0)
		{
			for(new i;i<GetMaxPlayers();i++)
			{
				if(RaceParticipant[i] != 3 && RaceParticipant[i] != 0)
				{
					GameTextForPlayer(i,"~r~You didn't make it in time!",6000,3);
					DisablePlayerRaceCheckpoint(i);
					RaceParticipant[i]=0;
					Participants--;
				}
				else if (RaceParticipant[i]!=0) SendClientMessage(i,COLOR_GREEN,"Pre-race countdown done, the race beings!");
			}
			KillTimer(MajStartTimer);
			cd=5;
			Countdown = SetTimer("Racecountdown",1000,1);
		}
		else
		{

			new hurry_string[64];
			format(ystring,sizeof(ystring),"~y~Race starting in ~w~%d~y~ seconds!",mscd);
			format(hurry_string,sizeof(hurry_string),"%s~n~~r~HURRY UP AND /READY",ystring);
			for(new i;i<GetMaxPlayers();i++)
			{
				if(RaceParticipant[i] < 3 && mscd < 31) GameTextForPlayer(i,hurry_string,6000,3);
				else if(RaceParticipant[i] > 0) GameTextForPlayer(i,ystring,6000,3);
			}
		}
	}
}

public CheckBestLap(playerid,laptime)
{
	if(TopLapTimes[4]<laptime && TopLapTimes[4] != 0 || Racemode == 0)
	{
		return 0;  // If the laptime is more than the previous 5th on the top list, skip to end
	}			  // Or the race is gamemode 0 where laps don't really apply
	for(new i;i<5;i++)
	{
		if(TopLapTimes[i] == 0)
		{
			new playername[MAX_PLAYER_NAME];
			GetPlayerName(playerid,playername,MAX_PLAYER_NAME);
			TopLappers[i]=playername;
			TopLapTimes[i]=laptime;
			ScoreChange=1;
			return i+1;
		}
		else if(TopLapTimes[i] > laptime)
		{
			for(new j=4;j>=i;j--)
			{
				TopLapTimes[j+1]=TopLapTimes[j];
				TopLappers[j+1]=TopLappers[j];
			}
			new playername[MAX_PLAYER_NAME];
			GetPlayerName(playerid,playername,MAX_PLAYER_NAME);
			TopLapTimes[i]=laptime;
			TopLappers[i]=playername;
			ScoreChange=1;
			return i+1;
		}
	}
	return -1; //Shouldn't get here.
}

public CheckBestRace(playerid,racetime)
{
	if(TopRacerTimes[4]<racetime && TopRacerTimes[4] != 0) return 0;
	for(new i;i<5;i++)
	{
		if(TopRacerTimes[i] == 0)
		{
			new playername[MAX_PLAYER_NAME];
			GetPlayerName(playerid,playername,MAX_PLAYER_NAME);
			TopRacers[i]=playername;
			TopRacerTimes[i]=racetime;
			ScoreChange=1;
			return i+1;
		}
		else if(TopRacerTimes[i] > racetime)
		{
			for(new j=4;j>=i;j--)
			{
				TopRacerTimes[j+1]=TopRacerTimes[j];
				TopRacers[j+1]=TopRacers[j];
			}
			new playername[MAX_PLAYER_NAME];
			GetPlayerName(playerid,playername,MAX_PLAYER_NAME);
			TopRacerTimes[i]=racetime;
			TopRacers[i]=playername;
			ScoreChange=1;
			return i+1;
		}
	}
	return -1; //Shouldn't get here.
}

public SaveScores()
{
	if(ScoreChange == 1)
	{
		fremove(CFile);
		new File:f,Float:x,Float:y,Float:z, templine[512];
		f = fopen(CFile,io_write);
		format(templine,sizeof(templine),"YRACE %d %s %d %d %d %f\n", RACEFILE_VERSION, CBuilder, ORacemode, ORacelaps, OAirrace, OCPsize);
		fwrite(f,templine);
		format(templine,sizeof(templine),"%s %d %s %d %s %d %s %d %s %d\n",
				TopRacers[0],TopRacerTimes[0],TopRacers[1], TopRacerTimes[1], TopRacers[2],TopRacerTimes[2],
	 			TopRacers[3],TopRacerTimes[3],TopRacers[4], TopRacerTimes[4]);
		fwrite(f,templine);
		format(templine,sizeof(templine),"%s %d %s %d %s %d %s %d %s %d\n",
				TopLappers[0],TopLapTimes[0],TopLappers[1], TopLapTimes[1], TopLappers[2],TopLapTimes[2],
	 			TopLappers[3],TopLapTimes[3],TopLappers[4], TopLapTimes[4]);
		fwrite(f,templine);
		for(new i = 0; i < LCurrentCheckpoint+1;i++)
		{
			x=RaceCheckpoints[i][0];
			y=RaceCheckpoints[i][1];
			z=RaceCheckpoints[i][2];
			format(templine,sizeof(templine),"%f %f %f\n",x,y,z);
			fwrite(f,templine);
		}
		fclose(f);
	}
	ScoreChange=0;
}
public ChangeLap(playerid)
{
	new LapTime, TimeString[10], checklap;
	LapTime=GetLapTick(playerid);
	TimeString=BeHuman(LapTime);
	format(ystring,sizeof(ystring),"~w~Lap %d/%d - time: %s", CurrentLap[playerid], Racelaps, TimeString);
	if(Racemode == ORacemode && ORacelaps == Racelaps)
	{
		checklap=CheckBestLap(playerid,LapTime);
		if(checklap==1) format(ystring,sizeof(ystring),"%s~n~~y~LAP RECORD!",ystring);
	}
	CurrentLap[playerid]++;
	if(CurrentLap[playerid] == Racelaps) format(ystring,sizeof(ystring),"%s~n~~g~Final lap!",ystring);
	GameTextForPlayer(playerid,ystring,6000,3);
}

BeHuman(ticks)
{
	new HumanTime[10], minutes, seconds, secstring[2], msecstring[3];
	minutes=ticks/60000;
	ticks=ticks-(minutes*60000);
	seconds=ticks/1000;
	ticks=ticks-(seconds*1000);
	if(seconds <10) format(secstring,sizeof(secstring),"0%d",seconds);
	else format(secstring,sizeof(secstring),"%d",seconds);
	format(HumanTime,sizeof(HumanTime),"%d:%s",minutes,secstring);
	if(ticks < 10) format(msecstring,sizeof(msecstring),"00%d", ticks);
	else if(ticks < 100) format(msecstring,sizeof(msecstring),"0%d",ticks);
	else format(msecstring,sizeof(msecstring),"%d",ticks);
	format(HumanTime,sizeof(HumanTime),"%s.%s",HumanTime,msecstring);
	return HumanTime;
}

public LoadTimes(playerid,timemode,tmp[])
{
	new temprace[67], idx;
	format(temprace,sizeof(temprace),"LOPTDM/Race/%s.yr",tmp);
	if(strlen(tmp))
	{
		if(!fexist(temprace))
		{
			format(ystring,sizeof(ystring),"Race \'%s\' doesn't exist!",tmp);
			SendClientMessage(playerid,COLOR_YELLOW,ystring);
			return 1;
		}
		else
		{
			new File:f, templine[256], TBuilder[MAX_PLAYER_NAME], TempLapper[MAX_PLAYER_NAME], TempLap;
			idx=0;
			f = fopen(temprace, io_read);
			fread(f,templine,sizeof(templine)); // Read header-line
			if(templine[0] == 'Y') //Checking if the racefile is v0.2+
			{
				new fileversion;
				strtok(templine,idx); // read off YRACE
				fileversion = strval(strtok(templine,idx)); // read off the file version
				if(fileversion > RACEFILE_VERSION) // Check if the race is made with a newer version of the racefile format
				{
					format(ystring,sizeof(ystring),"Race \'%s\' is created with a newer version of YRACE, unable to load.",tmp);
					SendClientMessage(playerid,COLOR_RED,ystring);
					return 1;
				}
				TBuilder=strtok(templine,idx); // read off RACEBUILDER
				fread(f,templine,sizeof(templine)); // read off best race times
				if(timemode ==1) fread(f,templine,sizeof(templine)); // read off best lap times
				idx=0;
				if(timemode == 0) format(ystring,sizeof(ystring),"%s by %s - Best race times:",tmp,TBuilder);
				else if(timemode == 1) format(ystring,sizeof(ystring),"%s by %s - Best laps:",tmp,TBuilder);
				else return 1;
				SendClientMessage(playerid,COLOR_GREEN,ystring);
				for(new i=0;i<5;i++)
				{
					TempLapper=strtok(templine,idx);
					TempLap=strval(strtok(templine,idx));
					if(TempLap == 0)
					{
						format(ystring,sizeof(ystring),"%d. None yet",i+1);
						i=6;
					}
					else format(ystring,sizeof(ystring),"%d. %s - %s",i+1,BeHuman(TempLap),TempLapper);
					SendClientMessage(playerid,COLOR_GREEN,ystring);
				}
				return 1;
			}
			else
			{
				format(ystring,sizeof(ystring),"Race \'%s\' doesn't contain any time data.",tmp);
				SendClientMessage(playerid,COLOR_GREEN,ystring);
				return 1;
			}
		}
	}
	return 0;
}

public IsNotAdmin(playerid)
{
	if (PlayerInfo[playerid][Level]==0)
	{
		SendClientMessage(playerid, COLOR_RED, "You need to be an admin to use this command!");
		return 1;
	}
	return 0;
}

public GetBuilderSlot(playerid)
{
	for(new i;i < MAX_BUILDERS; i++)
	{
		if(!(BuilderSlots[i] < GetMaxPlayers()+1))
		{
			BuilderSlots[i] = playerid;
			RaceBuilders[playerid] = i+1;
			return i+1;
		}
	}
	return 0;
}

public b(playerid) return RaceBuilders[playerid]-1;

public Float:Distance(Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2)
{
	new Float:temp=floatsqroot((x1-x2) * (x1-x2) + (y1-y2) * (y1-y2) + (z1-z2) * (z1-z2));
	if(temp < 0) temp=temp*(-1);
	return temp;
}

public clearrace(playerid)
{
	for(new i=0;i<BCurrentCheckpoints[b(playerid)];i++)
	{
		BRaceCheckpoints[b(playerid)][i][0]=0.0;
		BRaceCheckpoints[b(playerid)][i][1]=0.0;
		BRaceCheckpoints[b(playerid)][i][2]=0.0;
	}
	BCurrentCheckpoints[b(playerid)]=0;
	DisablePlayerRaceCheckpoint(playerid);
	SendClientMessage(playerid, COLOR_GREEN, "Your race has been cleared! Use /buildrace to start a new one.");
	BuilderSlots[b(playerid)] = GetMaxPlayers()+1;
	RaceBuilders[playerid]=0;
}

public startrace()
{
	format(ystring,128,"Race '%s' is about to start, type /join to join!",CRaceName);
	SendClientMessageToAll(COLOR_GREEN,ystring);
	if(Racemode == 0) format(ystring,sizeof(ystring),"default");
	else if(Racemode == 1) format(ystring,sizeof(ystring),"ring");
	else if(Racemode == 2) format(ystring,sizeof(ystring),"yoyo");
	else if(Racemode == 3) format(ystring,sizeof(ystring),"mirror");
	format(ystring,sizeof(ystring),"Racemode: %s Laps: %d",ystring,Racelaps);
	if(PrizeMode >= 2) format(ystring,sizeof(ystring),"%s Join fee: %d",ystring,JoinFee);
	if(Airrace == 1) format(ystring,sizeof(ystring),"%s AIR RACE",ystring);
	if(Racemode == 0 || Racemode == 3) format(ystring,sizeof(ystring),"%s Track lenght: %0.2fkm", ystring, RLenght/1000);
	else if(Racemode == 1) format(ystring,sizeof(ystring),"%s Lap lenght: %.2fkm, Total: %.2fkm", ystring, LLenght/1000, LLenght * Racelaps / 1000);
	SendClientMessageToAll(COLOR_GREEN,ystring);
	RaceStart=0;
	RaceActive=1;
	ScoreChange=0;
	Ranking=1;
	PrizeMP=3;
}

ReturnModeName(mode)
{
	new modename[8];
	if(mode == 0) modename="Default";
	else if(mode == 1) modename="Ring";
	else if(mode == 2) modename="Yoyo";
	else if(mode == 3) modename="Mirror";
	return modename;
}

public LoadRace(tmp[])
{
	new race_name[32],templine[512];
	format(CRaceName,sizeof(CRaceName), "%s",tmp);
	format(race_name,sizeof(race_name), "LOPTDM/Race/%s.yr",tmp);
	if(!fexist(race_name)) return -1; // File doesn't exist
	CFile=race_name;
	LCurrentCheckpoint=-1; RLenght=0; RLenght=0;
	new File:f, i;
	f = fopen(race_name, io_read);
	fread(f,templine,sizeof(templine));
	if(templine[0] == 'Y') //Checking if the racefile is v0.2+
	{
		new fileversion;
		strtok(templine,i); // read off YRACE
		fileversion = strval(strtok(templine,i)); // read off the file version
		if(fileversion > RACEFILE_VERSION) return -2; // Check if the race is made with a newer version of the racefile format
		CBuilder=strtok(templine,i); // read off RACEBUILDER
		ORacemode = strval(strtok(templine,i)); // read off racemode
		ORacelaps = strval(strtok(templine,i)); // read off amount of laps
		if(fileversion > 1)
		{
			Airrace = strval(strtok(templine,i));   // read off airrace
			CPsize = floatstr(strtok(templine,i));	// read off CP size
		}
		else // v1 file format, set to default
		{
			Airrace = 0;
			CPsize = 8.0;
		}
		OAirrace = Airrace;
		OCPsize = CPsize;
		Racemode=ORacemode; Racelaps=ORacelaps; //Allows changing the modes, but disables highscores if they've been changed.
		fread(f,templine,sizeof(templine)); // read off best race times
		i=0;
		for(new j=0;j<5;j++)
		{
			TopRacers[j]=strtok(templine,i);
			TopRacerTimes[j]=strval(strtok(templine,i));
		}
		fread(f,templine,sizeof(templine)); // read off best lap times
		i=0;
		for(new j=0;j<5;j++)
		{
			TopLappers[j]=strtok(templine,i);
			TopLapTimes[j]=strval(strtok(templine,i));
		}
	}
	else //Otherwise add the lines as checkpoints, the file is made with v0.1 (or older) version of the script.
	{
		LCurrentCheckpoint++;
		RaceCheckpoints[LCurrentCheckpoint][0] = floatstr(strtok(templine,i));
		RaceCheckpoints[LCurrentCheckpoint][1] = floatstr(strtok(templine,i));
		RaceCheckpoints[LCurrentCheckpoint][2] = floatstr(strtok(templine,i));
		Racemode=0; ORacemode=0; Racelaps=0; ORacelaps=0;   //Enables converting old files to new versions
		CPsize = 8.0; Airrace = 0;  			// v2 additions
		OCPsize = CPsize; OAirrace = Airrace;   // v2 additions
		CBuilder="UNKNOWN";
		for(new j;j<5;j++)
		{
			TopLappers[j]="A"; TopLapTimes[j]=0; TopRacers[j]="A"; TopRacerTimes[j]=0;
		}
	}
	while(fread(f,templine,sizeof(templine),false))
	{
		LCurrentCheckpoint++;
		i=0;
		RaceCheckpoints[LCurrentCheckpoint][0] = floatstr(strtok(templine,i));
		RaceCheckpoints[LCurrentCheckpoint][1] = floatstr(strtok(templine,i));
		RaceCheckpoints[LCurrentCheckpoint][2] = floatstr(strtok(templine,i));
		if(LCurrentCheckpoint >= 1)
		{
			RLenght+=Distance(RaceCheckpoints[LCurrentCheckpoint][0],RaceCheckpoints[LCurrentCheckpoint][1],
								RaceCheckpoints[LCurrentCheckpoint][2],RaceCheckpoints[LCurrentCheckpoint-1][0],
								RaceCheckpoints[LCurrentCheckpoint-1][1],RaceCheckpoints[LCurrentCheckpoint-1][2]);
		}
	}
	LLenght = RLenght + Distance(RaceCheckpoints[LCurrentCheckpoint][0],RaceCheckpoints[LCurrentCheckpoint][1],
								RaceCheckpoints[LCurrentCheckpoint][2],RaceCheckpoints[0][0],RaceCheckpoints[0][1],
								RaceCheckpoints[0][2]);
	fclose(f);
	return 1;
}

public RaceRotation()
{
	if(!fexist("LOPTDM/Race/YRace.rr"))
	{
		printf("ERROR in  YRACE's Race Rotation (YRace.rr): YRace.rr doesn't exist!");
		return -1;
	}
	if(RRotation == -1)
	{
		KillTimer(RotationTimer);
		return -1; // RRotation has been disabled
	}
	if(Participants > 0) return 1; // A race is still active.
	new File:f, templine[32], rotfile[]="LOPTDM/Race/YRace.rr", rraces=-1, rracenames[32][32], idx, fback;
	f = fopen(rotfile, io_read);
	while(fread(f,templine,sizeof(templine),false))
	{
		idx = 0;
		rraces++;
		rracenames[rraces]=strtok(templine,idx);
	}
	fclose(f);
	RRotation++;
	if(RRotation > rraces) RRotation = 0;
	fback = LoadRace(rracenames[RRotation]);
	if(fback == -1) printf("ERROR in YRACE's Race Rotation (YRace.rr): Race \'%s\' doesn't exist!",rracenames[RRotation]);
	else if (fback == -2) printf("ERROR in YRACE's Race Rotation (YRace.rr): Race \'%s\' is created with a newer version of YRACE",rracenames[RRotation]);
	else startrace();
//	print("Race Rotated!");
	return 1;
}

#if defined MENUSYSTEM
public RefreshMenuHeader(playerid,Menu:menu,text[])
{
	SetMenuColumnHeader(menu,0,text);
	ShowMenuForPlayer(menu,playerid);
}

public CreateRaceMenus()
{
	//Admin menu
	MAdmin = CreateMenu("Admin menu", 1, 25, 170, 220, 25);
	AddMenuItem(MAdmin,0,"Set prizemode...");
	AddMenuItem(MAdmin,0,"Set fixed prize...");
	AddMenuItem(MAdmin,0,"Set dynamic prize...");
	AddMenuItem(MAdmin,0,"Set entry fees...");
	AddMenuItem(MAdmin,0,"Majority delay...");
	AddMenuItem(MAdmin,0,"End current race");
	AddMenuItem(MAdmin,0,"Toggle Race Admin [RA]");
	AddMenuItem(MAdmin,0,"Toggle Build Admin [BA]");
	AddMenuItem(MAdmin,0,"Toggle Race Rotation [RR]");
	AddMenuItem(MAdmin,0,"Leave");
	if(RaceAdmin == 1) format(ystring,sizeof(ystring),"RA: ON");
	else format(ystring,sizeof(ystring),"RA: off");
	if(BuildAdmin == 1) format(ystring,sizeof(ystring),"%s BA: ON",ystring);
	else format(ystring,sizeof(ystring),"%s BA: off",ystring);
	if(RRotation >= 0) format(ystring,sizeof(ystring),"%s RR: ON",ystring);
	else format(ystring,sizeof(ystring),"%s RR: off",ystring);
	SetMenuColumnHeader(MAdmin,0,ystring);
	//Prizemode menu [Admin submenu]
	MPMode = CreateMenu("Set prizemode:", 1, 25, 170, 220, 25);
	AddMenuItem(MPMode,0,"Fixed");
	AddMenuItem(MPMode,0,"Dynamic");
	AddMenuItem(MPMode,0,"Entry Fee");
	AddMenuItem(MPMode,0,"Entry Fee + Fixed");
	AddMenuItem(MPMode,0,"Entry Fee + Dynamic");
	AddMenuItem(MPMode,0,"Back");
	SetMenuColumnHeader(MPMode,0,"Mode: Fixed");
	//Fixed prize menu
	MPrize = CreateMenu("Fixed prize:", 1, 25, 170, 220, 25);
	AddMenuItem(MPrize,0,"+100$");
	AddMenuItem(MPrize,0,"+1000$");
	AddMenuItem(MPrize,0,"+10000$");
	AddMenuItem(MPrize,0,"-100$");
	AddMenuItem(MPrize,0,"-1000$");
	AddMenuItem(MPrize,0,"-10000$");
	AddMenuItem(MPrize,0,"Back");
	format(ystring,sizeof(ystring),"Amount: %d",Prize);
	SetMenuColumnHeader(MPrize,0,ystring);
	//Dynamic prize menu
	MDyna = CreateMenu("Dynamic Prize:", 1, 25, 170, 220, 25);
	AddMenuItem(MDyna,0,"+1x");
	AddMenuItem(MDyna,0,"+5x");
	AddMenuItem(MDyna,0,"-1x");
	AddMenuItem(MDyna,0,"-5x");
	AddMenuItem(MDyna,0,"Leave");
	format(ystring,sizeof(ystring),"Multiplier: %dx",DynaMP);
	SetMenuColumnHeader(MDyna,0,ystring);
	//Build Menu
	MBuild = CreateMenu("Build Menu", 1, 25, 170, 220, 25);
	AddMenuItem(MBuild,0,"Set laps...");
	AddMenuItem(MBuild,0,"Set racemode...");
	AddMenuItem(MBuild,0,"Checkpoint size...");
	AddMenuItem(MBuild,0,"Toggle air race");
	AddMenuItem(MBuild,0,"Clear the race and exit");
	AddMenuItem(MBuild,0,"Leave");
	SetMenuColumnHeader(MBuild,0,"Air race: off");
	//Laps menu
	MLaps = CreateMenu("Set laps", 1, 25, 170, 220, 25);
	AddMenuItem(MLaps,0,"+1");
	AddMenuItem(MLaps,0,"+5");
	AddMenuItem(MLaps,0,"+10");
	AddMenuItem(MLaps,0,"-1");
	AddMenuItem(MLaps,0,"-5");
	AddMenuItem(MLaps,0,"-10");
	AddMenuItem(MLaps,0,"Back");
	//Racemode menu
	MRacemode = CreateMenu("Racemode", 1, 25, 170, 220, 25);
	AddMenuItem(MRacemode,0,"Default");
	AddMenuItem(MRacemode,0,"Ring");
	AddMenuItem(MRacemode,0,"Yoyo");
	AddMenuItem(MRacemode,0,"Mirror");
	AddMenuItem(MRacemode,0,"Back");
	//Race menu
	MRace = CreateMenu("Race Menu", 1, 25, 170, 220, 25);
	AddMenuItem(MRace,0,"Set laps...");
	AddMenuItem(MRace,0,"Set racemode...");
	AddMenuItem(MRace,0,"Set checkpoint size...");
	AddMenuItem(MRace,0,"Toggle air race");
	AddMenuItem(MRace,0,"Start race");
	AddMenuItem(MRace,0,"Abort new race");
	//Entry fee menu
	MFee = CreateMenu("Entry fees", 1, 25, 170, 220, 25);
	AddMenuItem(MFee,0,"+100");
	AddMenuItem(MFee,0,"+1000");
	AddMenuItem(MFee,0,"+10000");
	AddMenuItem(MFee,0,"-100");
	AddMenuItem(MFee,0,"-1000");
	AddMenuItem(MFee,0,"-10000");
	AddMenuItem(MFee,0,"Back");
	format(ystring,sizeof(ystring),"Fee: %d$",JoinFee);
	SetMenuColumnHeader(MFee,0,ystring);
	//CP size menu
	MCPsize = CreateMenu("CP size", 1, 25, 170, 220, 25);
	AddMenuItem(MCPsize,0,"+0.1");
	AddMenuItem(MCPsize,0,"+1");
	AddMenuItem(MCPsize,0,"+10");
	AddMenuItem(MCPsize,0,"-0.1");
	AddMenuItem(MCPsize,0,"-1");
	AddMenuItem(MCPsize,0,"-10");
	AddMenuItem(MCPsize,0,"Back");
	//Majority Delay menu
	MDelay = CreateMenu("Majority Delay", 1, 25, 170, 220, 25);
	AddMenuItem(MDelay,0,"+10s");
	AddMenuItem(MDelay,0,"+60s");
	AddMenuItem(MDelay,0,"-10s");
	AddMenuItem(MDelay,0,"-60s");
	AddMenuItem(MDelay,0,"Back");
	if(MajorityDelay == 0) format(ystring,sizeof(ystring),"Delay: disabled");
	else format(ystring,sizeof(ystring),"Delay: %ds",MajorityDelay);
	SetMenuColumnHeader(MDelay,0,ystring);
}
#endif
In this script the controls must be locked only while the countdown starts but when i join the race it locks controls too can anyone fix this ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)