Race Problem
#1

Well, In this script when the player enter the race checkpoint it asks him for the race vehicle wheels but it no gives him the race vehicle for example if the race vehicle is infernus it should give a player the vehicle but it doesn't give him I hope someone can fix it.Thanks!
+REP for who help me
Код:
public OnVehicleDamageStatusUpdate( vehicleid, playerid )
{
    new
		panels,
		doors,
		lights,
		tires;

    GetVehicleDamageStatus( vehicleid, panels, doors, lights, tires );

    ProcessRunflatTires( playerid, tires );

    UpdateVehicleDamageStatus( vehicleid, panels, doors, lights, tires );

    return 1;
}

public OnVehicleSpawn(vehicleid)
{
	if(GetVehicleVirtualWorld(vehicleid) == RaceWorld) SetVehicleVirtualWorld(vehicleid, 0);
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
	printf("pickup pickedup: %i, %i, %f, %f, %f", RaceParticipant[playerid], RaceStart, PickupLocations[0][0], PickupLocations[0][1], PickupLocations[0][2]);
	if(RaceParticipant[playerid] > 0 && RaceStart == 1)
	{
	    new pickupids = -1;
	    if(IsPlayerInRangeOfPoint(playerid, 30, PickupLocations[0][0], PickupLocations[0][1], PickupLocations[0][2])) pickupids = 0;
	    else if(IsPlayerInRangeOfPoint(playerid, 30, PickupLocations[1][0], PickupLocations[1][1], PickupLocations[1][2])) pickupids = 1;
	    else if(IsPlayerInRangeOfPoint(playerid, 30, PickupLocations[2][0], PickupLocations[2][1], PickupLocations[2][2])) pickupids = 2;
	    else if(IsPlayerInRangeOfPoint(playerid, 30, PickupLocations[3][0], PickupLocations[3][1], PickupLocations[3][2])) pickupids = 3;
	    else if(IsPlayerInRangeOfPoint(playerid, 30, PickupLocations[4][0], PickupLocations[4][1], PickupLocations[4][2])) pickupids = 4;
	    if(PickupType[pickupids] == 2)
	    {
	        if(!IsPlayerInAnyVehicle(playerid))
	        {
	            SendClientMessage(playerid, COLOUR_RED, "Error: You must be in a vehicle to pickup the pickup!");
	            return 1;
		 	}
	    	new Float:tX, Float:tY, Float:tZ, Float:tR, Float:vXR, Float:vYR, Float:vZR;
			new vehicleid = GetPlayerVehicleID(playerid);
			GetVehiclePos(vehicleid, tX, tY, tZ);
	    	GetVehicleZAngle(vehicleid, tR);
			GetVehicleVelocity(vehicleid, vXR, vYR, vZR);
			DestroyVehicle(vehicleid);
			switch (pickupids)
			{
			    case 0: PlayerVehicle[playerid] = CreateVehicle(PickupVehicle0, tX, tY, tZ, tR, -1, -1, 60);
			    case 1: PlayerVehicle[playerid] = CreateVehicle(PickupVehicle1, tX, tY, tZ, tR, -1, -1, 60);
			    case 2: PlayerVehicle[playerid] = CreateVehicle(PickupVehicle2, tX, tY, tZ, tR, -1, -1, 60);
			    case 3: PlayerVehicle[playerid] = CreateVehicle(PickupVehicle3, tX, tY, tZ, tR, -1, -1, 60);
			    case 4: PlayerVehicle[playerid] = CreateVehicle(PickupVehicle4, tX, tY, tZ, tR, -1, -1, 60);
			}
			SetVehicleZAngle(PlayerVehicle[playerid], tR);
			new Float:Angle;
			GetVehicleZAngle(GetPlayerVehicleID(playerid), Angle);
			SetVehicleZAngle(GetPlayerVehicleID(playerid), Angle);
			SetVehicleVirtualWorld(PlayerVehicle[playerid], 150);
			PutPlayerInVehicle(playerid, PlayerVehicle[playerid], 0);
			racevehicle[playerid] = GetVehicleModel(PlayerVehicle[playerid]);
			SetVehicleVelocity(PlayerVehicle[playerid], vXR, vYR, vZR);
		}
		else if(PickupType[pickupids] == 1)
		{
			RepairVehicle(GetPlayerVehicleID(playerid));
			xPlayerPlaySound(playerid, 1133);
		}
	}
	return 1;
}

public OnPlayerDisconnect(playerid,reason)
{
	print("Race disconnect");
	if(PlayerEditing[playerid] == 1) PlayerEditing[playerid] = false;
    TempRaceMaker[playerid] = 0;
	if(RaceParticipant[playerid]>=1)
	{
	    KillTimer(TimeTimer[playerid]);
    	TextDrawHideForPlayer(playerid, Times);
    	TextDrawHideForPlayer(playerid, Partici);
    	TextDrawHideForPlayer(playerid, TCountdown);
    	TextDrawHideForPlayer(playerid, Position[playerid]);
    	TextDrawHideForPlayer(playerid, TPosition[playerid]);
    	//TextDrawHideForPlayer(playerid, Diff[playerid]);
    	TextDrawHideForPlayer(playerid, Append1), TextDrawHideForPlayer(playerid, Append2), TextDrawHideForPlayer(playerid, Append3), TextDrawHideForPlayer(playerid, Append4);
    	Participants--;
	    RaceParticipant[playerid]=0;
		if(Participants == 0) //Last participant leaving, ending race.
		{
			endraceload();
		}
	    DisablePlayerRaceCheckpoint(playerid);
	}
	if(RaceBuilders[playerid] != 0)
	{
   	    DisablePlayerRaceCheckpoint(playerid);
	    for(new i;i<BCurrentCheckpoints[bb(playerid)];i++)
	    {
	        BRaceCheckpoints[bb(playerid)][i][0]=0.0;
   	        BRaceCheckpoints[bb(playerid)][i][1]=0.0;
	        BRaceCheckpoints[bb(playerid)][i][2]=0.0;
		}
		BuilderSlots[bb(playerid)] = MAX_PLAYERS+1;
		RaceBuilders[playerid] = 0;
	}
}

public UnlockRacers()
{
	for(new i;i<MAX_PLAYERS;i++)
	{
		if(RaceParticipant[i]>0)
		{
			TogglePlayerControllable(i,true);
			if(PlayerVehicles[i] != 0)
			{
				if(racevehicle[i] != 1) PutPlayerInVehicle(i,PlayerVehicles[i],0);
				PlayerVehicles[i]=0;
			}
		}
	}
}

public countdown()
{
	if(cd<5) RaceStart=1;
	if(cd>0)
	{
	    for(new i=0;i<MAX_PLAYERS;i++){
	    if(IsPlayerInAnyVehicle(i)) PlayerVehicles[i]=GetPlayerVehicleID(i);
		else PlayerVehicles[i]=0;

		if(RaceParticipant[i]>1) TextDrawShowForPlayer(i, TCountdown);
	    if(RaceParticipant[i] == 3)
		{
			TogglePlayerControllable(i, false);
	    	if(!IsPlayerInAnyVehicle(i)) PutPlayerInVehicle(i, PlayerVehicle[i], 0);
		}
	    }
		format(iString, sizeof(iString), "%d",cd);
		for(new i=0;i<MAX_PLAYERS;i++)
		{
			if(RaceParticipant[i]>1)
			{
			    new string[32];
				if(cd<10)RaceSound(i,1056);
                format(string, sizeof(string), "%i", cd);
				TextDrawSetString(TCountdown, string);
				if(cd<6)
				{
					GameTextForPlayer(i, string, 1000, 3);
				}
		    }
	    }
	}
	else if(cd == 0)
	{
		format(iString, sizeof(iString), "~g~GO!",cd);
		SendClientMessageToAll(COLOUR_GREEN, "The race has begun!");
		if(Participants == 0) endraceload();
	    KillTimer(Countdown);
	    RaceStart=1;
	    TextDrawHideForAll(TCountdown);
		for(new i=0;i<MAX_PLAYERS;i++)
		{
			if(RaceParticipant[i]>1)
			{
			    if(!IsPlayerInAnyVehicle(i))
				{
				    DestroyVehicle(PlayerVehicle[i]);
					PlayerF(i);
					TogglePlayerControllable(i, true);
					GivePlayerRunflats( i );
					KillTimer(PlayerFreeze[i]);
				}
				HideMenuForPlayer(WheelsMenu, i);
				RaceSound(i,1057);
			    GameTextForPlayer(i,iString,3000,3);
			    TogglePlayerControllable(i, true);
				RaceParticipant[i]=4;
				CurrentLap[i]=1;
				TextDrawShowForPlayer(i, Times);
				TextDrawHideForPlayer(i, TCountdown);
				TextDrawShowForPlayer(i, Partici);
   				TextDrawShowForPlayer(i, Position[i]);
   				TextDrawShowForPlayer(i, TPosition[i]);
   				//TextDrawShowForPlayer(i, Speed[i]);
   				KillTimer(TimeTimer[i]);
				TimeTimer[i] = SetTimerEx("TimeTDUpdate", 999, true, "i", i);
				if(Racemode == 3) SetRaceCheckpoint(i,LCurrentCheckpoint,LCurrentCheckpoint-1);
				else SetRaceCheckpoint(i,0,1);
		    }
	    }
		UnlockRacers();
		RaceTick=GetTickCount();
	}
	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[bb(playerid)];
	if(next == -1 && ar == 0) SetPlayerRaceCheckpoint(playerid,1,BRaceCheckpoints[bb(playerid)][target][0],BRaceCheckpoints[bb(playerid)][target][1],
								BRaceCheckpoints[bb(playerid)][target][2],0.0,0.0,0.0,BCPsize[bb(playerid)]);
	else if(next == -1 && ar == 1) SetPlayerRaceCheckpoint(playerid,4,BRaceCheckpoints[bb(playerid)][target][0],
				BRaceCheckpoints[bb(playerid)][target][1],BRaceCheckpoints[bb(playerid)][target][2],0.0,0.0,0.0,
				BCPsize[bb(playerid)]);
	else if(ar == 1) SetPlayerRaceCheckpoint(playerid,3,BRaceCheckpoints[bb(playerid)][target][0],BRaceCheckpoints[bb(playerid)][target][1],BRaceCheckpoints[bb(playerid)][target][2],
						BRaceCheckpoints[bb(playerid)][next][0],BRaceCheckpoints[bb(playerid)][next][1],BRaceCheckpoints[bb(playerid)][next][2],BCPsize[bb(playerid)]);
	else SetPlayerRaceCheckpoint(playerid,0,BRaceCheckpoints[bb(playerid)][target][0],BRaceCheckpoints[bb(playerid)][target][1],BRaceCheckpoints[bb(playerid)][target][2],
			BRaceCheckpoints[bb(playerid)][next][0],BRaceCheckpoints[bb(playerid)][next][1],BRaceCheckpoints[bb(playerid)][next][2],BCPsize[bb(playerid)]);
}

public GetLapTick(playerid)
{
	new tick, lap;
	tick=GetTickCount();
	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=GetTickCount();
	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(RaceStart == 1)
		{
		    new playerstate = GetPlayerState(playerid);
			if(playerstate != PLAYER_STATE_ONFOOT && GetVehicleModel(GetPlayerVehicleID(playerid)) != racevehicle[playerid])
			{
			    SendClientMessage(playerid,COLOUR_RED, "You need to be the driver of the appropriate race vehicle!");
				return 0;
   			}
			if(racevehicle[playerid] != 1) if(playerstate != PLAYER_STATE_DRIVER && playerstate != PLAYER_STATE_ONFOOT)
			{
			    SendClientMessage(playerid,COLOUR_RED, "You need to be the driver of the appropriate race vehicle!");
				return 0;
			}

			gPlayerProgress[playerid]++;
    		gRaceCheckpoints[gPlayerProgress[playerid]]++;
    		RacePosition[playerid]=floatround(gRaceCheckpoints[gPlayerProgress[playerid]],floatround_floor);
    		format(iString, sizeof(iString), "%i", RacePosition[playerid]);
			TextDrawSetString(TPosition[playerid], iString); //Set the race textdraws
			TextDrawHideForPlayer(playerid, Append1), TextDrawHideForPlayer(playerid, Append2), TextDrawHideForPlayer(playerid, Append3), TextDrawHideForPlayer(playerid, Append4);

			switch (RacePosition[playerid])
			{
				case 1,21,31,41,51,61,71,81,91:	TextDrawShowForPlayer(playerid, Append1);
				case 2,22,32,42,52,62,72,82,92:	TextDrawShowForPlayer(playerid, Append2);
				case 3,23,33,43,53,63,73,83,93: TextDrawShowForPlayer(playerid, Append3);
				default: TextDrawShowForPlayer(playerid, Append4);
			}
			/*new NewTick;
			TextDrawShowForPlayer(playerid, Diff[playerid]);
			if(RacePosition[playerid] == 1)
			{
				FirstTick[CurrentCheckpoint[playerid]][playerid]=GetTickCount();//Get the time at the latest checkpoint
			}
			else
			{
				NewTick = GetTickCount();//Get time current tick
				Difference[CurrentCheckpoint[playerid]][playerid] = NewTick - FirstTick[CurrentCheckpoint[playerid]][playerid];//Get the difference between before and now
				format(iString, sizeof(iString), "+%s", BeHumanR(Difference[CurrentCheckpoint[playerid]][playerid]));//Convert into a readable format
				TextDrawSetString(Diff[playerid], iString);
			}*/
		}
		if(RaceParticipant[playerid] == 6) // Player reaches the checkered flag.
		{
		    new RaceString[10];
		    SetPlayerVirtualWorld(playerid, 0);
		    KillTimer(TimeTimer[playerid]);
    		TextDrawHideForPlayer(playerid, Times);
    		TextDrawHideForPlayer(playerid, Partici);
	    	TextDrawHideForPlayer(playerid, Position[playerid]);
	    	TextDrawHideForPlayer(playerid, TPosition[playerid]);
	    	//TextDrawHideForPlayer(playerid, Diff[playerid]);
	    	TextDrawHideForPlayer(playerid, Append1), TextDrawHideForPlayer(playerid, Append2), TextDrawHideForPlayer(playerid, Append3), TextDrawHideForPlayer(playerid, Append4);
	    	//TextDrawHideForPlayer(playerid, Speed[playerid]);
		    if(racevehicle[playerid] != 1) DestroyVehicle(GetPlayerVehicleID(playerid));
			new names[MAX_PLAYER_NAME], LapTime, RaceTime;
			LapTime=GetLapTick(playerid);
			RaceTime=GetRaceTick(playerid);
			GetPlayerName(playerid, names, MAX_PLAYER_NAME);
			RaceParticipant[playerid]=0;
			RaceSound(playerid,1138);
			RaceString=BeHumanR(RaceTime);
			format(iString,sizeof(iString),"%s has finished %s in position %d, Time: %s", names, CRaceName, Ranking,RaceString);
			SendClientMessageToAll(COLOUR_GREEN,iString);
			SetPlayerInterior(playerid, interiorsave[playerid]);
			SetPlayerVirtualWorld(playerid, worldsave[playerid]);
			SetPlayerPos(playerid, xsave[playerid], ysave[playerid], zsave[playerid]);
			//SetPlayerGravity(playerid, 0.008);
			SetPlayerWeather(playerid, 0);
			if(Racemode == ORacemode && ORacelaps == Racelaps)
			{
				new	LapString[10], laprank, racerank;
				LapString=BeHumanR(LapTime);
				RaceString=BeHumanR(RaceTime);
				format(iString,sizeof(iString),"~w~Racetime: %s",RaceString);
				if(ORacemode!=0) format(iString,sizeof(iString),"%s~n~Laptime: %s",iString,LapString);
				laprank=CheckBestLap(playerid,LapTime);
				if(laprank == 1)
				{
				    format(iString,sizeof(iString),"%s~n~~y~LAP RECORD!",iString);
				    GameTextForPlayer(playerid,iString,13000,3);
				}
				racerank=CheckBestRace(playerid,RaceTime);
				if(racerank == 1)
				{
				    format(iString,sizeof(iString),"%s~n~~y~TRACK RECORD!",iString);
				    GameTextForPlayer(playerid,iString,13000,3);
				    format(iString,sizeof(iString),"%s has set a new top race record on %s: %s", names, CRaceName, RaceString);
					SendClientMessageToAll(COLOUR_YELLOW, iString);
				}
		    }
			new winrar;
			if(Ranking == 1)
			{
				winrar = Winnings1;
				EndingT = SetTimer("EndTimerR", 60000, false);
			}
			else if(Ranking == 2) winrar = Winnings2;
			else if(Ranking == 3) winrar = Winnings3;
			else if(Ranking == 4) winrar = Winnings4;
			else if(Ranking == 5) winrar = Winnings5;
			else if(Ranking > 5) winrar = RunnerUp;
			GivePlayerMoney(playerid, winrar);
			/*if(Ranking == 1) GivePlayerXp(playerid, 5);
			else if(Ranking == 2) GivePlayerXp(playerid, 4);
			else if(Ranking == 3) GivePlayerXp(playerid, 3);
			else if(Ranking == 4) GivePlayerXp(playerid, 2);
			else if(Ranking == 5) GivePlayerXp(playerid, 1);*/
			format(iString,sizeof(iString),"You have earned $%d from the race!",winrar);
			SendClientMessage(playerid,COLOUR_GREEN,iString);

   			Ranking++;
			Participants--;
	        DisablePlayerRaceCheckpoint(playerid);
	        if(Participants == 0)
			{
			    new ender;
				for(new i=0;i<MAX_PLAYERS;i++)
				{
				    if(GetPlayerVirtualWorld(i) == RaceWorld) continue;
				    ender = 1;
				}
				if(ender == 1) endraceload();
			}
            //RaceSound(playerid,1183);
  			//SetTimerEx("MusicStop", 10000, false, "i", playerid);
	    }
	    else if (RaceStart == 0 && RaceParticipant[playerid]==1) // Player arrives to the start CP for 1st time
	    {
   			PlayerFreeze[playerid] = SetTimerEx("PlayerF", 5000, false, "i", playerid);
			SendClientMessage(playerid,COLOUR_YELLOW,"NOTE: You will be frozen in 5 seconds, get into position!");
			RaceParticipant[playerid]=1;
			CurrentLap[playerid]=0;
	    }
	    else if (RaceStart == 0 && RaceParticipant[playerid]==0)
	    {
	    	SendClientMessage(playerid, COLOUR_YELLOW, "You need to type /join to enter the race!");
		}
	    else if (RaceStart==1) // Otherwise switch to the next race CP.
	    {
			RaceSound(playerid,1138);
			SetNextCheckpoint(playerid);
	    }
	}
	return 1;
}

public Cendrace()
{
    //SetServerRule("Current Race", "None");
    SaveScores(); //If the race had already started, and mode & laps are as originally, save the lapscores and racescores.
    ReadyRef = 0;
    Partsave = 0;
	for(new i=0;i<LCurrentCheckpoint;i++)
	{
	    RaceCheckpoints[i][0]=0.0;
	    RaceCheckpoints[i][1]=0.0;
	    RaceCheckpoints[i][2]=0.0;
	}
	LCurrentCheckpoint=0;
	TextDrawHideForAll(Append1), TextDrawHideForAll(Append2), TextDrawHideForAll(Append3), TextDrawHideForAll(Append4);
    TextDrawHideForAll(Times);
    TextDrawHideForAll(Partici);
    KillTimer(EndingT);
    KillTimer(LoadNextRace);


    if(PickupType[Pickup0] != 0)DestroyPickup(Pickup0);
    if(PickupType[Pickup1] != 0)DestroyPickup(Pickup1);
    if(PickupType[Pickup2] != 0)DestroyPickup(Pickup2);
    if(PickupType[Pickup3] != 0)DestroyPickup(Pickup3);
    if(PickupType[Pickup4] != 0)DestroyPickup(Pickup4);

    PickupVehicle0 = -1;
    PickupVehicle1 = -1;
    PickupVehicle2 = -1;
    PickupVehicle3 = -1;
    PickupVehicle4 = -1;

    PickupType[0] = -1;
    PickupType[1] = -1;
    PickupType[2] = -1;
    PickupType[3] = -1;
    PickupType[4] = -1;

    format(iString, sizeof(iString), "/iRaces/%s.iRo", CRaceName);
	if(fexist(iString)) for(new i=0;i<MAX_GAYME_OBJECTS;i++) DestroyObject(oObjectR[i]); // File doesn't exist

    for(new i=0;i<MAX_PLAYERS;i++)
    {
        KillTimer(PlayerFreeze[i]);
        KillTimer(TimeTimer[i]);
        if(GetVehicleVirtualWorld(PlayerVehicle[i]) == RaceWorld) DestroyVehicle(PlayerVehicle[i]);
        gPlayerProgress[i] = 0;
		if(i < MAX_RACECHECKPOINTS) gRaceCheckpoints[i] = 0;
    	RacePosition[i] = 0;
        KillTimer(TimeTimer[i]);
    	TextDrawHideForPlayer(i, Position[i]);
    	TextDrawHideForPlayer(i, TPosition[i]);
    	//TextDrawHideForPlayer(i, Diff[i]);
    	//TextDrawHideForPlayer(i, Speed[i]);
		LastLapTick[i]=0;
		if(RaceParticipant[i]>0 && RaceBuilders[i] == 0)
		{
		    //SetPlayerGravity(i, 0.008);
		    DisablePlayerRaceCheckpoint(i);
		    SetPlayerInterior(i, interiorsave[i]);
		    SetPlayerPos(i, xsave[i], ysave[i], zsave[i]);
			SetPlayerVirtualWorld(i, worldsave[i]);
			TogglePlayerControllable(i,1);
		    if(PlayerVehicles[i] != 0)
		    {
		        PlayerVehicles[i]=0;
		    }
		}
        RaceParticipant[i]=0;
    }
	RaceActive=0;
	RaceStart=0;
	Participants=0;
    KillTimer(RaceEnd);
    KillTimer(RaceFixTimer);
    KillTimer(Countdown);
	return 1;
}

public endraceload()
{
    //SetServerRule("Current Race", "None");
    SaveScores(); //If the race had already started, and mode & laps are as originally, save the lapscores and racescores.
    ReadyRef = 0;
    Partsave = 0;
	for(new i=0;i<LCurrentCheckpoint;i++)
	{
	    RaceCheckpoints[i][0]=0.0;
	    RaceCheckpoints[i][1]=0.0;
	    RaceCheckpoints[i][2]=0.0;
	}
	LCurrentCheckpoint=0;
	TextDrawHideForAll(Append1), TextDrawHideForAll(Append2), TextDrawHideForAll(Append3), TextDrawHideForAll(Append4);
    TextDrawHideForAll(Times);
    TextDrawHideForAll(Partici);
    KillTimer(EndingT);
    KillTimer(LoadNextRace);

    DestroyPickup(Pickup0);
    DestroyPickup(Pickup1);
    DestroyPickup(Pickup2);
    DestroyPickup(Pickup3);
    DestroyPickup(Pickup4);

    PickupVehicle0 = -1;
    PickupVehicle1 = -1;
    PickupVehicle2 = -1;
    PickupVehicle3 = -1;
    PickupVehicle4 = -1;

    PickupType[0] = -1;
    PickupType[1] = -1;
    PickupType[2] = -1;
    PickupType[3] = -1;
    PickupType[4] = -1;

    for(new i=0;i<MAX_GAYME_OBJECTS;i++) DestroyObject(oObjectR[i]);

    for(new i=0;i<MAX_PLAYERS;i++)
    {
        KillTimer(PlayerFreeze[i]);
        KillTimer(TimeTimer[i]);
        if(GetVehicleVirtualWorld(PlayerVehicle[i]) == RaceWorld) DestroyVehicle(PlayerVehicle[i]);
        gPlayerProgress[i] = 0;
		if(i < MAX_RACECHECKPOINTS) gRaceCheckpoints[i] = 0;
    	RacePosition[i] = 0;
        KillTimer(TimeTimer[i]);
    	TextDrawHideForPlayer(i, Position[i]);
    	TextDrawHideForPlayer(i, TPosition[i]);
    	//TextDrawHideForPlayer(i, Diff[i]);
    	//TextDrawHideForPlayer(i, Speed[i]);
		LastLapTick[i]=0;
		if(RaceParticipant[i]>0 && RaceBuilders[i] == 0)
		{
		    //SetPlayerGravity(i, 0.008);
		    DisablePlayerRaceCheckpoint(i);
		    SetPlayerInterior(i, interiorsave[i]);
		    SetPlayerPos(i, xsave[i], ysave[i], zsave[i]);
			SetPlayerVirtualWorld(i, worldsave[i]);
			TogglePlayerControllable(i,1);
		    if(PlayerVehicles[i] != 0)
		    {
		        PlayerVehicles[i]=0;
		    }
		}
        RaceParticipant[i]=0;
    }
	RaceActive=0;
	RaceStart=0;
	Participants=0;
    SendClientMessageToAll(COLOUR_YELLOW, "The current race has been finished. The next race will begin in 60 seconds.");
    KillTimer(RaceEnd);
    KillTimer(RaceFixTimer);
    KillTimer(Countdown);
	KillTimer(LoadNextRace);
    LoadNextRace = SetTimer("loadnext", 60000, false);
	return 1;
}

public loadnext()
{
    RaceRotation();
	return 1;
}

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

public RaceSound(playerid,sound)
{
	xPlayerPlaySound(playerid,sound);
}

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 RaceEnder()
{
if(RaceActive==1) endraceload();
return 1;
}

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)
	{
		/*Float:x,Float:y,Float:z,
		format(templine,sizeof(templine),"iRace %d %d %s %d %d %d %f\n", RACEFILE_VERSION, racevehicle, CBuilder, ORacemode, ORacelaps, OAirrace, OCPsize);
		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]);*/
	 	INI_Open(CFile);

		INI_WriteString("RaceTimesName/0", TopRacers[0]);
		INI_WriteInt("RaceTimesTime/0", TopRacerTimes[0]);
		INI_WriteString("RaceTimesName/1", TopRacers[1]);
		INI_WriteInt("RaceTimesTime/1", TopRacerTimes[1]);
		INI_WriteString("RaceTimesName/2", TopRacers[2]);
		INI_WriteInt("RaceTimesTime/2", TopRacerTimes[2]);
		INI_WriteString("RaceTimesName/3", TopRacers[3]);
		INI_WriteInt("RaceTimesTime/3", TopRacerTimes[3]);
		INI_WriteString("RaceTimesName/4", TopRacers[4]);
		INI_WriteInt("RaceTimesTime/4", TopRacerTimes[4]);

        INI_WriteString("LapTimesName/0", TopLappers[0]);
		INI_WriteInt("LapTimesTime/0", TopLapTimes[0]);
		INI_WriteString("LapTimesName/1", TopLappers[1]);
		INI_WriteInt("LapTimesTime/1", TopLapTimes[1]);
		INI_WriteString("LapTimesName/2", TopLappers[2]);
		INI_WriteInt("LapTimesTime/2", TopLapTimes[2]);
		INI_WriteString("LapTimesName/3", TopLappers[3]);
		INI_WriteInt("LapTimesTime/3", TopLapTimes[3]);
		INI_WriteString("LapTimesName/4", TopLappers[4]);
		INI_WriteInt("LapTimesTime/4", TopLapTimes[4]);

		INI_Save();
		INI_Close();
	}
	ScoreChange=0;
}
public ChangeLap(playerid)
{
	new LapTime, TimeString[10], checklap;
	LapTime=GetLapTick(playerid);
	TimeString=BeHumanR(LapTime);
	format(iString,sizeof(iString),"~w~Lap %d/%d - time: %s", CurrentLap[playerid], Racelaps, TimeString);
	if(Racemode == ORacemode && ORacelaps == Racelaps)
	{
		checklap=CheckBestLap(playerid,LapTime);
		if(checklap==1) format(iString,sizeof(iString),"%s~n~~y~LAP RECORD!",iString);
	}
	CurrentLap[playerid]++;
	if(CurrentLap[playerid] == Racelaps) format(iString,sizeof(iString),"%s~n~~g~Final lap!",iString);
	GameTextForPlayer(playerid,iString,6000,3);
}

BeHumanR(ticks)
{
	new HumanTime[10], minutes, seconds, secstring[3], 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;
}

BeHumanCP(ticks)
{
	new HumanTime[10], minutes, seconds, secstring[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);
	return HumanTime;
}

public LoadTimes(playerid,timemode,tmp[])
{
	new temprace[67];
	format(temprace,sizeof(temprace),"iRaces/%s.iR",tmp);
    if(strlen(tmp))
    {
		if(!fexist(temprace))
		{
			format(iString,sizeof(iString),"Race \'%s\' doesn't exist!",tmp);
			SendClientMessage(playerid,COLOUR_YELLOW,iString);
			return 1;
		}

		else
		{
			new TempLapper[256], TempLap;
			INI_Open(temprace);
			INI_ReadString(TBuilder, "Creator");
			if(timemode == 0) format(iString,sizeof(iString),"%s by %s - Best race times:",tmp,TBuilder);
			else if(timemode == 1) format(iString,sizeof(iString),"%s by %s - Best laps:",tmp,TBuilder);
			else return 1;
			SendClientMessage(playerid,COLOUR_GREEN,iString);

			if(timemode == 0){
				for(new i;i < 5; i++)
				{
					format(iString, sizeof(iString), "RaceTimesName/%d", i);
					INI_ReadString(iString, iString);
					format(TempLapper, sizeof(TempLapper), "RaceTimesTime/%d", i);
					TempLap = INI_ReadInt(TempLapper);
					if(TempLap != 0)
					{
						format(iString,sizeof(iString),"%d. %s - %s",i+1, BeHumanR(TempLap), iString);
						SendClientMessage(playerid,COLOUR_GREEN,iString);
					}
					if(TempLap == 0)
					{
					    format(iString,sizeof(iString),"%d. None yet",i+1);
						i=6;
					}
				}
			}

			if(timemode == 1){
				for(new i;i < 5; i++)
				{
					format(iString, sizeof(iString), "LapTimesName/%d", i);
					INI_ReadString(iString, iString);
					format(TempLapper, sizeof(TempLapper), "LapTimesTime/%d", i);
					TempLap = INI_ReadInt(TempLapper);
					if(TempLap != 0)
					{
						format(iString,sizeof(iString),"%d. %s - %s",i+1, BeHumanR(TempLap), iString);
						SendClientMessage(playerid,COLOUR_GREEN,iString);
					}
					if(TempLap == 0)
					{
					    format(iString,sizeof(iString),"%d. None yet",i+1);
						i=6;
					}
				}
			}
			INI_Save();
			INI_Close();
		}
		return 1;
		}
 	else 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] < MAX_PLAYERS+1))
	    {
	        BuilderSlots[i] = playerid;
	        RaceBuilders[playerid] = i+1;
			return i+1;
	    }
	}
	return 0;
}

public bb(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 Cclearrace(playerid)
{
	for(new i=0;i<BCurrentCheckpoints[bb(playerid)];i++)
	{
		BRaceCheckpoints[bb(playerid)][i][0]=0.0;
		BRaceCheckpoints[bb(playerid)][i][1]=0.0;
		BRaceCheckpoints[bb(playerid)][i][2]=0.0;
	}
	BCurrentCheckpoints[bb(playerid)]=0;
	DisablePlayerRaceCheckpoint(playerid);
	SendClientMessage(playerid, COLOUR_GREEN, "Your race has been cleared! Use /buildrace to start a new one.");
	BuilderSlots[bb(playerid)] = MAX_PLAYERS+1;
	RaceBuilders[playerid]=0;
}

public Cstartrace()
{
	format(iString,128,"Race \'%s\' by %s is about to start, type /JOIN to enter!",CRaceName, CBuilder);
	SendClientMessageToAll(COLOUR_YELLOW,iString);
	if(Racemode == 0) format(iString,sizeof(iString),"Sprint");
	else if(Racemode == 1) format(iString,sizeof(iString),"Ring");
	else if(Racemode == 2) format(iString,sizeof(iString),"Yoyo");
	else if(Racemode == 3) format(iString,sizeof(iString),"Mirror");
	format(iString,sizeof(iString),"Mode: %s Laps: %d",iString,Racelaps);
	format(iString,sizeof(iString),"%s Vehicle: %s",iString,RaceVehicleName);
	format(iString,sizeof(iString),"%s Gravity: %.3f",iString, Gravity);

	if(RWeather == 8) format(iString,sizeof(iString),"%s Weather: Rain",iString);
	else if(RWeather == 9) format(iString,sizeof(iString),"%s Weather: Foggy",iString);
	else if(RWeather == -68) format(iString,sizeof(iString),"%s Weather: Hurricane",iString);
	else if(RWeather == 1337) format(iString,sizeof(iString),"%s Weather: DD",iString);
	else format(iString,sizeof(iString),"%s Weather: Sunny",iString);

	if(Airrace == 1) format(iString,sizeof(iString),"%s AIR RACE",iString);
	if(Racemode == 0 || Racemode == 3) format(iString,sizeof(iString),"%s Track lenght: %0.2fkm", iString, RLenght/1000);
	else if(Racemode == 1) format(iString,sizeof(iString),"%s Lap lenght: %.2fkm, Total: %.2fkm", iString, LLenght/1000, LLenght * Racelaps / 1000);
	SendClientMessageToAll(COLOUR_GREEN,iString);
	RaceStart=0;
	ScoreChange=0;
	RaceActive=1;
	Ranking=1;
}

public LoadRace(tmp[])
{
    KillTimer(EndingT);
    KillTimer(RaceEnd);
    KillTimer(LoadNextRace);
    RaceEnd = SetTimer("RaceEnder", 760000, false);
	new race_name[64],templine[512];
	new File:f, templine2[64], Count, idx;
   	format(iString, sizeof(iString), "iRaces/iList.iRf");
   	if(!fexist(iString)) return -1; // File doesn't exist
	f = fopen(iString, io_read);
	while(fread(f,templine2,sizeof(templine2),false))
	{
		for(new i, x = strlen(templine2); i < x; i++)
		{
			if(templine2[i] == '\r') templine2[i] = '\0';
			//break;
		}
		idx = 0;
		RaceNames[Count] = strtok(templine2, idx);
		//printf("%s", RaceNames[Count]);
		Count++;
		GaymeCountR++;
	}
	for(new j=0;j<GaymeCountR-1;j++)
	{
	    if(strfind(RaceNames[j], tmp, true) != -1)
	    {
	        format(race_name,sizeof(race_name), "iRaces/%s.iR", RaceNames[j]);
	        printf("race load: %s", race_name);
	        format(CRaceName,sizeof(CRaceName), "%s", RaceNames[j]);
	        break;
	    }
	}
	//SetServerRule("Current Race", tmp);
	if(!fexist(race_name)) return -1; // File doesn't exist
	CFile=race_name;
    LCurrentCheckpoint=-1; RLenght=0; RLenght=0;
    INI_Open(race_name);
    new racevehicle2;
	racevehicle2 = INI_ReadInt("Vehicle"); // Read off vehicle
	for(new j=0;j<MAX_PLAYERS;j++)  racevehicle[j] = racevehicle2;
	AutoFixT = INI_ReadInt("AutoFix");
	if(AutoFixT == 1) RaceFixTimer = SetTimer("RaceFix", 3000, true);
	INI_ReadString(CBuilder, "Creator"); // read off RACEBUILDER
	ORacemode = INI_ReadInt("RaceMode"); // read off racemode
	ORacelaps = INI_ReadInt("Laps"); // read off amount of laps
	Nitrous = INI_ReadInt("Nos");
	Gravity = INI_ReadFloat("Gravity");
	if(Gravity == 0) Gravity = 0.008;
	INI_WriteFloat("Gravity", Gravity);
	RWeather = INI_ReadInt("Weather");
	//INI_WriteInt("Weather", RWeather);
	RaceWorld = INI_ReadInt("World");
	if(RaceWorld < 100){
		RaceWorld = 150;
	}
	//RaceWorld = 150;
	Airrace = INI_ReadInt("AirRace");   // read off airrace
	CPsize = INI_ReadFloat("CPSize");    // read off CP size
	Racemode=ORacemode; Racelaps=ORacelaps; //Allows changing the modes, but disables highscores if they've been changed.
	new tempstring[48];
	idx = 0;
	PickupModel = INI_ReadInt("PickupModel"); // read pickup model

	if(INI_ReadString(tempstring, "PickupLocations0")) // read pickup xyz
	{

		PickupLocations[0][0] = floatstr(strtok(tempstring, idx));
		PickupLocations[0][1] = floatstr(strtok(tempstring, idx));
		PickupLocations[0][2] = floatstr(strtok(tempstring, idx));

		PickupType[0] = INI_ReadInt("PickupType0");

		if(PickupType[0] != 0) Pickup0 = CreatePickup(PickupModel, 14, PickupLocations[0][0], PickupLocations[0][1], PickupLocations[0][2], 150);

		if(PickupType[0] == 2) PickupVehicle0 = INI_ReadInt("PickupVehicle0");
	}

	if(INI_ReadString(tempstring, "PickupLocations1"))
	{
	    idx = 0;
	    PickupLocations[1][0] = floatstr(strtok(tempstring, idx));
		PickupLocations[1][1] = floatstr(strtok(tempstring, idx));
		PickupLocations[1][2] = floatstr(strtok(tempstring, idx));
		PickupType[1] = INI_ReadInt("PickupType1");
		if(PickupType[1] != 0) Pickup1 = CreatePickup(PickupModel, 14, PickupLocations[1][0], PickupLocations[1][1], PickupLocations[1][2], 150);
		if(PickupType[1] == 2) PickupVehicle1 = INI_ReadInt("PickupVehicle1");
	}
	if(INI_ReadString(tempstring, "PickupLocations2"))
	{
	    idx = 0;
	    PickupLocations[2][0] = floatstr(strtok(tempstring, idx));
		PickupLocations[2][1] = floatstr(strtok(tempstring, idx));
		PickupLocations[2][2] = floatstr(strtok(tempstring, idx));
		PickupType[2] = INI_ReadInt("PickupType2");
		if(PickupType[2] != 0) Pickup2 = CreatePickup(PickupModel, 14, PickupLocations[2][0], PickupLocations[2][1], PickupLocations[2][2], 150);
		if(PickupType[2] == 2) PickupVehicle2 = INI_ReadInt("PickupVehicle2");
	}
	if(INI_ReadString(tempstring, "PickupLocations3"))
	{
	    idx = 0;
	    PickupLocations[3][0] = floatstr(strtok(tempstring, idx));
		PickupLocations[3][1] = floatstr(strtok(tempstring, idx));
		PickupLocations[3][2] = floatstr(strtok(tempstring, idx));
		PickupType[3] = INI_ReadInt("PickupType3");
		if(PickupType[3] != 0) Pickup3 = CreatePickup(PickupModel, 14, PickupLocations[3][0], PickupLocations[3][1], PickupLocations[3][2], 150);
		if(PickupType[3] == 2) PickupVehicle3 = INI_ReadInt("PickupVehicle3");
	}
	if(INI_ReadString(tempstring, "PickupLocations4"))
	{
	    idx = 0;
	    PickupLocations[4][0] = floatstr(strtok(tempstring, idx));
		PickupLocations[4][1] = floatstr(strtok(tempstring, idx));
		PickupLocations[4][2] = floatstr(strtok(tempstring, idx));
		PickupType[4] = INI_ReadInt("PickupType4");
		if(PickupType[4] != 0) Pickup4 = CreatePickup(PickupModel, 14, PickupLocations[4][0], PickupLocations[4][1], PickupLocations[4][2], 150);
		if(PickupType[4] == 2) PickupVehicle4 = INI_ReadInt("PickupVehicle4");
	}
	printf("type: %i location: %f, %f, %f", PickupType[0], PickupLocations[0][0], PickupLocations[0][1], PickupLocations[0][2]);
	printf("type: %i location: %f, %f, %f", PickupType[1], PickupLocations[1][0], PickupLocations[1][1], PickupLocations[1][2]);
	printf("type: %i location: %f, %f, %f", PickupType[2], PickupLocations[2][0], PickupLocations[2][1], PickupLocations[2][2]);
	printf("type: %i location: %f, %f, %f", PickupType[3], PickupLocations[3][0], PickupLocations[3][1], PickupLocations[3][2]);
	printf("type: %i location: %f, %f, %f", PickupType[4], PickupLocations[4][0], PickupLocations[4][1], PickupLocations[4][2]);
	for(new j=0;j<5;j++)
	{
	    format(templine,sizeof(templine), "RaceTimes1/%d",j);
	    format(iString,sizeof(iString), "RaceTimes2/%d",j);
	    INI_ReadString(TopRacers[j], templine);
	    TopRacerTimes[j]=INI_ReadInt(iString);
	}
	for(new j=0;j<5;j++)
	{
	    format(templine,sizeof(templine), "LapTimes1/%d",j);
	    format(iString,sizeof(iString), "LapTimes2/%d",j);
	    INI_ReadString(TopLappers[j], templine);
	    TopLapTimes[j]=INI_ReadInt(iString);
	}
 	INI_ReadString(TopRacers[0], "RaceTimesName/0");
	TopRacerTimes[0] = INI_ReadInt("RaceTimesTime/0");
 	INI_ReadString(TopRacers[1], "RaceTimesName/1");
	TopRacerTimes[1] = INI_ReadInt("RaceTimesTime/1");
 	INI_ReadString(TopRacers[2], "RaceTimesName/2");
	TopRacerTimes[2] = INI_ReadInt("RaceTimesTime/2");
	INI_ReadString(TopRacers[3], "RaceTimesName/3");
	TopRacerTimes[3] = INI_ReadInt("RaceTimesTime/3");
	INI_ReadString(TopRacers[4], "RaceTimesName/4");
	TopRacerTimes[4] = INI_ReadInt("RaceTimesTime/4");

	INI_ReadString(TopLappers[0], "LapTimesName/0");
	TopLapTimes[0] = INI_ReadInt("LapTimesTime/0");
	INI_ReadString(TopLappers[1], "LapTimesName/1");
	TopLapTimes[1] = INI_ReadInt("LapTimesTime/1");
	INI_ReadString(TopLappers[2], "LapTimesName/2");
	TopLapTimes[2] = INI_ReadInt("LapTimesTime/2");
	INI_ReadString(TopLappers[3], "LapTimesName/3");
	TopLapTimes[3] = INI_ReadInt("LapTimesTime/3");
	INI_ReadString(TopLappers[4], "LapTimesName/4");
	TopLapTimes[4] = INI_ReadInt("LapTimesTime/4");

	StartX = INI_ReadFloat("Tcp/1");
	StartY = INI_ReadFloat("Tcp/2");
	StartZ = INI_ReadFloat("Tcp/3");
	StartR = INI_ReadFloat("Tcp/4");
    LCurrentCheckpoint = -1;
    new i;
	for(new j=0;j<200;j++)
	{
	    i = 0;
		LCurrentCheckpoint++;
		format(iString,sizeof(iString), "CPs/%d", LCurrentCheckpoint);
		INI_ReadString(iString, iString);
		RaceCheckpoints[LCurrentCheckpoint][0] = floatstr(strtok(iString,i));
		if(RaceCheckpoints[LCurrentCheckpoint][0] > -1 && RaceCheckpoints[LCurrentCheckpoint][0] < 1)
		{
		    LCurrentCheckpoint=j-1;
			break;
		}

		RaceCheckpoints[LCurrentCheckpoint][1] = floatstr(strtok(iString,i));
		RaceCheckpoints[LCurrentCheckpoint][2] = floatstr(strtok(iString,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]);
	RaceVehicleName = ReturnVehicle(racevehicle[0]);
	INI_Save();
	INI_Close();
	// Preload objects
	format(iString, sizeof(iString), "/iRaces/%s.iRo", CRaceName);
	if(!fexist(iString)) printf("No object data"); // File doesn't exist
	else
	{
        f = fopen(iString, io_read);
        new Counter, fileline[128];
		while(fread(f,fileline,sizeof(fileline),false))
		{
		    idx = 0;
   			oModelR[Counter] = strval(strtok(fileline, idx));
   			oXR[Counter] = floatstr(strtok(fileline, idx));
   			oYR[Counter] = floatstr(strtok(fileline, idx));
   			oZR[Counter] = floatstr(strtok(fileline, idx));
   			oRXR[Counter] = floatstr(strtok(fileline, idx));
   			oRYR[Counter] = floatstr(strtok(fileline, idx));
   			oRZR[Counter] = floatstr(strtok(fileline, idx));
			oObjectR[Counter] = CreateObject(oModelR[Counter], oXR[Counter], oYR[Counter], oZR[Counter], oRXR[Counter], oRYR[Counter], oRZR[Counter]);
			Counter++;
		}
		fclose(f);
	}
	return 1;
}

public EndTimerR()
{
	endraceload();
	return 1;
}

public RaceRotation()
{
	if(!fexist("iRaces/iList.iRf"))
	{
	    printf("ERROR in  RacerX (iList.iRf): File doesn't exist!");
	    return -1;
	}

	if(Participants > 0) return 1; // A race is still active.

	new File:f, templine[32], rotfile[]="iRaces/iList.iRf", rraces=-1, rracenames[32], idx, mmk, rand;
	f = fopen(rotfile, io_read);
	while(fread(f,templine,sizeof(templine),false))
	{
	    rraces++;
	}
	fclose(f);
	f = fopen(rotfile, io_read);
	mmk = random(rraces);
	while(fread(f,templine,sizeof(templine),false))
	{
	    rand++;
		if(rand == mmk+1) rracenames=strtok(templine,idx);
	}
	fclose(f);
	fback = LoadRace(rracenames);
	if(fback == -1)
	{
		printf("ERROR in RacerX (iList.iRf): Race \'%s\' doesn't exist!",rracenames);
		RaceRotation();
	}
	else Cstartrace();
	return 1;
}

public PlayerF(playerid)
{
	if(!IsPlayerInAnyVehicle(playerid)){
	new Float:x2, Float:y2, Float:z2, Float:rott;
	GetPlayerPos(playerid, x2, y2, z2);
	GetPlayerFacingAngle(playerid, rott);
	//SetPlayerGravity(playerid, Gravity);
	if(racevehicle[playerid] != 1)
	{
		PlayerVehicle[playerid] = CreateVehicle(racevehicle[playerid], x2, y2, z2, rott, -1, -1, -1);
		new rand = random(MAX_CARCOLOURS);
		new rand2 = random(MAX_CARCOLOURS);
		ChangeVehicleColor(PlayerVehicle[playerid], CarColours[rand], CarColours[rand2]);
		SetVehicleNumberPlate(PlayerVehicle[playerid], "RacerX");
		SetVehicleVirtualWorld(PlayerVehicle[playerid], RaceWorld);
		PutPlayerInVehicle(playerid, PlayerVehicle[playerid], 0);
		if(!IsNosVehicleInvalid(racevehicle[playerid])) ShowMenuForPlayer(WheelsMenu, playerid);
		if(Nitrous != 0) AddVehicleComponent(PlayerVehicle[playerid], 1010);
		for(new j;j<MAX_PLAYERS;j++){
		if(!IsPlayerConnected(j)) continue;
		if(j == playerid) continue;
		SetVehicleParamsForPlayer(PlayerVehicle[playerid], j, false, true);
		}
		}
	}
	TogglePlayerControllable(playerid, false);
	RaceParticipant[playerid]=3;

	if(ReadyRef == 0)
	{
	    ReadyRef = 1;
		KillTimer(Countdown);
		Countdown = SetTimer("countdown", 1000, true);
		cd=60;
		SendClientMessageToAll(COLOUR_YELLOW, "Race will start in 60 seconds!");
	}
}

public MusicStop(playerid) RaceSound(playerid,0);

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

stock CreateRaceMenus()
{
	WheelsMenu = CreateMenu("Select Rims!", 1, 25, 170, 220, 25);
	AddMenuItem(WheelsMenu, 0, "Mega");
	AddMenuItem(WheelsMenu, 0, "RimShine");
	AddMenuItem(WheelsMenu, 0, "Classic");
	AddMenuItem(WheelsMenu, 0, "Twist");
	AddMenuItem(WheelsMenu, 0, "Cutter");
	AddMenuItem(WheelsMenu, 0, "Switch");
	AddMenuItem(WheelsMenu, 0, "Grove");
	AddMenuItem(WheelsMenu, 0, "Import");
	AddMenuItem(WheelsMenu, 0, "OffRoad");
	AddMenuItem(WheelsMenu, 0, "Dollar");
	AddMenuItem(WheelsMenu, 0, "Atomic");
}

stock ReturnVehicle(modelid)
{
	new vname[25]="Unknown";
	new foot[25]="On Foot";
	if(modelid == 1) return foot;
	else if((modelid < 400) || (modelid > 611)) return vname;
	memcpy(vname, VehicleNames[modelid - 400], 0, 100);
	return vname;
}

stock CreateText()
{
	TCountdown = TextDrawCreate(511, 95, " ");
	TextDrawLetterSize(TCountdown, 1.7, 3.8);
	TextDrawSetProportional(TCountdown, true);
	TextDrawFont(TCountdown, 1);
	TextDrawColor(TCountdown, COLOUR_YELLOW);
	Partici = TextDrawCreate(590, 360, "Par");
	Times = TextDrawCreate(550, 300, "Time");
	Append1 = TextDrawCreate(590, 335, "ST");
	TextDrawLetterSize(Append1, 0.5, 2.5);
	Append2 = TextDrawCreate(590, 335, "ND");
	TextDrawLetterSize(Append2, 0.5, 2.5);
	Append3 = TextDrawCreate(590, 335, "RD");
	TextDrawLetterSize(Append3, 0.5, 2.5);
	Append4 = TextDrawCreate(590, 335, "TH");
	TextDrawLetterSize(Append4, 0.5, 2.5);

	for(new i=0;i<MAX_PLAYERS;i++){
	Position[i] = TextDrawCreate(550, 310, "Checkpoints");
	//Diff[i] = TextDrawCreate(511, 95, " ");
	TPosition[i] = TextDrawCreate(560, 330, " ");
	TextDrawLetterSize(TPosition[i], 1.2, 6.2);
//	Speed[i] = TextDrawCreate(525, 310, "Speed");
	}
}

public RaceFix()
{
	new Float:Health;
    for(new i=0;i<MAX_PLAYERS;i++){
    if(!IsPlayerInAnyVehicle(i)) continue;
    GetVehicleHealth(PlayerVehicle[i], Float:Health);
 	if(RaceParticipant[i] > 1 && Health < 400)
 	{
 	    SetVehicleHealth(PlayerVehicle[i], 1000);
		RepairVehicle(PlayerVehicle[i]);
 	    xPlayerPlaySound(i, 1133);
 	}
 	}
}

stock LoadRandom()
{
	new File:f, templine[32], rotfile[]="iRaces/iList.iRf", rraces=-1, rracenames[32], mmk, rand, idx;
	f = fopen(rotfile, io_read);
	while(fread(f,templine,sizeof(templine),false))
	{
	    rraces++;
	}
	fclose(f);
	f = fopen(rotfile, io_read);
	mmk = random(rraces);
	while(fread(f,templine,sizeof(templine),false))
	{
	    rand++;
		if(rand == mmk+1) rracenames=strtok(templine,idx);
	}
	fclose(f);
	fback = LoadRace(rracenames);
	if(fback == -1)
	{
		printf("ERROR in RacerX's Random Load: Race \'%s\' doesn't exist!",rracenames);
		LoadRandom();
	}
	return 1;
}

public TimeTDUpdate(playerid)
{
	//Pos
	new string[32];
	if(Partsave < Participants)
	{
	    Partsave = Participants;
		format(string, sizeof(string), "/%i", Participants);
		TextDrawSetString(Partici, string);
	}

	for(new i=0;i<MAX_PLAYERS;i++){
	format(string, sizeof(string), "%i/%i", CurrentCheckpoint[i]-1, LCurrentCheckpoint);
	TextDrawSetString(Position[i], string);

/*	if(IsPlayerConnected(i) == 1)
	{
		GetPlayerPos(i, TelePos[i][3], TelePos[i][4], TelePos[i][5]);
		if(TelePos[i][5] > 550.0)
		{
			TelePos[i][0] = 0.0;
			TelePos[i][1] = 0.0;
		}
		if(TelePos[i][0] != 0.0)
		{
			new Float:xdist = TelePos[i][3]-TelePos[i][0];
			new Float:ydist = TelePos[i][4]-TelePos[i][1];
			new Float:sqxdist = xdist*xdist;
			new Float:sqydist = ydist*ydist;
			new Float:distance = (sqxdist+sqydist)/31;
			format(string, sizeof(string), "%.0f", distance);
			TextDrawSetString(Speed[i], string);
		}
		if(TelePos[i][5] < 550.0 && TelePos[i][3] != 0.0)
		{
			TelePos[i][0] = TelePos[i][3];
			TelePos[i][1] = TelePos[i][4];
		}
	}*/
	}
	//Time
	new	RaceString[10], RaceTime;
	RaceTime=GetRaceTick(playerid);
	RaceString=BeHumanCP(RaceTime);

	if(TopRacerTimes[0] == 0)
	{
        format(RaceString, sizeof(RaceString), "~y~%s", RaceString);
		TextDrawSetString(Times, RaceString);
	}
	else if(TopRacerTimes[0] < RaceTime)
	{
        format(RaceString, sizeof(RaceString), "~r~%s", RaceString);
		TextDrawSetString(Times, RaceString);
	}
	else if(TopRacerTimes[0] > RaceTime)
	{
        format(RaceString, sizeof(RaceString), "~g~%s", RaceString);
		TextDrawSetString(Times, RaceString);
	}
}

stock IsNumeric(const string[]) {
	new length=strlen(string);
	if (length==0) return false;
	for (new i = 0; i < length; i++) {
		if (
		(string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') // Not a number,'+' or '-'
		|| (string[i]=='-' && i!=0)                                             // A '-' but not at first.
		|| (string[i]=='+' && i!=0)                                             // A '+' but not at first.
		) return false;
	}
	if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
	return true;
}

ReturnServerStringVar(const varname[])
{
    new str[64];
    GetServerVarAsString(varname, str, sizeof(str));
    return str;
}

stock xPlayerPlaySound(playerid, soundid)
{
	new Float:x, Float:y, Float:z;
	GetPlayerPos(playerid, x, y, z);
    PlayerPlaySound(playerid, soundid, x, y, z);
}

stock IsNosVehicleInvalid(modelid)
{
    #define MAX_INVALID_NOS_VEHICLES 29

    new InvalidNosVehicles[MAX_INVALID_NOS_VEHICLES] =
    {
        581,523,462,521,463,522,461,448,468,586,
        509,481,510,472,473,493,595,484,430,453,
        452,446,454,590,569,537,538,570,449
    };

    for(new i = 0; i < MAX_INVALID_NOS_VEHICLES; i++)
    {
        if(modelid == InvalidNosVehicles[i])
        {
            return true;
        }
	}
	return false;
}

public fdeleteline(filename[], line[]){
	if(fexist(filename)){
		new temp[256];
		new File:fhandle = fopen(filename,io_read);
		fread(fhandle,temp,sizeof(temp),false);
		if(strfind(temp,line,true)==-1){return 0;}
		else{
			fclose(fhandle);
			fremove(filename);
			for(new i=0;i<strlen(temp);i++){
				new templine[256];
				strmid(templine,temp,i,i+strlen(line));
				if(equal(templine,line,true)){
					strdel(temp,i,i+strlen(line));
					fcreate(filename);
					fhandle = fopen(filename,io_write);
					fwrite(fhandle,temp);
					fclose(fhandle);
					return 1;
				}
			}
		}
	}
	return 0;
}

public fcreate(filename[]) {
	if (fexist(filename)){return false;}
	new File:fhandle = fopen(filename,io_write);
	fclose(fhandle);
	return true;
}

stock SendWrappedMessageToPlayer(playerid, colour, const msg[], maxlength=85, const prefix[]="    ")
{
	new length = strlen(msg);
	if(length <= maxlength) {
		SendClientMessage(playerid, colour, msg);
		return 1;
	}
	new string[256], idx, space, plen, bool:useprefix;
	for(new i;i<length;i++) {
		if(i-idx+plen >= maxlength) {
			if(idx == space || i-space >= 20) {
				strmid(string, msg, idx, i);
				idx = i;
			}
			else {
				strmid(string, msg, idx, space);
				idx = space+1;
			}
			if(useprefix) strins(string, prefix, 0);
			else {
				plen = strlen(prefix);
				useprefix = true;
			}
			SendClientMessage(playerid, colour, string);
		}
		else if(msg[i]==' ') space = i;
	}
	if(idx < length) {
		strmid(string, msg, idx, length);
		strins(string, prefix, 0);
		SendClientMessage(playerid, colour, string);
	}
	return true;
}

stock FindPlayer(const string[])
{
	new id = strval(string);
	if(isAllNumeric(string) && id >= 0 && id < GetMaxPlayers()) {
		return IsPlayerConnected(id) ? id : INVALID_PLAYER_ID;
	}
	return ReturnPlayerID(string);
}

stock isAllNumeric(const string[])
{
	if(string[0] == '\0') return false;
	for(new i; string[i] != '\0'; i++) if(string[i] > '9' || string[i] < '0') return false;
	return true;
}

stock ReturnPlayerID(const playername[])
{
	if(playername[0] == 0) return INVALID_PLAYER_ID;
	new pid = INVALID_PLAYER_ID;
	for(new i, maxp = GetMaxPlayers(), bool:found, pname[MAX_PLAYER_NAME], length = strlen(playername); i < maxp; i++) {
		if(!IsPlayerConnected(i)) continue;
		GetPlayerName(i, pname, sizeof(pname));
		new j = strfind(pname, playername, true);
		if((j == 0) && (strlen(pname) == length)) return i;
		if(!found) {
			if(j == 0) {
				pid = i;
				found = true;
			}
			else if(j != -1 && pid == INVALID_PLAYER_ID) {
				pid = i;
			}
		}
	}
	return pid;
}
Reply


Messages In This Thread
Race Problem - by Abanob - 04.06.2014, 23:19
Re: Race Problem - by Smileys - 05.06.2014, 13:26
Re: Race Problem - by Abanob - 05.06.2014, 14:55
Re: Race Problem - by Abanob - 07.06.2014, 14:56

Forum Jump:


Users browsing this thread: 1 Guest(s)