dener189 Posted November 24, 2018 Share Posted November 24, 2018 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
HDmaster0702 Posted November 24, 2018 Share Posted November 24, 2018 You haven't called the spawnPlayer function in the onPlayerWasted Event. It's not automatically calling spawnPlayer. Link to comment
dener189 Posted November 24, 2018 Author Share Posted November 24, 2018 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
HDmaster0702 Posted November 24, 2018 Share Posted November 24, 2018 No. At the end of the function put the spawnPlayer. You don't need the onPlayerSpawn. Link to comment
dener189 Posted November 24, 2018 Author Share Posted November 24, 2018 2 minutes ago, HDmaster0702 said: No. At the end of the function put the spawnPlayer. You don't need the onPlayerSpawn. could you pack it for me? Link to comment
HDmaster0702 Posted November 24, 2018 Share Posted November 24, 2018 I'm not home. Maybe when I arrive home. Link to comment
dener189 Posted November 24, 2018 Author Share Posted November 24, 2018 Just now, HDmaster0702 said: Eu não estou em casa. Talvez quando eu chegar em casa. ok, tranks Link to comment
holuzs Posted November 24, 2018 Share Posted November 24, 2018 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
dener189 Posted November 24, 2018 Author Share Posted November 24, 2018 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
holuzs Posted November 24, 2018 Share Posted November 24, 2018 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. 1 Link to comment
dener189 Posted November 24, 2018 Author Share Posted November 24, 2018 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. 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now