OnPlayerEnterCheckpoint for Random Checkpoints?
#1

So I've created a set of random checkpoints. I want it so when a player enters a checkpoint he will get 980$, and it will kill the remaining checkpoints until the player does /startflight again. How would I assign a variable to a set of random checkpoints?

Relevant code:
pawn Код:
new Float:RandomDropOff[4][] =
{
    {1609.1157,1642.1429,10.8203, 10.0},
    {404.6019,2483.4902,16.4844, 10.0},
    {-1345.8822,-522.7991,14.1484,10.0},
    {-1051.5347,-1195.1558,129.0394,10.0}
};
pawn Код:
CMD:startflight(playerid, params[])
{
    new rand = random(sizeof(RandomDropOff));
    SetPlayerCheckpoint(playerid, RandomDropOff[rand][0], RandomDropOff[rand][1], RandomDropOff[rand][2], RandomDropOff[rand][3]);
    return 1;
}
pawn Код:
public OnPlayerEnterCheckpoint(playerid)
{
    //what would i add here?
    return 1;
}
Reply
#2

new Float:RandomDropOff[4][] =

to

new Float:RandomDropOff[][4] =

and in public add your give player money...i suggest you to add a variable for each player to detect which checkpoint it is
Reply
#3

I'm not quite sure what you mean. Wouldn't I need to somehow add a variable for each random checkpoint? If I do, how would I do that exactly?
Reply
#4

What you should be using for readability is like this..

pawn Код:
enum DROPINFO {
    Float:DropX,
    Float:DropY,
    Float:DropZ,
    Float:DropCPSize
}

stock const RandomDropOff[][DROPINFO] =
{
    {1609.1157,1642.1429,10.8203, 10.0},
    {404.6019,2483.4902,16.4844, 10.0},
    {-1345.8822,-522.7991,14.1484,10.0},
    {-1051.5347,-1195.1558,129.0394,10.0}
};

CMD:startflight(playerid, params[])
{
    SetRandomDropCP(playerid);
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    if(IsDropCP(playerid))
    {
        // Do whatever you need now
        SetRandomDropCP(playerid);
    }
    return 1;
}

stock SetRandomDropCP(playerid)
{
    new random(sizeof(RandomDropOff));
    DisablePlayerCheckpoint(playerid);
    SetPlayerCheckpoint(playerid, RandomDropOff[rand][DropX], RandomDropOff[rand][DropY], RandomDropOff[rand][DropZ], RandomDropOff[rand][DropCPSize]);
    return 1;
}

stock IsDropCP(playerid)
{
    for(new i = 0; i < sizeof(RandomDropOff); i++)
    {
         if(IsPlayerInRangeOfPoint(playerid, RandomDropOff[i][DropCPSize] / 2, RandomDropOff[i][DropX], RandomDropOff[i][DropY], RandomDropOff[i][DropZ])
         {
              return 1;
         }
    }
    return 0;
}
Reply
#5

I appreciate your response. I'll try to read over the code and understand it a bit more.
Reply
#6

No problem, let me know if you get stuck or have any questions.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)