Files
ND_Core/client/vehicle.lua

156 lines
4.9 KiB
Lua
Raw Normal View History

2023-07-16 16:33:58 +02:00
local function getVehicleBlipSprite(entity)
if not IsEntityAVehicle(entity) then
return 148 -- circle blip
end
local class = GetVehicleClass(entity)
local model = GetEntityModel(entity)
local classBlip = {
[16] = 423, -- plane
[8] = 226, -- motorcycle
[15] = 64, -- helicopter
[14] = 427, -- boat
[6] = 825, -- sports
[7] = 523, -- super
[2] = 821, -- SUV
[4] = 663 -- muscle
}
local typeBlip = {
[`seashark`] = 471,
[`marquis`] = 410,
[`rhino`] = 421,
[`hydra`] = 424,
[`lazer`] = 424,
[`taxi`] = 198,
[`trash`] = 318,
[`trash2`] = 318
}
return typeBlip[model] or classBlip[class] or 225 -- 255 is default car blip
end
RegisterNetEvent("ND_Vehicles:blip", function(netid, status)
local veh = NetToVeh(netid)
if not veh then return end
if not status then
local blip = GetBlipFromEntity(veh)
if not blip or not DoesBlipExist(blip) then return end
return RemoveBlip(blip)
end
local blip = AddBlipForEntity(veh)
SetBlipSprite(blip, getVehicleBlipSprite(veh))
SetBlipColour(blip, 0)
SetBlipScale(blip, 0.8)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentSubstringPlayerName("Personal vehicle")
EndTextCommandSetBlipName(blip)
end)
RegisterNetEvent("ND_Vehicles:syncAlarm", function(netid, success, action)
local veh = NetToVeh(netid)
if not veh then return end
SetVehicleAlarmTimeLeft(veh, 1)
SetVehicleAlarm(veh, true)
StartVehicleAlarm(veh)
if success and action == "lockpick" then
setVehicleLocked(veh, false)
end
end)
RegisterNetEvent("ND_VehicleSystem:setOwnedIfNot", function(netid)
local veh = NetToVeh(netid)
if not veh then return end
setVehicleOwned(veh, true)
setVehicleLocked(veh, true)
end)
AddStateBagChangeHandler("props", nil, function(bagName, key, value, reserved, replicated)
local entity = GetEntityFromStateBagName(bagName)
if entity == 0 or not value then return end
lib.setVehicleProperties(entity, value)
end)
local function playKeyFob(veh)
local keyFob
local ped = cache.ped
2023-07-22 21:42:45 +02:00
local coords = GetEntityCoords(ped)
if #(coords-GetEntityCoords(veh)) > 25.0 then return end
2023-07-16 16:33:58 +02:00
if GetVehiclePedIsIn(ped) == 0 then
ClearPedTasks(ped)
lib.requestAnimDict("anim@mp_player_intmenu@key_fob@")
TaskPlayAnim(ped, "anim@mp_player_intmenu@key_fob@", "fob_click_fp", 8.0, 8.0, -1, 48, 1, false, false, false)
keyFob = CreateObject(`lr_prop_carkey_fob`, 0, 0, 0, true, true, true)
AttachEntityToEntity(keyFob, ped, GetPedBoneIndex(ped, 0xDEAD), 0.12, 0.04, -0.025, -100.0, 100.0, 0.0, true, true, false, true, 1, true)
Wait(700)
end
PlaySoundFromEntity(-1, "Remote_Control_Fob", ped, "PI_Menu_Sounds", true, 0)
SetVehicleLights(veh, 2)
Wait(100)
SetVehicleLights(veh, 0)
Wait(200)
SetVehicleLights(veh, 2)
Wait(100)
SetVehicleLights(veh, 0)
return keyFob and DeleteEntity(keyFob)
end
2023-07-22 21:42:45 +02:00
RegisterNetEvent("ND_Vehicles:keyFob", function(vehicleNetId)
playKeyFob(NetToVeh(vehicleNetId))
end)
2023-07-22 21:43:22 +02:00
local dontLock = {
[8] = true, -- Motorcycles
[13] = true, -- Cycles
[14] = true -- boats
}
2023-07-16 16:33:58 +02:00
AddStateBagChangeHandler("locked", nil, function(bagName, key, value, reserved, replicated)
local entity = GetEntityFromStateBagName(bagName)
if entity == 0 then return end
2023-07-22 21:43:22 +02:00
if dontLock[GetVehicleClass(entity)] then return end
2023-07-16 16:33:58 +02:00
if value then
2023-07-22 21:43:22 +02:00
-- SetVehicleDoorsLockedForAllPlayers(entity, true)
2023-07-16 16:33:58 +02:00
return SetVehicleDoorsLocked(entity, 2)
end
CreateThread(function()
2023-07-22 21:43:22 +02:00
while GetVehiclePedIsEntering(cache.ped) == entity do Wait(10) end
-- SetVehicleDoorsLockedForAllPlayers(entity, false)
SetVehicleDoorsLocked(entity, 0)
2023-07-16 16:33:58 +02:00
end)
end)
lib.callback.register("ND_Vehicles:getProps", function()
return lib.getVehicleProperties(GetVehiclePedIsIn(cache.ped))
end)
lib.callback.register("ND_Vehicles:getNearbyVehicleById", function(vehId)
local coords = GetEntityCoords(cache.ped)
local vehicles = lib.getNearbyVehicles(coords, 25.0, true)
for i=1, #vehicles do
local veh = vehicles[i]
local state = Entity(veh).state
if state and state.id == vehId then
return VehToNet(veh)
end
end
end)
2023-07-22 21:42:45 +02:00
lib.callback.register("ND_Vehicles:getVehicleModelMakeLabel", function(model)
local make = GetLabelText(GetMakeNameFromVehicleModel(model))
local name = GetLabelText(GetDisplayNameFromVehicleModel(model))
return ("%s %s"):format(make, name)
end)
2023-07-22 21:43:04 +02:00
SetTimeout(1000, function()
if GetResourceState("ox_inventory") ~= "started" or not Config.useInventoryForKeys then return end
exports.ox_inventory:displayMetadata({
vehPlate = "Plate",
vehModel = "Model"
})
end)