Light Bars

We are finding that people are stealing other peoples cars and now able to use the light script even when they shouldn’t have permission. They cannot edit the lights or add new ones… but they can still drive around with cars that have the lights and use them with keybinds - and its a problem :frowning: but I don’t think its the end of the world or anything. If someones car is stolen then so be it lol. But…


An idea/suggestion:

Is it possible to save with user only? Not plate? OR alternatively

If it is possible, maybe we have something that checks the permission based on who the user is. If the user does not have permission… then it kicks them out of the car. Much like how Ace Perms work only in this case its not ace perms its your script telling the identifier.

For example here is client code from a customized vehicle restriction script (Badger Vehicle Restrictions) that maybe could work if integrated to use your script’s identifier instead of ace perms in this case:

restrictions = Config.VehicleRestrictions;
myRoles = nil;

RegisterNetEvent("BadgerVehicles:CheckPermission:Return")
AddEventHandler("BadgerVehicles:CheckPermission:Return", function(roles)
    myRoles = roles;
end)

lastChecked = nil;
hasPerm = nil;
Citizen.CreateThread(function()
    TriggerServerEvent("BadgerVehicles:CheckPermission");
    while true do
        Citizen.Wait(1000)

		local ped = PlayerPedId()
		local veh = nil

		if IsPedInAnyVehicle(ped, false) then
			veh = GetVehiclePedIsUsing(ped)
		else
			veh = GetVehiclePedIsTryingToEnter(ped)
        end
        local model = GetEntityModel(veh)
        if (model ~= nil) then 
            local driver = GetPedInVehicleSeat(veh, -1)
            if (lastChecked ~= nil) and (lastChecked == model) and (hasPerm ~= nil) and (not hasPerm) then 
                if driver == ped then
                    ShowInfo(Config.RestrictedMessage)
--                    DeleteEntity(veh)
					local player = PlayerPedId()
					local vehicle = GetVehiclePedIsIn(player, false)
					local flag = 256 -- This number can be changed to dictate how the ped leaves the vehicle
					TaskLeaveVehicle(player, vehicle, flag)
                    ClearPedTasksImmediately(ped)
                end
                print("[DiscordVehicleRestrictions] Vehicle was last checked, but is not a driver...")
            end
        end
		
        if veh ~= nil and DoesEntityExist(veh) and lastChecked ~= model then
            local driver = GetPedInVehicleSeat(veh, -1)
			-- Check if it has one of the restricted vehicles
            local requiredPerm = nil;
            hasPerm = false;
            for role, val in pairs(myRoles) do 
                if (val == true) then 
                    local vehicles = Config.VehicleRestrictions[role];
                    for i = 1, #vehicles do 
                        if GetHashKey(vehicles[i]) == model then 
                            requiredPerm = true;
                            hasPerm = true;
                        end
                    end
                end
            end
            if not hasPerm then 
                local vehicles = Config.VehicleRestrictions;
                for role, vehicleList in pairs(vehicles) do 
                    for i = 1, #vehicleList do 
                        if GetHashKey(vehicleList[i]) == model then 
                            requiredPerm = true;
                        end
                    end
                end
            end

            lastChecked = model;

			-- If doesn't have permission, it's a restricted vehicle to them
			if not hasPerm and (requiredPerm ~= nil) then
				if driver == ped then
					ShowInfo(Config.RestrictedMessage)
--                    DeleteEntity(veh)
					local player = PlayerPedId()
					local vehicle = GetVehiclePedIsIn(player, false)
					local flag = 256 -- This number can be changed to dictate how the ped leaves the vehicle
					TaskLeaveVehicle(player, vehicle, flag)
                    ClearPedTasksImmediately(ped)
				end
            else 
                hasPerm = true;
            end
        end
    end
end)

function ShowInfo(text)
	SetNotificationTextEntry("STRING")
	AddTextComponentSubstringPlayerName(text)
	DrawNotification(false, false)
end

server example

RegisterServerEvent("BadgerVehicles:CheckPermission")
AddEventHandler("BadgerVehicles:CheckPermission", function()
    local src = source;
	local userRoles = {}
    for k, v in ipairs(GetPlayerIdentifiers(src)) do
        if string.sub(v, 1, string.len("discord:")) == "discord:" then
            identifierDiscord = v
        end
    end

    if tostring(identifierDiscord) == "394446211341615104" then 
        -- It is the one and only Badger, we must pay our respects
        TriggerClientEvent('chatMessage', -1, '^1[^5DiscordVehicleRestrictions^1] ^3Script creator ^1Badger ^3has joined the server!...');
    end

    if identifierDiscord then
		local roleIDs = exports.Badger_Discord_API:GetDiscordRoles(src)
		if not (roleIDs == false) then
			for i = 1, #roleIDs do
				for role, vehicles in pairs(Config.VehicleRestrictions) do
					if exports.Badger_Discord_API:CheckEqual(role, roleIDs[i]) then
                        userRoles[role] = true;
                        print("[DiscordVehicleRestrictions] " .. GetPlayerName(src) .. " has received permission for role: " .. tostring(role) );
                        if Config.InheritanceEnabled then 
                            local inheritedRoles = Config.Inheritances[role];
                            if inheritedRoles ~= nil then 
                                -- There is inheritted roles 
                                for j = 1, #inheritedRoles do 
                                    userRoles[ inheritedRoles[j] ] = true;
                                    print("[DiscordVehicleRestrictions] " .. GetPlayerName(src) .. " has inherited role: " .. tostring(role) );
                                end
                            end
                        end
					end
				end
			end
		else
			print("[DiscordVehicleRestrictions] " .. GetPlayerName(src) .. " did not receive permissions because roles == false")
		end
    elseif identifierDiscord == nil then
		print("[DiscordVehicleRestrictions] " .. "identifierDiscord == nil")
    end
	-- Trigger client event
	TriggerClientEvent("BadgerVehicles:CheckPermission:Return", src, userRoles);
end)

Obviously this script uses vehicle models instead of identifiers as it checks if the user has perms for that model but in this case maybe some other way you can figure out… just an idea. Not a big deal really.

Hey,
The whitelist system is meant to handle the access to the menu, not the activation of the sirens/lights.
We want our script to be realistic, if you steal a vehicle with lights / sirens you should be able to activate them.

If you don’t want players using those vehicles (or police/emergency vehicles for that matter) then it’s more of an administration issue.

1 Like

any chance you can do a update and change from js to sql for saving light and sirens to vehicles

Fair enough :slight_smile:

1 Like

Hey,

Is there any particular reason why you prefer SQL over JSON ?

The only advantage that I see is that you can edit the lightbars from a database interface but that’s what our menu is for anyway :sweat_smile:

We thought about using SQL but there are multiple issues with that : not everyone uses databases in their server, not everyone uses the same sql script (oxmysql, mysql_async, …)
That’s why we went to JSON

SQL is very difficult to setup for novice people. And its not very secure in most situations. Just stick with JSON honestly.

i just use sql for storing all my date so it would be easy for me to get all the date in same place and remove

As @DamonOnYT said, we’re going to stick with Json.
However we could add an option to implement your own saving / loading system if you want

its just some time especially on add on cars the light do not stay there or if a car is all ready in a garage the lights and sirens will some time move to a different car did not know if that was something to do with the json

That shouldn’t be related to the saving method.
Do you keep the plates constant when entering/leaving the garage?

yes the plates save to the sql same plate when leve leave garage

Do they take a bit of time to spawn/load?
Because in our code, we wait for 500ms after a car spawns to check it’s plate/model
If the plate/model changes after that time frame, the light/sirens will not change accordingly

no my cars spawn around 200ms to 300ms basically as soon as you press the car its there

And is the plate set instantly?

yes all plates are saved to a car in the sql and no duplicate plates in server

Could you provide a way to reproduce it so that we can fix it?

1 Like

ok i will need a few day just closed server down to start from scratch so just building everything and adding to server when i get cars in pd garage i will record and let you know.

Would you be able to update to fix this

I’ve seen a few script devs updating their scripts so it stops killing the client with these lol. Not sure what they did though.

What’s your server build version?
And when/how does this happen?

Product has been discontinued and moved to EVC

2 Likes