Mr. Maxilian Posted January 7, 2020 Posted January 7, 2020 Hi! I created a few coordinates with a point of spawn. I need the player to be revived after death at a point that is closer to him. How can this be realized? Is it possible to make with a array and radius?
Moderators Patrick Posted January 7, 2020 Moderators Posted January 7, 2020 (edited) onPlayerWasted event => call the respawn function => find the cloesest point from the array with for loop => spawnPlayer Edited January 7, 2020 by stPatrick
Mr. Maxilian Posted January 7, 2020 Author Posted January 7, 2020 1 hour ago, stPatrick said: onPlayerWasted event => call the respawn function => find the cloesest point from the array with for loop => spawnPlayer I understand the algorithm, but I don 't understand how to write it in code. I have x1, y1, z2 - the last coordinates before death, and there are x2, y2, z2 - the coordinates of spawn after death. I got the data, and then what? (How it should look to code)
Moderators Patrick Posted January 8, 2020 Moderators Posted January 8, 2020 19 hours ago, Mr. Maxilian said: I understand the algorithm, but I don 't understand how to write it in code. I have x1, y1, z2 - the last coordinates before death, and there are x2, y2, z2 - the coordinates of spawn after death. I got the data, and then what? (How it should look to code) Looks like something like this local respawnPoints = { {0, 0, 3}, } local function findNearestRespawnPoint(x, y, z) local nearestPoint = { distance = 99999, index = 1 } for i, v in ipairs(respawnPoints) do local distance = getDistanceBetweenPoints3D(x, y, z, v[1], v[2], v[3]) if distance < nearestPoint.distance then nearestPoint = { distance = distance, index = i } end end return respawnPoints[nearestPoint.index] end local function respawnPlayer(player) local x, y, z = getElementPosition(player) local point = findNearestRespawnPoint(x, y, z) spawnPlayer(player, point[1], point[2], point[3]) end addEventHandler("onPlayerWasted", root, function() setTimer(respawnPlayer, 1000, 1, source) end) 2
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