I need someone awake and full of coffee to spot what digit is missing here…

I got a server running, sql, everything run smooth… now im trying to learn to make my own mod and learning interaction between server and client…

I took something simple that esx does, showAdvancedNotification and try to call it from within my own code and invested many hours looking at something not working… and trying all sort of codes.

Its a bit messy but if someone can explain me why i cant see the notification… i’ll saves a visit to the mental institute.

__resource.lua

server_scripts {
	'server/main.lua'	
}

client_scripts {
	'config.lua',
	'client/main.lua'
}

server\main.lua

ESX = nil

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

RegisterServerEvent('esx_burn:tellALLPlayers')
AddEventHandler('esx_burn:tellALLPlayers', function() -- error #1 found!

	local xPlayer = ESX.GetPlayerFromId(source)

	for i=1, #xPlayers, 1 do
		local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
		
		--TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('Jessica'), _U('I need some weed babe!'), _U('work: ', xPlayer.job), 'CHAR_STRIPPER_JULIET', 9)
		TriggerClientEvent('esx_burn:MsgPlaya', xPlayer.source, _U('Unknown'), _U('Ill kill you motherfucker!!'), _U('you dead homey'), 'CHAR_LESTER_DEATHWISH', 9)

	end
	
end)

and the client\main.lua

local Keys = {
	["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
	["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
	["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
	["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
	["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
	["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
	["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
	["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
	["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
}

ESX = nil

Citizen.CreateThread(function()
	while ESX == nil do
		TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
		Citizen.Wait(0)
	end
end)

RegisterNetEvent('esx_burn:wanted')
AddEventHandler('esx_burn:wanted', function(wantedlevel)
	SetPlayerWantedLevel(PlayerId(), tonumber(wantedlevel), false)
	SetPlayerWantedLevelNow(PlayerId(), false)
end)

RegisterNetEvent('esx_burn:MsgPlaya')
AddEventHandler('esx_burn:MsgPlaya', function(title, subject, msg, icon, iconType)
    -- Get the ped headshot image.
    local handle = RegisterPedheadshot(PlayerPedId())
    while not IsPedheadshotReady(handle) or not IsPedheadshotValid(handle) do
        Citizen.Wait(0)
    end
    local txd = GetPedheadshotTxdString(handle)
	
    -- Add the notification text
    SetNotificationTextEntry("STRING")
    AddTextComponentSubstringPlayerName("This is the private message!")	

    -- Set the notification icon, title and subtitle.
    --local title = GetPlayerName(PlayerId())
    local subtitle = "Private Message"
    local flash = false -- Flash doesn't seem to work no matter what.
    SetNotificationMessage(txd, txd, flash, iconType, title, subtitle)
	
    -- Draw the notification
    local showInBrief = true
    local blink = false -- blink doesn't work when using icon notifications.
    DrawNotification(blink, showInBrief)

    -- Cleanup after yourself!
    UnregisterPedheadshot(handle)	
end)

--[[
local function MsgPlayer() -- TEST LOCAL
    -- Get the ped headshot image.
    local handle = RegisterPedheadshot(PlayerPedId())
    while not IsPedheadshotReady(handle) or not IsPedheadshotValid(handle) do
        Citizen.Wait(0)
    end
    local txd = GetPedheadshotTxdString(handle)
	
    -- Add the notification text
    SetNotificationTextEntry("STRING")
    AddTextComponentSubstringPlayerName("This is the private message!")	

    -- Set the notification icon, title and subtitle.
    local title = GetPlayerName(PlayerId())
    local subtitle = "Private Message"
    local iconType = 2
	--[[  iconType = ...
	
		1 → Chat Box
		2 → Email
		3 → Add Friend Request
		7 → Right Jumping Arrow
		8 → RP Icon
		9 → $ Icon
	
	]]
    local flash = false -- Flash doesn't seem to work no matter what.
    SetNotificationMessage(txd, txd, flash, iconType, title, subtitle)
	
    -- Draw the notification
    local showInBrief = true
    local blink = false -- blink doesn't work when using icon notifications.
    DrawNotification(blink, showInBrief)

    -- Cleanup after yourself!
    UnregisterPedheadshot(handle)	
end)
]]--

Citizen.CreateThread(function() --cant do shit here, dunno why, nothing happen
	while true do
		Citizen.Wait(1)

		if IsPedInAnyVehicle(GetPlayerPed(-1)) then --PlayerId()
			Citizen.Wait(1)
			
			--TriggerClientEvent('esx_burn:MsgPlaya', xPlayer.source, _U('Jessica'), _U('received_paycheck'), _U('Bitch im pregnant'), 'CHAR_STRIPPER_JULIET', 9)
			MsgPlayer()
			
			
			print('Inside a car!')
		else
			print('Not in a car!')
		end
		
		if IsControlPressed(0, Keys['F9']) then	-- F9
			MsgPlayer()
        end
		if IsControlPressed(0, Keys['F10']) then	-- F10
			esx_burn:tellALLPlayers()
        end
		
	end
end)

You registered the Event (serverside) “TellAllPlayers” but you add the eventhandler for the Event “MsgPlaya”

Both need the same namr

1 Like

Really ? The way i see it… the client hold the real function… with no need of the server side… like my working esx_burn:wanted function can be called by esx_holdup and its working. I did make a mistake tho

EDIT: i had the option to call esx.showadvancenotification … but it was only 4 lines of codes and its better that i learn how the client and server speak to themselves… so i want my own showadvancenotification… should be simple enough for you guys, so far i wasted a lot of time… well its not wasted but invested… in the learning progress i guess.

EDIT2: The other mystery is why i can’t intercept or do anything in the last Citizen.CreateThread(function()…

IsControlPressed(0, Keys[‘F9’]) or IsControlPressed(0, 56) == not working…
out of hope, also tryed IsPedInAnyVehicle to trigger something from this CreateThread… but its dead! not moving, not printing, etc…

ho shit, the AddEventHandler in the server… name is wrong! got it Coding at midnight, wasting hours that could be fix in 3 minutes the next day, classic me!

So probably you made a mistake with the copy-paste (we all do sometimes :stuck_out_tongue: )

Here’s why.

If I look at your client\main.lua, I see you registered the event, and made a Handler for ‘esx_burn:MsgPlaya’ so that you can trigger that from server side. That’s fine.

Then on the server\main.lua, you registered the server event ‘esx_burn:tellALLPlayers’ but the handler below that is ‘esx_burn:MsgPlaya’ when I believe that should be ‘esx_burn:tellALLPlayers’. This is an issue.

On your client side, on the bottom I see you have a Citizen.CreateThread with a function, commented as it doesn’t work. I believe there are 2 main issues there (without running the script).

  • The TriggerClientEvent you commented out is wrong. If you want to trigger a client event from client side, use TriggerEvent(“eventName”, args), if you want to trigger a server event, then TriggerServerEvent(“eventName”, args), and the “eventName” should be the name of the event you registered with RegisterServerEvent().
  • By looking at the code, you want to run MsgPlayer, and all that 1 time per button press, and not spamming after every frame while the button is pressed, so replace IsControlPressed with IsControlJustPressed.
  • Also one minor thing, that I’m like only 90% sure - because I’m also new to this, still learning - is that you should put the Citizen.Wait(1) to the end of the while loop, because you want the code to run first, then wait a frame, and AFAIK Citizen.Wait(0) yields the same result. This is where I read that: Citizen.Wait(X)

that is correct, true easy mistake… i fixed the original code at the top … but this is definitaly my fault.

That is good observation… thank you very much, i’ll recheck what you said. I was indeed just trying to make a tool to debug with F9 and F10

news flash for me…
So if a frame is 16 ms, citizen.wait(0-15) all behave the same. It’s always there because it stops the loop from executing more then once per frame.

Well, I’m coming from MultiTheftAuto, so a lot of things are like… why don’t they have this? Oh, I can do that!? :smiley:

1 Like

Okay, so I fired up my test server, put your thread code in it, stripped it a lil’ bit, just to see if the IsPedInAnyVehicle works or not, and it does.

Here’s the code:

Citizen.CreateThread(
	function()
		while true do
			if IsPedInAnyVehicle(GetPlayerPed(-1)) then
				ShowNotification("IsPedInAnyVehicle(GetPlayerPed(-1)) JUST RAN!! YAAY!!")
			end
			Citizen.Wait(0)
		end
	end
)

Keep in mind, that ShowNotification is not a native function, but it’s just the normal notification above the map.

EDIT:
And with this code:

Citizen.CreateThread(
	function()
		while true do
			if IsPedInAnyVehicle(GetPlayerPed(-1)) then
				--TriggerClientEvent('esx_burn:MsgPlaya', xPlayer.source, _U('Jessica'), _U('received_paycheck'), _U('Bitch im pregnant'), 'CHAR_STRIPPER_JULIET', 9)
				--MsgPlayer()
			else
				--print('Not in a car!')
			end
			
			if IsControlJustPressed(0, Keys['F9']) then	-- F9
				--MsgPlayer()
				print('F9 pressed!')
			elseif IsControlJustPressed(0, Keys['F10']) then	-- F10
				--esx_burn:tellALLPlayers()
				print('F10 pressed!')
	                end
			Citizen.Wait(0)
		end
	end
)

This is the result after pressing the buttons after each other:


I also merged the 2 if statements into an if-elseif.

1 Like

Wow, dude you are a rock star… thank you so much for taking the time … i usually expect nothing from humanity so its a huge deal. Tonight is yet another beggining of a coding-non-stop weekend marathon… and that feels like a great head start right here!

My end game was the advanced version with a picture, above the minimap, but with title, sub, message, little icon… the whole shebang… i directly copied esx here with the 4 lines…

More like this, but anyway you get what i mean…
https://i.imgur.com/LviutDl.png

The native is SetNotificationMessage … Native Reference - Cfx.re Docs

No worries, we are here to learn and help each other, and what’s a better way to learn than teaching, amirite?
Good luck with your coding marathon. :+1:

Yeah, I know what you mean, I did those back in MTA with a function called dxDrawImage. That made things so much easier, but what can I say, it is what it is.

Currently I’m looking at custom loading screens and a way to do nice little notifications, like a box containing the message coming down from the top of the screen, then going out the same way.
For the loading screen I see HTML + JS solutions, and by reading the [How-To] Use NUI (UI Creation with HTML) thread, I strongly believe that I can use NUI to create the notification too.

dxDrawImage… you may have a point, i think i saw that used in a ressource called FuelLegacy… when the car is close to the pump to refill… the push G to gas… it attracted my attention… the way its written… i want to try that soon… seamless integration of something into the environement…

my loadingscreen is just a wallpapers with an ogg of mc eith and kokane… but like the idea of multiple form of notifications… but that look way to much for me at this stage… learning lua, even tho i did assembler, c, c++, VB, cobol, gw basic, to name a few old school language… python did not existed at that time either… god i hated cobol! Assembler was necessary to reverse engineer software so i had fun with thousen of pages of code before… lol

Probably someone with a background of MTA recreated those functions for simplicity haha. Smart move tho.

Yeah some of them are really old school, I touched a few (Turbo Pascal, VB, C) when I was in high school, but lately I’m more interested on web dev, which can be used too, so I’m happy about that. :smiley:

Smart move indeed.

I really dont want to push my luck with your help but do i get the right path or am i over complicating things here


Now that F9 can actually trigger an action…

F9 could TriggerServerEvent(‘esx_burn:tellALLPlayers’) – no args for this test unless mendatory
that will TriggerClientEvent from the server/main.lua to client/esx_burn:MsgPlaya() that will do the job

Does esx_burn:MsgPlaya should live in the server reality ? and removing the need for an extra interaction…

or inception-style … put the TriggerEvent(esx_burn:MsgPlaya) from the F9 ? :slight_smile:


at the end when it will work, i may delete the entire tellALLPlayers (hate the name and it was put there for test anyway) and just have the esx_burn:MsgPlaya standing…

in my head i was aiming at triggering esx_burn:MsgPlaya from anywhere. or any other ressources in my ressources folder. esx_burn:MsgPlaya was suppose to be THE function… or be a global function if i use the term right. (my english blows donkey balls)

I don’t think there are mandatory args, but I think the server actually receives the source that triggered it.
So, I’m not sure if I understand it correctly, but you first need to do a TriggerServerEvent('esx_burn:tellAllPlayers') then on the server side you need to do the TriggerClientEvent. I see on the code, that you loop through players, and trigger each client, which is a good starting point.

However, ESX.GetPlayerFromID(source) is not the one you need. If you look at the documentation, it says that it returns A player. You need to use ESX.GetPlayers which returns “an array of all online players ID’s”.

As I was writing this up, I recalled, that in MTA, you could just trigger all clients at the same time, so I went to check, and look what I found: [Solved] TriggerClientEvent to all players?

So simply put:

...
RegisterServerEvent('esx_burn:tellALLPlayers')
AddEventHandler('esx_burn:tellALLPlayers',
    function()
	TriggerClientEvent('esx:showAdvancedNotification', -1, _U('Jessica'), _U('I need some weed babe!'), _U('work: ', xPlayer.job), 'CHAR_STRIPPER_JULIET', 9)
	TriggerClientEvent('esx_burn:MsgPlaya', -1, _U('Unknown'), _U('Ill kill you motherfucker!!'), _U('you dead homey'), 'CHAR_LESTER_DEATHWISH', 9)
    end
)
...

Which means, that you don’t need ESX on the server side anymore - if you wanted to use only for this code.

Also, I don’t know what the _U() function does, but don’t forget to create that too. :slight_smile:

If you have any questions, just let me know, I’m happy to help, if I can.

1 Like

that is pure gold… -1 … i tried so much different ways to specifie “player” … thats the whole point of every left overs inside the server.lua… ultimately esx_burn: will contain other stuff but i understand what happen now.

the U('___') was stolen directly from the way esx-showadvancenotification worked… but now that you are wondering “why…” could be just like MS word… some texttool for underline, underscore, itallique or whotheFknows option.

Now i debug everything remotely and in my head but as soon as i get close to my setup… will try everything with and everything else… you saved me so many headache… i owe you a beer or something!

Yeah, it’s always worth a try to google stuff that sound crazy, like triggering all clients lol, maybe someone has a solution, or a really optimized code - you never know.

Oh, I see, that’s a nice feature.

Looking at the code, it should work, but unexpected results always happen. What I learned from MTA and LUA, always assume, that it can go wrong. One tiny error, like a type mismatch (where the function requires a number, but you pass a string to it, never assume an implicit type conversion is going to happen), or lower-case / upper-case letters when passing arguments, timing (where the results are not ready yet), etc.

If the code doesn’t run properly, just paste the code, and I’ll try to help you debug it.

10-4
by the way, the most useful tool WAS the search function of the fivem.net forums… its been a week that i can’t search nothing on the forums and its one of the most tight and clean forums i have ever seen (my mama always said (kidding), dont EVER post in the wrong category mah boii… or else the boogyman is going to get me… )

Every answer to my code probleme is

:(
 
Server Error

while trying to load [/search](https://forum.cfx.re/search)

Error code: 503 error

I just joined a few days ago, so I have no experience with the forum search, but what I do is that when I need something, I just google search, and put the word “fivem” before that. For example when I was looking for a way to trigger all clients, I started with a search for “fivem triggerclientevent” and the first result was the solved forum thread of it lol.