Jump to content

hospitals


Recommended Posts

hey there, im making a script to when u die if u are in los santos u will spawn at los santos hospital or if u at las venturas u will spawn at las venturas hospital same with san fierro, now i want to know if someone can help me making when die check in what city he is at and then spawn him in correct hospital acording to the city, here is my code so far.

hospitalsTable = {
{ 1177.7994384766, -1323.0667724609, 14.088536262512 },
{ -2656.2421875, 635.99420166016, 14.453125 },
{ 1607.1225585938, 1817.8732910156, 10.8203125 },
}
 
 
function spawn( player )
 randomspawn = math.random( 1, #hospitalsTable)
spawnPlayer( player, hospitalsTable [randomspawn][1], hospitalsTable [randomspawn][2], hospitalsTable [randomspawn][3], hospitalsTable [randomspawn][4] )
end
addEventHandler("onPlayerWasted", getRootElement(),spawn)

Link to comment

I would use;

https://wiki.multitheftauto.com/wiki/GetZoneName

function scriptGetLoc ( source, command, playername ) --when getloc is called
local thePlayer = getPlayerFromNick ( playername ) --get the player from nickname
if ( thePlayer ~= false ) then --if there is a player from the nickname
local x, y, z = getElementPosition ( player )
local location = getZoneName ( x, y, z )
local city = getZoneName ( x, y, z, true )
outputChatBox ( playername .. " is at " .. location .. " (" .. city .. ")", source ) --announce his zone
else outputChatBox ( "Player does not exist" )
end
end
addCommandHandler( "getloc", scriptGetLoc ) -- add a command "getloc" which initiates "scriptGetloc" function

Link to comment

it will be MUCH easier just to check which hospital is nearest one :)

hospitalsTable = {
{ 1177.7994384766, -1323.0667724609, 14.088536262512 },
{ -2656.2421875, 635.99420166016, 14.453125 },
{ 1607.1225585938, 1817.8732910156, 10.8203125 },
}
 
 
function spawn( player )
local i=0
local minDistance=100000
local minHospital = 0
local posX, posY, posZ = getElementPosition(player)
for key,val in ipairs(hospitalsTable) do
   i=i+1
local distance = getDistanceBetweenPoints2D(posX, posY, val[1], val[2])
if (distance<minDistance) then
     minDistance=distance
     minHospital=i
end
end
spawnPlayer( player, hospitalsTable[minHospital][1], hospitalsTable [minHospital][2], hospitalsTable [minHospital][3], hospitalsTable [minHospital][4] )
end
addEventHandler("onPlayerWasted", getRootElement(),spawn)
 
-- btw: i dont see 4th value in your table (spawn player 5th argument)
-- ps: i didnt test it, try it. im not sure if i should use ipairs or pairs, so if mta will complain about, try to change it.

Link to comment

function getNearestHospital(player)
local smallest_i = 1;
local smallest_value = 9999999;
local x,y,z = getElementPosition(player);
for current_i, coords in ipairs(hospitalsTable) do
  local current_value = getDistanceBetweenPoints3D(x,y,z,coords[1],coords[2],coords[3]);
  if (current_value < smallest_value) then
    smallest_value = current_value;
    smallest_i = current_i;
  end
end
return hospitalsTable[smallest_i][1],hospitalsTable[smallest_i][2],hospitalsTable[smallest_i][3];
end

This automatically gets the nearest position and returns x,y,z.

Dunno if it simply works like that, I coded it on the fly, but its pretty simple and worth a try, isn't it?

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