Advertisement
TheBakkeseKing

Bug en el respawn

Jan 12th, 2024
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.30 KB | None | 0 0
  1. --[[
  2.  
  3.     SERVER SIDE
  4.  
  5. ]]
  6.  
  7. -- Function to detect a player's death
  8. function DeathDetect()
  9.     -- Retrieve the current state of the player
  10.     local varEstado = exports["MR2_Cuentas"]:getValue(source, 'Estado')
  11.    
  12.     -- Check if the player's state is valid
  13.     if not (varEstado ~= nil) then
  14.         return
  15.     end
  16.  
  17.     -- If the player is already marked as dead, trigger 'RematarClient' event
  18.     if (varEstado.Muerto == true) then
  19.         triggerClientEvent(source, "RematarClient", source, source)
  20.         return
  21.     end
  22.  
  23.     -- If the player is in a vehicle, remove them from it
  24.     if isPedInVehicle(source) then
  25.         removePedFromVehicle(source)
  26.     end
  27.    
  28.     -- Retrieve the player's weapons and current skin
  29.     local playerWeapons = exports["MR16_Armas"]:getPedWeapons(source)
  30.     iprint(playerWeapons)
  31.     local skin = getElementModel(source)
  32.  
  33.     -- Get the player's current position and respawn them at the same place
  34.     local varX, varY, varZ = getElementPosition(source)
  35.     spawnPlayer(source, varX, varY, varZ, 0, skin, getElementInterior(source), getElementDimension(source))
  36.  
  37.     -- Set death animation for the player
  38.     setPedAnimation(source, "CRACK", "crckidle4", -1, true, false, false, false)
  39.  
  40.     -- Mark the player as dead in their state
  41.     varEstado.Muerto = true
  42.     exports["MR2_Cuentas"]:setValue(source, 'Estado', varEstado)
  43.    
  44.     -- Trigger 'DeathClientUptade' event on the client
  45.     triggerClientEvent(source, "DeathClientUptade", source, source)
  46.  
  47.     -- Return the weapons to the player
  48.     if playerWeapons then
  49.         for i, v in ipairs(playerWeapons) do
  50.             giveWeapon(source, v[1], v[2])
  51.         end
  52.     end
  53.    
  54.     -- Unbind the 'H' key for the player
  55.     unbindKey(source, "H")
  56. end
  57.  
  58. -- Associate the 'onPlayerWasted' event with the 'DeathDetect' function
  59. addEventHandler("onPlayerWasted", root, DeathDetect)
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. --[[
  69.  
  70.     CLIENT SIDE
  71.  
  72. ]]
  73. -- Register and handle the 'DeathClientUptade' event
  74. addEvent("DeathClientUptade", true)
  75. addEventHandler("DeathClientUptade", root, function()
  76.     -- Set a timer to allow player respawn
  77.     timerS = setTimer(function()
  78.         AprobedSpawn = true
  79.         -- Display a message to the player about respawning
  80.         outputChatBox("#9AA498[#FF7800Server#9AA498] #53B440Use the command #FFFFFF/reaparecer #53B440to accept your death.", 200, 20, 20, true)
  81.     end, 30000, 1)
  82.  
  83.     -- Add command handler for 'reaparecer'
  84.     addCommandHandler('reaparecer', function(command)
  85.         -- Check if respawn is allowed
  86.         if not AprobedSpawn then
  87.             return
  88.         end
  89.         local localPlayer = getLocalPlayer()
  90.         local varEstado = exports["MR2_Cuentas"]:getValue(localPlayer, 'Estado')
  91.         -- Check if the player is marked as dead
  92.         if (varEstado == nil) or (varEstado.Muerto == false) then
  93.             return
  94.         end
  95.         -- Trigger the server event 'ReviveOrder'
  96.         triggerServerEvent("ReviveOrder", localPlayer)
  97.         AprobedSpawn = false
  98.     end)
  99.  
  100.     -- Remove the existing render handler
  101.     removeEventHandler("onClientRender", this, function()
  102.         -- [Render handler code here]
  103.     end)
  104.  
  105.     -- Add a new render handler
  106.     addEventHandler("onClientRender", this, function()
  107.         -- [Render handler code here]
  108.     end)
  109. end)
  110.  
Tags: lua MTA SA
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement