--[[------------------------------------------------------------------------ ActionMenu Created by WolfKnight Additional help from lowheartrate, TheStonedTurtle, and Briglair. Modified by Christopher for VisionaryRP ------------------------------------------------------------------------]]-- -- Define the variable used to open/close the menu local menuEnabled = false local togShot = false local togAr = false local togWin = false local vd0 = false local vd1 = false local vd2 = false local vd3 = false local vd4 = false local vd5 = false local vd6 = false local vd7 = false local SpawnedSpikes = {} local SpikesSpawned = false local SpikeConfig = {} local SpikeConfig = setmetatable(SpikeConfig, {}) SpikeConfig.MaxSpikes = 3 SpikeConfig.PedRestriction = true SpikeConfig.PedsList = { "s_m_y_cop_01", "s_f_y_cop_01", "s_m_y_hwaycop_01", "s_m_y_sheriff_01", "s_f_y_sheriff_01", "s_m_y_swat_01", "s_m_y_ranger_01", "s_f_y_ranger_01", "s_m_m_ciasec_01", "u_m_m_doa_01", "s_m_m_fibsec_01" } local gear = { {"WEAPON_COMBATPISTOL"}, {"WEAPON_NIGHTSTICK"}, {"WEAPON_STUNGUN"}, {"WEAPON_FLASHLIGHT"}, } --[[------------------------------------------------------------------------ ActionMenu Toggle Calling this function will open or close the ActionMenu. ------------------------------------------------------------------------]]-- function ToggleActionMenu() -- Make the menuEnabled variable not itself -- e.g. not true = false, not false = true menuEnabled = not menuEnabled if ( menuEnabled ) then -- Focuses on the NUI, the second parameter toggles the -- onscreen mouse cursor. SetNuiFocus( true, true ) -- Sends a message to the JavaScript side, telling it to -- open the menu. SendNUIMessage({ showmenu = true }) else -- Bring the focus back to the game SetNuiFocus( false ) -- Sends a message to the JavaScript side, telling it to -- close the menu. SendNUIMessage({ hidemenu = true }) end end --[[------------------------------------------------------------------------ ActionMenu HTML Callbacks This will be called every single time the JavaScript side uses the sendData function. The name of the data-action is passed as the parameter variable data. ------------------------------------------------------------------------]]-- RegisterNUICallback( "ButtonClick", function( data, cb ) if ( data == "shotgun" ) then if IsPedInAnyVehicle(GetPlayerPed(-1)) then if ( togShot ) then Citizen.CreateThread(function() RemoveAllPedWeapons(GetPlayerPed(-1),true) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_COMBATPISTOL"), 1000, false) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_STUNGUN"), 1000, false) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_FLASHLIGHT"), 1000, false) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_NIGHTSTICK"), 1000, false) GiveWeaponComponentToPed(GetPlayerPed(-1), GetHashKey("WEAPON_COMBATPISTOL"), GetHashKey("COMPONENT_AT_PI_FLSH")) SetCurrentPedWeapon(GetPlayerPed(-1), "WEAPON_UNARMED", true) chatPrint( "You put your Shotgun away" ) dontWant() togShot = false end) else Citizen.CreateThread(function() RemoveAllPedWeapons(GetPlayerPed(-1),true) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_COMBATPISTOL"), 1000, false) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_STUNGUN"), 1000, false) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_FLASHLIGHT"), 1000, false) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_NIGHTSTICK"), 1000, false) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_PUMPSHOTGUN"), 1000, false) GiveWeaponComponentToPed(GetPlayerPed(-1), GetHashKey("WEAPON_COMBATPISTOL"), GetHashKey("COMPONENT_AT_PI_FLSH")) GiveWeaponComponentToPed(GetPlayerPed(-1), GetHashKey("WEAPON_PUMPSHOTGUN"), GetHashKey("COMPONENT_AT_AR_FLSH")) SetCurrentPedWeapon(GetPlayerPed(-1), "WEAPON_PUMPSHOTGUN", true) chatPrint( "You unlock your Shotgun" ) want("0x1D073A89") togShot = true end) end else chatPrint( "I can't pull a Shotgun out of thin air..." ) end elseif ( data == "ar15" ) then if IsPedInAnyVehicle(GetPlayerPed(-1)) then if ( togAr ) then Citizen.CreateThread(function() RemoveAllPedWeapons(GetPlayerPed(-1),true) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_COMBATPISTOL"), 1000, false) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_STUNGUN"), 1000, false) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_FLASHLIGHT"), 1000, false) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_NIGHTSTICK"), 1000, false) GiveWeaponComponentToPed(GetPlayerPed(-1), GetHashKey("WEAPON_COMBATPISTOL"), GetHashKey("COMPONENT_AT_PI_FLSH")) SetCurrentPedWeapon(GetPlayerPed(-1), "WEAPON_UNARMED", true) chatPrint( "You put your AR-15 away" ) dontWant() togAr = false end) else Citizen.CreateThread(function() RemoveAllPedWeapons(GetPlayerPed(-1),true) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_COMBATPISTOL"), 1000, false) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_STUNGUN"), 1000, false) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_FLASHLIGHT"), 1000, false) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_NIGHTSTICK"), 1000, false) GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_CARBINERIFLE"), 1000, false) GiveWeaponComponentToPed(GetPlayerPed(-1), GetHashKey("WEAPON_COMBATPISTOL"), GetHashKey("COMPONENT_AT_PI_FLSH")) GiveWeaponComponentToPed(GetPlayerPed(-1), GetHashKey("WEAPON_CARBINERIFLE"), GetHashKey("COMPONENT_AT_AR_AFGRIP")) GiveWeaponComponentToPed(GetPlayerPed(-1), GetHashKey("WEAPON_CARBINERIFLE"), GetHashKey("COMPONENT_AT_AR_FLSH")) SetCurrentPedWeapon(GetPlayerPed(-1), "WEAPON_CARBINERIFLE", true) chatPrint( "You unlock your AR-15" ) want("0x83BF0278") togAr = true end) end else chatPrint( "I can't pull an AR15 out of thin air..." ) end elseif ( data == "gear" ) then if IsPedInAnyVehicle(GetPlayerPed(-1)) then RequestModel("s_m_y_hwaycop_01") while not HasModelLoaded("s_m_y_hwaycop_01") do Citizen.Wait(0) end SetPlayerModel(PlayerId(), GetHashKey("s_m_y_hwaycop_01")) for k, w in pairs(gear) do GiveWeaponToPed(GetPlayerPed(-1), w[1], 1000, false, false) end GiveWeaponComponentToPed(GetPlayerPed(-1), GetHashKey("WEAPON_COMBATPISTOL"), GetHashKey("COMPONENT_AT_PI_FLSH")) GiveWeaponComponentToPed(GetPlayerPed(-1), GetHashKey("WEAPON_PUMPSHOTGUN"), GetHashKey("COMPONENT_AT_AR_FLSH")) else chatPrint( "I can't pull my Gear out of thin air..." ) end elseif ( data == "d1" ) then ss(1) elseif ( data == "d2" ) then ss(2) elseif ( data == "d3" ) then ss(3) elseif ( data == "ds" ) then ds() elseif ( data == "togRadar" ) then if IsPedInAnyVehicle(GetPlayerPed(-1)) then togRadar() else chatPrint( "I can't pull a Radar out of thin air..." ) end elseif ( data == "cuff" ) then Citizen.CreateThread( function() AddTextEntry('FMMC_KEY_TIP1', "Enter the Civilian's ID") DisplayOnscreenKeyboard( false, "FMMC_KEY_TIP1", "", "", "", "", "", 4 ) while true do if ( UpdateOnscreenKeyboard() == 1 ) then local cuffStr = GetOnscreenKeyboardResult() if ( string.len( cuffStr ) > 0 ) then local cuff = tonumber( cuffStr ) if ( cuff < 999 and cuff >= 1 ) then local tPID = cuffStr TriggerEvent("Handcuff", tPID) end break else DisplayOnscreenKeyboard( false, "", "", "", "", "", "", 4 ) end elseif ( UpdateOnscreenKeyboard() == 2 ) then break end Citizen.Wait( 0 ) end end ) elseif ( data == "vd0" ) then if ( vd0 ) then closeDoor(0) vd0 = false else openDoor(0) vd0 = true end elseif ( data == "vd1" ) then if ( vd1 ) then closeDoor(1) vd1 = false else openDoor(1) vd1 = true end elseif ( data == "vd2" ) then if ( vd2 ) then closeDoor(2) vd2 = false else openDoor(2) vd2 = true end elseif ( data == "vd3" ) then if ( vd3 ) then closeDoor(3) vd3 = false else openDoor(3) vd3 = true end elseif ( data == "vd4" ) then if ( vd4 ) then closeDoor(4) vd5 = false else openDoor(4) vd4 = true end elseif ( data == "vd5" ) then if ( vd5 ) then closeDoor(5) vd5 = false else openDoor(5) vd5 = true end elseif ( data == "vd6" ) then if ( vd6 ) then closeDoor(6) vd6 = false else openDoor(6) vd6 = true end elseif ( data == "vd7" ) then if ( vd7) then closeDoor(7) vd7 = false else openDoor(7) vd7 = true end elseif ( data == "vdc" ) then closeAllDoors() elseif ( data == "engine" ) then toggleEngine() elseif ( data == "windows" ) then toggleWindows() elseif ( data == "exit" ) then -- We toggle the ActionMenu and return here, otherwise the function -- call below would be executed too, which would just open the menu again ToggleActionMenu() return end -- This will only be called if any button other than the exit button is pressed ToggleActionMenu() end ) --[[------------------------------------------------------------------------ ActionMenu Control and Input Blocking This is the main while loop that opens the ActionMenu on keypress. It uses the input blocking found in the ES Banking resource, credits to the authors. ------------------------------------------------------------------------]]-- Citizen.CreateThread( function() -- This is just in case the resources restarted whilst the NUI is focused. SetNuiFocus( false ) while true do -- Control ID 20 is the 'Z' key by default -- Use https://w...content-available-to-author-only...m.net/wiki/Controls to find a different key -- Now set to M if ( IsControlJustPressed( 1, 244 ) ) then ToggleActionMenu() end if ( menuEnabled ) then local ped = GetPlayerPed( -1 ) DisableControlAction( 0, 1, true ) -- LookLeftRight DisableControlAction( 0, 2, true ) -- LookUpDown DisableControlAction( 0, 24, true ) -- Attack DisablePlayerFiring( ped, true ) -- Disable weapon firing DisableControlAction( 0, 142, true ) -- MeleeAttackAlternate DisableControlAction( 0, 106, true ) -- VehicleMouseControlOverride end Citizen.Wait( 0 ) end end ) function chatPrint( msg ) TriggerEvent( 'chatMessage', "VisionaryRP", { 255, 255, 255 }, msg ) end function ss( num ) TriggerEvent( 'Spikestrips:SpawnSpikes', {isRestricted = SpikeConfig.PedRestriction, pedList = SpikeConfig.PedsList,}, num ) end function ds() TriggerEvent( 'Spikestrips:RemoveSpikes') end function togRadar() TriggerEvent( 'wk:radarRC') end function want(wea) TriggerEvent( 'PoliceVehicleWeaponDeleter:gettingAGun', wea) end function dontWant(wea) TriggerEvent( 'PoliceVehicleWeaponDeleter:notGettingAGun') end function openDoor(vd) local Veh = GetVehiclePedIsUsing(GetPlayerPed(-1)) SetVehicleDoorOpen(Veh, vd, false, false) end function closeDoor(vd) local Veh = GetVehiclePedIsUsing(GetPlayerPed(-1)) SetVehicleDoorShut(Veh, vd, false) end function closeAllDoors() local Veh = GetVehiclePedIsUsing(GetPlayerPed(-1)) SetVehicleDoorShut(Veh, 0, false) SetVehicleDoorShut(Veh, 1, false) SetVehicleDoorShut(Veh, 2, false) SetVehicleDoorShut(Veh, 3, false) SetVehicleDoorShut(Veh, 4, false) SetVehicleDoorShut(Veh, 5, false) SetVehicleDoorShut(Veh, 6, false) SetVehicleDoorShut(Veh, 7, false) end function toggleEngine() local vehicle = GetVehiclePedIsIn(PlayerPedId(), false) if vehicle ~= nil and vehicle ~= 0 and GetPedInVehicleSeat(vehicle, 0) then SetVehicleEngineOn(vehicle, (not GetIsVehicleEngineRunning(vehicle)), false, true) end end function toggleWindows() if ( togWin ) then RoleUpWindow(playerCar, 0) RoleUpWindow(playerCar, 1) RoleUpWindow(playerCar, 2) RoleUpWindow(playerCar, 3) togWin false else local playerCar = GetVehiclePedIsIn(playerPed, false) RollDownWindows(playerCar) togWin true end end function tablelength(T) local count = 0 for _ in pairs(T) do count = count + 1 end return count end --[[ Looped Thread ]]-- Citizen.CreateThread(function() while true do Citizen.Wait(0) if IsPedInAnyVehicle(GetPlayerPed(PlayerId()), false) then local vehicle = GetVehiclePedIsIn(GetPlayerPed(PlayerId()), false) local vehiclePos = GetEntityCoords(vehicle, false) local spikes = GetClosestObjectOfType(vehiclePos.x, vehiclePos.y, vehiclePos.z, 75.0, GetHashKey("P_ld_stinger_s"), false, 1, 1) local spikesCoords = GetEntityCoords(spikes, false) local distance = Vdist(vehiclePos.x, vehiclePos.y, vehiclePos.z, spikesCoords.x, spikesCoords.y, spikesCoords.z) if distance <= 75.0 then CheckDistanceToStrips() end end end end) RegisterCommand("spawn", function(source, args, string) SpawnSpikes() end, false) RegisterNetEvent("Spikestrips:SpawnSpikes") AddEventHandler("Spikestrips:SpawnSpikes", function(config, amount) if config.isRestricted then if CheckPedRestriction(GetPlayerPed(PlayerId()), config.pedList) then for a = 1, amount do local plyCoords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(PlayerId()), 0.0, 3.0 * a + 0.5, 0.0) local plyHead = GetEntityHeading(GetPlayerPed(PlayerId())) local spike = CreateObject(GetHashKey("P_ld_stinger_s"), plyCoords.x, plyCoords.y, plyCoords.z, true, 1, true) local spikeHeight = GetEntityHeightAboveGround(spike) SetEntityCoords(spike, plyCoords.x, plyCoords.y, plyCoords.z - spikeHeight + 0.05, 0.0, 0.0, 0.0, 0.0) SetEntityHeading(spike, plyHead) SetEntityAsMissionEntity(spike, 1, 1) table.insert(SpawnedSpikes, spike) SpikesSpawned = true end else chatPrint( "Where the hell am I meant to get Spike Strips from?!" ) end else for b = 1, amount do local plyCoords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(PlayerId()), 0.0, 3.0 * b + 0.5, 0.0) local plyHead = GetEntityHeading(GetPlayerPed(PlayerId())) local spike = CreateObject(GetHashKey("P_ld_stinger_s"), plyCoords.x, plyCoords.y, plyCoords.z, true, 1, true) local spikeHeight = GetEntityHeightAboveGround(spike) SetEntityCoords(spike, plyCoords.x, plyCoords.y, plyCoords.z - spikeHeight + 0.05, 0.0, 0.0, 0.0, 0.0) SetEntityHeading(spike, plyHead) SetEntityAsMissionEntity(spike, 1, 1) SetEntityCollision(spike, false, false) table.insert(SpawnedSpikes, spike) SpikesSpawned = true end end end) RegisterNetEvent("Spikestrips:RemoveSpikes") AddEventHandler("Spikestrips:RemoveSpikes", function() if SpikesSpawned then for i = 1, #SpawnedSpikes do DeleteEntity(SpawnedSpikes[i]) SpawnedSpikes[i] = nil SpikesSpawned = false end end end) function CheckDistanceToStrips() local vehicle = GetVehiclePedIsIn(GetPlayerPed(PlayerId()), false) FrontLeftTire(vehicle) FrontRightTire(vehicle) BackLeftTire(vehicle) BackRightTire(vehicle) end function FrontLeftTire(vehicle) local tirePosition = GetWorldPositionOfEntityBone(vehicle, GetEntityBoneIndexByName(vehicle, "wheel_lf")) local spikestrip = GetClosestObjectOfType(tirePosition.x, tirePosition.y, tirePosition.z, 15.0, GetHashKey("P_ld_stinger_s"), false, 1, 1) local spikeCoords = GetEntityCoords(spikestrip, false) local distance = Vdist(tirePosition.x, tirePosition.y, tirePosition.z, spikeCoords.x, spikeCoords.y, spikeCoords.z) if distance < 1.8 then if not IsVehicleTyreBurst(vehicle, 0, false) and not IsVehicleTyreBurst(vehicle, 0, true) then SetVehicleTyreBurst(vehicle, 0, false, 1000.0) end end end function FrontRightTire(vehicle) local tirePosition = GetWorldPositionOfEntityBone(vehicle, GetEntityBoneIndexByName(vehicle, "wheel_rf")) local spikestrip = GetClosestObjectOfType(tirePosition.x, tirePosition.y, tirePosition.z, 15.0, GetHashKey("P_ld_stinger_s"), false, 1, 1) local spikeCoords = GetEntityCoords(spikestrip, false) local distance = Vdist(tirePosition.x, tirePosition.y, tirePosition.z, spikeCoords.x, spikeCoords.y, spikeCoords.z) if distance < 1.8 then if not IsVehicleTyreBurst(vehicle, 1, false) and not IsVehicleTyreBurst(vehicle, 1, true) then SetVehicleTyreBurst(vehicle, 1, false, 1000.0) end end end function BackLeftTire(vehicle) local tirePosition = GetWorldPositionOfEntityBone(vehicle, GetEntityBoneIndexByName(vehicle, "wheel_lr")) local spikestrip = GetClosestObjectOfType(tirePosition.x, tirePosition.y, tirePosition.z, 15.0, GetHashKey("P_ld_stinger_s"), false, 1, 1) local spikeCoords = GetEntityCoords(spikestrip, false) local distance = Vdist(tirePosition.x, tirePosition.y, tirePosition.z, spikeCoords.x, spikeCoords.y, spikeCoords.z) if distance < 1.8 then if not IsVehicleTyreBurst(vehicle, 4, false) and not IsVehicleTyreBurst(vehicle, 4, true) then SetVehicleTyreBurst(vehicle, 4, false, 1000.0) SetVehicleTyreBurst(vehicle , 2, false, 1000.0) end end end function BackRightTire(vehicle) local tirePosition = GetWorldPositionOfEntityBone(vehicle, GetEntityBoneIndexByName(vehicle, "wheel_rr")) local spikestrip = GetClosestObjectOfType(tirePosition.x, tirePosition.y, tirePosition.z, 15.0, GetHashKey("P_ld_stinger_s"), false, 1, 1) local spikeCoords = GetEntityCoords(spikestrip, false) local distance = Vdist(tirePosition.x, tirePosition.y, tirePosition.z, spikeCoords.x, spikeCoords.y, spikeCoords.z) if distance < 1.8 then if not IsVehicleTyreBurst(vehicle, 5, false) and not IsVehicleTyreBurst(vehicle, 5, true) then SetVehicleTyreBurst(vehicle, 5, false, 1000.0) SetVehicleTyreBurst(vehicle , 3, false, 1000.0) end end end function CheckPedRestriction(ped, PedList) for i = 1, #PedList do print(tostring(GetHashKey(PedList[i]))) if GetHashKey(PedList[i]) == GetEntityModel(ped) then return true end end return false end Citizen.CreateThread(function() while true do Citizen.Wait(0) if SpikesSpawned then for i = 1, #SpawnedSpikes do FreezeEntityPosition(SpawnedSpikes[i], true) end end end end)