Jump to content

[HELP] What's wrong with the script?


dener189

Recommended Posts

When the player dies simply he is not born in the nearest hospital, he just goes under the camera

 

local spawnX, spawnY, spawnZ = 1480.9730224609, -1771.46875, 18.8 --Primeiro Spawn
function joinHandler()
	spawnPlayer(source, spawnX, spawnY, spawnZ)
	fadeCamera(source, true)
	setCameraTarget(source, source)
end
addEventHandler("onPlayerJoin", getRootElement(), joinHandler)

local spawnPos = { -- (Prefira usar no máximo 3 casas decimais.)
	[1] = {2034.9428710938, -1403.2003173828, 18},	-- Hospital 1 LS
	[2] = {-2655.3991699219, 638.16137695313, 15},	-- Hospital SF
	[3] = {-1514.6713867188, 2522.4748535156, 56},	-- Hospital Tierra Robada
	[4] = {1607.62890625, 1818.9958496094, 11},	-- Hospital LV
	[5] = {-2198.5632324219, -2306.6220703125, 31},	-- Hospital Whetstone
}

addEventHandler ("onPlayerWasted", getRootElement(), function () -- Executa essa função quando o player morre.
	local x, y, z = getElementPosition (source) -- x, y, z recebem a posição do player onde ele morreu.
	local dist = 99999 -- Distância do ponto mais próximo.
	local id = 0 -- ID da coordenada mais próxima.
	for i, v in ipairs (spawnPos) do -- Para cada table de coordenadas, faça:
		local pX, pY, pZ = unpack (spawnPos[i]) -- pX,pY, pZ recebem as coordenadas que estão no spawnPos[i]
		if getDistanceBetweenPoints3D (x, y, z, pX, pY, pZ) < dist then -- Se a distância dessa coordenada for menor que dist, então:
			dist = getDistanceBetweenPoints3D (x, y, z, pX, pY, pZ) -- Atualiza a distância para essa.
			id = i -- Atualiza o id para este.
		end
	end
	if id == 1 then -- Outputs que servem somente para testes.
		outputChatBox ("Hospital mais próximo: Los Santos", source)
	elseif id == 2 then
		outputChatBox ("Hospital mais próximo: San Fierro", source)
	elseif id == 3 then
		outputChatBox ("Hospital mais próximo: Tierra Robada", source)
	elseif id == 4 then
		outputChatBox ("Hospital mais próximo: Las Venturas", source)
	elseif id == 5 then
		outputChatBox ("Hospital mais próximo: Whetstone", source)
	end
	setElementData (source, "killNear", id) -- Seta o id mais próximo como data no player.
end)

function spawnMe ()
	if getElementData (source, "killNear") then -- Se o jogador que morreu tem essa data, então: (quando o jogador entra no server, ele spawna sem essa data)
		setElementPosition (source, unpack (spawnPos[getElementData (source, "killNear")])) -- Coloca ele na posição desse ID que está na data.
		removeElementData (source, "killNear") -- Remove essa data, que não será mais usada até que ele morra novamente e uma nova data seja criada.
	end
end
addEventHandler ("onPlayerSpawn", getRootElement(), spawnMe) -- Executa essa função quando o player spawna.

 

Link to comment
4 minutes ago, HDmaster0702 said:

Você não chamou a função spawnPlayer no evento onPlayerWasted. Não está chamando automaticamente o spawnPlayer.

so would you have to pack up the band for that?

addEventHandler ("onPlayerWasted", getRootElement(), function (spawnPlayer)

 

Link to comment
local spawnX, spawnY, spawnZ = 1480.9730224609, -1771.46875, 18.8
function joinHandler()
	spawnPlayer(source, spawnX, spawnY, spawnZ)
	fadeCamera(source, true)
	setCameraTarget(source, source)
end
addEventHandler("onPlayerJoin", getRootElement(), joinHandler)

local spawnPos = {
  	{2034.9428710938, -1403.2003173828, 18, "Hospital mais próximo: Los Santos"},
  	{-2655.3991699219, 638.16137695313, 15, "Hospital mais próximo: San Fierro"},
  	{-1514.6713867188, 2522.4748535156, 56, "Hospital mais próximo: Tierra Robada"},
  	{1607.62890625, 1818.9958496094, 11, "Hospital mais próximo: Las Venturas"},
  	{-2198.5632324219, -2306.6220703125, 31, "Hospital mais próximo: Whetstone"},
}

addEventHandler ("onPlayerWasted", getRootElement(), function ()
	local x, y, z = getElementPosition (source)
	local dist = 0
	local id = 0
	for i, v in ipairs (spawnPos) do
		local pX, pY, pZ = spawnPos[i][1], spawnPos[i][2], spawnPos[i][3]
		if getDistanceBetweenPoints3D (x, y, z, pX, pY, pZ) < dist then
			dist = getDistanceBetweenPoints3D (x, y, z, pX, pY, pZ)
        	id = i
		end
	end
	outputChatBox(spawnPos[id][4], source) --Write out spawn pos
    setTimer(function()
        spawnPlayer(source, spawnPos[id][1], spawnPos[id][2], spawnPos[id][3])
    end, 1000*3, 1) -- Respawn after 3 second (1000=1 second)
end)

 

Link to comment
26 minutes ago, holuzs said:

local spawnX, spawnY, spawnZ = 1480.9730224609, -1771.46875, 18.8
function joinHandler()
	spawnPlayer(source, spawnX, spawnY, spawnZ)
	fadeCamera(source, true)
	setCameraTarget(source, source)
end
addEventHandler("onPlayerJoin", getRootElement(), joinHandler)

local spawnPos = {
  	{2034.9428710938, -1403.2003173828, 18, "Hospital mais próximo: Los Santos"},
  	{-2655.3991699219, 638.16137695313, 15, "Hospital mais próximo: San Fierro"},
  	{-1514.6713867188, 2522.4748535156, 56, "Hospital mais próximo: Tierra Robada"},
  	{1607.62890625, 1818.9958496094, 11, "Hospital mais próximo: Las Venturas"},
  	{-2198.5632324219, -2306.6220703125, 31, "Hospital mais próximo: Whetstone"},
}

addEventHandler ("onPlayerWasted", getRootElement(), function ()
	local x, y, z = getElementPosition (source)
	local dist = 0
	local id = 0
	for i, v in ipairs (spawnPos) do
		local pX, pY, pZ = spawnPos[i][1], spawnPos[i][2], spawnPos[i][3]
		if getDistanceBetweenPoints3D (x, y, z, pX, pY, pZ) < dist then
			dist = getDistanceBetweenPoints3D (x, y, z, pX, pY, pZ)
        	id = i
		end
	end
	outputChatBox(spawnPos[id][4], source) --Write out spawn pos
    setTimer(function()
        spawnPlayer(source, spawnPos[id][1], spawnPos[id][2], spawnPos[id][3])
    end, 1000*3, 1) -- Respawn after 3 second (1000=1 second)
end)

 

attempt to index field '?' (a nil value)

Link to comment
local spawnX, spawnY, spawnZ = 1480.9730224609, -1771.46875, 18.8
function joinHandler()
	spawnPlayer(source, spawnX, spawnY, spawnZ)
	fadeCamera(source, true)
	setCameraTarget(source, source)
end
addEventHandler("onPlayerJoin", getRootElement(), joinHandler)

local spawnPos = {
  	{2034.9428710938, -1403.2003173828, 18, "Hospital mais próximo: Los Santos"},
  	{-2655.3991699219, 638.16137695313, 15, "Hospital mais próximo: San Fierro"},
  	{-1514.6713867188, 2522.4748535156, 56, "Hospital mais próximo: Tierra Robada"},
  	{1607.62890625, 1818.9958496094, 11, "Hospital mais próximo: Las Venturas"},
  	{-2198.5632324219, -2306.6220703125, 31, "Hospital mais próximo: Whetstone"},
}

addEventHandler ("onPlayerWasted", getRootElement(), function (ammo, attacker, weapon, bodypart)
	local x, y, z = getElementPosition (source)
	local dist = 99999
	local id = 0
	for i, v in ipairs (spawnPos) do
		local pX, pY, pZ = spawnPos[i][1], spawnPos[i][2], spawnPos[i][3]
		if getDistanceBetweenPoints3D (x, y, z, pX, pY, pZ) < dist then
			dist = getDistanceBetweenPoints3D (x, y, z, pX, pY, pZ)
        	id = i
		end
	end
	outputChatBox(spawnPos[id][4], source) --Write out spawn pos
    setTimer(spawnPlayer, 3000, 1, source, spawnPos[id][1], spawnPos[id][2], spawnPos[id][3]) -- Spawn after 3 second
end)

Try this.

  • Thanks 1
Link to comment
4 minutes ago, holuzs said:

local spawnX, spawnY, spawnZ = 1480.9730224609, -1771.46875, 18.8
function joinHandler()
	spawnPlayer(source, spawnX, spawnY, spawnZ)
	fadeCamera(source, true)
	setCameraTarget(source, source)
end
addEventHandler("onPlayerJoin", getRootElement(), joinHandler)

local spawnPos = {
  	{2034.9428710938, -1403.2003173828, 18, "Hospital mais próximo: Los Santos"},
  	{-2655.3991699219, 638.16137695313, 15, "Hospital mais próximo: San Fierro"},
  	{-1514.6713867188, 2522.4748535156, 56, "Hospital mais próximo: Tierra Robada"},
  	{1607.62890625, 1818.9958496094, 11, "Hospital mais próximo: Las Venturas"},
  	{-2198.5632324219, -2306.6220703125, 31, "Hospital mais próximo: Whetstone"},
}

addEventHandler ("onPlayerWasted", getRootElement(), function (ammo, attacker, weapon, bodypart)
	local x, y, z = getElementPosition (source)
	local dist = 99999
	local id = 0
	for i, v in ipairs (spawnPos) do
		local pX, pY, pZ = spawnPos[i][1], spawnPos[i][2], spawnPos[i][3]
		if getDistanceBetweenPoints3D (x, y, z, pX, pY, pZ) < dist then
			dist = getDistanceBetweenPoints3D (x, y, z, pX, pY, pZ)
        	id = i
		end
	end
	outputChatBox(spawnPos[id][4], source) --Write out spawn pos
    setTimer(spawnPlayer, 3000, 1, source, spawnPos[id][1], spawnPos[id][2], spawnPos[id][3]) -- Spawn after 3 second
end)

Try this.

Thank you, it worked. ❤️

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