How would I use this?

I attempted this:


function DisplayNotify(msg)
	local txt = msg:ReadString()
	GM:AddNotify( txt, msg:ReadShort(), msg:ReadLong() )
usermessage.Hook("Notify", DisplayNotify)

Now what? How would I call this in a serverside script and send a message? I would want it to be local.

Change GM:AddNotify to GAMEMODE:AddNotify.
Make sure you’re deriving from the Sandbox gamemode as well, if you’re going to use the AddNotify method.

To send a user message that is “local”, use: umsg.Start(“Notify”, <player>)

If I use

umsg.Start(“Notify”, ply)

Where would I input the text string to broadcast?

[editline]8th March 2012[/editline]

I tried this:

function PayDay( ply )
	Notify(ply, 1, 3, "TEST DERP") -- Line 30 of player.lua

but it gives me an error:

Timer Error: [gamemodes\herbrp\gamemode\player.lua:30] attempt to call global 'Notify' (a nil value)

I call PayDay through a timer.

Notify() isn’t a function.


function _R.Player:Notify(message)
umsg.Start(“notify”, self);

– Usage: ply:Notify(“Hello World!”)

usermessage.Hook(“notify”, function(msg)
GAMEMODE:AddNotify(msg:ReadString(), 0, 5);

I haven’t tested, but you should get the idea.

Thank you so much, it works!

You are a lifesaver, but I have a question.

What is the deal with the “_R.Player:” part?

[editline]8th March 2012[/editline]

Also, if I host a multiplayer server, my friend gets the issue that notify is an unhandled user message.

The _R.Player is the player metatable.

Your friend is getting that because the clientside code isn’t being included properly.
You should just stick the clientside code in the cl_init.lua of your gamemode.

By the way OP, Overv’s site will be going down in about a month, click my title for a mirror.

as for your unhandled usermessage, where are you putting the usermessage.Hook code

The usermessage is in cl_init.

include( "cl_mainmenu.lua" )

usermessage.Hook("notify", function(msg)
     GAMEMODE:AddNotify(msg:ReadString(), 0, 5);

the code is being called in a serverside code.

function Notify(ply, message)
	umsg.Start("notify", ply)

-- Payday + Money

function PayDay( ply )
	Notify( ply, "Payday! You recieved $" .. JobSalaries[ply:Team()] .. "!")

It looks to me all working…
You get no errors?

Remember to use AddCSLuaFile(“cl_mainmenu.lua”) on the serverside if it isn’t already.

The clientside code is in cl_init, not cl_mainmenu. That is included for something else.

The only error people are getting is unhandled user message. It works fine for me but does not work for anyone else on the server. It might be something else in my code messing things up, but I doubt it. I can upload it all if you wish to see, I would really appreciate some help on this.

Though. Is it in init.lua?
Including a file that doesn’t exist would halt the script from running rest of clientside. Which is the “handler” for the usermessage.
We’re asking for a reason.

[editline]9th March 2012[/editline]

please upload it yes

Okay, Uploading…

remember to include shared on client too

I have included shared in the client, But I can’t test it with another person right now.

I will try this out asap.

I’ve just downloaded your script. AddCSLuaFile, you didn’t include it.
in cl_init.lua
add include(“shared”)

That seems to work. Thanks.

You’re welcome.

If you don’t wanna / can’t derive from sandbox; just take
notification.AddLegacy(…) instead (same syntax though).