Jump to content

Get random coordinates on the map.


Tekken

Recommended Posts

Hi,

I want to get random coordinates on the map to spawn players.

I know I can do something like math.random(2000, 4000) but I don't know there the map starts and ends.

I know it ends at about 6000(or something similarly) but almost half of that value is water and I don't want players to spawn in water.

Can someone tel me there the ground actually starts and ends ? I mean the coordinates, the Z coordinate doesn't mean that much, I just need X and Y.

Thanks.

Link to comment
Hi,

I want to get random coordinates on the map to spawn players.

I know I can do something like math.random(2000, 4000) but I don't know there the map starts and ends.

I know it ends at about 6000(or something similarly) but almost half of that value is water and I don't want players to spawn in water.

Can someone tel me there the ground actually starts and ends ? I mean the coordinates, the Z coordinate doesn't mean that much, I just need X and Y.

Thanks.

Try this resource.

Link to comment
  • Discord Moderators

GTA: SA world is a square whose side is 6000 units long, starting in -3000 and ending in 3000 for the X and Y axes. Therefore, to get a random 2D position within the world, just use:

pos = Vector2(math.random(-3000, 3000), math.random(-3000, 3000)) 

In order to check if there is water in that position, just look at the result of this function call:

anyWaterInPos = testLineAgainstWater(pos.x, pos.y, -3000, pos.x, pos.y, 3000) 

Note that the -3000 and 3000 Z coordinates are some kind of dummy values to just check if there is any water in that position, which is what you may (or may not) want. You can use the ground height value returned by getGroundPosition to effectively control the length of the line you are testing water against, relative to the ground the player can step on.

Link to comment
Water level is at 0 !If it positive and > 0 it should spawn

Else get another x, y

I seriously don't know are you trolling with all your posts on this Forum, or are you just really really brainless.

Back to the topic,

I believe the map stretches (both on x and y value) from -3000 to 3000

So basically what you should do is use math.random and testLineAgainstWater to see if there's water or not

  
-- Client Side Example -- 
  
function SearchForSpawnPoint() 
  
    -- Generate random coordinates -- 
    local myX, myY = math.random(-3000, 3000), math.random(-3000, 3000); 
    local myZ = 25; -- You can edit Z value later how you like 
  
    -- If there's not water underneath the coordinates -- 
    if not testLineAgainstWater(myX, myY, myZ, myX, myY, -1) then 
  
        -- Teleport us -- 
        setElementPosition(localPlayer, myX, myY, myZ); 
  
    else 
        -- Otherwise search for another position -- 
        SearchForSpawnPoint(); 
    end 
  
end 
  
SearchForSpawnPoint(); 

The above is a client sided script, if you want a server sided one, use spawnPlayer if you're spawning a player, and replace localPlayer with your player element.

Link to comment

The above is a client sided script, if you want a server sided one, use spawnPlayer if you're spawning a player, and replace localPlayer with your player element.

Thanks

Won't work server-side cause testLineAgainstWater it's a client-only function.

Anyway I just needed the coordinates -3000 and 3000 cause players will anyway spawn really high up in the sky with a parachute.

Link to comment
Tekken,the reply was meant to help you by explaining that the water level is at z = 0.I don't know english very well so i think you misunderstood my comment

I am not trolling and i am not brainless

However i am sorry if i did something wrong

I haven't told you brainless, I actually haven't told you anything. I know you where trying to help and it's ok I appreciate any help I got.

Greetings. And please don't start a fight.

Link to comment
Tekken,the reply was meant to help you by explaining that the water level is at z = 0.I don't know english very well so i think you misunderstood my comment

I am not trolling and i am not brainless

However i am sorry if i did something wrong

I haven't told you brainless, I actually haven't told you anything. I know you where trying to help and it's ok I appreciate any help I got.

Greetings. And please don't start a fight.

i dont like to fight other people

And sorry another user insulted me not you

Link to comment

The above is a client sided script, if you want a server sided one, use spawnPlayer if you're spawning a player, and replace localPlayer with your player element.

Thanks

Won't work server-side cause testLineAgainstWater it's a client-only function.

Anyway I just needed the coordinates -3000 and 3000 cause players will anyway spawn really high up in the sky with a parachute.

Yep. It's client-side only indeed, but what i meant by my post up there is that you could have had two seperate scripts, one on client for client functions such as testLineAgainstWater, and on server for server functions such as spawnPlayer

I hope your issue is resolved now ^^

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...