Jump to content

MTA | WARNING: destroyElement


India

Recommended Posts

When I die with the backpack, i get that error on the console

WARNING: DayZ\survivorSystem.lua:88: Bad argument @ 'destroyElement' [Expected element at argument 1]

 

function rearmPlayerWeapon(weaponName,slot)
  takeAllWeapons(source)
  local ammoData,weapID = getWeaponAmmoType(weaponName)
  if getElementData(source,ammoData)<= 0 then
    triggerClientEvent(source,"displayClientInfo",source,"Rearm","No ammo!",255,22,0)
    return
  end
  setElementData(source,"currentweapon_"..slot,weaponName)
  local weapon = getElementData(source,"currentweapon_1")
  if weapon then
    for id,item in pairs(weaponTable)do
      if weapon == item[1] and getElementData(source,item[1])>= 1 and getElementData(source,item[2])>= 1 and item[5] == 1 then
        local ammoData,weapID = getWeaponAmmoType(weapon)
        giveWeapon(source,weapID,getElementData(source,ammoData),true)
      end
    end
  end
  local weapon = getElementData(source,"currentweapon_2")
  if weapon then
    for id,item in pairs(weaponTable)do
      if weapon == item[1] and getElementData(source,item[1])>= 1 and ((getElementData(source,item[2]) and getElementData(source,item[2])>= 1) or item[2] == "others") and item[5] == 2 then
        local ammoData,weapID = getWeaponAmmoType(weapon)
        giveWeapon(source,weapID,getElementData(source,ammoData),true)
      end
    end
  end
  local weapon = getElementData(source,"currentweapon_3")
  if weapon then
    for id,item in pairs(weaponTable)do
      if weapon == item[1] and getElementData(source,item[1])>= 1 and item[5] == 3 then
        local ammoData,weapID = getWeaponAmmoType(weapon)
        giveWeapon(source,weapID,getElementData(source,ammoData),true)
      end
    end
  end
  if elementWeaponBack[source] then
    detachElementFromBone(elementWeaponBack[source])
    destroyElement(elementWeaponBack[source])
    elementWeaponBack[source] = false
  end
  triggerClientEvent(source,"refreshInventoryManual",source)
end
addEvent("onPlayerRearmWeapon",true)
addEventHandler("onPlayerRearmWeapon",getRootElement(),rearmPlayerWeapon)

function isVestVar(dataName)
  for _,vest in pairs(VestsTable)do
    if dataName == vest[2]then
      return true
    end
  end
  return false
end

function isHelmetVar(dataName)
  for _,vest in pairs(HelmetsTable)do
    if dataName == vest[2]then
      return true
    end
  end
  return false
end

function getVestIDByDataName(dataName)
  for _,vesst in pairs(VestsTable)do
    if dataName == vesst[2]then
      return vesst[3]
    end
  end
  return false
end

function getHelmetIDByDataName(dataName)
  for _,helmett in pairs(HelmetsTable)do
    if dataName == helmett[2]then
      return helmett[3]
    end
  end
  return false
end

local elementBackpack = {}
function backPackBack(dataName,oldValue)
  if getElementType(source)== "player" and dataName == "MAX_Slots" then
    newValue = getElementData(source,"MAX_Slots")
    if elementBackpack[source] then
      detachElementFromBone(elementBackpack[source])
      destroyElement(elementBackpack[source])
      elementBackpack[source] = false
    end
    local x,y,z = getElementPosition(source)
    local rx,ry,rz = getElementRotation(source)
    if newValue == 8 then
      return
    elseif getBackpackIDFromSlots(newValue) then
      backpackID = getBackpackIDFromSlots(newValue)
      local x,y,z,rx,ry,rz = getBackpackCordsFromSlots(newValue)
      elementBackpack[source] = createObject(backpackID,x,y,z)
      attachElementToBone(elementBackpack[source],source,3,x,y,z,rx,ry,rz)
    end
  end
  --------- Vests ---------
  if getElementType(source)== "player" and isVestVar(dataName) then
    if getElementData(source,dataName) == true then
      local x,y,z = getElementPosition(source)
      for _,vest in pairs(VestsTable)do
        if vest[2] == dataName then
          vestt = createObject(vest[3],x,y,z)
          setElementData(source,"VestModel",vestt)
          attachElementToBone(vestt,source,3,vest[6][1],vest[6][2],vest[6][3],vest[6][4],vest[6][5],vest[6][6])
        end
      end
    else
      if isElement(getElementData(source,"VestModel"))then
        if getElementModel(getElementData(source,"VestModel")) == getVestIDByDataName(dataName) then
          detachElementFromBone(getElementData(source,"VestModel"))
          destroyElement(getElementData(source,"VestModel"))
          setElementData(source,"VestModel",false)
        end
      end
    end
  end
  --------- Helmets ---------
  if getElementType(source)== "player" and isHelmetVar(dataName) then
    if getElementData(source,dataName) == true then
      local x,y,z = getElementPosition(source)
      for _,helmet in pairs(HelmetsTable)do
        if helmet[2] == dataName then
          Helmet = createObject(helmet[3],x,y,z)
          setElementData(source,"HelmetModel",Helmet)
          attachElementToBone(Helmet,source,1,helmet[6][1],helmet[6][2],helmet[6][3],helmet[6][4],helmet[6][5],helmet[6][6])
        end
      end
    else
      if isElement(getElementData(source,"HelmetModel"))then
        if getElementModel(getElementData(source,"HelmetModel")) == getHelmetIDByDataName(dataName) then
          detachElementFromBone(getElementData(source,"HelmetModel"))
          destroyElement(getElementData(source,"HelmetModel"))
          setElementData(source,"HelmetModel",false)
        end
      end
    end
  end
end
function backpackRemoveQuit()
  if getElementData(source,"HelmetModel") then
    local helmet = getElementData(source,"HelmetModel")
    if isElement(helmet) then
      destroyElement(helmet)
    end
  end
  if getElementData(source,"VestModel") then
    local vest = getElementData(source,"VestModel")
    if isElement(vest) then
      destroyElement(vest)
    end
  end
  if elementWeaponBackSec[source] then
    detachElementFromBone(elementWeaponBackSec[source])
    destroyElement(elementWeaponBackSec[source])  
    elementWeaponBackSec[source] = false
  end
  if elementWeaponBackSpe[source] then
    detachElementFromBone(elementWeaponBackSpe[source])
    destroyElement(elementWeaponBackSpe[source])  
    elementWeaponBackSpe[source] = false
  end
  if elementWeaponBackPistol[source] then
    detachElementFromBone(elementWeaponBackPistol[source])
    destroyElement(elementWeaponBackPistol[source])  
    elementWeaponBackPistol[source] = false
  end
  if elementWeaponRaplace[source] then
    detachElementFromBone(elementWeaponRaplace[source])
    destroyElement(elementWeaponRaplace[source])         
    elementWeaponRaplace[source] = false
  end
  if elementWeaponRaplaceb[source] then
    detachElementFromBone(elementWeaponRaplaceb[source])
    destroyElement(elementWeaponRaplaceb[source])         
    elementWeaponRaplaceb[source] = false
  end
  if elementWeaponRaplacec[source] then
    detachElementFromBone(elementWeaponRaplacec[source])
    destroyElement(elementWeaponRaplacec[source])         
    elementWeaponRaplacec[source] = false
  end
  if elementBackpack[source] then
    detachElementFromBone(elementBackpack[source])
    destroyElement(elementBackpack[source])
  end
  if elementWeaponBack[source] then
    detachElementFromBone(elementWeaponBack[source])
    destroyElement(elementWeaponBack[source])
    elementWeaponBack[source] = false
  end
end

elementWeaponRaplace = {}
function weaponReplace(previousWeaponID,currentWeaponID)
 --local source = getRootElement()
  local weapon = getElementData(source,"currentweapon_1")
  if not weapon then return end
  local ammoData,weapID = getWeaponAmmoType(weapon)
  local x,y,z = getElementPosition(source)
  local rx,ry,rz = getElementRotation(source)
  if currentWeaponID == weapID then
    if elementWeaponRaplace[source] then
      detachElementFromBone(elementWeaponRaplace[source])
      destroyElement(elementWeaponRaplace[source])
      elementWeaponRaplace[source] = false
    end
    for id,item in ipairs(weaponTable)do
      if weapon == item[1] and item[5] == 1 then
        elementWeaponRaplace[source] = createObject(item[6],x,y,z)
      end
    end
    attachElementToBone(elementWeaponRaplace[source],source,12,0,0,0,0,270,0)
  elseif previousWeaponID == weapID then
    detachElementFromBone(elementWeaponRaplace[source])
    if elementWeaponRaplace[source] then
      destroyElement(elementWeaponRaplace[source])
    end
    elementWeaponRaplace[source] = false
  end
end

elementWeaponRaplaceb = {}
function weaponReplaceb(previousWeaponID,currentWeaponID)
 --local source = getRootElement()
  local weapon = getElementData(source,"currentweapon_2")
  if not weapon then return end
  local ammoData,weapID = getWeaponAmmoType(weapon)
  local x,y,z = getElementPosition(source)
  local rx,ry,rz = getElementRotation(source)
  if currentWeaponID == weapID then
    if elementWeaponRaplaceb[source] then
      detachElementFromBone(elementWeaponRaplaceb[source])
      destroyElement(elementWeaponRaplaceb[source])
      elementWeaponRaplaceb[source] = false
    end
    for id,item in ipairs(weaponTable)do
      if weapon == item[1] and item[5] == 2 then
        elementWeaponRaplaceb[source] = createObject(item[6],x,y,z)
      end
    end
    attachElementToBone(elementWeaponRaplaceb[source],source,12,0,0,0,0,270,0)
  elseif previousWeaponID == weapID then
    detachElementFromBone(elementWeaponRaplaceb[source])
    if elementWeaponRaplaceb[source] then
      destroyElement(elementWeaponRaplaceb[source])
    end
    elementWeaponRaplaceb[source] = false
  end
end

elementWeaponRaplacec = {}
function weaponReplacec(previousWeaponID,currentWeaponID)
 --local source = getRootElement()
  local weapon = getElementData(source,"currentweapon_4")
  if not weapon then return end
  local ammoData,weapID = getWeaponAmmoType(weapon)
  local x,y,z = getElementPosition(source)
  local rx,ry,rz = getElementRotation(source)
  if currentWeaponID == weapID then
    if elementWeaponRaplacec[source] then
      detachElementFromBone(elementWeaponRaplacec[source])
      destroyElement(elementWeaponRaplacec[source])
      elementWeaponRaplacec[source] = false
    end
    for id,item in ipairs(weaponTable)do
      if weapon == item[1] and item[5] == 4 then
        elementWeaponRaplacec[source] = createObject(item[6],x,y,z)
      end
    end
    attachElementToBone(elementWeaponRaplacec[source],source,12,0,0,0,0,270,0)
  elseif previousWeaponID == weapID then
    detachElementFromBone(elementWeaponRaplacec[source])
    if elementWeaponRaplacec[source] then
      destroyElement(elementWeaponRaplacec[source])
    end
    elementWeaponRaplacec[source] = false
  end
end

elementWeaponBack = {}
function weaponSwitchBack(previousWeaponID,currentWeaponID)
  local weapon1 = getElementData(source,"currentweapon_1")
  if not weapon1 then return end
  local ammoData1,weapID1 = getWeaponAmmoType(weapon1)
  local x,y,z = getElementPosition(source)
  local rx,ry,rz = getElementRotation(source)
  if previousWeaponID == weapID1 then
    if elementWeaponBack[source] then
      detachElementFromBone(elementWeaponBack[source])
      destroyElement(elementWeaponBack[source])
      elementWeaponBack[source] = false
    end
    for id,item in ipairs(weaponTable)do
      if weapon1 == item[1] and item[5] == 1 then
        elementWeaponBack[source] = createObject(item[6],x,y,z)
        setObjectScale(elementWeaponBack[source],0.875)
      end
    end
    if elementBackpack[source] then
      attachElementToBone(elementWeaponBack[source],source,3,0.19,-0.31,-0.1,-4,270,-90)
    else
      attachElementToBone(elementWeaponBack[source],source,3,0.19,-0.15,-0.1,-8,270,0)
    end
  elseif currentWeaponID == weapID1 then
    detachElementFromBone(elementWeaponBack[source])
    if not elementWeaponBack[source] then return end
    destroyElement(elementWeaponBack[source])
    elementWeaponBack[source] = false
  end
end

elementWeaponBackSec = {}
function weaponSwitchbBack(previousWeaponID,currentWeaponID)
  local weapon1 = getElementData(source,"currentweapon_2")
  if not weapon1 then return end
  local ammoData1,weapID1 = getWeaponAmmoType(weapon1)
  local x,y,z = getElementPosition(source)
  local rx,ry,rz = getElementRotation(source)
  if previousWeaponID == weapID1 then
    if elementWeaponBackSec[source] then
      detachElementFromBone(elementWeaponBackSec[source])
      destroyElement(elementWeaponBackSec[source])
      elementWeaponBackSec[source] = false
    end
    for id,item in ipairs(weaponTable)do
      if weapon1 == item[1] and item[5] == 2 then
        elementWeaponBackSec[source] = createObject(item[6],x,y,z)
        setObjectScale(elementWeaponBackSec[source],1)
      end
    end
    if elementBackpack[source] then
      if weapID1 == 28 or weapID1 == 29 or weapID1 == 32 then
        attachElementToBone(elementWeaponBackSec[source],source,3,-0.15,-0.35,0.25,7,100,90)
    elseif weapID1 == 4 then
        attachElementToBone(elementWeaponBackSec[source],source,3,-0.21,-0.15,-0.17,0.05,3,280)
      elseif weapID1 == 9 then
        attachElementToBone(elementWeaponBackSec[source],source,3,-0.23,-0.39,-0.25,0.20,-55,90)
      elseif weapID1 == 6 then
        attachElementToBone(elementWeaponBackSec[source],source,3,-0.19,-0.20,-0.20,0.20,-05,0)
      elseif weapID1 == 23 then
        attachElementToBone(elementWeaponBackSec[source],source,13,-0.07,0,0.1,7,285,100)        
      else    
        attachElementToBone(elementWeaponBackSec[source],source,3,-0.21,-0.10,-0.15,-0.30,0,267)
      end
    else
      if weapID1 == 28 or weapID1 == 29 or weapID1 == 32 then
        attachElementToBone(elementWeaponBackSec[source],source,3,-0.2,-0.2,0.2,10,100,0)
      elseif weapID1 == 4 then
        attachElementToBone(elementWeaponBackSec[source],source,3,-0.05,-0.2,0.3,10,180,15)
      elseif weapID1 == 9 then
        attachElementToBone(elementWeaponBackSec[source],source,3,0,-0.2,0.5,0,125,0)
      elseif weapID1 == 6 then
        attachElementToBone(elementWeaponBackSec[source],source,3,-0.15,-0.15,-0.1,185,170,260)
      elseif weapID1 == 23 then
        attachElementToBone(elementWeaponBackSec[source],source,13,-0.07,0,0.1,7,285,100)            
      else
        attachElementToBone(elementWeaponBackSec[source],source,3,-0.01,-0.15,0.25,01,179,0)
      end
    end
  elseif currentWeaponID == weapID1 then
    if not elementWeaponBackSec[source] then return end
    detachElementFromBone(elementWeaponBackSec[source])
    destroyElement(elementWeaponBackSec[source])
    elementWeaponBackSec[source] = false
  end
end

elementWeaponBackSpe = {}
function weaponSwitchcBack(previousWeaponID,currentWeaponID)
  local weapon1 = getElementData(source,"currentweapon_3")
  if not weapon1 then return end
  local ammoData1,weapID1 = getWeaponAmmoType(weapon1)
  local x,y,z = getElementPosition(source)
  local rx,ry,rz = getElementRotation(source)
  if previousWeaponID == weapID1 then
    if elementWeaponBackSpe[source] then
      detachElementFromBone(elementWeaponBackSpe[source])
      destroyElement(elementWeaponBackSpe[source])
      elementWeaponBackSpe[source] = false
    end
    for id,item in ipairs(weaponTable)do
      if weapon1 == item[1] and item[1] ~= "Parachute" and item[5] == 3 then
        elementWeaponBackSpe[source] = createObject(item[6],x,y,z)
        setObjectScale(elementWeaponBackSpe[source],1)
      end
    end
    if weapon1 == "Grenade" then
      attachElementToBone(elementWeaponBackSpe[source],source,14,0.05,0,0.15,180,-20,0)
    elseif weapon1 == "Tear Gas" then
      attachElementToBone(elementWeaponBackSpe[source],source,14,0.05,0,0.15,180,0,0)
    else
      attachElementToBone(elementWeaponBackSpe[source],source,14,0.05,0.1,0.05,180,90,0)
    end
  elseif currentWeaponID == weapID1 then
    if not elementWeaponBackSpe[source] then return end
    detachElementFromBone(elementWeaponBackSpe[source])
    destroyElement(elementWeaponBackSpe[source])
    elementWeaponBackSpe[source] = false
  end
end

elementWeaponBackPistol = {}
function weaponSwitchDBack(previousWeaponID,currentWeaponID)
  local weapon1 = getElementData(source,"currentweapon_4")
  if not weapon1 then return end
  local ammoData1,weapID1 = getWeaponAmmoType(weapon1)
  local x,y,z = getElementPosition(source)
  local rx,ry,rz = getElementRotation(source)
  if previousWeaponID == weapID1 then
    if elementWeaponBackPistol[source] then
      detachElementFromBone(elementWeaponBackPistol[source])
      destroyElement(elementWeaponBackPistol[source])
      elementWeaponBackPistol[source] = false
    end
    for id,item in ipairs(weaponTable)do
      if weapon1 == item[1] and item[5] == 4 then
        elementWeaponBackPistol[source] = createObject(item[6],x,y,z)
        setObjectScale(elementWeaponBackPistol[source],1)
      end
    end
    attachElementToBone(elementWeaponBackPistol[source],source,13,-0.07,0,0.1,7,285,100)
  elseif currentWeaponID == weapID1 then
    if not elementWeaponBackPistol[source] then return end
    detachElementFromBone(elementWeaponBackPistol[source])
    destroyElement(elementWeaponBackPistol[source])
    elementWeaponBackPistol[source] = false
  end
end


function removeBackWeaponOnDrop()
  if elementWeaponBackSec[source] then
    detachElementFromBone(elementWeaponBackSec[source])
    destroyElement(elementWeaponBackSec[source])  
    elementWeaponBackSec[source] = false
  end
  if elementWeaponBackSpe[source] then
    detachElementFromBone(elementWeaponBackSpe[source])
    destroyElement(elementWeaponBackSpe[source])  
    elementWeaponBackSpe[source] = false
  end
  if elementWeaponBackPistol[source] then
    detachElementFromBone(elementWeaponBackPistol[source])
    destroyElement(elementWeaponBackPistol[source])  
    elementWeaponBackPistol[source] = false
  end
  if elementWeaponRaplace[source] then
    detachElementFromBone(elementWeaponRaplace[source])
    destroyElement(elementWeaponRaplace[source])         
    elementWeaponRaplace[source] = false
  end
  if elementWeaponRaplaceb[source] then
    detachElementFromBone(elementWeaponRaplaceb[source])
    destroyElement(elementWeaponRaplaceb[source])         
    elementWeaponRaplaceb[source] = false
  end
  if elementWeaponRaplacec[source] then
    detachElementFromBone(elementWeaponRaplacec[source])
    destroyElement(elementWeaponRaplacec[source])         
    elementWeaponRaplacec[source] = false
  end
  if elementWeaponBack[source] then
    detachElementFromBone(elementWeaponBack[source])
    destroyElement(elementWeaponBack[source])
    elementWeaponBack[source] = false
  end
end
addEvent("removeBackWeaponOnDrop",true)
addEventHandler("removeBackWeaponOnDrop",getRootElement(),removeBackWeaponOnDrop)
function removeAttachedOnDeath()
  if getPedOccupiedVehicle(source) then
    setVehicleEngineState(getPedOccupiedVehicle(source),false)
    removePedFromVehicle(source)
  end
  if getElementData(source,"HelmetModel") then
    local Mask = getElementData(source,"HelmetModel")
    if isElement(Mask) then
      destroyElement(Mask)
      setElementData(source,"HelmetModel",false)
      setElementData(source,"HelmetOn",false)
      setElementData(source,"GasMaskOn",false)
    end 
  end
  if getElementData(source,"VestModel") then
    local Colete2 = getElementData(source,"VestModel")
    if isElement(Colete2) then
      destroyElement(Colete2)
      setElementData(source,"VestModel",false)
      setElementData(source,"VestOn",false)
    end
  end
  if elementWeaponBackSec[source] then
    detachElementFromBone(elementWeaponBackSec[source])
    destroyElement(elementWeaponBackSec[source])  
    elementWeaponBackSec[source] = false
  end
  if elementWeaponBackSpe[source] then
    detachElementFromBone(elementWeaponBackSpe[source])
    destroyElement(elementWeaponBackSpe[source])  
    elementWeaponBackSpe[source] = false
  end    
  if elementWeaponBackPistol[source] then
    detachElementFromBone(elementWeaponBackPistol[source])
    destroyElement(elementWeaponBackPistol[source])  
    elementWeaponBackPistol[source] = false
  end
  if elementWeaponRaplace[source] then
    detachElementFromBone(elementWeaponRaplace[source])
    destroyElement(elementWeaponRaplace[source])         
    elementWeaponRaplace[source] = false
  end
  if elementWeaponRaplaceb[source] then
    detachElementFromBone(elementWeaponRaplaceb[source])
    destroyElement(elementWeaponRaplaceb[source])         
    elementWeaponRaplaceb[source] = false
  end
  if elementWeaponRaplacec[source] then
    detachElementFromBone(elementWeaponRaplacec[source])
    destroyElement(elementWeaponRaplacec[source])         
    elementWeaponRaplacec[source] = false
  end
  if elementBackpack[source] then
    detachElementFromBone(elementBackpack[source])
    destroyElement(elementBackpack[source])
  end
  if elementWeaponBack[source] then
    detachElementFromBone(elementWeaponBack[source])
    destroyElement(elementWeaponBack[source])
    elementWeaponBack[source] = false
  end
end
addEvent("kilLDayZPlayer",true)
addEventHandler("kilLDayZPlayer",getRootElement(),removeAttachedOnDeath)
function weaponDelete(dataName,oldValue)
  if getElementType(source)== "player" then
    local weapon1 = getElementData(source,"currentweapon_1")
    local weapon2 = getElementData(source,"currentweapon_2")
    local weapon3 = getElementData(source,"currentweapon_3")
    local weapon4 = getElementData(source,"currentweapon_4")
    if(dataName == weapon1 or dataName == weapon2 or dataName == weapon3 or dataName == weapon4) and getElementData(source,dataName)== 0 then
      local ammoData,weapID = getWeaponAmmoType(dataName)
      takeWeapon(source,weapID)
    end
    local weapon1 = getElementData(source,"currentweapon_1")
    local weapon2 = getElementData(source,"currentweapon_2")
    local weapon3 = getElementData(source,"currentweapon_3")
    local weapon4 = getElementData(source,"currentweapon_4")
    local ammoData1,weapID1 = getWeaponAmmoType(weapon1)
    local ammoData2,weapID2 = getWeaponAmmoType(weapon2)
    local ammoData3,weapID3 = getWeaponAmmoType(weapon3)
    local ammoData4,weapID4 = getWeaponAmmoType(weapon4)
    if dataName == ammoData1 then
      if not oldValue then
        return
      end
      local newammo = oldValue - getElementData(source,dataName)
      if newammo == 1 then
        return
      end
      if oldValue > getElementData(source,dataName) then
        takeWeapon(source,weapID1,newammo)
        if elementWeaponBack[source] then
          detachElementFromBone(elementWeaponBack[source])
          destroyElement(elementWeaponBack[source])
          elementWeaponBack[source] = false
        end
      elseif oldValue < getElementData(source,dataName) then
        for id,item in ipairs(weaponTable)do
          if weapon1 == item[1] and getElementData(source,item[1])>= 1 and getElementData(source,item[2])>= 1 and item[5] == 1 then
            giveWeapon(source,weapID1,getElementData(source,dataName)- oldValue,true)
          end
        end
      end
    end
    if dataName == ammoData2 then
      if not oldValue then
        return
      end
      local newammo = oldValue - getElementData(source,dataName)
      if newammo == 1 then
        return
      end
      if oldValue > getElementData(source,dataName) then
        takeWeapon(source,weapID2,newammo)
      elseif oldValue < getElementData(source,dataName) then
        for id,item in ipairs(weaponTable)do
          if weapon2 == item[1] and getElementData(source,item[1])>= 1 and ((getElementData(source,item[2]) and getElementData(source,item[2])>= 1) or item[2] == "others") and item[5] == 2 then
            giveWeapon(source,weapID2,getElementData(source,dataName)- oldValue,false)
          end
        end
      end
    end
    if dataName == ammoData3 then
      if not oldValue then
        return
      end
      local newammo = oldValue - getElementData(source,dataName)
      if newammo == 1 then
        return
      end
      if oldValue > getElementData(source,dataName) then
        takeWeapon(source,weapID3,newammo)
      elseif oldValue < getElementData(source,dataName) then
        for id,item in ipairs(weaponTable)do
          if weapon3 == item[1] and getElementData(source,item[1])>= 1 and item[5] == 3 then
            giveWeapon(source,weapID3,getElementData(source,dataName)- oldValue,false)
          end
        end
      end
    end
    if dataName == ammoData4 then
      if not oldValue then
        return
      end
      local newammo = oldValue - getElementData(source,dataName)
      if newammo == 1 then
        return
      end
      if oldValue > getElementData(source,dataName) then
        takeWeapon(source,weapID4,newammo)
      elseif oldValue < getElementData(source,dataName) then
        for id,item in ipairs(weaponTable)do
          if weapon4 == item[1] and getElementData(source,item[1])>= 1 and getElementData(source,item[2])>= 1 and item[5] == 4 then
            giveWeapon(source,weapID4,getElementData(source,dataName)- oldValue,false)
          end
        end
      end
    end
  end
end
addEventHandler("onElementDataChange",getRootElement(),weaponDelete)
function addPlayerStats(player,data,value)
  if data == "food" then
    do
      local current = getElementData(player,data)
      if current + value > 100 then
        setElementData(player,data,100)
      elseif current + value < 1 then
        setElementData(player,data,0)
        setElementData(player,"blood",getElementData(player,"blood")- math.random(50,120))
      else
        setElementData(player,data,current + value)
      end
    end
  elseif data == "thirst" then
    do
      local current = getElementData(player,data)
      if current + value > 100 then
        setElementData(player,data,100)
      elseif current + value < 1 then
        setElementData(player,data,0)
        setElementData(player,"blood",getElementData(player,"blood")- math.random(50,120))
      else
        setElementData(player,data,current + value)
      end
    end
  elseif data == "blood" then
    do
      local current = getElementData(player,data)
      if current + value > 12000 then
        setElementData(player,data,12000)
      elseif current + value < 1 then
        setElementData(player,data,0)
      else
        setElementData(player,data,current + value)
      end
    end
  elseif data == "temperature" then
    do
      local current = getElementData(player,data)
      if current + value > 41 then
        setElementData(player,data,41)
      elseif current + value <= 31 then
        setElementData(player,data,31)
      else
        setElementData(player,data,current + value)
      end
    end
  elseif data == "humanity" then
    local current = getElementData(player,data)
    if current + value > 5000 then
      setElementData(player,data,5000)
    else
      setElementData(player,data,current + value)
    end
  end
end
function checkTemperature()
  for i,player in ipairs(getElementsByType("player"))do
    if getElementData(player,"logedin") then
      value = 0
      if getWeather == 7 then
        value = -0.1
      elseif getWeather == 12 then
        value = 0
      elseif getWeather == 16 then
        value = -0.4
      elseif getWeather == 4 then
        value = -0.1
      end
      local hour,minutes = getTime()
      if hour >= 21 and hour <= 8 then
        value = value - 0.05
      end
      addPlayerStats(player,"temperature",value)
    end
  end
end
setTimer(checkTemperature,60000,0)
function checkTemperature2()
  for i,player in ipairs(getElementsByType("player"))do
    if getElementData(player,"logedin") then
      value = 0
      if isElementInWater(player) then
        value = gameplayVariables.temperaturewater
      end
      if getControlState(player,"sprint") then
        value = value + gameplayVariables.temperaturesprint
      end
      addPlayerStats(player,"temperature",value)
    end
  end
end
setTimer(checkTemperature2,10000,0)
function setHunger()
  for i,player in ipairs(getElementsByType("player"))do
    if getElementData(player,"logedin") then
      value = gameplayVariables.loseHunger
      addPlayerStats(player,"food",value)
    end
  end
end
setTimer(setHunger,60000,0)
function setThirsty()
  for i,player in ipairs(getElementsByType("player"))do
    if getElementData(player,"logedin") then
      value = gameplayVariables.loseThirst
      addPlayerStats(player,"thirst",value)
    end
  end
end
setTimer(setThirsty,60000,0)
function checkThirsty()
  for i,player in ipairs(getElementsByType("player"))do
    if getElementData(player,"logedin") then
      value = 0
      if getControlState(player,"sprint") then
        value = gameplayVariables.sprintthirst
      end
      addPlayerStats(player,"thirst",value)
    end
  end
end
setTimer(checkThirsty,10000,0)
function checkHumanity()
  for i,player in ipairs(getElementsByType("player"))do
    if getElementData(player,"logedin") and getElementData(player,"humanity")< 2500 then
      addPlayerStats(player,"humanity",30)
      if getElementData(player,"humanity")> 2000 then
        setElementData(player,"bandit",false)
      end
    end
  end
end
setTimer(checkHumanity,60000,0)
elementEating = {}
function onPlayerRequestChangingStats(itemName,itemInfo,data)
  local x,y,z = getElementPosition(source)
  if isElement(elementEating[source]) then 
    detachElementFromBone(elementEating[source])
    destroyElement(elementEating[source])
    elementEating[source] = false
  end
  if data == "food" then
    if itemName == "Burger" then
      blood = 300
      elementEating[source] = createObject(2768,x,y,z)
      attachElementToBone(elementEating[source],source,12,-0.01,0,0.1,87,0,0)
    elseif itemName == "Cooked Meat" then
      blood = 800
      elementEating[source] = createObject(2806,x,y,z)
      attachElementToBone(elementEating[source],source,12,0,0.01,0.02,190,0,-90)
    elseif itemName == "Canned Baked Beans (Open)" then
      blood = 200
      elementEating[source] = createObject(2601,x,y,z)
      attachElementToBone(elementEating[source],source,12,-0.03,0.02,0.07,87,0,-85)
    elseif itemName == "Canned Spaghetti (Open)" then
      blood = 200
      elementEating[source] = createObject(2770,x,y,z)
      attachElementToBone(elementEating[source],source,12,-0.02,0.02,0.07,-179,0,-85)
    elseif itemName == "Canned Sardines (Open)" then
      blood = 200
      elementEating[source] = createObject(1242,x,y,z)
      attachElementToBone(elementEating[source],source,12,-0.04,0.02,0.07,80,0,-85)
    elseif itemName == "Can of Tactical Bacon (Open)" then
      blood = 200
      elementEating[source] = createObject(1247,x,y,z)
      attachElementToBone(elementEating[source],source,12,-0.04,0.01,0.08,-07,0,-85)
    end
    setPedAnimation(source,"FOOD","EAT_Burger",-1,false,false,nil,false)
    setElementData(source,itemName,getElementData(source,itemName)- 1)
    addPlayerStats(source,"blood",blood)
    addPlayerStats(source,data,gameplayVariables.foodrestore)
    triggerClientEvent(source,"displayClientInfo",source,"Food","Eat: "..itemName,22,255,0)

  elseif data == "thirst" then
    if itemName == "Water Bottle" then
      blood = 1500
      elementEating[source] = createObject(2683,x,y,z)
      attachElementToBone(elementEating[source],source,11,0.02,0.03,0.08,22,-75,180)
    elseif itemName == "Soda Bottle" then
      blood = 100
      elementEating[source] = createObject(2856,x,y,z)
      attachElementToBone(elementEating[source],source,11,0.01,0.02,0.1,0,-15,-10)
    elseif itemName == "Milk" then
      blood = 250
      elementEating[source] = createObject(2647,x,y,z)
      attachElementToBone(elementEating[source],source,11,0.01,0.02,0.1,0,-15,-10)
    end
    setElementData(source,itemName,getElementData(source,itemName)- 1)
    addPlayerStats(source,data,gameplayVariables.thirstrestore)
    setPedAnimation(source,"VENDING","VEND_Drink2_P",-1,false,false,nil,false)
    triggerClientEvent(source,"refreshInventoryManual",source)
    if itemName == "Water Bottle" then
      setElementData(source,"Empty Water Bottle",getElementData(source,"Empty Water Bottle")+ 1)
      triggerClientEvent(source,"refreshInventoryManual",source)
    end
    triggerClientEvent(source,"displayClientInfo",source,"Food","Drank: "..itemName,22,255,0)
  end
  triggerClientEvent(source,"refreshInventoryManual",source)
  setTimer(function(source)
    if isElement(elementEating[source]) then
      detachElementFromBone(elementEating[source])
      destroyElement(elementEating[source])
    end
  end,5000,1,source)
end


function onPlayerOpenFood(itemName)
  if itemName == "Canned Baked Beans (Close)" then
    setElementData(source,itemName,getElementData(source,itemName)-1)
    setElementData(source,"Canned Baked Beans (Open)",getElementData(source,"Canned Baked Beans (Open)")+1)
  elseif itemName == "Canned Spaghetti (Close)" then
    setElementData(source,itemName,getElementData(source,itemName)-1)
    setElementData(source,"Canned Spaghetti (Open)",getElementData(source,"Canned Spaghetti (Open)")+1)
  elseif itemName == "Canned Sardines (Close)" then
    setElementData(source,itemName,getElementData(source,itemName)-1)
    setElementData(source,"Canned Sardines (Open)",getElementData(source,"Canned Sardines (Open)")+1)
  elseif itemName == "Can of Tactical Bacon (Close)" then
    setElementData(source,itemName,getElementData(source,itemName)-1)
    setElementData(source,"Can of Tactical Bacon (Open)",getElementData(source,"Can of Tactical Bacon (Open)")+1)
  end
  triggerClientEvent(source,"refreshInventoryManual",source)
end
addEvent("onPlayerOpenFood",true)
addEventHandler("onPlayerOpenFood",getRootElement(),onPlayerOpenFood)

function onPlayerUseMedicObject(itemName)
  local playersource = source
  setPedAnimation(playersource,"BOMBER","BOM_Plant",-1,false,false,nil,false)
  setTimer(function()
    if itemName == "Bandage" then
      setElementData(playersource,"bleeding",0)
      setElementData(playersource,itemName,getElementData(playersource,itemName)- 1)
    elseif itemName == "Antibiotics" then
      addPlayerStats(playersource,"blood",269)
      setElementData(playersource,"bleeding",0)
      setElementData(playersource,"infection",false)
      setElementData(playersource,itemName,getElementData(playersource,itemName)-1)
    elseif itemName == "Medic Kit" then
      addPlayerStats(playersource,"blood",7000)
      setElementData(playersource,"bleeding",0)
      setElementData(playersource,itemName,getElementData(playersource,itemName)- 1)
    elseif itemName == "Heat Pack" then
      setElementData(playersource,"cold",false)
      setElementData(playersource,"temperature",37)
      setElementData(playersource,itemName,getElementData(playersource,itemName)- 1)
    elseif itemName == "Painkiller" then
      setElementData(playersource,"pain",false)
      setElementData(playersource,itemName,getElementData(playersource,itemName)- 1)
    elseif itemName == "Morphine" then
      setElementData(playersource,"brokenbone",false)
      setElementData(playersource,itemName,getElementData(playersource,itemName)- 1)
    elseif itemName == "Blood Bag" then
      addPlayerStats(playersource,"blood",12000)
      setElementData(playersource,itemName,getElementData(playersource,itemName)- 1)
    end
  end,1500,1)
  triggerClientEvent(playersource,"refreshInventoryManual",playersource)
end
function onPlayerGiveMedicObject(itemName,player)
  local playersource = source
  setPedAnimation(playersource,"BOMBER","BOM_Plant",-1,false,false,nil,false)
  setTimer(function()
    if itemName == "bandage" then
      setElementData(player,"bleeding",0)
      setElementData(playersource,"Bandage",getElementData(playersource,"Bandage")- 1)
      addPlayerStats(playersource,humanity,40)
    elseif itemName == "giveblood" then
      addPlayerStats(player,"blood",12000)
      setElementData(playersource,"Blood Bag",getElementData(playersource,"Blood Bag")- 1)
      addPlayerStats(playersource,humanity,250)
    end
  end,1500,1)
end
addEvent("onPlayerGiveMedicObject",true)
addEventHandler("onPlayerGiveMedicObject",getRootElement(),onPlayerGiveMedicObject)
skinTable = {
  {"Survivor Clothing",0},
  {"Ghillie Desert",287},
  {"Civilian[F] Clothing",93},
  {"Ghillie Suit",285},
  {"Ghillie[F] Suit",94},
}
function getSkinIDFromName(name)
  for i,skin in ipairs(skinTable)do
    if name == skin[1] then
      return skin[2]
    end
  end
end
function getSkinNameFromID(id)
  for i,skin in ipairs(skinTable)do
    if id == skin[2] then
      return skin[1]
    end
  end
end
function addPlayerSkin(skin)
  local current = getElementData(source,"skin")
  local name = getSkinNameFromID(current)
  setElementData(source,name,getElementData(source,name)+ 1)
  setElementData(source,skin,getElementData(source,skin)- 1)
  local id = getSkinIDFromName(skin)
  setElementData(source,"skin",id)
  setElementModel(source,id)
  triggerClientEvent(source,"refreshInventoryManual",source)
end
addEvent("onPlayerChangeSkin",true)
addEventHandler("onPlayerChangeSkin",getRootElement(),addPlayerSkin)
function onPlayerRefillWaterBottle(itemName)
  if isElementInWater(source) then
    setElementData(source,"Water Bottle",getElementData(source,"Water Bottle")+ 1)
    setElementData(source,itemName,getElementData(source,itemName)- 1)
    triggerClientEvent(source,"refreshInventoryManual",source)
    triggerClientEvent(source,"displayClientInfo",source,"WaterBottle","You fill up the Water Bottle!",22,255,0)
  else
    triggerClientEvent(source,"displayClientInfo",source,"WaterBottle","You need to be in water!",255,22,0)
  end
end
addEvent("onPlayerRefillWaterBottle",true)
addEventHandler("onPlayerRefillWaterBottle",getRootElement(),onPlayerRefillWaterBottle)
-----Tent
function getPointFromDistanceRotation(x,y,dist,angle)
  local a = math.rad(90 - angle)
  local dx = math.cos(a)* dist
  local dy = math.sin(a)* dist
  return x + dx,y + dy
end
function onPlayerPitchATent(itemName)
  setElementData(source,itemName,getElementData(source,itemName)- 1)
  local source = source
  local x,y,z = getElementPosition(source)
  local xr,yr,zr = getElementRotation(source)
  px,py,pz = getElementPosition(source)
  prot = getPedRotation(source)
  local offsetRot = math.rad(prot + 90)
  local vx = px + 5 * math.cos(offsetRot)
  local vy = py + 5 * math.sin(offsetRot)
  local vz = pz + 2
  local vrot = prot + 180
  tent = createObject(3243,vx,vy,z - 1,0,0,vrot)
  setElementAlpha(tent,0)
  setObjectScale(tent,1.1)
  tentCol = createColSphere(x,y,z,4)
  attachElements(tentCol,tent,0,0,0)
  setElementData(tentCol,"parent",tent)
  setElementData(tent,"parent",tentCol)
  setElementData(tentCol,"tent",true)
  setElementData(tentCol,"vehicle",true)
  setElementData(tentCol,"visible",true)
  setElementData(tentCol,"MAX_Slots",100)
  setElementData(tentCol,"Bandage",0)
  setElementData(tentCol,"Painkiller",0)
  setElementData(tentCol,"Morphine",0)
  triggerClientEvent(source,"refreshInventoryManual",source)
  triggerClientEvent(source,"hideInventoryManual",source)
  setElementData(source,"currentCol",tentCol)
  triggerClientEvent(source,"moveTent",source)
end
addEvent("onPlayerPitchATent",true)
addEventHandler("onPlayerPitchATent",getRootElement(),onPlayerPitchATent)
----Big Tent
function getPointFromDistanceRotation(x,y,dist,angle)
  local a = math.rad(90 - angle)
  local dx = math.cos(a)* dist
  local dy = math.sin(a)* dist
  return x + dx,y + dy
end
function onPlayerPitchABigTent(itemName)
  setElementData(source,itemName,getElementData(source,itemName)- 1)
  local source = source
  local x,y,z = getElementPosition(source)
  local xr,yr,zr = getElementRotation(source)
  px,py,pz = getElementPosition(source)
  prot = getPedRotation(source)
  local offsetRot = math.rad(prot + 90)
  local vx = px + 5 * math.cos(offsetRot)
  local vy = py + 5 * math.sin(offsetRot)
  local vz = pz + 2
  local vrot = prot + 180
  tent = createObject(2779,vx,vy,z - 1,0,0,vrot)
  setElementAlpha(tent,0)
  setObjectScale(tent,1.7)
  tentCol = createColSphere(x,y,z,4)
  attachElements(tentCol,tent,0,0,0)
  setElementData(tentCol,"parent",tent)
  setElementData(tent,"parent",tentCol)
  setElementData(tentCol,"tent",true)
  setElementData(tentCol,"vehicle",true)
  setElementData(tentCol,"visible",true)
  setElementData(tentCol,"MAX_Slots",200)
  setElementData(tentCol,"Bandage",0)
  setElementData(tentCol,"Painkiller",0)
  setElementData(tentCol,"Morphine",0)
  triggerClientEvent(source,"refreshInventoryManual",source)
  triggerClientEvent(source,"hideInventoryManual",source)
  setElementData(source,"currentCol",tentCol)
  triggerClientEvent(source,"moveTent",source)
end
addEvent("onPlayerPitchABigTent",true)
addEventHandler("onPlayerPitchABigTent",getRootElement(),onPlayerPitchABigTent)
--------------------------Mine-------------------------------------------------
function onPlayerPutMine(itemName) 
    setPedAnimation(source, "BOMBER", "BOM_Plant", -1, false, false, false, false)
    setElementData(source,"Mine",getElementData(source,"Mine")-1)
    local x,y,z = getElementPosition(source)
    local carmine = createObject(1897,x,y,z-1.5,0,2,3.18)
    local carmineCol = createColSphere(x,y,z,2)
    setElementFrozen(carmine, true)
    setElementData(carmineCol,"type","pedhit")
    setElementData(carmineCol,"carmine",carmine)
    setElementData(carmineCol,"terror",source)
    triggerClientEvent(source,"refreshInventoryManual",source)
    setTimer(function()
        destroyElement(carmineCol)
        destroyElement(carmine)
    end,1000000,1)
end
addEvent("onPlayerPutMine",true)
addEventHandler("onPlayerPutMine",getRootElement(),onPlayerPutMine)

function boomCarmine(player)
    if (getElementData (source, "type") == "pedhit") then
        local carmine = getElementData(source, "carmine")
        local terror = getElementData (source, "terror")
        local x,y,z = getElementPosition (source)
        setTimer(function(carmine_destroy)
            if not isElement ( carmine_destroy ) then return true end
            local mx,my,mz = getElementPosition(carmine_destroy)
            local px,py,pz = getElementPosition(player)
            local distance = getDistanceBetweenPoints3D(px,py,pz,mx,my,mz) or 0
            if distance <= 10 then
                setElementData(player,"blood",getElementData(player,"blood")-33600)
                createExplosion(x,y,z,20,terror)
                destroyElement(carmine_destroy)
                destroyElement(source)
            end
        end,300,1, carmine)
    end
end
addEventHandler("onColShapeHit", getRootElement(), boomCarmine)

addEvent("destroyCarmine", true)
addEventHandler("destroyCarmine", getRootElement(), function(carmine)
    local x,y,z = getElementPosition(carmine)
    local terror = getElementData(carmine, "terror")
    local carmineCol = getElementData(carmine, "carmine")
    setTimer(function()
        createExplosion(x,y,z,20,terror)
        destroyElement(carmineCol)
        destroyElement(carmine)
    end,100,1)
end)
---------------------------------------------------------------------
function onPlayerBuildAWireFence(itemName)
  setElementData(source,itemName,getElementData(source,itemName)- 1)
  setPedAnimation(source,"BOMBER","BOM_Plant",-1,false,false,nil,false)
  local source = source
  setTimer(function()
    local x,y,z = getElementPosition(source)
    local xr,yr,zr = getElementRotation(source)
    px,py,pz = getElementPosition(source)
    prot = getPedRotation(source)
    local offsetRot = math.rad(prot + 90)
    local vx = px + 1 * math.cos(offsetRot)
    local vy = py + 1 * math.sin(offsetRot)
    local vz = pz + 2
    local vrot = prot + 90
    tent = createObject(983,vx,vy,pz,xr,yr,vrot)
    setObjectScale(tent,1)
    tentCol = createColSphere(x,y,z,2)
    attachElements(tentCol,tent,0,0,0)
    setElementData(tentCol,"parent",tent)
    setElementData(tent,"parent",tentCol)
    setElementData(tentCol,"wirefence",true)
    triggerClientEvent(source,"refreshInventoryManual",source)
  end,1500,1)
end
addEvent("onPlayerBuildAWireFence",true)
addEventHandler("onPlayerBuildAWireFence",getRootElement(),onPlayerBuildAWireFence)
function removeWirefence(object)
  destroyElement(getElementData(object,"parent"))
  destroyElement(object)
end
addEvent("removeWirefence",true)
addEventHandler("removeWirefence",getRootElement(),removeWirefence)

function removeTent(object)
  local x,y,z = getElementPosition(source)
  local item,itemString = getItemTablePosition("Tent")
  local itemPickup = createItemPickup(item,x,y,z + 1,itemString)
  destroyElement(getElementData(object,"parent"))
  destroyElement(object)
end
addEvent("removeTent",true)
addEventHandler("removeTent",getRootElement(),removeTent)

function addPlayerCookMeat()
  local playersource = source
  setPedAnimation(playersource,"BOMBER","BOM_Plant",-1,false,false,nil,false)
  local meat = getElementData(playersource,"Raw Meat")
  setTimer(function()
    setElementData(playersource,"Raw Meat",0)
    setElementData(playersource,"Cooked Meat",getElementData(playersource,"Cooked Meat")+ meat)
    triggerClientEvent(playersource,"displayClientInfo",playersource,"Fireplace","You cooked "..meat.." Raw Meat.",22,255,0)
  end,5000,1)
end
addEvent("addPlayerCookMeat",true)
addEventHandler("addPlayerCookMeat",getRootElement(),addPlayerCookMeat)
function onPlayerMakeAFire(itemName)
  setElementData(source,"Wood Pile",getElementData(source,"Wood Pile")- 1)
  local x,y,z = getElementPosition(source)
  local xr,yr,zr = getElementRotation(source)
  px,py,pz = getElementPosition(source)
  prot = getPedRotation(source)
  local offsetRot = math.rad(prot + 90)
  local vx = px + 1 * math.cos(offsetRot)
  local vy = py + 1 * math.sin(offsetRot)
  local vz = pz + 2
  local vrot = prot + 90
  local wood = createObject(1463,vx,vy,pz - 0.75,xr,yr,vrot)
  setObjectScale(wood,1.5)
  setElementCollisionsEnabled(wood,false)
  setElementFrozen(wood,true)
  local fire = createObject(3525,vx,vy,pz - 0.75,xr,yr,vrot)
  setObjectScale(fire,0)
  local fireCol = createColSphere(x,y,z,2)
  setElementData(fireCol,"parent",wood)
  setElementData("Wood Pile","parent",fireCol)
  setElementData(fireCol,"fireplace",true)
  triggerClientEvent(source,"refreshInventoryManual",source)
  setPedAnimation(playersource,"BOMBER","BOM_Plant",-1,false,false,nil,false)
  setTimer(function()
    destroyElement(fireCol)
    destroyElement(fire)
    destroyElement(wood)
  end,120000,1)
end
addEvent("onPlayerMakeAFire",true)
addEventHandler("onPlayerMakeAFire",getRootElement(),onPlayerMakeAFire)
function onPlayerPlaceRoadflare(itemName)
  setElementData(source,itemName,getElementData(source,itemName)- 1)
  local x,y,z = getElementPosition(source)
  local object = createObject(354,x,y,z - 0.6)
  setTimer(destroyElement,300000,1,object)
  triggerClientEvent(source,"refreshInventoryManual",source)
end
addEvent("onPlayerPlaceRoadflare",true)
addEventHandler("onPlayerPlaceRoadflare",getRootElement(),onPlayerPlaceRoadflare)
function math.round(number,decimals,method)
  decimals = decimals or 0
  local factor = 10 ^ decimals
  if method == "ceil" or method == "floor" then
    return math[method](number * factor)/ factor
  else
    -- return tonumber("%."..decimals.."f":format(number))
  end
end
local chatRadius = 15
local chatEadioRadius = 250
function sendMessageToNearbyPlayers(message,messageType)
  cancelEvent()
  if messageType == 0 then
    local posX,posY,posZ = getElementPosition(source)
    local chatSphere = createColSphere(posX,posY,posZ,chatRadius)
    local nearbyPlayers = getElementsWithinColShape(chatSphere,"player")
    destroyElement(chatSphere)
    for index,nearbyPlayer in ipairs(nearbyPlayers)do
      outputChatBox("[LOCAL]"..string.gsub(getPlayerName(source).." : "..message,"#%x%x%x%x%x%x",""),nearbyPlayer,211,211,211,true)
    end
  end
end
addEventHandler("onPlayerChat",getRootElement(),sendMessageToNearbyPlayers)
function playerRadioChat(playersource,cmd,...)
  if cmd == "radiochat" then
    local msg2 = table.concat({
     ...
    }," ")
    if(getElementData(playersource,"Radio Device")or 0)<= 0 then
      outputChatBox("You don't have a Radio Device!",playersource)
      return
    end
    local posX,posY,posZ = getElementPosition(playersource)
    local chatSphere = createColSphere(posX,posY,posZ,chatEadioRadius)
    local nearbyPlayers = getElementsWithinColShape(chatSphere,"player")
    destroyElement(chatSphere)
    for index,nearbyPlayer in ipairs(nearbyPlayers)do
      if getElementData(nearbyPlayer,"Radio Device")> 0 then
        outputChatBox("[RADIO]"..string.gsub(getPlayerName(playersource).." : "..msg2,"#%x%x%x%x%x%x",""),nearbyPlayer,238,238,0,true)
      end
    end
  end
end
addCommandHandler("radiochat",playerRadioChat)
function blockChatMessage(m,mt)
  if mt == 1 then
    cancelEvent()
  end
end
addEventHandler("onPlayerChat",getRootElement(),blockChatMessage)
function checkBandit()
  for i,player in ipairs(getElementsByType("player"))do
    if getElementData(player,"logedin") then
      local current = getElementData(player,"skin")
      if getElementData(player,"bandit") then
        if current == 179 or current == 287 then
          setElementModel(player,0)
        elseif current == 73 or current == 93 or current == 191 then
          setElementModel(player,0)
        end
      elseif getElementData(player,"humanity")>= 5000 then
        if current == 73 or current == 179 or current == 287 or current == 93 or current == 94 or current == 191 then
          setElementModel(player,0)
        end
      else
        setElementModel(player,getElementData(player,"skin"))
      end
    end
  end
end
setTimer(checkBandit,20000,0)
local infoTimer = 240000
function outputInfo1()
  for i,player in ipairs(getElementsByType("player"))do
    triggerClientEvent(player,"displayClientInfo",player,"Info","You can use the middle mouse button or '-' to do certain actions",200,200,22)
  end
  setTimer(outputInfo2,infoTimer,1)
end
setTimer(outputInfo1,infoTimer,1)
function outputInfo2()
  for i,player in ipairs(getElementsByType("player"))do
    triggerClientEvent(player,"displayClientInfo",player,"Info","Need help? Contact an admin at discord",200,200,22)
  end
  setTimer(outputInfo3,infoTimer,1)
end
function outputInfo3()
  for i,player in ipairs(getElementsByType("player"))do
    triggerClientEvent(player,"displayClientInfo",player,"Info","Like us on fb : www.facebook.com/dynamicdayz",200,200,22)
  end
  setTimer(outputInfo4,infoTimer,1)
end
function outputInfo4()
  for i,player in ipairs(getElementsByType("player"))do
    triggerClientEvent(player,"displayClientInfo",player,"Info","You can enable/disable the debugmonitor by pressing F5",200,200,22)
  end
  setTimer(outputInfo5,infoTimer,1)
end
function outputInfo5()
  for i,player in ipairs(getElementsByType("player"))do
    triggerClientEvent(player,"displayClientInfo",player,"Info","",200,200,22)
  end
  setTimer(outputInfo1,infoTimer,1)
end
function getTeamMemberOnline()
  theTableMembersOnline = ""
  for i,player in ipairs(getElementsByType("player"))do
    local account = getPlayerAccount(player)
    if not isGuestAccount(account) and(getElementData(player,"supporter")or getElementData(player,"admin")) then
      theTableMembersOnline = theTableMembersOnline..","..getPlayerName(player)
    end
  end
  if theTableMembersOnline == "" then
    return "None"
  else
    return theTableMembersOnline
  end
end
function getPlayerWildcard(namePart)
  namePart = string.lower(namePart)
  local bestaccuracy = 0
  local foundPlayer,b,e
  for _,player in ipairs(getElementsByType("player"))do
    b,e = string.find(string.lower(string.gsub(getPlayerName(player),"#%x%x%x%x%x%x","")),namePart)
    if b and e and bestaccuracy < e - b then
      bestaccuracy = e - b
      foundPlayer = player
    end
  end
  if foundPlayer then
    return foundPlayer
  else
    return false
  end
end
function setGroup(playersource,command,teamName,targetString)
  if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(playersource)),aclGetGroup("Admin")) then
    do
      local foundTargetPlayer = getPlayerWildcard(targetString)
      if foundTargetPlayer then
        if teamName ~= "admin" and teamName ~= "supporter" then
          if teamName == "remove" then
          else
            outputChatBox("#FFFFFFCorrect names are admin, supporter and remove!",playersource,27,89,224,true)
            return
          end
        end
        if teamName == "remove" then
          value = false
          account = getPlayerAccount(foundTargetPlayer)
          setAccountData(account,"admin",value)
          setAccountData(account,"supporter",value)
          setElementData(foundTargetPlayer,"admin",value)
          setElementData(foundTargetPlayer,"supporter",value)
        else
          value = true
        end
        account = getPlayerAccount(foundTargetPlayer)
        accountname = getAccountName(account)
        setAccountData(account,teamName,value)
        setElementData(foundTargetPlayer,teamName,value)
        if value == true then
          outputChatBox("#FFFFFF"..getPlayerName(foundTargetPlayer).." #FF0000 has been promoted to "..teamName.."!",getRootElement(),27,89,224,true)
        else
          outputChatBox("#FFFFFF"..getPlayerName(foundTargetPlayer).." #FF0000 lost his status...",getRootElement(),27,89,224,true)
        end
      else
        outputChatBox("#FFFFFFCan't find player! Did you input the correct name?",playersource,27,89,224,true)
      end
    end
  else
    outputChatBox("#FFFFFFYou are not an admin!",playersource,27,89,224,true)
  end
end
addCommandHandler("add",setGroup)
function banPLayer(playersource,command,targetString,banTime,reason)
  if getAccountData(getPlayerAccount(playersource),"admin")== true then
    do
      local foundTargetPlayer = getPlayerWildcard(targetString)
      local banTime = banTime or 0
      local reason = reason or "Unknown"
      if foundTargetPlayer then
        do
          local account = getPlayerAccount()
          local ip = getPlayerIP(foundTargetPlayer)
          local serial = getPlayerSerial(foundTargetPlayer)
          local name = getPlayerName(foundTargetPlayer)
          kickPlayer(foundTargetPlayer,playersource,reason)
          addBan(ip,name,serial,playersource,reason,banTime * 86400)
          outputChatBox("#FFFFFF"..name.." #FF0000 has been banned for "..banTime.." Day(Z)'s.",getRootElement(),27,89,224,true)
        end
      else
        outputChatBox("#FFFFFFCan't find player! Did you input the correct name?",playersource,27,89,224,true)
      end
    end
  else
    outputChatBox("#FFFFFFYou are not an admin! ",playersource,27,89,224,true)
  end
end
addCommandHandler("playerban",banPLayer)
function pmsgAdmin(playersource,command,...)
  local msg = table.concat({
   ...
  }," ")
  if getAccountData(getPlayerAccount(playersource),"admin")== true then
    outputChatBox("[GLOBAL]"..getPlayerName(playersource)..": "..msg,getRootElement(),60,200,40,true)
  else
    outputChatBox("#FFFFFFYou are not an admin! ",playersource,27,89,224,true)
  end
end
addCommandHandler("pmsg",pmsgAdmin)
botSupportTable = {
  {"website","what","","The URL is: eoLDayZ.net.","","James"},
  {"website","where","","The URL is: eoLDayZ.net.","","James"},
  {"website","which","","The URL is: eoLDayZ.net.","","James"},
  {"website","how","","The URL is: eoLDayZ.net.","","James"},
  {"website","got","","The URL is: eoLDayZ.net.","","James"},
  {"website","know","","The URL is: eoLDayZ.net.","","James"},
  {"hey","james","","Hey.","","James"},
  {"hey","paul","","Yo!.","","Paul"},
  {"hey","sandra","","Hello.","","Sandra"},
  {"how are","you","james","I am fine,thank you.","","James"},
  {"how are","you","paul","Feeling absolutely splendid today,why,thanks!","","Paul"},
  {"how are","you","sandra","I am perfectly fine.","","Sandra"},
  {"i love","you","sandra","ERROR: Can't access emotions.exe.","Thanks.","Sandra"},
  {"thank","you","james","You are welcome.","","James"},
  {"thank","paul","you","Hey,that's my job!","","Paul"},
  {"thank","sandra","you","You are welcome.","Sandra"},
  {"how","use","map","Press F11 to use the map.","","James"},
  {"how","use","gps","The GPS activates automatically. You can see it at the lower left corner.","","James"},
  {"how","take","items","Press 'J' to open your inventory. Alternatively,you can press the middle mouse button or '-' to pick items up.","","James"},
  {"how","open","inven","By pressing 'J',you can open your inventory.","","James"},
  {"drop","item","","Press 'J' to open your inventory,select the item you want to drop and press the arrow pointing to the left.","","Paul"},
  {"fuel","car","how","You need an 'Empty Gas Canister'. You can fill it at a gas station.","","Sandra"},
  {"pick","items","how","Press the middle mouse button(or '-')when the name of the item is written on the left of your screen.","","Sandra"},
  {"fence","wire","destroy","You need a toolbox to destroy a wirefence.","","James"},
  {"register","how","to","You need to fill in your name and password. Afterwards,press 'Register'. If it doesn't work,reconnect.","","James"},
  {"bugged","stuck","help","Wait until an admin contacts and helps you.","","Sandra"},
  {"radio","chat","","Press 'Z' to use the radio device.","","James"}
}
function botCheck(text,player)
  for i,data in ipairs(botSupportTable)do
    if string.find(text:lower(),data[1]:lower(),1,true) and string.find(text:lower(),data[2]:lower(),1,true) and string.find(text:lower(),data[3]:lower(),1,true) then
      answere = data[4]
      if data[5] ~= "" then
        local randomNumber = math.random(4,5)
        answere = data[randomNumber]
      end
      setTimer(onServerSupportChatMessage,math.random(3000,6000),1,data[6],string.gsub(getPlayerName(player),"#%x%x%x%x%x%x","")..","..answere)
    end
  end
end
function onServerSupportChatMessage(player2,text)
  notGoOn = false
  mutedmessage = false
  for i,player in ipairs(getElementsByType("player"))do
    if player2 == "Sandra" or player2 == "James" or player2 == "Paul" then
      triggerClientEvent(player,"onSupportChatMessage",player,player2,text)
      notGoOn = true
    elseif(getElementData(player,"supporter")or getElementData(player,"admin")) and not getElementData(player2,"admin") and not getElementData(player2,"supporter") and not isPlayerMuted(player2) then
      outputChatBox("#E01BBCNew Support Message by "..getPlayerName(player2),player,255,255,255,true)
    end
    if not notGoOn then
      if not isPlayerMuted(player2) then
        triggerClientEvent(player,"onSupportChatMessage",player,player2,text)
      else
        mutedmessage = true
      end
    end
  end
  if not notGoOn then
    botCheck(text,player2)
  end
  if mutedmessage then
    outputChatBox("#2200ddYou are muted!",player2,255,255,255,true)
  end
end
addEvent("onServerSupportChatMessage",true)
addEventHandler("onServerSupportChatMessage",getRootElement(),onServerSupportChatMessage)

--Weapon Property
function givePlayerWeaponss ( thePlayer )

setWeaponProperty("m4", "poor", "weapon_range", 350)
setWeaponProperty("m4", "std", "weapon_range", 350)
setWeaponProperty("m4", "pro", "weapon_range", 350)


setWeaponProperty("ak-47", "poor", "weapon_range", 350)
setWeaponProperty("ak-47", "std", "weapon_range", 350)
setWeaponProperty("ak-47", "pro", "weapon_range", 350)

setWeaponProperty("uzi", "poor", "weapon_range", 150)
setWeaponProperty("uzi", "std", "weapon_range", 150)
setWeaponProperty("uzi", "pro", "weapon_range", 150)

setWeaponProperty("mp5", "poor", "weapon_range", 150)
setWeaponProperty("mp5", "std", "weapon_range", 150)
setWeaponProperty("mp5", "pro", "weapon_range", 150)

setWeaponProperty("rifle", "poor", "weapon_range", 500)
setWeaponProperty("rifle", "std", "weapon_range", 500)
setWeaponProperty("rifle", "pro", "weapon_range", 500)

setWeaponProperty("deagle", "poor", "weapon_range", 100)
setWeaponProperty("deagle", "std", "weapon_range", 100)
setWeaponProperty("deagle", "pro", "weapon_range", 100)

setWeaponProperty("silenced", "poor", "weapon_range", 100)
setWeaponProperty("silenced", "std", "weapon_range", 100)
setWeaponProperty("silenced", "pro", "weapon_range", 100)

setWeaponProperty(22, "poor", "weapon_range", 100)
setWeaponProperty(22, "std", "weapon_range", 100)
setWeaponProperty(22, "pro", "weapon_range", 100)

setWeaponProperty("shotgun", "poor", "weapon_range", 70)
setWeaponProperty("shotgun", "std", "weapon_range", 70)
setWeaponProperty("shotgun", "pro", "weapon_range", 70)

setWeaponProperty(26, "poor", "weapon_range", 70)
setWeaponProperty(26, "std", "weapon_range", 70)
setWeaponProperty(26, "pro", "weapon_range", 70)

setWeaponProperty("sniper", "poor", "weapon_range", 600)
setWeaponProperty("sniper", "std", "weapon_range", 600)
setWeaponProperty("sniper", "pro", "weapon_range", 600)
end
addEventHandler("onPlayerLogin", getRootElement(), givePlayerWeaponss)
addEventHandler("onResourceStart", getRootElement(), givePlayerWeaponss)
--Weapon Property

setWeaponProperty("m4","poor","maximum_clip_ammo",30)
setWeaponProperty("m4","std","maximum_clip_ammo",30)
setWeaponProperty("m4","pro","maximum_clip_ammo",30)

addEventHandler("onPlayerWeaponSwitch",getRootElement(),function(previousWeaponID,currentWeaponID)
    local current_1 = getElementData(source,"currentweapon_1")
    if currentWeaponID == 30 and current_1 == "PKM" then
        setWeaponProperty("30","poor","maximum_clip_ammo",200)
        setWeaponProperty("30","std","maximum_clip_ammo",200)
        setWeaponProperty("30","pro","maximum_clip_ammo",200)
    elseif currentWeaponID == 30 and current_1 == "M249 SAW" then
        setWeaponProperty("30","poor","maximum_clip_ammo",200)
        setWeaponProperty("30","std","maximum_clip_ammo",200)
        setWeaponProperty("30","pro","maximum_clip_ammo",200)
    elseif currentWeaponID == 30 and current_1 == "M240" then
        setWeaponProperty("30","poor","maximum_clip_ammo",100)
        setWeaponProperty("30","std","maximum_clip_ammo",100)
        setWeaponProperty("30","pro","maximum_clip_ammo",100)        
    elseif currentWeaponID == 30 and current_1 == "PKP" then
        setWeaponProperty("30","poor","maximum_clip_ammo",200)
        setWeaponProperty("30","std","maximum_clip_ammo",200)
        setWeaponProperty("30","pro","maximum_clip_ammo",200)        
    elseif currentWeaponID == 30 and current_1 == "Mk 48 Mod 0" then
        setWeaponProperty("30","poor","maximum_clip_ammo",100)
        setWeaponProperty("30","std","maximum_clip_ammo",100)
        setWeaponProperty("30","pro","maximum_clip_ammo",100)            
    end
end) 

function kickPLayer(playersource,command,targetString,banTime,reason)
  if getAccountData(getPlayerAccount(playersource),"admin")== true then
    for i,player in ipairs(getElementsByType("player"))do
      if player ~= playersource then
        kickPlayer(player,"Server Script Restart,#Hotfix")
      end
    end
  else
    outputChatBox("#FFFFFFYou are not an admin! ",playersource,27,89,224,true)
  end
end
addCommandHandler("kickplayer",kickPLayer)
function kickAll(playersource,command,reason)
  if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(playersource)),aclGetGroup("Admin")) then
    for i,player in ipairs(getElementsByType("player"))do
      if player == playersource then
        break
      end
      kickPlayer(player,reason)
    end
  else
    outputChatBox("#FFFFFFYou are not an admin!",playersource,27,89,224,true)
  end
end
addCommandHandler("kickall",kickAll)
local supporterMode = {}
local foodd = {}
local thirstt = {}
function Supportermode(playersource,command)
  if getAccountData(getPlayerAccount(playersource),"supporter")== true then
    if not supporterMode[playersource] then
      -- unhandled boolean indicator
    else
    end
    supporterMode[playersource] = true
    if supporterMode[playersource] then
      setElementAlpha(playersource,0)
      setElementFrozen(playersource,true)
      foodd[playersource] = getElementData(playersource,"food")
      thirstt[playersource] = getElementData(playersource,"thirst")
    else
      setElementAlpha(playersource,255)
      setElementFrozen(playersource,false)
    end
  else
    outputChatBox("#FFFFFFYou are not a supporter,you can't use this command!",playersource,27,89,224,true)
  end
end
addCommandHandler("supportmode",Supportermode)
function StatsSupportermode()
  for i,player in ipairs(getElementsByType("player"))do
    if supporterMode[player] then
      setElementData(player,"food",foodd[player])
      setElementData(player,"thirst",thirstt[player])
    end
  end
end
setTimer(StatsSupportermode,60000,0)
function preventCommandSpam(commandName)
  if commandName == "login" or commandName == "logout" then
    cancelEvent()
  end
end
addEventHandler("onPlayerCommand",root,preventCommandSpam)
function kickPlayerOnHighPing()
  outputChatBox(getPlayerName(source).." was kicked due to high ping!",getRootElement(),27,89,224,true)
  kickPlayer(source,"Your Ping was straight too high.")
end
addEvent("kickPlayerOnHighPing",true)
addEventHandler("kickPlayerOnHighPing",getRootElement(),kickPlayerOnHighPing)
local handsUp = false
local siting = false
local lying = false
function funcBindHandsup(player,key,keyState)
  if handsUp then
    setPedAnimation(player,false)
    handsUp = false
  else
    if isPedInVehicle(player) then
      return
    end
    setPedAnimation(player,"BEACH","ParkSit_M_loop",-1,true,true,true,true)
    handsUp = true
  end
end
function funcBindSit(player,key,keyState)
  if siting then
    setPedAnimation(player,false)
    siting = false
  else
    if isPedInVehicle(player) then
      return
    end
    setPedAnimation(player,"SHOP","SHP_Rob_HandsUp",-1,true,true,true,true)
    siting = true
  end
end
function funcBindLie(player,key,keyState)
  if lying then
    setPedAnimation(player,false)
    lying = false
  else
    if isPedInVehicle(player) then
      return
    end
    setPedAnimation(player,"WUZI","CS_Dead_Guy",-1,true,true,true,true)
    lying = true
    function setVisibility()
      value = 0
    end
  end
end
function bindTheKeys()
  bindKey(source,",","down",funcBindHandsup)
  bindKey(source,".","down",funcBindSit)
  bindKey(source,"l","down",funcBindLie)
end
addEventHandler("onPlayerLogin",getRootElement(),bindTheKeys)
function makeRadioStayOff()
  setRadioChannel(0)
  cancelEvent()
end
addEventHandler("onClientPlayerVehicleEnter",getRootElement(),makeRadioStayOff)
addEventHandler("onClientPlayerRadioSwitch",getRootElement(),makeRadioStayOff)

------------------------------------------------------------------------------

function hideBodyClientS()
  local col = getElementData(source,"currentCol")
  if isElement(col) then
   if getElementData(col,"deadman") then
    setPedAnimation(source,"BOMBER","BOM_Plant",-1,false,true,true,false)
    setElementData(source,"loot",false)
    setElementData(source,"currentCol",false)
    outputChatBox("You buried the body: "..getElementData(col,"playername"):gsub('#%x%x%x%x%x%x', ''):gsub('#%x%x%x%x%x%x', ''),source,150,150,150) -- Mensagem que aparece quando esconder o corpo
    setTimer(function(colision)
     if isElement(getElementData(colision,"parent")) then
      destroyElement(getElementData(colision,"parent"))
     end
     destroyElement(colision)
    end,1500,1,col)
   end
  end
end
addEvent("hideBodyClient",true)
addEventHandler("hideBodyClient", getRootElement(),hideBodyClientS)

function BurnBody()
  local x,y,z = getElementPosition(source)
  local xr,yr,zr = getElementRotation(source)
  px, py, pz = getElementPosition(source)
  prot = getPedRotation(source)
  local offsetRot = math.rad(prot+90)
  local vx = px + 1 * math.cos(offsetRot)
  local vy = py + 1 * math.sin(offsetRot)
  local vz = pz + 2
  local vrot = prot+90
  local fire = createObject(3525,vx,vy,pz-0.75,xr,yr,vrot)
  setObjectScale(fire,0)
  triggerClientEvent(source,"refreshInventoryManual",source)
  setTimer(function()
    destroyElement(fire)
  end,5000,1)
  local col = getElementData(source,"currentCol")
  parentt = getElementData(col,"parent")
  if isElement(col) then
    if getElementData(col,"deadman") then
      setElementData(source,"loot",false)
      setElementData(source,"currentCol",false)
      destroyElement(col)
      setTimer(function(parent)
        if isElement (parent) then
          destroyElement(parent)
        end
      end,5000,1,parentt)
    end
  end
end        
addEvent("BurnBody",true)
addEventHandler("BurnBody",getRootElement(),BurnBody)

------------------------------------------------------------------------------
createTrap = function(x, y, z)
  local trap = createObject(1920,x,y,z,0,0,math.random(0,360))
  local ColAct = createColSphere(x,y,z,1)
  setElementData(ColAct,"trap2",true)
  TrapCol = createColSphere(x, y, z, 2)
  attachElements(TrapCol,trap,0,0,0)
  setElementData(TrapCol,"parent",trap)
  setElementData(trap,"parent",TrapCol)
  setElementData(TrapCol,"trap",true)
  setElementData(trap,"closed",false)
end
addEvent("CreateTrap", true)
addEventHandler("CreateTrap", getRootElement(), createTrap)

function checkTrapPlace(theElement)
  if getElementType(theElement) == "player" then
    if getElementData(source,"trap2") then
      if not getElementData(getElementData(getElementData(theElement,"currentCol"),"parent"),"closed") and not getPedOccupiedVehicle(theElement) then
        local object = getElementData(getElementData(theElement,"currentCol"),"parent")
        if isElement(object) then
          setElementData(object,"closed",true)
          setElementModel(object,1918)
          setElementData(theElement,"brokenbone",true)
          setElementData(theElement,"bleeding",getElementData(theElement, "bleeding")+700)
          triggerClientEvent(theElement,"playTrapSound",source)
        end
      end
    end
  end
end
addEventHandler("onColShapeHit",getRootElement(),checkTrapPlace)

function RemoveTrap(object)
  setTimer(function()
    destroyElement(getElementData(object,"parent"))
    destroyElement(object)
  end, 2000,1)
  setElementData(source,"Trap",getElementData(source,"Trap")+1)
end
addEvent("RemoveTrapServer", true)
addEventHandler("RemoveTrapServer", getRootElement(), RemoveTrap)

function OpenTrap(object)
  setElementData(object,"closed",false)
  setElementModel(object,1920)
end
addEvent("OpenTrapServer", true)
addEventHandler("OpenTrapServer", getRootElement(),OpenTrap)

------------------------------------------------------------------------------

Stingers = {}
createStinger = function(x,y,z,rotation)
  Stinger = createObject(2899,x,y,z,0,0,rotation)
  table.insert(Stingers,Stinger)

  StingerCol = createColSphere(x,y,z,3)
  --StingerCol = createColRectangle(x-2,y-2,4,4)
  attachElements(StingerCol,Stinger,0,0,0)
  setElementData(StingerCol,"parent",Stinger)
  setElementData(Stinger,"parent",StingerCol)
  setElementData(StingerCol,"stinger",true)
end
addEvent("CreateStinger", true)
addEventHandler("CreateStinger", getRootElement(), createStinger)

function checkStingerPlace(theElement)
  if getElementType(theElement) == "vehicle" then
    if getElementData(source,"stinger") then
      setVehicleWheelStates(theElement,1,1,1,1)
    end
  end
end
addEventHandler("onColShapeHit",getRootElement(),checkStingerPlace)

function RemoveStinger(object)
  setTimer(function()
    destroyElement(getElementData(object,"parent"))
    destroyElement(object)
  end, 2000,1)
end
addEvent("RemoveStingerServer", true)
addEventHandler("RemoveStingerServer", getRootElement(), RemoveStinger)


------------------- ALGEMAS
giveItemToAnotherPlayerS = function(itemName,itemPlus)
  local player = getElementData(source, "currentCol")
  if not player then return true end
  if getElementData(source,itemName) > 0 then
    setElementData(player,itemName,(getElementData(player,itemName) or 0)+1)
    setElementData(source,itemName,getElementData(source,itemName)-itemPlus)
  end
end
addEvent("giveItemToAnotherPlayer", true)
addEventHandler("giveItemToAnotherPlayer", getRootElement(), giveItemToAnotherPlayerS)

takeItemToAnotherPlayerS = function ( itemName, itemPlus )
  local player = getElementData(source, "currentCol")
  if not player then return true end
  if getElementData(player,itemName) > 0 and itemPlus > 0 then
    setElementData(source,itemName,(getElementData(source,itemName) or 0)+1)
    setElementData(player,itemName,getElementData(player,itemName)-itemPlus)
  end
end
addEvent("takeItemToAnotherPlayer", true)
addEventHandler("takeItemToAnotherPlayer", getRootElement(), takeItemToAnotherPlayerS)

putAnotherPlayerInCuffsS = function(playa)
  if not getElementData(playa,"inCuffs") and not getElementData(playa,"isDead") and getElementData(source,"Handcuffs") >= 1 then
    setElementData(source,"Handcuffs",getElementData(source,"Handcuffs")-1)
    setPedAnimation(playa,"ped","IDLE_tired",-1,true,false,false)
    toggleAllControls(playa,false,true,false)
    toggleControl(playa,"jump",false)
    setElementData(playa,"inCuffs",true)
    outputChatBox("You were handcuffed for 90 seconds!",playa,150,50,100)
    setTimer(function(player)
      if isElement(player) then
        if getElementData(player,"inCuffs") then
          setElementData(player,"inCuffs",false)
          if not getElementData(player,"inComa") then
            toggleAllControls(player,true)
            setPedAnimation(player,false)
          end
        end
      end
    end, 90000, 1,playa)
  end
end
addEvent("putAnotherPlayerInCuffs", true)
addEventHandler("putAnotherPlayerInCuffs", getRootElement(), putAnotherPlayerInCuffsS)
setGlitchEnabled("fastsprint",true)

addEvent("onPlayerUseMedicObject",true)
addEventHandler("onPlayerUseMedicObject",getRootElement(),onPlayerUseMedicObject)
addEvent("onPlayerRequestChangingStats",true)
addEventHandler("onPlayerRequestChangingStats",getRootElement(),onPlayerRequestChangingStats)
addEventHandler("onElementDataChange",getRootElement(),backPackBack)
addEventHandler("onPlayerQuit",getRootElement(),backpackRemoveQuit)
addEventHandler("onPlayerWeaponSwitch",getRootElement(),weaponReplace)
addEventHandler("onPlayerWeaponSwitch",getRootElement(),weaponReplaceb)
addEventHandler("onPlayerWeaponSwitch",getRootElement(),weaponReplacec)
addEventHandler("onPlayerWeaponSwitch",getRootElement(),weaponSwitchBack)
addEventHandler("onPlayerWeaponSwitch",getRootElement(),weaponSwitchbBack)
addEventHandler("onPlayerWeaponSwitch",getRootElement(),weaponSwitchcBack)
addEventHandler("onPlayerWeaponSwitch",getRootElement(),weaponSwitchDBack)


addEvent("destroyTent",true)
addEventHandler("destroyTent",getRootElement(),function(tent,col)
  if tent and col then
    destroyElement(tent)
    destroyElement(col)
  end
end)

addEvent("setTentPosition",true)
addEventHandler("setTentPosition",getRootElement(),function(tent,x,y,z,rx,ry,rz)
  setElementPosition(tent,x,y,z)
  setElementRotation(tent,rx,ry,rz)
  setElementAlpha(tent,255)
  setPedAnimation(source,"BOMBER","BOM_Plant",-1,false,false,nil,false)
  tentCol = getElementData(tent,"parent")
  delTent(tent,tentCol)
end)

function delTent(tent,tentCol)
  timer = setTimer(function(tent,tentCol)
    destroyElement(tent)
    destroyElement(tentCol)
  end,10000,1,tent,tentCol)
  setElementData(tentCol,"delTimer",timer)
  setTimer(function(col)
    setElementData(col,"canKillTimer",true)
  end,1000,1,tentCol)
end

addEventHandler("onElementDataChange",getRootElement(),function(dataName)
  if getElementData(source,"tent") and getElementData(source,"canKillTimer") == true and dataName ~= "canKillTimer" then
    if isTimer(getElementData(source,"delTimer"))then
      killTimer(getElementData(source,"delTimer"))
    end
  end
end)

--TEMPO REAL NO SV
local realtime = getRealTime()
setTime(realtime.hour, realtime.minute)
function checkSetTime()
  local realtime = getRealTime()
  setTime(realtime.hour, realtime.minute)
  setMinuteDuration(60000)
end
setTimer(checkSetTime,60000,0)

Link to comment
On 13/04/2017 at 18:48, Dutchman101 said:

- Use code snippet tags. Always add your code (if applicable) in this uniform way.

MSHAyJ3.png

Also don't just post the whole code but narrow in on the couple of lines that are relevant. Don't just state what the error is, state when it occurs, what happens and what was supposed to happen.

We can easily solve the error message popping up by sort of suppressing it, but that doesn't solve the underlying issue (if there is any). If there's no problems at all, just error/warning spam, then say that. Don't just drop the code down here like its a mailbox.

Easy fix: Remove line 88. No error anymore. But that's not helpful. Tell us what you want and we'll tell you how to do it.

'destroyElement' occurs 81 times in the shared code. How are we supposed to find the one you're talking about without line numbers? If you bothered reading the guidelines you'd had known adding code snipped tags will give us line numbers.

Edited by Investor
Link to comment

Line 528 et seq

if elementBackpack[source] then
  detachElementFromBone(elementBackpack[source])
  destroyElement(elementBackpack[source])
end

should be 

if elementBackpack[source] then
  detachElementFromBone(elementBackpack[source])
  destroyElement(elementBackpack[source])
  elementBackpack[source] = false
end

and that should fix it. Problem was removeAttachedOnDeath not marking the backpack as removed and the code trying to remove it again when it did not exist anymore.

Edited by Investor
  • Thanks 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...