Help for TrafficAlert script (Server Side)


#1

First of all, Hello,
I download TrafficAlert script from here : [RELEASE] TrafficAlert - A Traffic Broadcast System
I try to replace the title by the name of the player who created the message so that it is visible “server-Side” by the other player.

The problem each player sees his own name during the message.

That’s what I did:

Client_Script

RegisterNetEvent("FacebookAlert")
	AddEventHandler("FacebookAlert",function()
		DisplayOnscreenKeyboard(false, "FMMC_KEY_TIP8", "", "", "", "", "", 60)
		local input = true
		Citizen.CreateThread(function()
		while input do
		if input == true then
		HideHudAndRadarThisFrame()
		if UpdateOnscreenKeyboard() == 3 then
		input = false
		elseif UpdateOnscreenKeyboard() == 1 then
		local inputText = GetOnscreenKeyboardResult()
		if string.len(inputText) > 0 then
		TriggerServerEvent('SyncFacebookAlert', inputText)
		input = false
		else
			DisplayOnscreenKeyboard(false, "FMMC_KEY_TIP8", "", "", "", "", "", 60)
		end
		elseif UpdateOnscreenKeyboard() == 2 then
		input = false
		end
		end
		 Citizen.Wait(0)
		 end
			
	end)
end)

RegisterNetEvent('DisplayFacebookAlert')
AddEventHandler('DisplayFacebookAlert',function(inputText)

local id = PlayerId()
local source = GetPlayerName(id)

SetNotificationTextEntry("STRING");
AddTextComponentString(inputText);
SetNotificationMessage("CHAR_FACEBOOK", "CHAR_FACEBOOK", true, 1, source, "");
DrawNotification(false, true);

end)

Server_Script

RegisterServerEvent("SyncFacebookAlert")
AddEventHandler('SyncFacebookAlert', function(inputText)
TriggerClientEvent('DisplayFacebookAlert', -1, inputText)
end)

AddEventHandler('chatMessage', function(from, name, message)
	if message == "/facebook" then
		CancelEvent()
		TriggerClientEvent("FacebookAlert", from)
	end
end)

Ty for ur help and sorry for my grammar.


#2

Can you post a screenshot of it in chat? And a little better explanation. Are you wanting the message in chat to have the person that did “/facebook” to be in chat?


#3

Here is a video.
No, I want all server players to see the name of the person who posted the “/ facebook” message.


#4

Jesus Christ… Please please learn how Lua works.

Also, there’s a cool new native (actually, it’s been out a while) that allows you to Register Commands (see what I did there?).

Is getting the current players ID and name… You’ll need to get the source from the server event and pass it to this. You can then use the GET_PLAYER_FROM_SERVER_ID native to get the player who triggered the event.


#5

Thank you for your answer, I start in .lua.
I will read the documentation of your links.
That’s why my question looks like noob.