Random checkpoint except last one
#1

How I can put random checkpoint to somebody when is working without give him same location as last one?
Reply
#2

Put many checkpoints will make the change to be the same cp littlest

EDIT: Or you could try something like that:

Код HTML:
new CPs[8][3] =
{
	{ 0.0, 0.0, 0.0 },
	{ 0.0, 0.0, 0.0 },
	{ 0.0, 0.0, 0.0 },
    { 0.0, 0.0, 0.0 },
    { 0.0, 0.0, 0.0 },
    { 0.0, 0.0, 0.0 },
    { 0.0, 0.0, 0.0 }
}

new pLastCP[MAX_PLAYERS];

// where you set

new rNum = random(sizeof(CPs));
SetPlayerCheckPoint(playerid, CPs[rNum][0], CPs[rNum][1], CPs[rNum][2], 1.0);
pLastCP[playerid] = rNum;


// Where you give another CP

new rNum = random(sizeof(CPs));

if(rNum == pLastCP[playerid)
{
	if(rNum == 8) { SetPlayerCheckPoint(playerid, CPs[rNum-1][0], CPs[rNum-1][1], CPs[rNum-1][2], 1.0); pLastCP[playerid] = (rNum - 1); }
	if(rNum < 8) { SetPlayerCheckPoint(playerid, CPs[rNum+1][0], CPs[rNum+1][1], CPs[rNum+1][2], 1.0); pLastCP[playerid] = (rNum - 1); }
}
Reply
#3

PHP код:
//global at the top of the script:
new LastCheckpoint[MAX_PLAYERS];
new 
Float:RandomCheckpoints[][] =
{
    {
123.145,123.123,123.123},
    {
156.156,156.156,156.156}
};
//Where you want to use it:
RandomCheckpoint_goto:
new 
rand random(sizeof(RandomCheckpoints));
if(
rand == LastCheckpoint[playerid])goto RandomCheckpoint_goto;
LastCheckpoint[playerid] = rand;
SetPlayerCheckpoint(playerid,RandomCheckpoints[rand][0],RandomCheckpoints[rand][1],RandomCheckpoints[rand][2]); 
I don't know if goto is a good solution but try this
If anyone have a better idea how it is solvable without goto please let me know it
Reply
#4

Never use goto. If anything use do-while.

PHP код:
do 
{
    
newthing random(/* ... */);
}
while(
newthing == oldthing); 
This has the possibility of an infinite loop so create some kind of guard (maximum 50 iterations or so) so it doesn't go on forever.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)