Checkpoint System
#5

pawn Код:
new Float:CPX, Float:CPY, Float:CPZ; // Top of script - These will be used to store the checkpoints location

#define CHECKPOINT_RADIUS 10 // The radius of the random checkpoints in units

SetTimer("Checkpoints", 600000, true); // OnGameModeInit - here we set the timer

// Bottom of script:
forward Checkpoints(); // Forward the timer
public Checkpoints()
{
    SetNewRandomCheckpoint(); // A custom stock for this script is called here
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
            GameTextForPlayer(i, "~w~A new ~r~checkpoint ~w~~n~has been set!", 5000, 5);
    }
    return 1;
}


stock SetNewRandomCheckpoint() // Also in the bottom
{

/* When we make this a stock instead of putting it in the timer,
   we can call this more than just when the timer is up.
   For example, you can make a "/newcheckpoint"-command with this stock. */


    new rand = Random(20) // Number of checkpoints that you have - edit 20!
    switch(rand) // We make a switch to set a checkpoint for each random number
    {
   
        /* SetCheckpointForAll is another custom stock - this is to set
           the checkpoint to all players easily, instead of having
           a player loop at every 'case' */

           
        case 0: SetCheckpointForAll(x, y, z); // Replace the X, Y and Z coordinates with the ones of your checkpoints
        case 1: SetCheckpointForAll(x, y, z); // Same here
        case 2: SetCheckpointForAll(x, y, z); // Etc.
        case 3: SetCheckpointForAll(x, y, z);
        case 4: SetCheckpointForAll(x, y, z);
        case 5: SetCheckpointForAll(x, y, z);
        case 6: SetCheckpointForAll(x, y, z);
        case 7: SetCheckpointForAll(x, y, z);
        case 8: SetCheckpointForAll(x, y, z);
        case 9: SetCheckpointForAll(x, y, z);
        case 10: SetCheckpointForAll(x, y, z);
        case 11: SetCheckpointForAll(x, y, z);
        case 12: SetCheckpointForAll(x, y, z);
        case 13: SetCheckpointForAll(x, y, z);
        case 14: SetCheckpointForAll(x, y, z);
        case 15: SetCheckpointForAll(x, y, z);
        case 16: SetCheckpointForAll(x, y, z);
        case 17: SetCheckpointForAll(x, y, z);
        case 18: SetCheckpointForAll(x, y, z);
        case 19: SetCheckpointForAll(x, y, z);
    }
    return 1;
}


stock SetCheckpointForAll(x, y, z) // Also in the bottom of the script
{
    CPX = x;
    CPY = y;
    CPZ = z;
    for(new i = 0; i < MAX_PLAYERS; i++) // Loop through all players and set their checkpoint
    {
   
            /* Here we set the checkpoint for the individual player
               to the designated coordinates from the previous stock.
               We also use the radius defined at the top of the script. */

               
            SetPlayerCheckpoint(i, x, y, z, CHECKPOINT_RADIUS);
    }
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    if(IsPlayerInRangeOfPoint(playerid, 10.0, CPX, CPY, CPZ) // Checks if the player is within the coordinates of the current checkpoint
    {
        /* Here you can put the code of what will happen
           when the player enters the random checkpoint */

    }
    return 1;
}
I can't remember if I made a mistake in the SetCheckpointForAll-stock. I'm not sure if I have to define in the stock that the numbers are indeed floats... oh well, try it, tell me if it fails.

You're welcome.
Reply


Messages In This Thread
Checkpoint System - by ColdXX - 13.10.2010, 18:09
Re: Checkpoint System - by Naxix - 13.10.2010, 18:12
Re: Checkpoint System - by ColdXX - 13.10.2010, 18:18
Re: Checkpoint System - by CrucixTM - 13.10.2010, 18:25
Re: Checkpoint System - by CrucixTM - 13.10.2010, 18:54
Re: Checkpoint System - by ColdXX - 14.10.2010, 12:27
Re: Checkpoint System - by CrucixTM - 14.10.2010, 13:26
Re: Checkpoint System - by ColdXX - 14.10.2010, 13:42
Re: Checkpoint System - by Nero_3D - 14.10.2010, 13:53
Re: Checkpoint System - by CrucixTM - 14.10.2010, 14:17

Forum Jump:


Users browsing this thread: 5 Guest(s)