Jump to content

[HELP!]Respawn


scolen

Recommended Posts

Well first wee need only 1 resource!

a) you need a table with all spawn locations like this

local spawns = {
	[1] = {0,0,0};
	[2] = {5,5,5}; --etc this is just an example 
}
-- in this table u will put your spawn coords from the hospitals

b) you need this event -> onPlayerWasted

c) also this https://wiki.multitheftauto.com/wiki/GetDistanceBetweenPoints3D

d) and another function

math.min()

e) and if u know how to loop through a table u wont need many lines of code to do this.

  • Thanks 1
Link to comment
local spawns = {
    [1] = {1829.65564,-1842.47327,13.57813,178}; -- x , y ,z , and z rotation
    [2] = {2083.15747,-1844.75122,12.79247,359};
    [3] = {2893.39746,-1638.96423,10.45679,333};
}
local distances = {}

respawn = function(ammo, attacker, weapon, bodypart)
    local x,y,z = getElementPosition(source)
    for k,v in ipairs(spawns) do 
        distances[k] = getDistanceBetweenPoints3D(x,y,z,spawns[k][1],spawns[k][2],spawns[k][3])
    end 
    local a = math.min(distances[1],distances[2],distances[3])
        for i=1,#distances do 
           if  distances[i] == a then 
                spawnPlayer(source,spawns[i][1],spawns[i][2],spawns[i][3],spawns[i][4])
                end 
            end 
    distances = nil 
    distances = {}
end 

addEventHandler("onPlayerWasted",getRootElement(),respawn)

-- my spawns are random coordinates to test the script, they are not hospital spawns and also u have to change the z rotation to your wanted rotation.

also if u have in spawns table more indexes u need to add more distances in local a = math.min()

if u have 5 then u add five distances, here i have 3 spawns so 3 distances

  • Thanks 1
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...