Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/SOH69/mm_carkeys
Browse files Browse the repository at this point in the history
  • Loading branch information
SOH69 committed May 4, 2024
2 parents f20c43e + 00bb18d commit 9b6335f
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 12 deletions.
34 changes: 34 additions & 0 deletions bridge/framework/ox.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
if Shared.Framework == 'ox' then
local KeyManagement = require 'client.modules.keys'
local VehicleKeys = require 'client.interface'

local function setupData()
VehicleKeys.currentVehicle = cache.vehicle and cache.vehicle or 0
if cache.vehicle then
VehicleKeys.isInDrivingSeat = GetPedInVehicleSeat(cache.vehicle, -1) == cache.ped
VehicleKeys.currentVehiclePlate = GetVehicleNumberPlateText(cache.vehicle)
end
end

RegisterNetEvent('ox:playerLoaded', function()
KeyManagement:SetVehicleKeys()
VehicleKeys:Thread()
VehicleKeys:Init()
end)

AddEventHandler('onResourceStart', function(resource)
if GetCurrentResourceName() == resource and player then
setupData()
KeyManagement:SetVehicleKeys()
VehicleKeys:Thread()
VehicleKeys:Init()
end
end)

AddEventHandler('ox_inventory:updateInventory', function()
KeyManagement:SetVehicleKeys()
VehicleKeys:Init()
end)

exports.ox_inventory:displayMetadata({platestxt = 'Vehicle Plates'})
end
18 changes: 11 additions & 7 deletions client/modules/keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function KeyManagement:GetKeys()
end)
end

function KeyManagement:ToggleVehicleLock(vehicle)
function KeyManagement:ToggleVehicleLock(vehicle, remote)
lib.requestAnimDict("anim@mp_player_intmenu@key_fob@")
TaskPlayAnim(cache.ped, 'anim@mp_player_intmenu@key_fob@', 'fob_click', 3.0, 3.0, -1, 49, 0, false, false, false)
TriggerServerEvent("InteractSound_SV:PlayWithinDistance", 5, "lock", 0.3)
Expand All @@ -49,12 +49,16 @@ function KeyManagement:ToggleVehicleLock(vehicle)
type = 'success'
})
end
SetVehicleLights(vehicle, 2)
Wait(250)
SetVehicleLights(vehicle, 1)
Wait(200)
SetVehicleLights(vehicle, 0)
Wait(300)

if remote or not Shared.toggleLightsOnlyRemote then
SetVehicleLights(vehicle, 2)
Wait(250)
SetVehicleLights(vehicle, 1)
Wait(200)
SetVehicleLights(vehicle, 0)
Wait(300)
end

ClearPedTasks(cache.ped)
end

Expand Down
14 changes: 12 additions & 2 deletions client/modules/steal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,19 @@ function Steal:CarjackVehicle(target)
TaskPlayAnim(cache.ped, "mp_common", "givetake1_b", 8.0, -8, -1, 12, 1, false, false, false)
TaskPlayAnim(target, "mp_common", "givetake1_b", 8.0, -8, -1, 12, 1, false, false, false)
local targetPos = GetEntityCoords(target)
TaskWanderInArea(target, targetPos.x, targetPos.y, targetPos.z, 5.0, 5.0, 5.0)
TaskSmartFleePed(target, cache.ped, 50, -1, false, false)
TriggerServerEvent('hud:server:GainStress', Shared.steal.stressIncrease)
TriggerServerEvent('mm_carkeys:server:acquiretempvehiclekeys', GetVehicleNumberPlateText(vehicle))
TriggerServerEvent('mm_carkeys:server:setVehLockState', NetworkGetNetworkIdFromEntity(vehicle), 1)

local plate = GetVehicleNumberPlateText(vehicle)
local modelName = GetDisplayNameFromVehicleModel(GetEntityModel(vehicle))
if Shared.steal.getKey then
TriggerServerEvent('mm_carkeys:server:acquirevehiclekeys', plate, modelName)
else
TriggerServerEvent('mm_carkeys:server:acquiretempvehiclekeys', plate)
end


else
StopAnimTask(target, "missminuteman_1ig_2", "handsup_base", 1.0)
self.isCarjacking = false
Expand Down
2 changes: 2 additions & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ shared_scripts {
}

client_scripts {
'@ox_core/imports/client.lua', -- Can be commented in case not using ox_core to prevent warning on startup
'bridge/framework/*.lua',
'client/init.lua'
}

server_scripts {
'@ox_core/imports/server.lua', -- Can be commented in case not using ox_core to prevent warning on startup
'server/commands.lua',
'server/server.lua'
}
Expand Down
8 changes: 8 additions & 0 deletions server/bridge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ function Bridge:GetPlayerCitizenId(id)
elseif Shared.Framework == 'esx' then
local xPlayer = ESX.GetPlayerFromId(id)
return xPlayer.getIdentifier()
elseif Shared.Framework == 'ox' then
local player = Ox.GetPlayer(id)
return player.charId
end
end

Expand All @@ -20,6 +23,8 @@ function Bridge:GetPlayer(id)
return QBCore.Functions.GetPlayer(id)
elseif Shared.Framework == 'esx' then
return ESX.GetPlayerFromId(id)
elseif Shared.Framework == 'ox' then
return Ox.GetPlayer(id)
end
end

Expand All @@ -30,6 +35,9 @@ function Bridge:GetPlayerJob(id)
elseif Shared.Framework == 'esx' then
local xPlayer = ESX.GetPlayerFromId(id)
return xPlayer.getJob().name
elseif Shared.Framework == 'ox' then
local player = Ox.GetPlayer(id)
return player.getGroups()
end
end

Expand Down
6 changes: 3 additions & 3 deletions server/commands.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local Bridge = require 'server.bridge'

lib.addCommand('givetempkeys', {
help = 'Remove Temporary Keys',
help = 'Give Temporary Keys',
params = {
{
name = 'target',
Expand Down Expand Up @@ -72,7 +72,7 @@ lib.addCommand('givekeys', {
}, function(source)
local src = source
local playerJob = Bridge:GetPlayerJob(src)
if playerJob == "police" or playerJob == "cardealer" or IsPlayerAceAllowed(src, "admin") then
if playerJob == "police" or playerJob == "cardealer" or IsPlayerAceAllowed(src, "admin") or playerJob['police'] or playerJob['cardealer'] then
TriggerClientEvent('mm_carkeys:client:givekeyitem', src)
return
end
Expand All @@ -90,7 +90,7 @@ lib.addCommand('removekeys', {
}, function(source)
local src = source
local playerJob = Bridge:GetPlayerJob(src)
if playerJob == "police" or playerJob == "cardealer" or IsPlayerAceAllowed(src, "admin") then
if playerJob == "police" or playerJob == "cardealer" or IsPlayerAceAllowed(src, "admin") or playerJob['police'] or playerJob['cardealer'] then
TriggerClientEvent('mm_carkeys:client:removekeyitem', src)
return
end
Expand Down
2 changes: 2 additions & 0 deletions shared/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ elseif GetResourceState('qbx_core') == 'started' then -- change your core script
Shared.Framework = 'qbx' -- dont touch this
elseif GetResourceState('es_extended') == 'started' then -- change your core script
Shared.Framework = 'esx' -- dont touch this
elseif GetResourceState('ox_core') == 'started' then -- change your core script
Shared.Framework = 'ox' -- dont touch this
else
Shared.Framework = false
Shared.Ready = false
Expand Down
2 changes: 2 additions & 0 deletions shared/shared.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Shared = {
LockNPCVehicle = true, -- lock all npc vehicles
playerDraggable = true, -- allow players to drag other players
toggleLightsOnlyRemote = true, -- true if you want the vehicle lights to toggle only when not in the vehicle
keepVehicleEngineOn = true, -- keep the engine on when exiting a vehicle
steal = {
available = true, -- allow players to carjack vehicles
getKey = true, -- if true you get a permanent instead of a temporary key
label = 'Stealing Vehicle...',
minTime = 5000,
maxTime = 7000,
Expand Down

0 comments on commit 9b6335f

Please sign in to comment.