Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- SERVER SIDE
- ]]
- -- Function to detect a player's death
- function DeathDetect()
- -- Retrieve the current state of the player
- local varEstado = exports["MR2_Cuentas"]:getValue(source, 'Estado')
- -- Check if the player's state is valid
- if not (varEstado ~= nil) then
- return
- end
- -- If the player is already marked as dead, trigger 'RematarClient' event
- if (varEstado.Muerto == true) then
- triggerClientEvent(source, "RematarClient", source, source)
- return
- end
- -- If the player is in a vehicle, remove them from it
- if isPedInVehicle(source) then
- removePedFromVehicle(source)
- end
- -- Retrieve the player's weapons and current skin
- local playerWeapons = exports["MR16_Armas"]:getPedWeapons(source)
- iprint(playerWeapons)
- local skin = getElementModel(source)
- -- Get the player's current position and respawn them at the same place
- local varX, varY, varZ = getElementPosition(source)
- spawnPlayer(source, varX, varY, varZ, 0, skin, getElementInterior(source), getElementDimension(source))
- -- Set death animation for the player
- setPedAnimation(source, "CRACK", "crckidle4", -1, true, false, false, false)
- -- Mark the player as dead in their state
- varEstado.Muerto = true
- exports["MR2_Cuentas"]:setValue(source, 'Estado', varEstado)
- -- Trigger 'DeathClientUptade' event on the client
- triggerClientEvent(source, "DeathClientUptade", source, source)
- -- Return the weapons to the player
- if playerWeapons then
- for i, v in ipairs(playerWeapons) do
- giveWeapon(source, v[1], v[2])
- end
- end
- -- Unbind the 'H' key for the player
- unbindKey(source, "H")
- end
- -- Associate the 'onPlayerWasted' event with the 'DeathDetect' function
- addEventHandler("onPlayerWasted", root, DeathDetect)
- --[[
- CLIENT SIDE
- ]]
- -- Register and handle the 'DeathClientUptade' event
- addEvent("DeathClientUptade", true)
- addEventHandler("DeathClientUptade", root, function()
- -- Set a timer to allow player respawn
- timerS = setTimer(function()
- AprobedSpawn = true
- -- Display a message to the player about respawning
- outputChatBox("#9AA498[#FF7800Server#9AA498] #53B440Use the command #FFFFFF/reaparecer #53B440to accept your death.", 200, 20, 20, true)
- end, 30000, 1)
- -- Add command handler for 'reaparecer'
- addCommandHandler('reaparecer', function(command)
- -- Check if respawn is allowed
- if not AprobedSpawn then
- return
- end
- local localPlayer = getLocalPlayer()
- local varEstado = exports["MR2_Cuentas"]:getValue(localPlayer, 'Estado')
- -- Check if the player is marked as dead
- if (varEstado == nil) or (varEstado.Muerto == false) then
- return
- end
- -- Trigger the server event 'ReviveOrder'
- triggerServerEvent("ReviveOrder", localPlayer)
- AprobedSpawn = false
- end)
- -- Remove the existing render handler
- removeEventHandler("onClientRender", this, function()
- -- [Render handler code here]
- end)
- -- Add a new render handler
- addEventHandler("onClientRender", this, function()
- -- [Render handler code here]
- end)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement