Here's my code: (sorry it's so long and the indentation has been messed up by the forum)
Код:
public OnPlayerEnterDynamicRaceCP(playerid, checkpointid)
{
if(checkpointid == PlayerRaceCP[playerid]) //If player enters their race checkpoint
{
if(RaceBegun == 1 && InRace[playerid] == 1) //Check if the race has started and the player is in the race
{
DestroyDynamic3DTextLabel(RacePickupLabels[playerid]); //Destroy a label which informs of vehicle-spawning checkpoints
if(RaceCheckpointsType[PlayerCheckpoint[playerid]] == 0) //If the checkpoint type is 0 (on-foot trigger)
{
DestroyVehicle(GetPlayerVehicleID(playerid)); //Destroy player's vehicle
SendClientMessage(playerid, -1, C_RACE"Continue on-foot!"); //Tell them to continue on-foot
}
else if(RaceCheckpointsType[PlayerCheckpoint[playerid]] > 1) //If type is higher than 1 (a vehicle ID) (vehicle spawner)
{
format(strang, sizeof(strang), "%d", RaceCheckpointsType[PlayerCheckpoint[playerid]]);
cmd_vrace(playerid, strang); //spawn the type's vehicle
}
if(RaceCheckpointsType[PlayerCheckpoint[playerid]+1] == 0) //if the next checkpoint's type is 0, add a textlabel saying so
{
RacePickupLabels[playerid] = CreateDynamic3DTextLabel("On-foot!", 0xFFFFFFFF, RaceCheckpoints[PlayerCheckpoint[playerid]+1][0], RaceCheckpoints[PlayerCheckpoint[playerid]+1][1], RaceCheckpoints[PlayerCheckpoint[playerid]+1][2], 500.0);
}
else if(RaceCheckpointsType[PlayerCheckpoint[playerid]+1] > 1) //and the same for vehicle spawning checkpoints
{
format(strang, sizeof(strang), "%s!", aVehicleNames[RaceCheckpointsType[PlayerCheckpoint[playerid]+1] - 400]);
RacePickupLabels[playerid] = CreateDynamic3DTextLabel(strang, 0xFFFFFFFF, RaceCheckpoints[PlayerCheckpoint[playerid]+1][0], RaceCheckpoints[PlayerCheckpoint[playerid]+1][1], RaceCheckpoints[PlayerCheckpoint[playerid]+1][2], 500.0);
}
PlayerPlaySound(playerid, 1056, 0, 0, 0); //play the checkpoint sound
PlayerCheckpoint[playerid] ++; //add one to the player's checkpoint progress
DestroyDynamicRaceCP(PlayerRaceCP[playerid]); //Destroy the CP they just went through
if(PlayerCheckpoint[playerid] == checkpointamount+1) //If the checkpoint is the finish
{
SetPlayerVirtualWorld(playerid, 0); //Send them back to the real world
SetVehicleVirtualWorld(GetPlayerVehicleID(playerid), 0); //along with their vehicle
InRace[playerid] = 0; //Set the player out of the race
Racers --; //Take racers down by one
//REMOVED UNRELATED CODE
}
else
{
if(PlayerCheckpoint[playerid] == checkpointamount) //If player's checkpoint is second from last
{
PlayerRaceCP[playerid] = CreatePlayerRaceCP(playerid, 1); //create FINISH LINE checkpoint
}
else
{
PlayerRaceCP[playerid] = CreatePlayerRaceCP(playerid); //otherwise create a normal checkpoint
}
}
}
}
return 1;
}
pawn Код:
public OnPlayerUpdate(playerid)
{
if(IsPlayerInDynamicRaceCP(playerid, PlayerRaceCP[playerid]) && InRace[playerid] == 1 && RaceBegun == 1)
{ //If player is in their race CP and they're in the race and the race has started
if(PlayerRaceCP[playerid] == 1) //If the player's Race checkpoint is the first one
{
PlayerPlaySound(playerid, 4202, 0, 0, 0); //play sound
PlayerCheckpoint[playerid] ++; //Add to progress
DestroyDynamicRaceCP(PlayerRaceCP[playerid]); //Destroy checkpoint they just went through
PlayerRaceCP[playerid] = CreatePlayerRaceCP(playerid); //Create next checkpoint
}
}
return 1;
}