Need help with this code

client

RegisterNetEvent("TrafficStop")
AddEventHandler("TrafficStop",function()
    local PedModels = {
        "s_m_y_cop_01",
        's_m_m_snowcop_01',
        's_m_y_hwaycop_01',
        's_f_y_cop_01',
        's_m_y_sheriff_01',
        's_f_y_sheriff_01',
        's_m_y_ranger_01',
        's_m_m_armoured_01',
        's_m_m_armoured_02',
        's_f_y_ranger_01',
        's_m_m_ciasec_01',
        'u_m_m_fibarchitect',
        's_m_y_swat_01',
		's_m_y_blackops_01',
		's_m_y_blackops_02',
		's_m_y_blackops_03',
		's_m_y_hwaycop_01',
		'u_m_m_doa_01',
		}
    local ped = PlayerPedId()
    local x,y,z = table.unpack(GetEntityCoords(ped, false))
    local streetName, crossing = GetStreetNameAtCoord(x, y, z)
    streetName = GetStreetNameFromHashKey(streetName)
    local message = ""
    if crossing ~= nil then
        crossing = GetStreetNameFromHashKey(crossing)
        message = "^1" .. GetPlayerName(source) .. " is Traffic at ^3" .. streetName .. " ^1and ^3" .. crossing .. " ^1no asst required."
    else
        message = "^1" .. GetPlayerName(source) .. " is Traffic at ^3" .. streetName .. " ^1no asst required."
    end
    TriggerServerEvent('TrafficStop', message)
end, false)

and server

AddEventHandler('chatMessage', function(message)
	if message == "/ts" then
		CancelEvent()
		TriggerClientEvent("TrafficStop", from)
	end
end)

any ideas, not working at all.

If im not mistaken having a comma on the last entry there will make it not work… Also any errors in the log?

Ill check my errors, when I did the command it just said command entered with no output

Wtf is ā€œfromā€?? It doesn’t exist. That’s your problem.

3 Likes

i dont know, it was from another script, however i changed that to match ā€œmessageā€ and i still get nothing. No errors, just says command ts entered

TriggerClientEvent requires an integer as the second argument. This is the player whom you want to trigger the event on.

https://wiki.fivem.net/wiki/TriggerClientEvent

Edit: on server events there’s a variable ā€œsourceā€ which is the ID of the player.

so would it look like this?

AddEventHandler('chatMessage', function(message)
	if message == "/ts" then
		CancelEvent()
		TriggerClientEvent("TrafficStop", -1, message)
	end
end)

And should the it be triggerserverevent or the way i have it?

-1 will send message to all players on server. Use source instead.

Roger, ill give a go

Still not working, says command ts entered… I dont get this shit

You’re trying to call the server event ā€œTrafficStopā€.
From the code you’ve shown you only have a client event, not a server one.
Also, what is that list of ped models used for? It’s not being used at all in the code.

the peds are there so that the person making the /ts are the only one. I will change the serverevent to client and see if that works

ok so i took the code that was given in the panic emergency code, however i want to have that list of peds for people to use it and see it and way you can help with that