Random checkpoints
#1

So I defined some checkpoint coordinates.

Код:
#define pizzapoint1	2335.4380,121.7660,26.4844
#define pizzapoint2 2336.0911,196.6093,26.4963
#define pizzapoint3	2383.0081,76.8258,26.6191
#define pizzapoint4	2474.4753,62.9863,26.5167
#define pizzapoint5	2477.8123,-18.2540,26.4844
#define pizzapoint6	1287.3582,161.7786,20.0188
#define pizzapoint7	1474.8644,375.0096,19.1666
#define pizzapoint8	1414.7236,360.8005,18.6996
#define pizzapoint9	784.4283,354.9356,19.1105
#define pizzapoint10 749.5011,277.9444,26.8651
#define pizzapoint11 244.3139,-33.5519,1.1310
#define pizzapoint12 243.7217,-127.8746,1.2918
#define pizzapoint13 311.3992,42.7057,2.3888
#define pizzapoint14 744.3607,-514.4095,17.1509
#define pizzapoint15 766.0096,-551.7446,16.8070
#define pizzapoint16 793.7676,-511.0729,16.8068
I made a code that when you get into a vehicle, the mission starts and creates a checkpoint. But I want those checkpoints to be randomly chosen. How do I do that?
Reply
#2

Use an array.

pawn Код:
static const Float:pizzaPoint[][3] = {
    {2335.4380,121.7660,26.4844},
    {2336.0911,196.6093,26.4963},
    // ...
    {793.7676,-511.0729,16.8068}
};
pawn Код:
new rand = random(sizeof(pizzaPoint));
SetPlayerCheckpoint(playerid, pizzaPoint[rand][0], pizzaPoint[rand][1], pizzaPoint[rand][2], 2.0);
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
Use an array.

pawn Код:
static const Float:pizzaPoint[][3] = {
    {2335.4380,121.7660,26.4844},
    {2336.0911,196.6093,26.4963},
    // ...
    {793.7676,-511.0729,16.8068}
};
pawn Код:
new rand = random(sizeof(pizzaPoint));
SetPlayerCheckpoint(playerid, pizzaPoint[rand][0], pizzaPoint[rand][1], pizzaPoint[rand][2], 2.0);
I tried using this before, but what happens is that when I drive over the checkpoint, nothing happens.
Reply
#4

You need the public "OnPlayerEnterCheckpoint" for that.

https://sampwiki.blast.hk/wiki/OnPlayerEnterCheckpoint
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)