SA-MP Forums Random spawn coords in a gangzone
 New Account Members List Search Today's Posts Mark Forums Read

 22/09/2018, 08:27 PM #1 v1k1nG Huge Clucker     Join Date: Feb 2018 Posts: 412 Reputation: 31 Random spawn coords in a gangzone How would you spawn players in a random point, within a zone borders? I am trying to figure it out.. I am using this function to get if player is in zone: PHP Code: ``` bool: IsPlayerInZone(playerid, Float:minx, Float:miny, Float:maxx, Float:maxy)  { GetPlayerPos(playerid, P[playerid][px], P[playerid][py], P[playerid][pz]); if (P[playerid][px] > minx && P[playerid][px] < maxx && P[playerid][py] > miny && P[playerid][py] < maxy) return true; return false; }  ```
 23/09/2018, 12:26 AM #2 DarkBr Huge Clucker   Join Date: Feb 2017 Location: ∫ f(x) dx Posts: 372 Reputation: 11 Re: Random spawn coords in a gangzone Maybe if you try to use the random () function with the minimum and maximum end of the X and Y positions
23/09/2018, 12:41 AM   #3
Y_Less
Beta Tester

Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,686
Reputation: 3226
Re: Random spawn coords in a gangzone

From YSI:

Code:
```new Float:x = FloatRandom(minx, maxx);
new Float:y = FloatRandom(miny, maxy);```
__________________
 | Worst. Exit. Ever. |
 | git.io/Y | y-less.com | jump.pk |

23/09/2018, 12:13 PM   #4
v1k1nG
Huge Clucker

Join Date: Feb 2018
Posts: 412
Reputation: 31
Re: Random spawn coords in a gangzone

Quote:
 Originally Posted by Y_Less From YSI: Code: ```new Float:x = FloatRandom(minx, maxx); new Float:y = FloatRandom(miny, maxy);```
Which file to include in the gamemode exactly? I have all of them already
Is it something like this?

PHP Code:
``` frandom(Float:max, Float:min = 0.0, dp = 4) {     new         // Get the multiplication for storing fractional parts.         Float:mul = floatpower(10.0, dp),         // Get the max and min as integers, with extra dp.         imin = floatround(min * mul),         imax = floatround(max * mul);     // Get a random int between two bounds and convert it to a float.     return float(random(imax - imin) + imin) / mul; }  ```
This was an old post of yours

 25/09/2018, 12:59 AM #5 v1k1nG Huge Clucker     Join Date: Feb 2018 Posts: 412 Reputation: 31 Re: Random spawn coords in a gangzone Bump
25/09/2018, 01:14 AM   #6
Y_Less
Beta Tester

Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,686
Reputation: 3226
Re: Random spawn coords in a gangzone

Probably.
__________________
 | Worst. Exit. Ever. |
 | git.io/Y | y-less.com | jump.pk |

 26/09/2018, 12:58 PM #7 v1k1nG Huge Clucker     Join Date: Feb 2018 Posts: 412 Reputation: 31 Re: Random spawn coords in a gangzone Nothing, I am getting tag mismatch warning at PHP Code: ``` return float(random(imax - imin) + imin) / mul;  ``` Also I was looking for the FloatRandom function in YSI files, but I didn't manage to find the file to include yet. EDIT It compiles, but does not seem to work though PHP Code: ``` Float:frandom(Float:max, Float:min = 0.0, dp = 4) {     new         // Get the multiplication for storing fractional parts.         Float:mul = floatpower(10.0, dp),         // Get the max and min as integers, with extra dp.         imin = floatround(min * mul),         imax = floatround(max * mul);     new Float: x = float(random(imax - imin) + imin) / mul;     // Get a random int between two bounds and convert it to a float.     return x; }  ``` Last edited by v1k1nG; 26/09/2018 at 02:10 PM.

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Scropion Scripting Help 6 21/08/2015 11:00 PM fuckingcruse Scripting Help 1 12/03/2015 07:11 PM bajskorv123 Help Archive 2 26/12/2009 10:17 PM XtremeChio Help Archive 2 01/09/2009 02:57 PM _Vortex Help Archive 5 25/08/2009 05:27 PM

All times are GMT. The time now is 04:19 AM.

 -- (EN) English -- (RU) Русски Contact Us - SA-MP - Archive - Top