SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 22/09/2018, 07:27 PM   #1
v1k1nG
Huge Clucker
 
v1k1nG's Avatar
 
Join Date: Feb 2018
Location: 𝕯𝖗𝖆𝖐𝖐𝖆𝖗
Posts: 257
Reputation: 14
Default 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:
boolIsPlayerInZone(playeridFloat:minxFloat:minyFloat:maxxFloat:maxy)  {
GetPlayerPos(playeridP[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;

__________________
v1k1nG is offline   Reply With Quote
Old 22/09/2018, 11:26 PM   #2
DarkBr
Huge Clucker
 
Join Date: Feb 2017
Location: Brazil (SP)
Posts: 337
Reputation: 10
Default 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
DarkBr is online now   Reply With Quote
Old 22/09/2018, 11:41 PM   #3
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,122
Reputation: 3170
Default Re: Random spawn coords in a gangzone

From YSI:

Code:
new Float:x = FloatRandom(minx, maxx);
new Float:y = FloatRandom(miny, maxy);
Y_Less is online now   Reply With Quote
Old 23/09/2018, 11:13 AM   #4
v1k1nG
Huge Clucker
 
v1k1nG's Avatar
 
Join Date: Feb 2018
Location: 𝕯𝖗𝖆𝖐𝖐𝖆𝖗
Posts: 257
Reputation: 14
Default Re: Random spawn coords in a gangzone

Quote:
Originally Posted by Y_Less View Post
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:maxFloat:min 0.0dp 4)
{
    new
        
// Get the multiplication for storing fractional parts.
        
Float:mul floatpower(10.0dp),
        
// 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
__________________
v1k1nG is offline   Reply With Quote
Old 24/09/2018, 11:59 PM   #5
v1k1nG
Huge Clucker
 
v1k1nG's Avatar
 
Join Date: Feb 2018
Location: 𝕯𝖗𝖆𝖐𝖐𝖆𝖗
Posts: 257
Reputation: 14
Default Re: Random spawn coords in a gangzone

Bump
__________________
v1k1nG is offline   Reply With Quote
Old 25/09/2018, 12:14 AM   #6
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,122
Reputation: 3170
Default Re: Random spawn coords in a gangzone

Probably.
Y_Less is online now   Reply With Quote
Old 26/09/2018, 11:58 AM   #7
v1k1nG
Huge Clucker
 
v1k1nG's Avatar
 
Join Date: Feb 2018
Location: 𝕯𝖗𝖆𝖐𝖐𝖆𝖗
Posts: 257
Reputation: 14
Default 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:maxFloat:min 0.0dp 4)
{
    new
        
// Get the multiplication for storing fractional parts.
        
Float:mul floatpower(10.0dp),
        
// Get the max and min as integers, with extra dp.
        
imin floatround(min mul),
        
imax floatround(max mul);
    new 
Floatfloat(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 01:10 PM.
v1k1nG is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Random Spawns Scropion Scripting Help 6 21/08/2015 10:00 PM
Random spawns fuckingcruse Scripting Help 1 12/03/2015 06:11 PM
[HELP]Random Spawns? bajskorv123 Help Archive 2 26/12/2009 09:17 PM
Random Spawns + Previous Spawns XtremeChio Help Archive 2 01/09/2009 01:57 PM
Random spawns _Vortex Help Archive 5 25/08/2009 04:27 PM


All times are GMT. The time now is 10:06 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.