Skip to content

Commit

Permalink
Update v4.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Musiker15 committed Oct 28, 2024
1 parent 13118b5 commit f88e448
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 131 deletions.
17 changes: 7 additions & 10 deletions client/hotwire.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ if Config.EnableLockpick and Config.LockpickHotkey.enable then
end

toggleLockpick = function()
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local playerPed = MSK.Player.ped
local coords = MSK.Player.coords

if IsPedInAnyVehicle(playerPed, false) then return end
if not IsAnyVehicleNearPoint(coords.x, coords.y, coords.z, 5.0) then return end
Expand Down Expand Up @@ -110,8 +110,8 @@ toggleLockpick = function()
TaskEnterVehicle(playerPed, vehicle, 10.0, -1, 1.0, 1, 0)
Wait(5000)

local playerPed = PlayerPedId()
local vehicle = GetVehiclePedIsIn(playerPed)
local playerPed = MSK.Player.ped
local vehicle = MSK.Player.vehicle
local plate = GetVehicleNumberPlateText(vehicle)

if Config.VehicleKeys.enable or Config.LockpickSettings.enableSearchKey then
Expand Down Expand Up @@ -193,14 +193,11 @@ exports('toggleHotwire', toggleLockpick) -- Support for old Versions
RegisterNetEvent('msk_enginetoggle:toggleLockpick', toggleLockpick)

RegisterNetEvent('msk_enginetoggle:installAlarmStage', function(stage)
local playerPed = PlayerPedId()

if not IsPedInAnyVehicle(playerPed, false) then
Config.Notification(nil, Translation[Config.Locale]['sit_in_vehicle'], 'error')
return
if not IsPedInAnyVehicle(MSK.Player.ped, false) then
return Config.Notification(nil, Translation[Config.Locale]['sit_in_vehicle'], 'error')
end

local vehicle = GetVehiclePedIsIn(playerPed)
local vehicle = MSK.Player.vehicle
local plate = GetVehicleNumberPlateText(vehicle)

Config.progressBar(1000 * 15, Translation[Config.Locale]['install_alarm'])
Expand Down
46 changes: 27 additions & 19 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,37 @@ if Config.Command.enable then
end

toggleEngine = function(bypass)
local playerPed = PlayerPedId()
local playerPed = MSK.Player.ped
local canToggleEngine = true

if not IsPedInAnyVehicle(playerPed) then return end
local vehicle = GetVehiclePedIsIn(playerPed)
local vehicle = MSK.Player.vehicle

if not Config.EngineFromSecondSeat and GetPedInVehicleSeat(vehicle, -1) ~= playerPed then return end

if Config.EngineFromSecondSeat then
if IsVehicleSeatFree(vehicle, -1) then return end

if playerPed ~= GetPedInVehicleSeat(vehicle, -1) and playerPed ~= GetPedInVehicleSeat(vehicle, 0) then
return
end

if IsVehicleSeatFree(vehicle, -1) then return end
end

if GetVehicleDamaged(vehicle) then
return Config.Notification(nil, Translation[Config.Locale]['veh_is_damaged'], 'error')
end

if IsAnyWheelClamped(vehicle) then
return Config.Notification(nil, Translation[Config.Locale]['vehicle_wheel_clamped'], 'error')
end

-- Cheat protection, remove this if you don't care
if bypass then
if not MSK.IsAceAllowed(Config.AdminCommand.command) then
return Config.Notification(nil, 'You don\'t have permission to bypass the engine start/stop!', 'error')
end
end
-- Cheat protection, remove this if you don't care

if not bypass then
local isBlacklisted = IsVehicleBlacklisted(vehicle)
Expand Down Expand Up @@ -83,7 +95,7 @@ RegisterNetEvent('msk_enginetoggle:toggleEngine', toggleEngine)

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

if seat == -1 and not isEngineOn then
Expand All @@ -99,7 +111,7 @@ end)

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

if seat == -1 and not isEngineOn then
Expand All @@ -118,7 +130,7 @@ end)
AddEventHandler('msk_enginetoggle:exitedVehicle', function(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 playerPed = MSK.Player.ped
local vehicleModel = GetEntityModel(vehicle)

if seat == -1 and not isEngineOn then
Expand All @@ -129,7 +141,7 @@ end)
CreateThread(function()
while true do
local sleep = 500
local playerPed = PlayerPedId()
local playerPed = MSK.Player.ped
local vehiclePool = GetGamePool('CVehicle')

for i = 1, #vehiclePool do
Expand Down Expand Up @@ -163,7 +175,7 @@ end)
CreateThread(function()
while true do
local sleep = 200
local playerPed = PlayerPedId()
local playerPed = MSK.Player.ped

if not isInVehicle and not IsPlayerDead(PlayerId()) then
if DoesEntityExist(GetVehiclePedIsTryingToEnter(playerPed)) and not isEnteringVehicle then
Expand All @@ -183,7 +195,7 @@ CreateThread(function()
elseif IsPedInAnyVehicle(playerPed, false) then
isEnteringVehicle = false
isInVehicle = true
currentVehicle.vehicle = GetVehiclePedIsIn(playerPed)
currentVehicle.vehicle = GetVehiclePedIsIn(playerPed, false)
currentVehicle.plate = GetVehicleNumberPlateText(currentVehicle.vehicle)
currentVehicle.seat = GetPedVehicleSeat(playerPed, currentVehicle.vehicle)
currentVehicle.netId = VehToNet(currentVehicle.vehicle)
Expand Down Expand Up @@ -226,7 +238,7 @@ exports('SetEngineState', SetEngineState) -- Do not use this Export if you don't
RegisterNetEvent('msk_enginetoggle:setEngineState', SetEngineState) -- Do not use this Event if you don't know what you are doing!!!

GetEngineState = function(vehicle)
if not vehicle then vehicle = GetVehiclePedIsIn(PlayerPedId()) end
if not vehicle then vehicle = MSK.Player.vehicle end
assert(vehicle and DoesEntityExist(vehicle), 'Parameter "vehicle" is nil or the Vehicle does not exist on function GetEngineState')

if Entity(vehicle).state.isEngineOn == nil then
Expand All @@ -235,7 +247,6 @@ GetEngineState = function(vehicle)
return Entity(vehicle).state.isEngineOn
end
exports('GetEngineState', GetEngineState)
exports('getEngineState', GetEngineState) -- Support for old versions

SetVehicleDamaged = function(vehicle, state)
assert(vehicle and DoesEntityExist(vehicle), 'Parameter "vehicle" is nil or the Vehicle does not exist on function SetVehicleDamaged')
Expand All @@ -246,20 +257,18 @@ SetVehicleDamaged = function(vehicle, state)
if state then
SetEngineState(vehicle, false, true)

local playerPed = PlayerPedId()
if IsPedInAnyVehicle(playerPed) then
if vehicle == GetVehiclePedIsIn(playerPed) then
if IsPedInAnyVehicle(MSK.Player.ped) then
if vehicle == MSK.Player.vehicle then
CreateThread(disableDrive)
end
end
end
end
exports('SetVehicleDamaged', SetVehicleDamaged)
exports('setVehicleDamaged', SetVehicleDamaged) -- Support for old versions
RegisterNetEvent('msk_enginetoggle:setVehicleDamaged', SetVehicleDamaged)

GetVehicleDamaged = function(vehicle)
if not vehicle then vehicle = GetVehiclePedIsIn(PlayerPedId()) end
if not vehicle then vehicle = MSK.Player.vehicle end
assert(vehicle and DoesEntityExist(vehicle), 'Parameter "vehicle" is nil or the Vehicle does not exist on function GetVehicleDamaged')

if Entity(vehicle).state.isDamaged == nil then
Expand All @@ -268,13 +277,12 @@ GetVehicleDamaged = function(vehicle)
return Entity(vehicle).state.isDamaged
end
exports('GetVehicleDamaged', GetVehicleDamaged)
exports('getVehicleDamaged', GetVehicleDamaged) -- Support for old versions

disableDrive = function()
if disabledDrive then return end
disabledDrive = true

while isInVehicle and disabledDrive and GetPedVehicleSeat() == -1 and not currentVehicle.isEngineOn do
while isInVehicle and disabledDrive and MSK.Player.seat == -1 and not currentVehicle.isEngineOn do
local sleep = 1

DisableControlAction(0, 71, true) -- W (accelerate)
Expand Down
7 changes: 3 additions & 4 deletions client/steeringwheel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ if Config.SaveSteeringAngle then
CreateThread(function()
while true do
local sleep = 500
local playerPed = PlayerPedId()

if isInVehicle and GetPedVehicleSeat(playerPed) == -1 then
if isInVehicle and MSK.Player.seat == -1 then
sleep = 1

if IsControlJustPressed(0, Config.SaveAngleOnExit) then
local vehicle = currentVehicle and currentVehicle.vehicle or GetVehiclePedIsIn(playerPed)
local vehicle = currentVehicle and currentVehicle.vehicle or MSK.Player.vehicle
local steeringAngle = GetVehicleSteeringAngle(vehicle)

while not IsControlJustReleased(0, Config.SaveAngleOnExit) do
Expand All @@ -35,7 +34,7 @@ end
exports('SetSteeringAngle', SetSteeringAngle)

GetSteeringAngle = function(vehicle)
if not vehicle then vehicle = GetVehiclePedIsIn(PlayerPedId()) end
if not vehicle then vehicle = MSK.Player.vehicle end
assert(vehicle and DoesEntityExist(vehicle), 'Parameter "vehicle" is nil or the Vehicle does not exist on function GetSteeringAngle')

if Entity(vehicle).state.SteeringAngle == nil then
Expand Down
17 changes: 15 additions & 2 deletions client/utils.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
GetPedVehicleSeat = function(playerPed, vehicle)
if not playerPed then playerPed = PlayerPedId() end
if not vehicle then vehicle = currentVehicle and currentVehicle.vehicle or GetVehiclePedIsIn(playerPed) end
if not playerPed then playerPed = MSK.Player.ped end
if not vehicle then vehicle = currentVehicle and currentVehicle.vehicle or MSK.Player.vehicle or GetVehiclePedIsIn(playerPed, false) end
if not vehicle or not DoesEntityExist(vehicle) then return end

if vehicle == MSK.Player.vehicle then
return MSK.Player.seat
end

for i = -1, 16 do
if (GetPedInVehicleSeat(vehicle, i) == playerPed) then
return i
end
end

return -1
end

Expand Down Expand Up @@ -65,4 +70,12 @@ IsVehicleBlacklisted = function(vehicle)
return true
end
end
end

IsAnyWheelClamped = function(vehicle)
if not Config.VehicleClamp or GetResourceState('VehicleClamp') ~= 'started' then
return false
end

return exports["VehicleClamp"]:IsAnyWheelClamped(vehicle)
end
15 changes: 8 additions & 7 deletions client/vehiclekeys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,31 @@ getInventory = function()
elseif (GetResourceState("core_inventory") == "started") then
return 'core_inventory'
end

return false
end

getKeyFromInventory = function(plate)
plate = MSK.String.Trim(plate, true)
local inv = getInventory()

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

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

for k, v in pairs(inventory) do
if v.name == Config.VehicleKeys.item and MSK.String.Trim(v.info.plate or v.info.Plate or '', true) == plate then
return true
end
end
elseif getInventory() == 'core_inventory' then
elseif inv == 'core_inventory' then
local inventory = MSK.Trigger('msk_enginetoggle:getInventory', 'core_inventory')

for k, v in pairs(inventory) do
Expand All @@ -45,10 +48,10 @@ exports('getKeyFromInventory', getKeyFromInventory)

getIsKeyOwner = function(vehicle)
if not Config.VehicleKeys.enable then return true end
local isKeyOwner, ignoreVehicle, ignorePlate = false, false, false
local plate = GetVehicleNumberPlateText(vehicle)
local isKeyOwner = getKeyFromInventory(plate)

if not Config.VehicleKeys.uniqueItems then
if not isKeyOwner 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
Expand All @@ -62,8 +65,6 @@ getIsKeyOwner = function(vehicle)
else
-- Add your own code here
end
else
isKeyOwner = getKeyFromInventory(plate)
end

return isKeyOwner
Expand Down
10 changes: 4 additions & 6 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ Config.VehicleKeys = {
-- Supported Scripts: 'msk_vehiclekeys', 'VehicleKeyChain', 'vehicles_keys', 'okokGarage', 'wasabi_carlock', 'qs-vehiclekeys'
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
-- For msk_vehiclekeys you have to set this to false
uniqueItems = false, -- If set to true, it will search for the item in the inventory
-- For uniqueItems in ox_inventory, qs-inventory or core_inventory
item = 'keys', -- Item in your inventory for vehicle keys
}
----------------------------------------------------------------
Config.VehicleClamp = GetResourceState('VehicleClamp') ~= 'missing'
----------------------------------------------------------------
Config.SaveSteeringAngle = true
Config.SaveAngleOnExit = 75 -- default: F - 75 (Exit Vehicle)
----------------------------------------------------------------
Expand Down Expand Up @@ -93,7 +91,7 @@ Config.Blacklist = {
Config.EnableLockpick = true -- Set false if you want to deactivate this feature

Config.progressBar = function(time, message)
MSK.Progressbar(time, message)
MSK.Progress.Start(time, message)
end

Config.LockpickHotkey = {
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ games { 'gta5' }
author 'Musiker15 - MSK Scripts'
name 'msk_enginetoggle'
description 'EngineToggle for Vehicles'
version '4.3.2'
version '4.3.3'

lua54 'yes'

Expand Down
26 changes: 7 additions & 19 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,13 @@ GetPlayerJob = function(Player)
end

if Config.AdminCommand.enable then
local allowedGroups = Config.AdminCommand.groups

for i = 1, #allowedGroups do
ExecuteCommand(('add_ace group.%s command.%s allow'):format(allowedGroups[i], Config.AdminCommand.command))
end

local isAceAllowed = function(playerId, command)
return IsPlayerAceAllowed(playerId, ('command.%s'):format(command))
end

RegisterCommand(Config.AdminCommand.command, function(source, args, rawCommand)
local src = source

if not isAceAllowed(src, Config.AdminCommand.command) then
return Config.Notification(src, 'You don\'t have permission to do that!', 'error')
end

TriggerClientEvent('msk_enginetoggle:toggleEngine', src, true)
end)
MSK.RegisterCommand(Config.AdminCommand.command, function(source, args, raw)
TriggerClientEvent('msk_enginetoggle:toggleEngine', source, true)
end, {
allowConsole = false,
restricted = Config.AdminCommand.groups,
help = 'Toggle Engine as an Admin',
})
end

RegisterNetEvent('msk_enginetoggle:addTempKey', function(plate, model)
Expand Down
Loading

0 comments on commit f88e448

Please sign in to comment.