Random spawn in area
#1

I make area with minx, maxx, miny, maxy. How to make random spawn in that area? Spawn anywhere in that area?
Reply
#2

Save 12 (or more) coordinates then use random()
https://sampwiki.blast.hk/wiki/Random
pawn Код:
new c = random(12)+1; //creates a random number from 0 to 12
        switch (c)
        {
        case 0:{SetPlayerPos(playerid,286.9416,1410.9337,10.3947);}
        case 1:{SetPlayerPos(playerid,286.9416,1410.9337,10.3947);}
        case 2:{SetPlayerPos(playerid,215.0739,1411.1678,10.5859);}
        case 3:{SetPlayerPos(playerid,111.3430,1410.3840,10.6022);}
        case 4:{SetPlayerPos(playerid,189.9601,1483.5343,10.5859);}
        case 5:{SetPlayerPos(playerid,205.5110,1347.1440,10.5859);}
        case 6:{SetPlayerPos(playerid, 215.0226,1466.8556,23.7344);}
        case 7:{SetPlayerPos(playerid,246.6161,1361.7271,23.3703);}
        case 8:{SetPlayerPos(playerid, 246.3493,1435.4602,23.3750);}
        case 9:{SetPlayerPos(playerid, 215.0226,1466.8556,23.7344);}
        case 10:{SetPlayerPos(playerid, 187.6121,1371.7318,23.7344);}
        case 11:{SetPlayerPos(playerid, 187.6121,1371.7318,23.7344);}
        case 12:{SetPlayerPos(playerid, 246.6161,1361.7271,23.3703);}
        }
Reply
#3

Here is the problem, I want to make random spawn in that area without saving spawn positions,just having MinX, MaxX, MinY, MaxY. How to make that ?
Reply
#4

pawn Код:
SetPlayerPos(
 random(maxx-minx)+minx,
 random(maxy-miny)+minz,
 z
);
Reply
#5

Quote:
Originally Posted by yezizhu
pawn Код:
SetPlayerPos(
 random(maxx-minx)+minx,
 random(maxy-miny)+minz,
 z
);
pawn Код:
SetPlayerPos(
 random(maxx-minx)+minx,
 random(maxy-miny)+minz, // +miny here i think :)
 z
);
Thanks
Reply
#6

You're right^^
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)