Custom Notification System

Keeping it simple…
I’m only a very very novice to the field of LUA and am in need of some help.

Going through Pistachio’s gamemode, I’ve noticed that Chessnut takes advantage of the net library for his Notification system. Using his code provided, I’ve tried implementing it into my own base-gamemode (this is all from scratch, so no conflicts with other gamemodes). How ever everything I try fails to work.

I was hoping for a written example/minor-tutorial on a basic Notify system just so I can wrap my head around it all.

Any help is appreciated.

There’s a tutorial for the net library on the wiki. Try writing the networking portion first. You’ll likely need to send a message type (integer) and the message (string). Of course that would be a rather simple messaging system. You could also consider implementing messages as a table of some sort to serialize and embed colors, etc.

At the moment I’ve got the following:

[lua]
local _R = debug.getregistry();
local playerMeta = _R.Player;

if (SERVER) then
util.AddNetworkString(“notify”)

function playerMeta:Notify(text)
	net.Start("notify")
		net.WriteString(text)
	net.Send(self)
end

else
net.Receive(“notify”, function(length)
local text = net.ReadString()
MsgC(Color(255, 125, 50), "Test: “…text…”
")
end)
end
[/lua]

Tucked nicely in a shared file.

No success when calling ply:Notify(“Test”) how ever.

Do you have any code defining playerMeta?

[lua]local playerMeta = FindMetaTable(“Player”)
if !playerMeta then return end[/lua]

Add that to the top of the code if it’s not there already.

[lua]local _R = debug.getregistry();
local playerMeta = _R.Player;[/lua]

?

That works, but for future reference you should be using the following:

[lua]local playerMeta = FindMetaTable(“Player”)[/lua]

I’ve seen the discussion of using debug compared to MetaTable, what is the sole difference/positive about using FindMetaTable?

_r does not work anymore pretty sure

oh fml sorry i didn’t read the posts lol

boxes are accepted

Heh no problem, back on topic though… I can’t for the life of me get this to just print in chat, print in console, print anywhere.

I got the same problem over here. Ive tried almost everything…

http://www.facepunch.com/showthread.php?t=1240184

Any help or insight into the matter at all guys?

-snip- Didn’t read where you said you put it in a shared file, my mistake.

For instance, if I run the following;

[lua]function Test(ply)
ply:Notify(“Test you bastard!”)
end
concommand.Add(“test”, Test)[/lua]

No errors are thrown.

Are lines 1-18 in the your gamemode’s shared.lua? Or another file?

Either way you need to make sure that somewhere the server is AddCSLuaFile’ing said file, and somewhere the client is including it. Didn’t see any of that in your snippet

In init.lua I’ve got them added like so;
[lua]
include(“modules/shared/sh_player.lua”)
AddCSLuaFile(“modules/shared/sh_player.lua”)[/lua]

sh_player.lua is where the code is stored.

You have to include it somewhere clientside.

Hi-fucking-yah .\Shadow}

Thank you very much!, something so simple…

VERY, VERY appreciated.