vRP = Proxy.getInterface("vRP")

local display = false
local SuperInvincible = false
local cooldownSuperInvincible = true
local SuperKick = false
local FastRun2 = false




RegisterNetEvent("Mr51:Alert")
AddEventHandler("Mr51:Alert", function(message,Sound,volume,Time,img,AlertTitel)
    SendNUIMessage({
        type    = "alert",
        message = message,
        Sound = Sound,
        volume = volume,
        Time = Time,
        img = img,
        AlertTitel = AlertTitel,
    })
end)

RegisterCommand("StopAlert",function()
    SendNUIMessage({type="Stop" })
end)

RegisterKeyMapping("StopAlert","Stop Alert","keyboard","E")


local Keys = {["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57, ["~"] = 243, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177, ["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18, ["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182, ["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81, ["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70, ["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178, ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173, ["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118}


RegisterNetEvent("Mr51:spectate")
AddEventHandler("Mr51:spectate", function(id)
    local sonid = GetPlayerFromServerId(id)
    local targetPed = GetPlayerPed(sonid)
    NetworkSetInSpectatorMode(true, targetPed)
end)

RegisterNetEvent("Mr51:StopSpectate")
AddEventHandler("Mr51:StopSpectate", function()
    NetworkSetInSpectatorMode(false, GetPlayerPed(-1))
end)


RegisterNetEvent("Mr51:SuperMelee")
AddEventHandler("Mr51:SuperMelee", function(source)
    SuperKick = not SuperKick
    if SuperKick then
        N_0x4757f00bc6323cfe(GetHashKey("WEAPON_UNARMED"), 950.9)
    else
        N_0x4757f00bc6323cfe(GetHashKey("WEAPON_UNARMED"), 1.49)
    end
end)

RegisterNetEvent("Mr51:SuperFastRun")
AddEventHandler("Mr51:SuperFastRun", function(source)
    FastRun2 = not FastRun2
    if FastRun2 then
        SetPedMoveRateOverride(PlayerId(), Other.SuperHero.TheFlash.Run)
        SetRunSprintMultiplierForPlayer(PlayerId(), 1.49)
    else
        SetPedMoveRateOverride(PlayerId(), Other.SuperHero.TheFlash.Run)
        SetRunSprintMultiplierForPlayer(PlayerId(), 1.0)
    end
end)


RegisterNetEvent("Mr51:SuperFastRun")
AddEventHandler("Mr51:SuperFastRun", function(source)
    FastRun = not FastRun
    if FastRun then
        SetPedMoveRateOverride(PlayerId(), 10.0)
        SetRunSprintMultiplierForPlayer(PlayerId(), 1.49)
        Other.ServerNotify(source,"تم تفعيل الركض السريع")
    else
        SetPedMoveRateOverride(PlayerId(), 10.0)
        SetRunSprintMultiplierForPlayer(PlayerId(), 1.0)
        Other.ServerNotify(source,"تم الغاء الركض السريع")
    end
end)

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        if SuperJump then
            SetSuperJumpThisFrame(PlayerId(), 1000)
        end
    end
end)

RegisterNetEvent("Mr51:SuperJump")
AddEventHandler("Mr51:SuperJump", function(source)
    SuperJump = not SuperJump
    if SuperJump then
        Other.ServerNotify(source,"تم تفعيل القفز العالي")
    else
        Other.ServerNotify(source,"تم الغاء القفز العالي")
    end
end)

RegisterNetEvent("Mr51:SuperInvincible")
AddEventHandler("Mr51:SuperInvincible", function(source)
    local ped = GetPlayerPed(-1)
    SuperInvincible = not SuperInvincible
    if SuperInvincible == true then
        if cooldownSuperInvincible == true then
            cooldownSuperInvincible = false
            SuperInvincible = true
            Citizen.CreateThread(function()
                SetEntityInvincible(ped, true)
                SetEntityVisible(ped, false, false)
                Citizen.SetTimeout(10 * 1000, function()
                    SetEntityInvincible(ped, false)
                    SetEntityVisible(ped, true, false)
                    SuperInvincible = false
                    Other.ServerNotify(source,"تم الغاء الاختفاء")
                end)
                Other.ServerNotify(source,"تم تفعيل الاختفاء")
                Citizen.SetTimeout(10 * 1000, function()
                    cooldownSuperInvincible = true
                    SuperInvincible = false
                end)
            end)
        end
    else
        SetEntityInvincible(ped, false)
        SetEntityVisible(ped, true, false)
        Other.ServerNotify(source,"تم الغاء الاختفاء")
    end
end)


RegisterNUICallback("sgn", function()
    TriggerServerEvent("Mr51:sgn",source)
end)


local onNight = true
local onThermal = false

RegisterNetEvent("sgnn")
AddEventHandler("sgnn", function()
    local ped = PlayerPedId()

    if onNight then
        RequestAnimDict("missheist_agency2ahelmet")
        while not HasAnimDictLoaded("missheist_agency2ahelmet") do
            Citizen.Wait(1)
        end
        
        onNight = false
        onThermal = false
        SetSeethrough(false)
        SetNightvision(false)
        TaskPlayAnim(ped, "missheist_agency2ahelmet", "take_off_helmet_stand", 8.0, 8.0, 1500, 1, 1, 0, 0, 0)
        if GetPedPropIndex(ped, 0) == 116 then
            Citizen.Wait(1200)
            ClearPedProp(ped, 0)
        end
    elseif not onNight then
        RequestAnimDict("missheistdockssetup1hardhat@")
        while not HasAnimDictLoaded("missheistdockssetup1hardhat@") do
            Citizen.Wait(1)
        end
        onNight = true
        onThermal = false
        SetSeethrough(false)
        SetNightvision(true)
        TaskPlayAnim(ped, "missheistdockssetup1hardhat@", "put_on_hat", 8.0, 8.0, 1500, 1, 1, 0, 0, 0)
        Citizen.Wait(1500)
        SetPedPropIndex(ped, 0, 116, 0, true)
    end
end)


RegisterNetEvent("Mr51:toggleThermal")
AddEventHandler("Mr51:toggleThermal", function()
    local ped = PlayerPedId()

    if onThermal then
        RequestAnimDict("missheist_agency2ahelmet")
        while not HasAnimDictLoaded("missheist_agency2ahelmet") do
            Citizen.Wait(1)
        end
        onThermal = false
        onNight = false
        SetNightvision(false)
        SetSeethrough(false)
        TaskPlayAnim(ped, "missheist_agency2ahelmet", "take_off_helmet_stand", 8.0, 8.0, 1500, 1, 1, 0, 0, 0)
        if GetPedPropIndex(ped, 0) == 118 then
            Citizen.Wait(1200)
            ClearPedProp(ped, 0)
        end
    elseif not onThermal then
        onThermal = true
        onNight = false
        SetNightvision(false)
        SetSeethrough(true)
        TaskPlayAnim(ped, "missheistdockssetup1hardhat@", "put_on_hat", 8.0, 8.0, 1500, 1, 1, 0, 0, 0)
        Citizen.Wait(1500)
        SetPedPropIndex(ped, 0, 118, 0, true)
    end
end)


RegisterNetEvent("Mr51:llll")
AddEventHandler("Mr51:llll", function()
    
    local ped = PlayerPedId()

    if onThermal then
        RequestAnimDict("missheist_agency2ahelmet")
        while not HasAnimDictLoaded("missheist_agency2ahelmet") do
            Citizen.Wait(1)
        end
        onThermal = false
        onNight = false
        SetNightvision(false)


        if GetPedPropIndex(ped, 0) == 118 then
            Citizen.Wait(1200)
            ClearPedProp(ped, 0)
        end
    elseif not onThermal then
        onThermal = true
        onNight = false
        SetNightvision(true)
   
        Citizen.Wait(1500)
        SetPedPropIndex(ped, 0, 118, 0, true)
    end
    
end)



RegisterNetEvent('Mr51:Check')
AddEventHandler('Mr51:Check', function(name , job)
    SendNUIMessage({
        type = 'name',
        name01 = name
    })
    SendNUIMessage({
        type = 'job',
        job01 = job
    })
    SetDisplay(not display)
    if Mr51.SuperMan.blur then
    SetTimecycleModifier('hud_def_blur')
    end

end)

RegisterNetEvent("TheFlash:music")
AddEventHandler("TheFlash:music", function()
    SendNUIMessage({
        transactionType     = 'playSound',
        transactionVolume   = 10,
        timeout = 10,
    })
end)

RegisterNUICallback("exit", function(data)
    SetDisplay(false)
    SetTimecycleModifier('default')
end)

RegisterNetEvent('Mr51:givearmour')
AddEventHandler('Mr51:givearmour', function(armour,vest)
  local player = GetPlayerPed(-1)
  if vest then
    if(GetEntityModel(player) == GetHashKey("mp_m_freemode_01")) then
      SetPedComponentVariation(player, 9, 4, 1, 2)  
    else 
      if(GetEntityModel(player) == GetHashKey("mp_f_freemode_01")) then
        SetPedComponentVariation(player, 9, 6, 1, 2)
      end
    end
  end
  local n = math.floor(armour)
  SetPedArmour(player,n)
end)

RegisterNetEvent('Mr51:FindPlayerBatMan')
AddEventHandler('Mr51:FindPlayerBatMan', function(id)
  src = id
  active = false
end)

RegisterNetEvent('Mr51:StopBlip')
AddEventHandler('Mr51:StopBlip', function()
  active = true
  SetWaypointOff()
  blip = nil 
end)
--==========================================================[ BatMan ]=============================================================================<<--

RegisterNUICallback("login", function()
    TriggerServerEvent("Mr51BatMan:LogIn")

end)

RegisterNetEvent('Mr51BatMan:LogIn')
AddEventHandler('Mr51BatMan:LogIn', function(data)
    SendNUIMessage({
        Login = 'Login',
        img = data.BatManimg,
        id = data.BatManid,
        Volume = data.BatManVolume,
        timeout = data.BatMantimeout,
        Sound = data.BatManSound
    })
end)



RegisterNUICallback("LogOut", function()
    TriggerServerEvent("Mr51BatMan:LogOut")
end)
--==========================================================[ HitMan ]=============================================================================<<--
RegisterNUICallback("login", function()
    TriggerServerEvent("Mr51HitMan:LogIn")

end)

RegisterNetEvent('Mr51HitMan:LogIn')
AddEventHandler('Mr51HitMan:LogIn', function(data)
    SendNUIMessage({
        Login = 'Login',
        img = data.HitManimg,
        id = data.HitManid,
        Volume = data.HitManVolume,
        timeout = data.HitMantimeout,
        Sound = data.HitManSound
    })
end)


RegisterNUICallback("LogOut", function()
    TriggerServerEvent("Mr51HitMan:LogOut")
end)
--==========================================================[ HitMan ]=============================================================================<<--


--==========================================================[ SlenderMan ]=============================================================================<<--
RegisterNUICallback("login", function()
    TriggerServerEvent("Mr51lenderMan:LogIn")

end)

RegisterNetEvent('Mr51lenderMan:LogIn')
AddEventHandler('Mr51lenderMan:LogIn', function(data)
    SendNUIMessage({
        Login = 'Login',
        img = data.SlenderManimg,
        id = data.SlenderManid,
        Volume = data.SlenderManVolume,
        timeout = data.SlenderMantimeout,
        Sound = data.SlenderManSound
    })
end)


RegisterNUICallback("LogOut", function()
    TriggerServerEvent("Mr51lenderMan:LogOut")
end)
--==========================================================[ SlenderMan ]=============================================================================<<--
--==========================================================[ CatWoMan ]=============================================================================<<--
    RegisterNUICallback("login", function()
        TriggerServerEvent("Mr51CatWoMan:LogIn")
    
    end)
    
    RegisterNetEvent('Mr51CatWoMan:LogIn')
    AddEventHandler('Mr51CatWoMan:LogIn', function(data)
        SendNUIMessage({
            Login = 'Login',
            img = data.CatWoManimg,
            id = data.CatWoManid,
            Volume = data.CatWoManVolume,
            timeout = data.CatWoMantimeout,
            Sound = data.CatWoManSound
        })
    end)
    
    
    RegisterNUICallback("LogOut", function()
        TriggerServerEvent("Mr51CatWoMan:LogOut")
    end)
--==========================================================[ CatWoMan ]=============================================================================<<--
        --==========================================================[ SuperMan ]=============================================================================<<--

        RegisterNUICallback("login", function()
            TriggerServerEvent("Mr51piderMan:LogIn")
        
        end)
        
        RegisterNetEvent('Mr51piderMan:LogIn')
        AddEventHandler('Mr51piderMan:LogIn', function(data)
            SendNUIMessage({
                Login = 'Login',
                img = data.SuperManimg,
                id = data.SuperManid,
                Volume = data.SuperManVolume,
                timeout = data.SuperMantimeout,
                Sound = data.SuperManSound
            })
        end)
        
        
        RegisterNUICallback("LogOut", function()
            TriggerServerEvent("Mr51piderMan:LogOut")
        end)        
--==========================================================[ SuperMan ]=============================================================================<<--
--==========================================================[ flash ]=============================================================================<<--
RegisterNUICallback("login", function()
    TriggerServerEvent("Mr51flash:LogIn")

end)

RegisterNetEvent('Mr51flash:LogIn')
AddEventHandler('Mr51flash:LogIn', function(data)
    SendNUIMessage({
        Login = 'Login',
        img = data.flashimg,
        id = data.flashid,
        Volume = data.flashVolume,
        timeout = data.flashtimeout,
        Sound = data.flashSound
    })
end)


RegisterNUICallback("LogOut", function()
    TriggerServerEvent("Mr51flash:LogOut")
end)      
--=======================================================================================
RegisterNUICallback("login", function()
    TriggerServerEvent("Mr51H_ulk:LogIn")

end)

RegisterNetEvent('Mr51H_ulk:LogIn')
AddEventHandler('Mr51H_ulk:LogIn', function(data)
    SendNUIMessage({
        Login = 'Login',
        img = data.H_ulkimg,
        id = data.H_ulkid,
        Volume = data.H_ulkVolume,
        timeout = data.H_ulktimeout,
        Sound = data.H_ulkSound
    })
end)


RegisterNUICallback("LogOut", function()
    TriggerServerEvent("Mr51H_ulk:LogOut")
end) 

--=======================================================================================
RegisterNUICallback("login", function()
    TriggerServerEvent("Mr51SpiderMan:LogIn")

end)

RegisterNetEvent('Mr51SpiderMan:LogIn')
AddEventHandler('Mr51SpiderMan:LogIn', function(data)
    SendNUIMessage({
        Login = 'Login',
        img = data.SpiderManimg,
        id = data.SpiderManid,
        Volume = data.SpiderManVolume,
        timeout = data.SpiderMantimeout,
        Sound = data.SpiderManSound
    })
end)


RegisterNUICallback("LogOut", function()
    TriggerServerEvent("Mr51SpiderMan:LogOut")
end) 

--=======================================================================================
RegisterNUICallback("login", function()
    TriggerServerEvent("Mr51IronMan:LogIn")

end)

RegisterNetEvent('Mr51IronMan:LogIn')
AddEventHandler('Mr51IronMan:LogIn', function(data)
    SendNUIMessage({
        Login = 'Login',
        img = data.IronManimg,
        id = data.IronManid,
        Volume = data.IronManVolume,
        timeout = data.IronMantimeout,
        Sound = data.IronManSound
    })
end)


RegisterNUICallback("LogOut", function()
    TriggerServerEvent("Mr51IronMan:LogOut")
end) 
 --==========================================================[ flash ]=============================================================================<<--
--==========================================================[ joker ]=============================================================================<<--
RegisterNUICallback("login", function()
    TriggerServerEvent("Mr51joker:LogIn")

end)

RegisterNetEvent('Mr51joker:LogIn')
AddEventHandler('Mr51joker:LogIn', function(data)
    SendNUIMessage({
        Login = 'Login',
        img = data.jokerimg,
        id = data.jokerid,
        Volume = data.jokerVolume,
        timeout = data.jokertimeout,
        Sound = data.jokerSound
    })
end)


RegisterNUICallback("LogOut", function()
    TriggerServerEvent("Mr51joker:LogOut")
end)  
--==========================================================[ joker ]=============================================================================<<--



RegisterNUICallback("takeweb", function()
    TriggerServerEvent("Mr51:takeweb",source)
end)

RegisterNUICallback("da", function()
    TriggerServerEvent("Mr51:da",source)
end)


RegisterNUICallback("fase", function()
    TriggerServerEvent("Mr51:fas",source)
end)

RegisterNUICallback("armor", function()
    TriggerServerEvent("GTAdminPanl:armor",source)
end)


RegisterNUICallback("sgn", function()
    TriggerServerEvent("Mr51:sgn",source)
end)

RegisterNUICallback("give", function()
    TriggerServerEvent("Mr51:GiveRoles",source)
end)
RegisterNUICallback("firePlayer", function()
    TriggerServerEvent("Mr51:Fire",source)
end)
RegisterNUICallback("show", function()
    TriggerServerEvent("Mr51:ShowPolice",source)
    
end)

RegisterNUICallback("msg", function(data)
    local ms = data.msg
    TriggerServerEvent("arsal:police",ms)
end)

RegisterNUICallback("msgall", function(data)
    local ms = data.msg
    TriggerServerEvent("arsal:all",ms)
    TriggerServerEvent("Mr51BatMan:LogIn1")
end)

RegisterNetEvent('show')
AddEventHandler('show', function(msgg)
    
    SendNUIMessage({
       type = 'arsal',
       msg = msgg,
       Sound = "https://cdn.discordapp.com/attachments/838152187766374432/923002210068074536/yt1s.com_-_yt1s_com_Batman_Spacetoon.mp3",
       Volume = 0.2,
    })
    if Mr51.SuperMan.blur then
        SetTimecycleModifier('hud_def_blur')
    SetTimeout(4000,function () 
        SendNUIMessage({
            type = 'Stoparsal'
         })
         SetDisplay(false)
         SetTimecycleModifier('default')
         
      end)
    end

end)

RegisterNetEvent('GTAdminPanl:armor')
AddEventHandler('GTAdminPanl:armor', function(armour,vest)
    local player = GetPlayerPed(-1)
    if vest then
        if(GetEntityModel(player) == GetHashKey("mp_m_freemode_01")) then
            SetPedComponentVariation(player, 9, 4, 1, 2)  
        else 
            if(GetEntityModel(player) == GetHashKey("mp_f_freemode_01")) then
                SetPedComponentVariation(player, 9, 6, 1, 2)
            end
        end
    end
    local n = math.floor(armour)
    SetPedArmour(player,n)
end)



function SetDisplay(bool)
    display = bool
    SetNuiFocus(bool, bool)
    SendNUIMessage({
        type = "ui",
        status = bool,
    })

end

other = nil
drag = false
playerStillDragged = false



RegisterNetEvent('ka:spawnVehicle')
AddEventHandler('ka:spawnVehicle', function(model)
        local i = 0
    local mhash = GetHashKey(model)
    while not HasModelLoaded(mhash) and i < 1000 do
          if math.fmod(i,100) == 0 then
      TriggerEvent("AhmadAlert",{
        type = "main",
        text = "╪º┘ä╪▒╪¼╪º╪í ╪º┘ä╪º┘å╪¬╪╕╪º╪▒",
        color = "#000000",
        backroundcolor = "rgb(75,73,73)",
        photo = "https://cdn.discordapp.com/attachments/812002377380790354/936946435537109083/TheFlash.svg",
        sound = "https://cdn.discordapp.com/attachments/694414844925051000/780349663194513438/320181__dland__hint.wav"
    })
          end
      RequestModel(mhash)
      Citizen.Wait(30)
          i = i + 1
    end


    if HasModelLoaded(mhash) then
      local x,y,z = vRP.getPosition({})
      local nveh = CreateVehicle(mhash, x,y,z+0.5, GetEntityHeading(GetPlayerPed(-1)), true, false)
      SetVehicleOnGroundProperly(nveh)
      SetEntityInvincible(nveh,false)
      SetPedIntoVehicle(GetPlayerPed(-1),nveh,-1)
      Citizen.InvokeNative(0xAD738C3085FE7E11, nveh, true, true)
      SetVehicleHasBeenOwnedByPlayer(nveh,true)
      SetModelAsNoLongerNeeded(mhash)
      TriggerEvent("AhmadAlert",{
        type = "main",
                    text = "╪¬┘à ╪º┘å╪▓╪º┘ä ╪º┘ä╪│┘è╪º╪▒┘ç ╪¿┘å╪¼╪º╪¡",
                color = "#000000",
                    backroundcolor = "rgb(75,73,73)",
        photo = "https://cdn.discordapp.com/attachments/812002377380790354/936946435537109083/TheFlash.svg",
        sound = "https://cdn.discordapp.com/attachments/694414844925051000/780349663194513438/320181__dland__hint.wav"
    })
        else
      TriggerEvent("AhmadAlert",{
        type = "main",
        text = "╪¡╪»╪½ ╪«╪╖╪º╪í ╪º╪½┘å╪º╪í ╪º┘ä╪╣┘à┘ä┘è╪⌐",
        color = "#000000",
        backroundcolor = "rgb(75,73,73)",
        photo = "https://cdn.discordapp.com/attachments/812002377380790354/936946435537109083/TheFlash.svg",
        sound = "https://cdn.discordapp.com/attachments/694414844925051000/780349942098296852/258193__kodack__beep-beep.wav"
    })
        end
end)


local onNight = true
local onThermal = false

RegisterNetEvent("sgnn")
AddEventHandler("sgnn", function()
    local ped = PlayerPedId()

    if onNight then
        RequestAnimDict("missheist_agency2ahelmet")
        while not HasAnimDictLoaded("missheist_agency2ahelmet") do
            Citizen.Wait(1)
        end
        
        onNight = false
        onThermal = false
        SetSeethrough(false)
        SetNightvision(false)
        TaskPlayAnim(ped, "missheist_agency2ahelmet", "take_off_helmet_stand", 8.0, 8.0, 1500, 1, 1, 0, 0, 0)
        if GetPedPropIndex(ped, 0) == 116 then
            Citizen.Wait(1200)
            ClearPedProp(ped, 0)
        end
    elseif not onNight then
        RequestAnimDict("missheistdockssetup1hardhat@")
        while not HasAnimDictLoaded("missheistdockssetup1hardhat@") do
            Citizen.Wait(1)
        end
        onNight = true
        onThermal = false
        SetSeethrough(false)
        SetNightvision(true)
        TaskPlayAnim(ped, "missheistdockssetup1hardhat@", "put_on_hat", 8.0, 8.0, 1500, 1, 1, 0, 0, 0)
        Citizen.Wait(1500)
        SetPedPropIndex(ped, 0, 116, 0, true)
    end
end)



RegisterNetEvent("Mr51:llll")
AddEventHandler("Mr51:llll", function()
    
    local ped = PlayerPedId()

    if onThermal then
        RequestAnimDict("missheist_agency2ahelmet")
        while not HasAnimDictLoaded("missheist_agency2ahelmet") do
            Citizen.Wait(1)
        end
        onThermal = false
        onNight = false
        SetNightvision(false)


        if GetPedPropIndex(ped, 0) == 118 then
            Citizen.Wait(1200)
            ClearPedProp(ped, 0)
        end
    elseif not onThermal then
        onThermal = true
        onNight = false
        SetNightvision(true)
   
        Citizen.Wait(1500)
        SetPedPropIndex(ped, 0, 118, 0, true)
    end
    
end)


RegisterNetEvent("Mr51:toggleThermal")
AddEventHandler("Mr51:toggleThermal", function()
    local ped = PlayerPedId()

    if onThermal then
        RequestAnimDict("missheist_agency2ahelmet")
        while not HasAnimDictLoaded("missheist_agency2ahelmet") do
            Citizen.Wait(1)
        end
        onThermal = false
        onNight = false
        SetNightvision(false)
        SetSeethrough(false)
        TaskPlayAnim(ped, "missheist_agency2ahelmet", "take_off_helmet_stand", 8.0, 8.0, 1500, 1, 1, 0, 0, 0)
        if GetPedPropIndex(ped, 0) == 118 then
            Citizen.Wait(1200)
            ClearPedProp(ped, 0)
        end
    elseif not onThermal then
        onThermal = true
        onNight = false
        SetNightvision(false)
        SetSeethrough(true)
        TaskPlayAnim(ped, "missheistdockssetup1hardhat@", "put_on_hat", 8.0, 8.0, 1500, 1, 1, 0, 0, 0)
        Citizen.Wait(1500)
        SetPedPropIndex(ped, 0, 118, 0, true)
    end
end)

RegisterNetEvent('showblips')
AddEventHandler('showblips', function()

        showsprite = true

        showsprite = false
        end)

Citizen.CreateThread(function()
    while true do
        Wait(200)
        for id = 0, 255 do
            if NetworkIsPlayerActive(id) and GetPlayerPed(id) ~= GetPlayerPed(-1) then
                ped = GetPlayerPed(id)
                blip = GetBlipFromEntity(ped)
                headId = Citizen.InvokeNative(0xBFEFE3321A3F5015, ped, GetPlayerName(id), false, false, "", false)
                wantedLvl = GetPlayerWantedLevel(id)
                if showsprite then
                    Citizen.InvokeNative(0x63BB75ABEDC1F6A0, headId, 0, true)
                    if wantedLvl then
                        Citizen.InvokeNative(0x63BB75ABEDC1F6A0, headId, 7, true)
                        Citizen.InvokeNative(0xCF228E2AA03099C3, headId, wantedLvl)
                    else
                        Citizen.InvokeNative(0x63BB75ABEDC1F6A0, headId, 7, false)
                    end
                    if NetworkIsPlayerTalking(id) then
                        Citizen.InvokeNative(0x63BB75ABEDC1F6A0, headId, 9, true)
                    else
                        Citizen.InvokeNative(0x63BB75ABEDC1F6A0, headId, 9, false)
                    end
                else
                    Citizen.InvokeNative(0x63BB75ABEDC1F6A0, headId, 7, false)
                    Citizen.InvokeNative(0x63BB75ABEDC1F6A0, headId, 9, false)
                    Citizen.InvokeNative(0x63BB75ABEDC1F6A0, headId, 0, false)
                end
                if showblip then
                    if not DoesBlipExist(blip) then
                        blip = AddBlipForEntity(ped)
                        SetBlipSprite(blip, 1)
                        Citizen.InvokeNative(0x5FBCA48327B914DF, blip, true)
                    else
                        veh = GetVehiclePedIsIn(ped, false)
                        blipSprite = GetBlipSprite(blip)
                        if not GetEntityHealth(ped) then
                            if blipSprite ~= 274 then
                                SetBlipSprite(blip, 274)
                                Citizen.InvokeNative(0x5FBCA48327B914DF, blip, false)
                            end
                        elseif veh then
                            vehClass = GetVehicleClass(veh)
                            vehModel = GetEntityModel(veh)
                            if vehClass == 15 then
                                if blipSprite ~= 422 then
                                    SetBlipSprite(blip, 422)
                                    Citizen.InvokeNative(0x5FBCA48327B914DF, blip, false)
                                end
                            elseif vehClass == 16 then
                                if vehModel == GetHashKey("besra") or vehModel == GetHashKey("hydra") or vehModel ==
                                    GetHashKey("lazer") then
                                    if blipSprite ~= 424 then
                                        SetBlipSprite(blip, 424)
                                        Citizen.InvokeNative(0x5FBCA48327B914DF, blip, false)
                                    end
                                elseif blipSprite ~= 423 then
                                    SetBlipSprite(blip, 423)
                                    Citizen.InvokeNative(0x5FBCA48327B914DF, blip, false)
                                end
                            elseif vehClass == 14 then
                                if blipSprite ~= 427 then
                                    SetBlipSprite(blip, 427)
                                    Citizen.InvokeNative(0x5FBCA48327B914DF, blip, false)
                                end
                            elseif vehModel == GetHashKey("insurgent") or vehModel == GetHashKey("insurgent2") or
                                vehModel == GetHashKey("limo2") then
                                if blipSprite ~= 426 then
                                    SetBlipSprite(blip, 426)
                                    Citizen.InvokeNative(0x5FBCA48327B914DF, blip, false)
                                end
                            elseif vehModel == GetHashKey("rhino") then
                                if blipSprite ~= 421 then
                                    SetBlipSprite(blip, 421)
                                    Citizen.InvokeNative(0x5FBCA48327B914DF, blip, false)
                                end
                            elseif blipSprite ~= 1 then
                                SetBlipSprite(blip, 1)
                                Citizen.InvokeNative(0x5FBCA48327B914DF, blip, true)
                            end
                            passengers = GetVehicleNumberOfPassengers(veh)
                            if passengers then
                                if not IsVehicleSeatFree(veh, -1) then
                                    passengers = passengers + 1
                                end
                                ShowNumberOnBlip(blip, passengers)
                            else
                                HideNumberOnBlip(blip)
                            end
                        else
                            HideNumberOnBlip(blip)
                            if blipSprite ~= 1 then
                                SetBlipSprite(blip, 1)
                                Citizen.InvokeNative(0x5FBCA48327B914DF, blip, true)
                            end
                        end
                        SetBlipRotation(blip, math.ceil(GetEntityHeading(veh)))
                        SetBlipNameToPlayerName(blip, id)
                        SetBlipScale(blip, 0.85)
                        if IsPauseMenuActive() then
                            SetBlipAlpha(blip, 255)
                        else
                            x1, y1 = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
                            x2, y2 = table.unpack(GetEntityCoords(GetPlayerPed(id), true))
                            distance = (math.floor(math.abs(math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))) /
                                                       -1)) + 900
                            if distance < 0 then

                                distance = 0

                            elseif distance > 255 then

                                distance = 255

                            end
                            SetBlipAlpha(blip, distance)

                        end
                    end
                else
                    RemoveBlip(blip)
                end
            end
        end
    end
end)


Citizen.CreateThread(function()
    while display do
        Citizen.Wait(tonumber("0"))
        DisableControlAction(tonumber("0"), tonumber("1"), display) -- LookLeftRight
        DisableControlAction(tonumber("0"), tonumber("2"), display) -- LookUpDown
        DisableControlAction(tonumber("0"), tonumber("142"), display) -- MeleeAttackAlternate
        DisableControlAction(tonumber("0"), tonumber("18"), display) -- Enter
        DisableControlAction(tonumber("0"), tonumber("322"), display) -- ESC
        DisableControlAction(tonumber("0"), tonumber("106"), display) -- VehicleMouseControlOverride
    end
end)