Random checkpoint except last one - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Random checkpoint except last one (
/showthread.php?tid=584075)
Random checkpoint except last one -
TheWay - 02.08.2015
How I can put random checkpoint to somebody when is working without give him same location as last one?
Re: Random checkpoint except last one -
Mariciuc223 - 02.08.2015
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); }
}
Re: Random checkpoint except last one -
Mencent - 02.08.2015
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
![Wink](images/smilies/wink.png)
If anyone have a better idea how it is solvable without goto please let me know it
Re: Random checkpoint except last one -
Vince - 02.08.2015
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.