Jump to content

Hospital spawn problem


Dardex

Recommended Posts

Hey.

Here i created some onPlayerWasted spawn location but there is an error, when I die in SF it spawns me in SF, same for LS but when I die in LV it spawns me again in LS can you find whats wrong here?

PS:Is there any way to type if ( xx1 > xx2 ) and ( xx2 > xx3 ) then .... ,or something like that when I want to compare 3 elements in same if else

createBlip ( 1177.5682373047, -1323.2587890625, 14.077121734619 , 22,getRootElement()) 
createBlip ( 1607.1494140625 , 1819.6416015625 , 10.828001022339 , 22,getRootElement()) 
createBlip ( -2654.5205078125 , 638.2412109375 , 14.453125 , 22,getRootElement()) 
addEventHandler( "onPlayerWasted", getRootElement( ), 
    function() 
      local x,y,z = getElementPosition (source) 
  local sf = getDistanceBetweenPoints3D (x,y,z,-2654.5205078125 , 638.2412109375 , 14.453125) 
  local lv = getDistanceBetweenPoints3D (x,y,z,1607.1494140625 , 1819.6416015625 , 10.828001022339) 
  local ls = getDistanceBetweenPoints3D (x,y,z,1177.5682373047, -1323.2587890625, 14.077121734619) 
    if (ls < sf) then 
        setTimer( spawnPlayer, 15000, 1, source, 1177.5682373047, -1323.2587890625, 14.077121734619 ) 
        setTimer( setCameraMatrix, 5000,1, source, 1208.8115234375 , -1287.755859375 , 38.246742248535 ,1177.5682373047, -1323.2587890625, 14.077121734619,0,70 ) 
        elseif (lv < ls) then 
        setTimer( spawnPlayer, 15000, 1, source, 1607.1494140625 , 1819.6416015625 , 10.828001022339 ) 
        setTimer( setCameraMatrix, 5000,1, source,  1581.2802734375 , 1853.708984375 , 30.209064483643,1607.1494140625 , 1819.6416015625 , 10.828001022339,0,70 ) 
        elseif (lv < sf) then 
        setTimer( spawnPlayer, 15000, 1, source, 1607.1494140625 , 1819.6416015625 , 10.828001022339 ) 
        setTimer( setCameraMatrix, 5000,1, source,  1581.2802734375 , 1853.708984375 , 30.209064483643,1607.1494140625 , 1819.6416015625 , 10.828001022339,0,70 ) 
        elseif (sf < lv) then 
        setTimer( spawnPlayer, 15000, 1, source,  -2654.5205078125 , 638.2412109375 , 14.453125 ) 
        setTimer( setCameraMatrix, 5000,1, source,   -2584.6865234375 , 568.95703125 , 40.101623535156,-2654.5205078125 , 638.2412109375 , 14.453125,0,70 ) 
            end 
            end 
            ) 
            addEventHandler("onPlayerWasted",getRootElement(), 
            function() 
            setTimer( setCameraTarget, 15000,1, source, source,source ) 
            end 
            ) 

Link to comment
  
createBlip(1177.5682373047,-1323.2587890625,14.077121734619,22,root) 
createBlip(1607.1494140625,1819.6416015625,10.828001022339,22,root) 
createBlip(-2654.5205078125,638.2412109375,14.453125,22,root) 
  
local spawn_locations = { 
    {1177.5682373047,-1323.2587890625,14.077121734619}, 
    {1607.1494140625,1819.6416015625 ,10.828001022339}, 
    {-2654.5205078125,638.2412109375,14.453125} 
} 
addEventHandler("onPlayerWasted",root,function() 
    local list = {} 
    local x,y,z = getElementPosition(source) 
    for _,location in ipairs (spawn_locations) do 
        local dist = getDistanceBetweenPoints3D(x,y,z,location[1],location[2],location[3]) 
        list[dist] = location 
    end 
    table.sort(list) 
    setTimer(spawnPlayer,1500,1,source,list[1][1],list[1][2],list[1][3]) 
end) 
  

Link to comment

Even though someone else posted just before I was about to, I'll leave the code I had written which has comments so you know what each line does.

local hospitals = 
    { 
        { -2654.5205078125 , 638.2412109375 , 14.453125 }, -- SF 
        { 1607.1494140625 , 1819.6416015625 , 10.828001022339 }, -- LV 
        { 1177.5682373047, -1323.2587890625, 14.077121734619 }, -- LS 
    } 
  
function getNearestHospital ( x, y ) 
    local temp = { } -- Define a table to store our data. 
    for index = 1, #hospitals do -- Loop from 1 to the total items in "hospitals" table. 
        local dist = getDistanceBetweenPoints2D ( x, y, hospitals [ index ] [ 1 ], hospitals [ index ] [ 2 ] ) -- Get the distance between the hospital coordinates and the given coordinates. 
        table.insert ( temp, { index = index, dist = dist } ) -- Insert it into our "temp" table. 
    end 
  
    table.sort ( -- Sort the "temp" table by lowest distance. 
        temp, 
        function ( a, b ) 
            return ( ( a.dist or 0 ) < ( b.dist or 0 ) ) 
        end 
    ) 
  
    return unpack ( hospitals [ temp [ 1 ].index ] ) -- Return the X, Y and Z from the nearest hospital. 
end 

Link to comment
createBlip(1177.5682373047,-1323.2587890625,14.077121734619,22,root) 
createBlip(1607.1494140625,1819.6416015625,10.828001022339,22,root) 
createBlip(-2654.5205078125,638.2412109375,14.453125,22,root) 
  
local spawn_locations = { 
    {1177.5682373047,-1323.2587890625,14.077121734619}, 
    {1607.1494140625,1819.6416015625 ,10.828001022339}, 
    {-2654.5205078125,638.2412109375,14.453125} 
} 
addEventHandler("onPlayerWasted",root,function() 
    local list = {} 
    local x,y,z = getElementPosition(source) 
    for _,location in ipairs (spawn_locations) do 
        local dist = getDistanceBetweenPoints3D(x,y,z,location[1],location[2],location[3]) 
        list[dist] = location 
    end 
    table.sort(list) 
    setTimer(spawnPlayer,1500,1,source,list[1][1],list[1][2],list[1][3]) 
end) 

this looks easier for me, but how do I add camera matrix here too?

Link to comment
local hospitals = 
    { 
        { -2654.5205078125 , 638.2412109375 , 14.453125, -2584.6865234375 , 568.95703125 , 40.101623535156,-2654.5205078125 , 638.2412109375 , 14.453125 }, -- SF 
        { 1607.1494140625 , 1819.6416015625 , 10.828001022339, 1581.2802734375 , 1853.708984375 , 30.209064483643,1607.1494140625 , 1819.6416015625 , 10.828001022339 }, -- LV 
        { 1177.5682373047, -1323.2587890625, 14.077121734619, 1208.8115234375 , -1287.755859375 , 38.246742248535 ,1177.5682373047, -1323.2587890625, 14.077121734619, }, -- LS 
    } 
for index = 1, #hospitals do 
    createBlip ( hospitals [ index ] [ 1 ], hospitals [ index ] [ 2 ], hospitals [ index ] [ 3 ], 22, root ) 
end 
  
function getNearestHospital ( x, y ) 
    local temp = { } -- Define a table to store our data. 
    for index = 1, #hospitals do -- Loop from 1 to the total items in "hospitals" table. 
        local dist = getDistanceBetweenPoints2D ( x, y, hospitals [ index ] [ 1 ], hospitals [ index ] [ 2 ] ) -- Get the distance between the hospital coordinates and the given coordinates. 
        table.insert ( temp, { index = index, dist = dist } ) -- Insert it into our "temp" table. 
    end 
  
    table.sort ( -- Sort the "temp" table by lowest distance. 
        temp, 
        function ( a, b ) 
            return ( ( a.dist or 0 ) < ( b.dist or 0 ) ) 
        end 
    ) 
  
    return unpack ( hospitals [ temp [ 1 ].index ] ) -- Return coordinates from the nearest hospital. 
end 
  
addEventHandler ( "onPlayerWasted", root, 
    function ( ) 
        local x, y, z = getElementPosition ( source ) 
        local hx, hy, hz, cx, cy, cz, clx, cly, clz = getNearestHospital ( x, y ) 
        if ( hx and hy and hz ) then 
            setTimer ( spawnPlayer, 15000, 1, source, hx, hy, hz ) 
            setTimer ( setCameraMatrix, 5000, 1, source, cx, cy, cz, clx, cly, clz, 0, 70 ) 
        end 
    end 
) 
  
addEventHandler ( "onPlayerWasted", root, 
    function ( ) 
        setTimer ( setCameraTarget, 15000,1, source, source ) 
    end 
) 

Link to comment
  
createBlip(1177.5682373047,-1323.2587890625,14.077121734619,22,root) 
createBlip(1607.1494140625,1819.6416015625,10.828001022339,22,root) 
createBlip(-2654.5205078125,638.2412109375,14.453125,22,root) 
  
local spawn_locations = { 
    {1177.5682373047,-1323.2587890625,14.077121734619,-2584.6865234375,568.95703125,40.101623535156,-2654.5205078125,638.2412109375 , 14.453125}, 
    {1607.1494140625,1819.6416015625 ,10.828001022339,1581.2802734375,1853.708984375,30.209064483643,1607.1494140625,1819.6416015625,10.828001022339}, 
    {-2654.5205078125,638.2412109375,14.453125,1208.8115234375,-1287.755859375,38.246742248535,1177.5682373047,-1323.2587890625,14.077121734619} 
} 
addEventHandler("onPlayerWasted",root,function() 
    local list = {} 
    local x,y,z = getElementPosition(source) 
    for _,location in ipairs (spawn_locations) do 
        local dist = getDistanceBetweenPoints3D(x,y,z,location[1],location[2],location[3]) 
        list[dist] = location 
    end 
    table.sort(list) 
    setTimer(function() 
        setCameraMatrix(source,list[4],list[5],list[6],list[7],list[8],list[9]) 
        spawnPlayer(source,list[1][1],list[1][2],list[1][3]) 
        setTimer(setCameraTarget,15000,1,source,source) 
    end,1500,1) 
     
end) 
  

Link to comment
{1177.5682373047,-1323.2587890625,14.077121734619,-2584.6865234375,568.95703125,40.101623535156,-2654.5205078125,638.2412109375 , 14.453125} 

may I know why are there more than 1 location coordinates here?

Edited by Guest
Link to comment
Thanks it works , now i have to find out how to add more hospitals :P gotta try since im new at scripting

It's really easy to add new hospitals, all you have to do is edit the "hospitals" table:

local hospitals = 
    { 
        { -2654.5205078125 , 638.2412109375 , 14.453125, -2584.6865234375 , 568.95703125 , 40.101623535156,-2654.5205078125 , 638.2412109375 , 14.453125 }, -- SF 
        { 1607.1494140625 , 1819.6416015625 , 10.828001022339, 1581.2802734375 , 1853.708984375 , 30.209064483643,1607.1494140625 , 1819.6416015625 , 10.828001022339 }, -- LV 
        { 1177.5682373047, -1323.2587890625, 14.077121734619, 1208.8115234375 , -1287.755859375 , 38.246742248535 ,1177.5682373047, -1323.2587890625, 14.077121734619, }, -- LS 
        { X, Y, Z, CameraX, CameraY, CameraZ, CameraLookX, CameraLookY, CameraLookZ }, 
    } 

Edit: Because it also contains the camera position/look at.

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