SA-MP Forums Archive
Using random - 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: Using random (/showthread.php?tid=583081)



Using random - DavidSparks - 25.07.2015

pawn Code:
new rand = random(4);
   
    case 1: {
   
        gPlayerCheckpointStatus[playerid] = CHECKPOINT_TRASH1;
        SetPlayerCheckpoint(playerid, 1799.2505,-1808.7913,13.5402, 3);
        return 1;
    }
    case 2: {

        gPlayerCheckpointStatus[playerid] = CHECKPOINT_TRASH2;
        SetPlayerCheckpoint(playerid, 1907.1907,-1787.6948,13.5469, 3);
        return 1;
    }
    case 3: {

        gPlayerCheckpointStatus[playerid] = CHECKPOINT_TRASH3;
        SetPlayerCheckpoint(playerid, 1337.6495,-1773.3040,13.5469, 3);
        return 1;
    }
    case 4: {

        gPlayerCheckpointStatus[playerid] = CHECKPOINT_TRASH4;
        SetPlayerCheckpoint(playerid, 861.9600,-1384.0540,13.6971, 3);
        return 1;
    }
Whats wrong with this code?


Re: Using random - SickAttack - 25.07.2015

"random" starts from 0. So using "random(4)", your values are 0 to 3.


Re: Using random - DavidSparks - 25.07.2015

Quote:
Originally Posted by SickAttack
View Post
"random" starts from 0. So using "random(4)", your values are 0 to 3.
Also I missed the switch

Thanks for helping.