Skip to content

Commit

Permalink
Update v4.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Musiker15 committed Sep 11, 2024
1 parent 3c92f7b commit 6e3b5ee
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 189 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2.1
4.2.2
79 changes: 18 additions & 61 deletions client/client_hotwire.lua → client/hotwire.lua
Original file line number Diff line number Diff line change
@@ -1,40 +1,14 @@
if Config.EnableLockpick and Config.LockpickHotkey.enable then
RegisterCommand(Config.LockpickHotkey.command, function(source, args, rawCommand)
if Config.Framework == 'ESX' then
ESX = exports["es_extended"]:getSharedObject()

ESX.TriggerServerCallback('msk_enginetoggle:hasItem', function(hasItem)
if not hasItem then
return Config.Notification(nil, Translation[Config.Locale]['hasno_lockpick'], 'error')
end

toggleLockpick()
end, Config.LockpickSettings.item)
elseif Config.Framework == 'QBCore' then
QBCore = exports['qb-core']:GetCoreObject()

QBCore.Functions.TriggerCallback('msk_enginetoggle:hasItem', function(hasItem)
if not hasItem then
return Config.Notification(nil, Translation[Config.Locale]['hasno_lockpick'], 'error')
end

toggleLockpick()
end, Config.LockpickSettings.item)
else
-- Add your own code here
end
end)
RegisterKeyMapping(Config.LockpickHotkey.command, 'Lockpick Vehicle', 'keyboard', Config.LockpickHotkey.key)
end
local hasItem = MSK.HasItem(Config.LockpickSettings.item)

loadAnimDict = function(dict)
if not HasAnimDictLoaded(dict) then
RequestAnimDict(dict)
if not hasItem then
return Config.Notification(nil, Translation[Config.Locale]['hasno_lockpick'], 'error')
end

while not HasAnimDictLoaded(dict) do
Wait(1)
end
end
toggleLockpick()
end)
RegisterKeyMapping(Config.LockpickHotkey.command, 'Lockpick Vehicle', 'keyboard', Config.LockpickHotkey.key)
end

toggleLockpick = function()
Expand All @@ -46,28 +20,11 @@ toggleLockpick = function()

local vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 3.0, 0, 71)
if not DoesEntityExist(vehicle) then return end

local plate = GetVehicleNumberPlateText(vehicle)
local animation = {dict = Config.Animation.lockpick.dict, anim = Config.Animation.lockpick.anim}

local p = promise.new()
if Config.Framework == 'ESX' then
ESX.TriggerServerCallback('msk_enginetoggle:getAlarmStage', function(owner, alarmStage)
p:resolve({owner, alarmStage})
end, plate)
elseif Config.Framework == 'QBCore' then
QBCore.Functions.TriggerCallback('msk_enginetoggle:getAlarmStage', function(owner, alarmStage)
p:resolve({owner, alarmStage})
end, plate)
else
-- Add your own code here
end

SetTimeout(5000, function()
p:resolve({nil, 'stage_1'})
end)

local cbResult = Citizen.Await(p)
local owner, stage = table.unpack(cbResult)

local owner, stage = MSK.Trigger('msk_enginetoggle:getAlarmStage', plate)
local alarmStage = Config.SafetyStages[stage]

if alarmStage.alarm then
Expand All @@ -87,7 +44,7 @@ toggleLockpick = function()
TriggerServerEvent('msk_enginetoggle:liveCoords', owner, NetworkGetNetworkIdFromEntity(vehicle), GetEntityCoords(vehicle))
end

loadAnimDict(animation.dict)
MSK.LoadAnimDict(animation.dict)
TaskPlayAnim(playerPed, animation.dict, animation.anim, 8.0, 1.0, -1, 49, 0, false, false, false)
FreezeEntityPosition(playerPed, true)

Expand Down Expand Up @@ -128,18 +85,18 @@ toggleLockpick = function()

if success then
if GetResourceState('msk_vehiclekeys') == "started" then
exports.msk_vehiclekeys:SetVehicleLockState(vehicle, false)
exports.msk_vehiclekeys:SetVehicleLockState(vehicle, false, true) -- vehicle, state, force
else
SetVehicleDoorsLocked(vehicle, 1)
SetVehicleDoorsLockedForAllPlayers(vehicle, false)
end
FreezeEntityPosition(playerPed, false)
ClearPedTasksImmediately(playerPed)
ClearPedTasks(playerPed)
Config.Notification(nil, Translation[Config.Locale]['vehicle_unlocked'], 'success')
elseif not success then
TriggerServerEvent('msk_enginetoggle:removeLockpickItem')
FreezeEntityPosition(playerPed, false)
ClearPedTasksImmediately(playerPed)
ClearPedTasks(playerPed)
Config.Notification(nil, Translation[Config.Locale]['hotwiring_failed'], 'error')
return
end
Expand All @@ -162,7 +119,7 @@ toggleLockpick = function()
local anim = Config.Animation.searchKey.anim
local time = Config.Animation.searchKey.time * 1000

loadAnimDict(dict)
MSK.LoadAnimDict(dict)
TaskPlayAnim(playerPed, dict, anim, 8.0, 1.0, -1, 49, 0, false, false, false)
if Config.Animation.searchKey.enableProgressbar then
Config.progressBar(time, Translation[Config.Locale]['search_key'])
Expand All @@ -179,7 +136,7 @@ toggleLockpick = function()
Config.Notification(nil, Translation[Config.Locale]['hotwiring_notfoundkey'], 'error')
end

ClearPedTasksImmediately(playerPed)
ClearPedTasks(playerPed)
RemoveAnimDict(dict)
end

Expand All @@ -188,7 +145,7 @@ toggleLockpick = function()
local anim = Config.Animation.hotwire.anim
local action = Config.Animation.hotwire.action
local time = Config.Animation.hotwire.time * 1000
loadAnimDict(dict)
MSK.LoadAnimDict(dict)
TaskPlayAnim(playerPed, dict, anim, 8.0, 1.0, -1, 49, 0, false, false, false)

local success = false
Expand Down Expand Up @@ -219,7 +176,7 @@ toggleLockpick = function()
end
end

ClearPedTasksImmediately(playerPed)
ClearPedTasks(playerPed)
RemoveAnimDict(dict)

if success and Config.LockpickSettings.startEngine then
Expand Down
25 changes: 16 additions & 9 deletions client/client.lua → client/main.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
if Config.Framework == 'ESX' then
if Config.Framework == 'AUTO' then
if GetResourceState('es_extended') ~= 'missing' then
ESX = exports["es_extended"]:getSharedObject()
elseif GetResourceState('qb-core') ~= 'missing' then
QBCore = exports['qb-core']:GetCoreObject()
end
elseif Config.Framework == 'ESX' then
ESX = exports["es_extended"]:getSharedObject()
elseif Config.Framework == 'QBCore' then
QBCore = exports['qb-core']:GetCoreObject()
Expand Down Expand Up @@ -63,7 +69,7 @@ exports('toggleEngine', toggleEngine)
RegisterNetEvent('msk_enginetoggle:toggleEngine', toggleEngine)

AddEventHandler('msk_enginetoggle:enteringVehicle', function(vehicle, plate, seat, netId, isEngineOn, isDamaged)
logging('enteringVehicle', vehicle, plate, seat, netId, isEngineOn, isDamaged)
logging('debug', 'enteringVehicle', vehicle, plate, seat, netId, isEngineOn, isDamaged)
local playerPed = PlayerPedId()
local vehicleModel = GetEntityModel(vehicle)

Expand All @@ -79,7 +85,7 @@ AddEventHandler('msk_enginetoggle:enteringVehicle', function(vehicle, plate, sea
end)

AddEventHandler('msk_enginetoggle:enteredVehicle', function(vehicle, plate, seat, netId, isEngineOn, isDamaged)
logging('enteredVehicle', vehicle, plate, seat, netId, isEngineOn, isDamaged)
logging('debug', 'enteredVehicle', vehicle, plate, seat, netId, isEngineOn, isDamaged)
local playerPed = PlayerPedId()
local vehicleModel = GetEntityModel(vehicle)

Expand All @@ -97,7 +103,8 @@ AddEventHandler('msk_enginetoggle:enteredVehicle', function(vehicle, plate, seat
end)

AddEventHandler('msk_enginetoggle:exitedVehicle', function(vehicle, plate, seat, netId, isEngineOn, isDamaged)
logging('exitedVehicle', vehicle, plate, seat, netId, isEngineOn, isDamaged)
logging('debug', 'exitedVehicle', vehicle, plate, seat, netId, isEngineOn, isDamaged)
if not vehicle or not DoesEntityExist(vehicle) then return end
local playerPed = PlayerPedId()
local vehicleModel = GetEntityModel(vehicle)

Expand Down Expand Up @@ -187,7 +194,7 @@ end)

SetEngineState = function(vehicle, state, engine)
assert(vehicle and DoesEntityExist(vehicle), 'Parameter "vehicle" is nil or the Vehicle does not exist on function SetEngineState')
logging('SetEngineState', vehicle, state)
logging('debug', 'SetEngineState', vehicle, state)

currentVehicle.isEngineOn = state
Entity(vehicle).state:set('isEngineOn', state, true)
Expand Down Expand Up @@ -253,7 +260,7 @@ exports('getVehicleDamaged', GetVehicleDamaged) -- Support for old versions
GetPedVehicleSeat = function(playerPed, vehicle)
if not playerPed then playerPed = PlayerPedId() end
if not vehicle then vehicle = currentVehicle and currentVehicle.vehicle or GetVehiclePedIsIn(playerPed) end
assert(vehicle and DoesEntityExist(vehicle), 'Parameter "vehicle" is nil or the Vehicle does not exist on function GetPedVehicleSeat')
if not vehicle or not DoesEntityExist(vehicle) then return end

for i = -1, 16 do
if (GetPedInVehicleSeat(vehicle, i) == playerPed) then
Expand All @@ -273,7 +280,7 @@ disableDrive = function()
DisableControlAction(0, 71, true) -- W (accelerate)
DisableControlAction(0, 72, true) -- S (brake/reverse)

if currentVehicle then
if currentVehicle.vehicle and DoesEntityExist(currentVehicle.vehicle) then
SetVehicleUndriveable(currentVehicle.vehicle, true)
end

Expand All @@ -283,7 +290,7 @@ disableDrive = function()
disabledDrive = false
end

logging = function(...)
logging = function(code, ...)
if not Config.Debug then return end
print('[^3DEBUG^0]', ...)
MSK.Logging(code, ...)
end
File renamed without changes.
40 changes: 13 additions & 27 deletions client/client_vehiclekeys.lua → client/vehiclekeys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,30 @@ getInventory = function()
end
end

trim = function(str)
return tostring(str):gsub("%s+", "")
end

getKeyFromInventory = function(plate)
plate = MSK.Trim(plate)

if getInventory() == 'ox_inventory' then
local inventory = exports.ox_inventory:GetPlayerItems()

for k, v in pairs(inventory) do
if v.name == Config.VehicleKeys.item and trim(v.metadata[Config.VehicleKeys.plate]) == trim(plate) then
if v.name == Config.VehicleKeys.item and MSK.Trim(v.metadata.plate or v.metadata.Plate or '') == plate then
return true
end
end
elseif getInventory() == 'qs-inventory' then
local inventory = exports['qs-inventory']:getUserInventory()

for k, v in pairs(inventory) do
if v.name == Config.VehicleKeys.item and trim(v.info[Config.VehicleKeys.plate]) == trim(plate) then
if v.name == Config.VehicleKeys.item and MSK.Trim(v.info.plate or v.info.Plate or '') == plate then
return true
end
end
elseif getInventory() == 'core_inventory' then
local p = promise.new()

if Config.Framework == 'ESX' then
ESX.TriggerServerCallback('core_inventory:server:getInventory', function(inventory)
p:resolve(inventory)
end)
elseif Config.Framework == 'QBCore' then
QBCore.Functions.TriggerCallback('core_inventory:server:getInventory', function(inventory)
p:resolve(inventory)
end)
elseif Config.Framework == 'Standalone' then
-- Add your own code here
end

local inventory = Citizen.Await(p)
local inventory = MSK.Trigger('msk_enginetoggle:getInventory', 'core_inventory')

for k, v in pairs(inventory) do
if v.name == Config.VehicleKeys.item and trim(v.metadata[Config.VehicleKeys.plate]) == trim(plate) then
if v.name == Config.VehicleKeys.item and MSK.Trim(v.metadata.plate or v.metadata.Plate or '') == plate then
return true
end
end
Expand All @@ -66,12 +50,14 @@ getIsKeyOwner = function(vehicle)
local canToggleEngine = true

if not Config.VehicleKeys.uniqueItems then
if Config.VehicleKeys.script == 'VehicleKeyChain' and (GetResourceState("VehicleKeyChain") == "started") then
if Config.VehicleKeys.script == 'msk_vehiclekeys' and (GetResourceState("msk_vehiclekeys") == "started") then
isKeyOwner = exports["msk_vehiclekeys"]:HasPlayerKeyOrIsVehicleOwner(vehicle)
elseif Config.VehicleKeys.script == 'VehicleKeyChain' and (GetResourceState("VehicleKeyChain") == "started") then
isKeyOwner = exports["VehicleKeyChain"]:IsVehicleOrKeyOwner(vehicle)
elseif Config.VehicleKeys.script == 'vehicle_keys' and (GetResourceState("vehicle_keys") == "started") then
isKeyOwner = exports["vehicle_keys"]:doesPlayerOwnPlate(plate)
elseif Config.VehicleKeys.script == 'msk_vehiclekeys' and (GetResourceState("msk_vehiclekeys") == "started") then
isKeyOwner = exports["msk_vehiclekeys"]:HasPlayerKeyOrIsVehicleOwner(vehicle)
elseif Config.VehicleKeys.script == 'wasabi_carlock' and (GetResourceState("wasabi_carlock") == "started") then
isKeyOwner = exports.wasabi_carlock:HasKey(plate)
else
-- Add your own code here
end
Expand All @@ -80,14 +66,14 @@ getIsKeyOwner = function(vehicle)
end

for k, v in pairs(Config.Whitelist.vehicles) do
if GetHashKey(v) == GetEntityModel(vehicle) then
if GetEntityModel(vehicle) == IsModelValid(v) and v or GetHashKey(v) then
ignoreVehicle = true
break
end
end

for k, v in pairs(Config.Whitelist.plates) do
if string.find(trim(plate), trim(v)) then
if string.find(MSK.Trim(plate), MSK.Trim(v)) then
ignorePlate = true
break
end
Expand Down
20 changes: 10 additions & 10 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Config.Locale = 'de'
Config.Debug = true
Config.VersionChecker = true
----------------------------------------------------------------
-- Supported Frameworks: 'ESX', 'QBCore'
Config.Framework = 'ESX'
-- Supported Frameworks: AUTO, ESX, QBCore
Config.Framework = 'AUTO'
----------------------------------------------------------------
-- !!! This function is clientside AND serverside !!!
Config.Notification = function(source, message, typ)
if IsDuplicityVersion() then -- serverside
exports.msk_core:Notification(source, 'Engine', message, typ)
MSK.Notification(source, 'Engine', message, typ)
else -- clientside
exports.msk_core:Notification('Engine', message, typ)
MSK.Notification('Engine', message, typ)
end
end
----------------------------------------------------------------
Expand Down Expand Up @@ -48,15 +48,14 @@ Config.EngineFromSecondSeat = false
Config.VehicleKeys = {
enable = true, -- Set true to enable this feature

-- Supported Scripts: 'msk_vehiclekeys', 'VehicleKeyChain', 'vehicle_keys', 'okokGarage'
-- Supported Scripts: 'msk_vehiclekeys', 'VehicleKeyChain', 'vehicle_keys', 'okokGarage', 'wasabi_carlock'
script = 'msk_vehiclekeys',

-- This is for inventories with metadata like ox_inventory
-- Supported Inventories: ox_inventory, qs-inventory, core_inventory
-- For okokGarage you have to set this to true!
uniqueItems = false, -- If set to true, it will search for the item in the inventory
item = 'keys', -- Item in your inventory for vehicle keys
plate = 'plate' -- Metadata Keyname for "plate" in your inventory
}
----------------------------------------------------------------
Config.SaveSteeringAngle = true
Expand All @@ -66,17 +65,18 @@ Config.SaveAngleOnExit = 75 -- default: F - 75 (Exit Vehicle)
-- either exact plates or just a string that should be in the vehicles plate e.g. "ESX" will ignore te plate "ESX1234" too
Config.Whitelist = {
vehicles = {
"caddy", "caddy2",
-- Please use `` and NOT '' or ""
`caddy`, `caddy2`, `caddy3`, `airtug`, `docktug`, `forklift`, `mower`, `tractor2`,
},
plates = {
"ESX", "MSK",
"ESX", "MSK", "Test"
},
}
----------------------------------------------------------------
Config.EnableLockpick = true -- Set false if you want to deactivate this feature

Config.progressBar = function(time, message)
exports.msk_core:ProgressStart(time, message)
MSK.Progressbar(time, message)
end

Config.LockpickHotkey = {
Expand Down Expand Up @@ -176,7 +176,7 @@ Config.Animation = {
hotwire = { -- Animation for hotwire
dict = 'veh@forklift@base',
anim = 'hotwire',
action = 'progressbar', -- Set to 'skillbar' or 'progressbar' // skillbar might cause the player to get out of the vehicle...
action = 'skillbar', -- Set to 'skillbar' or 'progressbar'
time = 15, -- in seconds // How long does it take to hotwire the vehicle // Only for 'progressbar'
}
}
Loading

0 comments on commit 6e3b5ee

Please sign in to comment.