[HELP] Adding a Stolen Vehicle Notification | Any FeedBack is Welcome

lua
help

#1

The Idea is simple, if someone is in a stolen car, there is a 1 in 5 chance of the server spitting out a message saying Stolen Vehicle at X Position
Client:

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)


		--==--==--==--==--==--==--==--==--==--==--==--==--
		--==============================================--
		--	BIG THANKS TO @MsQuerade for the street  	--
		--	names										--
		--==============================================--
		--==--==--==--==--==--==--==--==--==--==--==--==--

		local streetA, streetB = Citizen.InvokeNative( 0x2EB41072B4C1E4C0, playerPos.x, playerPos.y, playerPos.z, Citizen.PointerValueInt(), Citizen.PointerValueInt() )
        
		--== End Of MsQuerade ==--


		if IsPedTryingToEnterALockedVehicle(GetPlayerPed(-1)) or IsPedJacking(GetPlayerPed(-1)) then

			x = math.random (5)

			if x = 3 then

				TriggerServerEvent('stolenVeh', streetA, streetB)

			elseif x ~= 3 then

				Wait(0)

			end
		end
	end
end)

Server:

RegisterServerEvent('stolenVeh')
AddEventHandler('stolenVeh', function(streetA, StreetB)
	if veh == "NULL" then
		TriggerClientEvent("chatMessage", -1, '', { 0, 0, 0 }, "Someone has stolen a vehicle by "..streetA.."and "..StreetB)
	else
		Wait(0)
	end
end)

Now I am new to Lua, and GTA 5 scripting, so don’t be afraid to roast me :D. Let me know if there’s something wrong, something I can improve on, or something just so terrible it needs to get out immediately. Any feedback is welcome. Thanks.

Edit by Havoc: why abuse the formatting? It makes it harder to read. Just type normally.


#2

This will only run when math.random spews out a 3. You may want to use the less than operator instead here. You can read about the math library here.

Could just use PlayerPedId() :stuck_out_tongue:

What’s “veh”? And why would this be "NULL"? This is what the server is going to be asking. Since you’re never setting it or declaring it anywhere the statement will never execute (I’m surprised if you don’t get an error).


#3

Thank you so much man, I’ll be sure to try those suggestions and read that library. But as per the errors, I don’t see any but then again I’m new to this so I might have to add an arg to see the errors.
So would this fix the NULL? @Havoc Or is that just completely wrong

RegisterServerEvent('stolenVeh')
AddEventHandler('stolenVeh', function(streetA, StreetB)
	
		TriggerClientEvent("chatMessage", -1, '', { 0, 0, 0 }, "Someone has stolen a vehicle by "..streetA.."and "..StreetB)
	
end)

Thanks!


#4

Have you seen simple outlaw alert?


#5

Ill check that out thanks.


#6

Server:

RegisterServerEvent('stolenVeh:server')
AddEventHandler('stolenVeh:server', function(streetA, StreetB)
	local String = "Someone has stolen a vehicle by "..streetA.." and "..StreetB .. "!"
	TriggerClientEvent("stolenVeh:policeString", -1, String)
end)

Client

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(5)       
		if IsPedTryingToEnterALockedVehicle(GetPlayerPed(-1)) or IsPedJacking(GetPlayerPed(-1)) then
			x = math.random(5)
			if x == 3 then
				local streetA, streetB = Citizen.InvokeNative( 0x2EB41072B4C1E4C0, playerPos.x, playerPos.y, playerPos.z, Citizen.PointerValueInt(), Citizen.PointerValueInt() )
				TriggerServerEvent('stolenVeh:server', streetA, streetB)
			else
				Citizen.Wait(15000)
			end
		end
	end
end)

isCop = false
RegisterNetEvent("stolenVeh:isCop")
AddEventHandler('stolenVeh:isCop', function()
	isCop = not isCop
end)

RegisterNetEvent("stolenVeh:policeString")
AddEventHandler('stolenVeh:policeString', function(string)
	if isCop then
		TriggerEvent("chatmessage", -1, 'DISPATCH: ', { 0, 0, 0 }, string)
	end
end)

Then just Trigger the below anytime you want someone to be able to see the message, IE a cop clocks on duty.

TriggerEvent("stolenVeh:isCop")

#7

Thanks you for your response Koil. I’ll be sure to test this when I get home, but so far she looks good :slight_smile:. Thanks again <3.