mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-17 05:56:01 +01:00
157 lines
4.9 KiB
Lua
157 lines
4.9 KiB
Lua
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
|
|
local coords = GetEntityCoords(ped)
|
|
if #(coords-GetEntityCoords(veh)) > 25.0 then return end
|
|
|
|
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
|
|
|
|
RegisterNetEvent("ND_Vehicles:keyFob", function(vehicleNetId)
|
|
playKeyFob(NetToVeh(vehicleNetId))
|
|
end)
|
|
|
|
local dontLock = {
|
|
[8] = true, -- Motorcycles
|
|
[13] = true, -- Cycles
|
|
[14] = true -- boats
|
|
}
|
|
|
|
AddStateBagChangeHandler("locked", nil, function(bagName, key, value, reserved, replicated)
|
|
local entity = GetEntityFromStateBagName(bagName)
|
|
if entity == 0 then return end
|
|
if dontLock[GetVehicleClass(entity)] then return end
|
|
|
|
if value then
|
|
-- SetVehicleDoorsLockedForAllPlayers(entity, true)
|
|
return SetVehicleDoorsLocked(entity, 2)
|
|
end
|
|
|
|
CreateThread(function()
|
|
while GetVehiclePedIsEntering(cache.ped) == entity do Wait(10) end
|
|
-- SetVehicleDoorsLockedForAllPlayers(entity, false)
|
|
SetVehicleDoorsLocked(entity, 0)
|
|
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)
|
|
|
|
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)
|
|
|
|
AddEventHandler("onResourceStart", function(resourceName)
|
|
if resourceName ~= "ox_inventory" or not Config.useInventoryForKeys then return end
|
|
Wait(1000)
|
|
exports.ox_inventory:displayMetadata({
|
|
vehPlate = "Plate",
|
|
vehModel = "Model"
|
|
})
|
|
end)
|