Taking over the ShowAdvanceNotification for myself (learning tool)

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 … https://runtime.fivem.net/doc/natives/#_0x1CCD9A37359072CF

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.

good old google, yeah that is the only way i can fall accidentally on the answer around here … and most moderator here use the answer “did you try the search engine before posting” … a lot! since some people think everything is easy to mash together and are generally lazy in their research… tell me how now!! and be quick about it!

I started my 40+ ressources esx server about a week ago… and with google was about to change my interface, get rid of the black money, add cops, add nitro to my own code (need to interface with the fuel mod to burn more fuel instead of buying a “nitro” at the store) i had codded a VRP 4-5 years ago and it was not the same game at all… i am way more advance now in way less time.

Yeah, sometimes forming an efficient question takes a lot, but this is where a really good documentation can help, because that tells you what you need, which makes your life so much easier. The current documentation is okay-ish, I can find my way around it, but it could definitely be improved.

I’m kind of a freak in this thing, I don’t like to implement resources written by someone else. I know, that I shouldn’t be “inventing the wheel” again, but I like to get ideas from those resources, and build my own. Probably this comes from a habit, where we wanted our MTA server to be “unique”, so every single resource was done by us (2-3 devs), and people liked it, 4-500 players on peak times.

This is where im at… F9 work, F10 tries…

server \ main.lua

RegisterServerEvent('esx_burn:testMsg')
AddEventHandler('esx_burn:testMsg', 
	function()
		TriggerClientEvent('esx_burn:MsgPlaya', -1, 'Unknown', 'Ill kill you motherfucker!!', 'msg msg you dead homey', 'CHAR_LESTER_DEATHWISH', 9)
	end
)

Client \ main.lua

RegisterNetEvent('esx_burn:MsgPlaya')
AddEventHandler('esx_burn:MsgPlaya', function(title, subject, msg, icon, iconType)
	print('esx_burn:MsgPlaya == BEGIN') -- debug

    SetNotificationTextEntry('STRING')
    AddTextComponentSubstringPlayerName(msg)
    SetNotificationMessage(icon, icon, false, iconType, title, subject)
    DrawNotification(false, false)

	print('esx_burn:MsgPlaya == FINISHED') -- debug
end)

Citizen.CreateThread(function() 
	while true do
		if IsControlJustPressed(0, Keys['F9']) then	-- F9
			print('F9 pressed!') --debug
		elseif IsControlJustPressed(0, Keys['F10']) then -- F10
			print('F10 pressed!') --debug
			TriggerServerEvent('esx_burn:testMsg') 
		end		
		------------------------------------------------------------------		
		Citizen.Wait(0)
	end
end)

F10 start esx_burn:MsgPlaya
Now i got an attempt to call a nil value (global ‘AddTextComponentSubstringPlayerName’)

There seem to be old native and new native, or old vs new information about some function and the use of it… from 2016-17 to today exemple dont matchs sometimes… or im too high…

The damn paycheck notification is exactly what i try to do! Its laughing at me with a welfaire check everytime i try to make mine!

Took me the rest of the day cursing god and lucifer! at the end everything work… i can generate my advance notification from within my code… lua language is picky as hell… took hours to find forgotten “;” and small anoyance in my code… im learning! thank you to the community and par4doxon!

https://i.imgur.com/2c03u30.jpg