Notify

How would I use this?

http://luasearch.overvprojects.nl/?keywords=Gamemode.AddNotify

I attempted this:

cl_init.lua



function DisplayNotify(msg)
	local txt = msg:ReadString()
	GM:AddNotify( txt, msg:ReadShort(), msg:ReadLong() )
end
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)
umsg.End

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
end


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.

Here:

Serverside:
[lua]
function _R.Player:Notify(message)
umsg.Start(“notify”, self);
umsg.String(message);
umsg.End();
end;

– Usage: ply:Notify(“Hello World!”)
[/lua]

Clientside:
[lua]
usermessage.Hook(“notify”, function(msg)
GAMEMODE:AddNotify(msg:ReadString(), 0, 5);
end);
[/lua]

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.


DeriveGamemode("sandbox")
include( "cl_mainmenu.lua" )

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

the code is being called in a serverside code.



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

-- Payday + Money

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

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…

http://www.mediafire.com/?8t4rjq6qcn4vg79

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).
Source: http://glua.me/bin/?path=/gamemodes/sandbox/gamemode/cl_notice.lua