Hashes In array error

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(50)
		local ped = PlayerPedId()
		local handle, vehicle = FindFirstVehicle()
		local finished = false
		repeat
			Wait(1)
			for k,v in pairs (BlacklistedCars) do
				if IsPedSittingInAnyVehicle(PlayerPedId()) then
					local cVeh = GetVehiclePedIsUsing(PlayerPedId(), false)
					local vehicle_name = GetDisplayNameFromVehicleModel(v)
					if GetEntityModel(cVeh) == v then
						print(vehicle_name)
						ReqAndDelete(cVeh, false)
					end
				end
				if GetEntityModel(vehicle) == (v) then
					ReqAndDelete(vehicle, false)
				end
			end
			finished, vehicle = FindNextVehicle(handle)
		until not finished
		EndFindVehicle(handle)
	end
end)

i’m not spawning them i’m trying to delete them
the print native will become a DropPlayer when kicking player out of server

“v” should be the hash i put into the local array… (the fact is that i don’t want modders to decrypt and know what vehicles i blacklist but instead they would read the hashes and should look for those vehicles… if they know how to do)

You could try using the IS_VEHICLE_MODEL native, which compares a vehicle with a hash and returns true if it is correct.

if i use " if GetEntityModel(cVeh) == GetHashKey(v) then " it works using vehicles names… i might try when i get back home…

the same check is made for peds and weapons ^^ could IS_WEAPON_VALID work for weapons and IS_PED_MODEL work for peds?

I think looking at the code in [Release] Model Blacklist v1.1 may be beneficial. It seems to do the same functionality that you’re looking to create. FWIW, when I used that resource, I kicked Citizen.Wait(0) up to Citizen.Wait(250), meaning it checked every quarter second instead of every frame, which is intensive.

of course it’s still in development… i was thinking to throw it once a second so every Wait(1000) the problem is the crash using hashes

I believe hashes are typically strings. I don’t believe using GetHashKey should cause any significant performance issues. What does something like this do? You may need to add quotes around the hashes.

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(50)
		local ped = PlayerPedId()
		local handle, vehicle = FindFirstVehicle()
		local finished = false
		repeat
			Wait(1)
			for k,v in pairs (BlacklistedCars) do
				if IsVehicleModel(vehicle, v) then
					ReqAndDelete(vehicle, false)
				end
			end
			finished, vehicle = FindNextVehicle(handle)
		until not finished
		EndFindVehicle(handle)
	end
end)

I’m not sure what is being accomplished with:

if IsPedSittingInAnyVehicle(PlayerPedId()) then
	local cVeh = GetVehiclePedIsUsing(PlayerPedId(), false)
	local vehicle_name = GetDisplayNameFromVehicleModel(v)
	if GetEntityModel(cVeh) == v then
		print(vehicle_name)
		ReqAndDelete(cVeh, false)
	end
end

Seems like an unnecessary double check.

You could also consider using the Entity Iterator if you’re running into issues, it has worked for me a lot.

the entire check looks for the vehicle near player, the second one checks if the player is inside that vehicle and once it’ll be working will kickhim out of server

that way if you spawn a vehicle and automatically set ped driving (using mod menu) you’ll be kicked out while if the vehicle spawns without player inside it simply get deleted

Ah, I understand. In that case, I would personally do it like this to prevent two checks unless needed.

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(50)
		local ped = PlayerPedId()
		local handle, vehicle = FindFirstVehicle()
		local finished = false
		repeat
			Wait(1)
			for k,v in pairs (BlacklistedCars) do
				if IsVehicleModel(vehicle, v) then
					if IsPedSittingInAnyVehicle(PlayerPedId()) and GetVehiclePedIsUsing(PlayerPedId(), false) == vehicle then
						-- Player is in the blacklisted vehicle, kick'em. Remember DropPlayer is a server sided native, so it'll need to trigger a server event.
					end
					ReqAndDelete(vehicle, false)
				end
			end
			finished, vehicle = FindNextVehicle(handle)
		until not finished
		EndFindVehicle(handle)
	end
end)

I believe you could also just do if GetVehiclePedIsUsing(PlayerPedId(), false) == vehicle then instead of if IsPedSittingInAnyVehicle(PlayerPedId()) and GetVehiclePedIsUsing(PlayerPedId(), false) == vehicle then, but it may through an error if the player isn’t in a vehicle. I think it just returns 0 if they aren’t in a vehicle.

1 Like

ooooh i see! it’s awesome! well i’m doing the same check with ped (IsPedModel)

and the only thing i’m missin is about objects

using this

	while true do
		Citizen.Wait(1000)
		local ped = PlayerPedId()
		local handle, object = FindFirstObject()
		local finished = false
		repeat
			Wait(1)
			for k,v in pairs(entimonio) do
				if IsEntityAttached(object) and DoesEntityExist(object) then
					if GetEntityModel(object) == v then
						ReqAndDelete(object, true)
					end
				end
				if GetEntityModel(object) == v then
					ReqAndDelete(object, false)
				end
			end
			finished, object = FindNextObject(handle)
		until not finished
		EndFindObject(handle)
	end
end)

this is to check if the entity is attached or only spawned (i noted that some modders don’t spawn random vehicle on the head of player… but spawn those vehicles as objects)

You could look into setting Decor integers to something unique, and check entities for that decor int.
https://runtime.fivem.net/doc/reference.html#_0x0CE3AA5E1CA19E10

Just a thought. I’ve seen that done and am working on implementing that on my server. It may be better than blacklisting lots of things.

mmm i see… i might try this one too… this way i can see who is spawning vehicles with mod menu…

so… can i ask you another thing? i opened another thread regarding blips… can you help me there?
i’m looking to find a way to show an entity blip only to police once a player spawns it

Which framework? I’m only familiar with ESX. If it’s ESX I can show you how

using esx i can send you privately the scripts… i created two missions gta online style… the only problem is how to make only police to see the blip when a player is stealing the mission vehicle

still nothing about the hashes… if i stop the script and restart it after i’m spawned it works perfectly… if join the server with the script already started then i get this

What does the citizen.log file in your Five M Application Data folder have to say?