SA-MP Forums Archive
How I do this? - 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: How I do this? (/showthread.php?tid=659046)



How I do this? - LOLITO - 21.09.2018

I would like to know how random objects appear.


Re: How I do this? - GTLS - 21.09.2018

You store Coordinates to a Multidimensional Array and from that, using random() function, you can choose a random index of array and can spawn any object on that coordinates.


Re: How I do this? - LOLITO - 21.09.2018

Quote:
Originally Posted by GTLS
Посмотреть сообщение
You store Coordinates to a Multidimensional Array and from that, using random() function, you can choose a random index of array and can spawn any object on that coordinates.
Can you give me a simple example?


Re: How I do this? - kingmk - 21.09.2018

Код:
#define MAX_WORLD_CO 4

//You can also add the object ID, after coordinates like so {2443.20, 2872.08, 182.14, 2399/*Object ID*/}
new Float:WorldCoordinates[MAX_WORLD_CO][3] = {
    {2443.20, 2872.08, 182.14},      //0
    {2683.04, -1340.28, 150.90},   //1
    {398.05, 1427.73, 184.44},     //2
    {2283.20, 187.08, 182.14}      //3
};


stock randomEx(min, max)
{    
    //Credits to ******    
    new rand = random(max-min)+min;    
    return rand;
}

forward RandomWorldCoordinates(playerid);
public RandomWorldCoordinates(playerid)
{
      new ID = randomEx(0, MAX_WORLD_CO-1);

      //Create objects with this ID. (random).
      
      new Float: X, Float: Y, Float: Z;

      X = WorldCoordinates[ID][0];
      Y = WorldCoordinates[ID][1];
      Z = WorldCoordinates[ID][2];

   
      CreateObject(2587, X, Y, Z, 0.0, 0.0, 96.0); // Object will render at its default distance.

      return 1;
}



Re: How I do this? - v1k1nG - 21.09.2018

Actually if you set the coordinates manually that's not random!
I guess MapAndreas could help