Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- netmsg = netmsg or {}
- netmsg.Hooks = {}
- function netmsg.Hook(tag, callback)
- netmsg.Hooks[tag] = callback
- end
- if CLIENT then
- function netmsg.Send(id, ...)
- netmsg.RawSend(glon.encode(id, ...))
- end
- function netmsg.NetHook(str)
- local args = glon.decode(str)
- if args then
- local id = args[1]
- if id and netmsg.Hooks[id] then
- table.remove(args, 1)
- printf("NETMSG %q FROM SERVER RECEIEVED : %s", id, str)
- netmsg.Hooks[id](unpack(args))
- end
- end
- end
- end
- if SERVER then
- function netmsg.Send(id, ply, ...)
- netmsg.RawSend(glon.encode(id, ...), ply)
- end
- function netmsg.NetHook(str, ply)
- if ply then
- local args = glon.decode(str)
- if args then
- local id = args[1]
- if id and netmsg.Hooks[id] then
- table.remove(args, 1)
- printf("NETMSG %q FROM %s RECEIEVED : %s", id, tostring(ply), str)
- netmsg.Hooks[id](ply, unpack(args))
- end
- end
- end
- end
- end
- hook.Add("OnNetMsgReceived", "netmsg", netmsg.NetHook, print)
Advertisement
Add Comment
Please, Sign In to add comment