Jump to content

Help with spawning


xyz

Recommended Posts

Posted

I'm in middle of making a hospital spawn script, but how can I get the respawns from table and spawn the player to the one that is nearest?

local LSH = {2030.03125, -1418.8076171875, 16.9921875} 
local LSMH = {2030.03515625, -1418.8623046875, 16.9921875} 
local hospitals = {LSH, LSMH} 
  
function respawn(player) 
    spawnPlayer() 
    fadeCamera(player, true) 
    setCameraTarget(player, player) 
end 

Posted
local Hospitals = 
{ 
    {2030.03125, -1418.8076171875, 16.9921875}, 
    {2030.03515625, -1418.8623046875, 16.9921875}, 
} 
  
  
  
  
function DeathSpawn( thePlayer, Hospitals ) 
    local random = math.random( 1, #Hospitals ) 
    spawnPlayer( 
        thePlayer, 
        Hospitals[random][1], 
        Hospitals[random][2] 
    ) 
end 
  
function respawn(player) 
   fadeCamera ( source, false, 1.0, 255, 0, 0 ) 
    setTimer( DeathSpawn, 3000, 1, source,Hospitals ) 
    setTimer( fadeCamera, 2500, 1, source, true, 0.5 ) 
end 
addEventHandler("onPlayerWasted", root, respawn 

Posted

That looks like it spawns them randomly, I want it to be like spawn the person to the closest hospital.

Posted

I know that I have to use that, but how can I get the hospital with the closest range to the player that was killed

Posted
I know that I have to use that, but how can I get the hospital with the closest range to the player that was killed

Why do you ask if you know you've got to use that?

Posted

I don't know how to get the closest hospital as I said.

Get player position

Get hospital position

What then?

Posted
  
if getDistanceBetweenPoints3D(px, py, pz, 1x, 1y, 1z) > getDistanceBetweenPoints3D(px, py, pz, 1x, 1y, 1z) 
 --Code to spawn at the first hospital. 
else 
 --Code to spawn at the second hospital. 
end 
  

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...