SA-MP Forums Archive
Random spawn coords in a gangzone - 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: Random spawn coords in a gangzone (/showthread.php?tid=659077)



Random spawn coords in a gangzone - v1k1nG - 22.09.2018

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 код:
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;




Re: Random spawn coords in a gangzone - DarkBr - 22.09.2018

Maybe if you try to use the random () function with the minimum and maximum end of the X and Y positions


Re: Random spawn coords in a gangzone - v1k1nG - 23.09.2018

Quote:
Originally Posted by ******
Посмотреть сообщение
From YSI:

Код:
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 код:
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


Re: Random spawn coords in a gangzone - v1k1nG - 24.09.2018

Bump


Re: Random spawn coords in a gangzone - v1k1nG - 26.09.2018

Nothing, I am getting tag mismatch warning at
PHP код:
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 код:
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;