Ok so I've been trying to make a small Hud notification show up whenever a player leaves or connects, but I have no clue why it doesn't work. Recently I asked a friend of mine and he said that I can connect Serverside hooks with Clients. My Reaction: omffukcyus! But, go figure, my code just doesn't work....like ever...:
[lua]if( CLIENT ) then
local xbox = surface.GetTextureID("vgui/xbox")
local client = LocalPlayer()
local Alpha
local Title = ""
local Desc = ""
function DrawXboxHud()
surface.CreateFont ("Trebuchet18", ScreenScale(12), 400, true, false, "XboxTitlebar")
surface.CreateFont ("default", ScreenScale(6), 400, true, false, "XboxDesc")
surface.SetTexture( xbox )
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect( ScrW() / 3.2 , ScrH() / 1.4 , ScrW() / 2.8 , ScrH() / 3 )
draw.DrawText( "Need testing", "XboxTitlebar", ScrW() / 2.35 , ScrH() / 1.185, Color( 255,255,255,255 ), ALIGN_CENTER)
draw.DrawText( Desc, "XboxDesc", ScrW() / 2.5 , ScrH() / 1.13, Color( 255,255,255,255 ), ALIGN_CENTER)
end
hook.Add( "HUDPaint", "DrawXboxHud", DrawXboxHud )
function my_message_hook( um )
Desc = um:ReadString()
end
usermessage.Hook("my_message", my_message_hook)
function PlayerConnect( name, loc )
local rp = RecipientFilter()
rp:AddAllPlayers()
for _, v in pairs(player.GetAll()) do
v:EmitSound("xbox360.mp3", 100, 100)
end
umsg.Start("my_message", rp)
umsg.String( name:GetName().. " has joined the server." )
umsg.End()
end
function PlayerDisconnect( ply )
local rp = RecipientFilter()
rp:AddAllPlayers()
for _, v in pairs(player.GetAll()) do
v:EmitSound("xbox360.mp3", 100, 100)
end
umsg.Start("my_message", rp)
umsg.String( name:GetName().. " has joined the server." )
umsg.End()
end
end[/lua]
The problem is that the notification I want to show up doesn't work. The text it just blank.
PS I would also like to know how to make another string so i can use it seperately, because I want to fill my other spot
PPS I also want this to be client side only.
Don't create fonts in HUDPaint, do it once in Initialize.
You are sending usermessages to the client from the client. Don't do this, the player connect and disconnect functions need to be on the server.
You have functions PlayerConnect and PlayerDisconnect, but they are never called. They need to be hooked.
[QUOTE=MakeR;21143227]Don't create fonts in HUDPaint, do it once in Initialize.
You are sending usermessages to the client from the client. Don't do this, the player connect and disconnect functions need to be on the server.
You have functions PlayerConnect and PlayerDisconnect, but they are never called. They need to be hooked.[/QUOTE]
Putting what MakeR said in Lua terms
At Line 27 put:
[lua]
end
if ( SERVER ) then
[/lua]
At Line 40 put:
[lua]
hook.Add("PlayerInitialSpawn", "PlayerConnect", PlayerConnect)
[/lua]
At Line 54 put:
[lua]
hook.Add("PlayerDisconnected", "PlayerDisconnect", PlayerDisconnect)
[/lua]
It is 99% guaranteed that it works with those fixed :P
Also, move lines 11 and 12 into an initialize hook, like so:
[lua]hook.Add("Initialize", "createFonts", function()
surface.CreateFont ("Trebuchet18", ScreenScale(12), 400, true, false, "XboxTitlebar")
surface.CreateFont ("default", ScreenScale(6), 400, true, false, "XboxDesc")
end)[/lua]
Doesn't work. Does this have to be on a server I'm hosting or does this completely work Client side?
Well, you need a copy of the script both clientside and serverside
And we've forgot a little thing to make it work
after the "if ( SERVER ) then"
you must put:
[lua]AddCSLuaFile("yourfilenamehere")[/lua]
stupid question cause i want to do the same what lua file do you put all of this in
[QUOTE=dpoolas;21155374]stupid question cause i want to do the same what lua file do you put all of this in[/QUOTE]
lua/autorun/namthisfiletowhatever.lua
for some reason it doesnt show when a player connects and leaves so i have no idea what is wrong this is my file
if ( SERVER ) then
AddCSLuaFile("playerconnect.lua")
hook.Add("PlayerInitialSpawn", "PlayerConnect", PlayerConnect)
hook.Add("PlayerDisconnected", "PlayerDisconnect", PlayerDisconnect)
hook.Add("Initialize", "createFonts", function()
surface.CreateFont ("Trebuchet18", ScreenScale(12), 400, true, false, "XboxTitlebar")
surface.CreateFont ("default", ScreenScale(6), 400, true, false, "XboxDesc")
end)
[QUOTE=dpoolas;21156128]for some reason it doesnt show when a player connects and leaves so i have no idea what is wrong this is my file
if ( SERVER ) then
AddCSLuaFile("playerconnect.lua")
hook.Add("PlayerInitialSpawn", "PlayerConnect", PlayerConnect)
hook.Add("PlayerDisconnected", "PlayerDisconnect", PlayerDisconnect)
hook.Add("Initialize", "createFonts", function()
surface.CreateFont ("Trebuchet18", ScreenScale(12), 400, true, false, "XboxTitlebar")
surface.CreateFont ("default", ScreenScale(6), 400, true, false, "XboxDesc")
end)[/QUOTE]
Um for one where are your functions, PlayerConnect and Player Disconnect? and for 2 don't name your hooks something thats widely used.
i dont know i was listening to what cubar i thought i was just suppose to put these in there lol fuck i need help with this then
[code]
if ( SERVER ) then
AddCSLuaFile("playerconnect.lua")
hook.Add("PlayerInitialSpawn", "PlayerConnect", function(name, address) PrintMessage( HUD_PRINTTALK, name.. " has joined the server." ) end)
hook.Add("PlayerDisconnected", "PlayerDisconnect", function(ply) PrintMessage( HUD_PRINTTALK, ply:Name().. " has disconnected from the server." ) end)
hook.Add("Initialize", "createFonts", function()
surface.CreateFont ("Trebuchet18", ScreenScale(12), 400, true, false, "XboxTitlebar")
surface.CreateFont ("default", ScreenScale(6), 400, true, false, "XboxDesc")
end)
end
[/code]
damn for some reason it doesnt say when they connect also is there a way so it displays there steam id
ohh cause you are using player initial spawn, gah damn so confusing when you use a hook and then you name the hook another hooks name.
[code]
if ( SERVER ) then
AddCSLuaFile("playerconnect.lua")
hook.Add("PlayerInitialSpawn", "PlayerConnect", function(ply) PrintMessage( HUD_PRINTTALK, ply:Name().." has joined the server.".." Steam ID: "..ply:SteamID() ) end)
hook.Add("PlayerDisconnected", "PlayerDisconnect", function(ply) PrintMessage( HUD_PRINTTALK, ply:Name().. " has disconnected from the server." ) end)
hook.Add("Initialize", "createFonts", function()
surface.CreateFont ("Trebuchet18", ScreenScale(12), 400, true, false, "XboxTitlebar")
surface.CreateFont ("default", ScreenScale(6), 400, true, false, "XboxDesc")
end)
end
[/code]
thank you so much tb ok this is probably getting annoying me requesting shit but is there a way that admins only see the peoples ip address when they join
You know what just add me on steam lol.
[code]
if ( SERVER ) then
AddCSLuaFile("playerconnect.lua")
hook.Add("PlayerInitialSpawn", "PlayerConnect", function(ply) PrintMessage( HUD_PRINTTALK, ply:Name().." has joined the server.".." Steam ID: "..ply:SteamID() ) end)
hook.Add("PlayerDisconnected", "PlayerDisconnect", function(ply) PrintMessage( HUD_PRINTTALK, ply:Name().. " has disconnected from the server." ) end)
hook.Add("PlayerConnect", "BLEEPBLOPBOOPBOOP", function(name, address) for k,v in pairs(player.GetAll()) do if(v:IsAdmin()) then v:ChatPrint(name.." has connected.".." IP Address: "..address )end end end)
hook.Add("Initialize", "createFonts", function()
surface.CreateFont ("Trebuchet18", ScreenScale(12), 400, true, false, "XboxTitlebar")
surface.CreateFont ("default", ScreenScale(6), 400, true, false, "XboxDesc")
end)
end
[/code]
lol once again thanks hey i tried to add you but it said invalid steam idea i gave you an informative thing lol
[editline]06:07AM[/editline]
ok lol you probably already hate me but how can i make it also that admins also see steam ids and ip address's
Well they are going to see the steam Id the same time everyone else see's the steam ids, unless you want only admins to see the steam ids.
no for some reason it is only showing the ip address for admins very weird
You could use this in place of TB's code.
[lua]
hook.Add("PlayerInitialSpawn", "MessageConnect", function(pl)
local Msg1 = pl:Name() .. " ( " .. pl:SteamID() .. ") has connected."
local Msg2 = Msg1 .. "IP: " .. pl:IPAddress() .. "."
for k,v in pairs(player.GetAll()) do
if (v:IsAdmin()) then
v:ChatPrint(Msg2)
else
v:ChatPrint(Msg1)
end
end
end)
[/lua]
Still doesn't work. This is my code so far:
[lua]if( CLIENT ) then
local xbox = surface.GetTextureID("vgui/xbox")
local client = LocalPlayer()
local Alpha
local Title = ""
local Desc = ""
hook.Add("Initialize", "createFonts", function()
surface.CreateFont ("Trebuchet18", ScreenScale(12), 400, true, false, "XboxTitlebar")
surface.CreateFont ("default", ScreenScale(6), 400, true, false, "XboxDesc")
end)
function DrawXboxHud()
surface.SetTexture( xbox )
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect( ScrW() / 3.2 , ScrH() / 1.4 , ScrW() / 2.8 , ScrH() / 3 )
draw.DrawText( "Need testing", "XboxTitlebar", ScrW() / 2.35 , ScrH() / 1.185, Color( 255,255,255,255 ), ALIGN_CENTER)
draw.DrawText( Desc, "XboxDesc", ScrW() / 2.5 , ScrH() / 1.13, Color( 255,255,255,255 ), ALIGN_CENTER)
end
hook.Add( "HUDPaint", "DrawXboxHud", DrawXboxHud )
end
if ( SERVER ) then
AddCSLuaFile("xbox.lua")
function my_message_hook( um )
Desc = um:ReadString()
end
usermessage.Hook("my_message", my_message_hook)
function PlayerConnect( name, loc )
local rp = RecipientFilter()
rp:AddAllPlayers()
for _, v in pairs(player.GetAll()) do
v:EmitSound("xbox360.mp3", 100, 100)
end
umsg.Start("my_message", rp)
umsg.String( name:GetName().. " has joined the server." )
umsg.End()
end
hook.Add("PlayerInitialSpawn", "PlayerConnect", PlayerConnect)
function PlayerDisconnect( ply )
local rp = RecipientFilter()
rp:AddAllPlayers()
for _, v in pairs(player.GetAll()) do
v:EmitSound("xbox360.mp3", 100, 100)
end
umsg.Start("my_message", rp)
umsg.String( name:GetName().. " has joined the server." )
umsg.End()
end
hook.Add("PlayerDisconnected", "PlayerDisconnect", PlayerDisconnect)
end
[/lua]
Lines 28, 29, and 30 need to go in the CLIENT if
Omfg. I forgot to move those to the client part.
1> on the umsg when sending, you dont need the rp thing, just use player.GetAll()
2> use tables to make addons in, not random function names also, you could break something for others!
3> when making functions for hooking, make them local or just make them inside the hook.
4> Your using quite offten the function ' ScrW and ScrH ', try doing local scrw = ScrW(), it wil save some FPS/CPU
5> Your using ent:EmitSound(), you should do this clientside, becouse mainly if theres a large groep of people in one spot, it could get loud! ([URL="http://wiki.garrysmod.com/?title=Surface.PlaySound"]surface.PlaySound[/URL])
edit:
[lua]
if( CLIENT ) then
xbox_theme = {}
xbox_theme.xbox = surface.GetTextureID("vgui/xbox")
xbox_theme.client = LocalPlayer()
xbox_theme.Alpha = 255
xbox_theme.Title = ""
xbox_theme.Desc = ""
hook.Add("Initialize", "createFonts", function()
surface.CreateFont ("Trebuchet18", ScreenScale(12), 400, true, false, "XboxTitlebar")
surface.CreateFont ("default", ScreenScale(6), 400, true, false, "XboxDesc")
end)
local function DrawXboxHud()
local ScrW,ScrH = ScrW(),ScrH() // localize then, inproofs FPS
surface.SetTexture( xbox_theme.xbox )
surface.SetDrawColor(255,255,255,255)
surface.DrawTexturedRect( ScrW() / 3.2 , ScrH() / 1.4 , ScrW() / 2.8 , ScrH() / 3 )
draw.DrawText( "Need testing", "XboxTitlebar", ScrW() / 2.35 , ScrH() / 1.185, Color( 255,255,255,255 ), ALIGN_CENTER)
draw.DrawText( xbox_theme.Desc, "XboxDesc", ScrW() / 2.5 , ScrH() / 1.13, Color( 255,255,255,255 ), ALIGN_CENTER)
end
hook.Add( "HUDPaint", "DrawXboxHud", DrawXboxHud )
local function my_message_hook( um )
xbox_theme.Desc = um:ReadString()
surface.PlaySound("xbox360.mp3")
end
usermessage.Hook("xbox_theme.my_message", xbox_theme.my_message_hook)
end
if ( SERVER ) then
AddCSLuaFile("xbox.lua")
local function PlayerConnect( name, loc )
umsg.Start("xbox_theme.my_message", player.GetAll())
umsg.String( name:GetName().. " has joined the server." )
umsg.End()
end
hook.Add("PlayerInitialSpawn", "PlayerConnect", PlayerConnect)
local function PlayerDisconnect( ply )
umsg.Start("xbox_theme.my_message", player.GetAll())
umsg.String( name:GetName().. " has joined the server." )
umsg.End()
end
hook.Add("PlayerDisconnected", "PlayerDisconnect", PlayerDisconnect)
end
[/lua]
this is going to be the most retarded question but right now it keeps showing up twice which means i have another lua file that is doing it how can i find out what lua file is making it display this twice because i dont think i put the two as the same name
on notepadd++ you have a search function to find in files,
else then that just browse until you find itP
Sorry, you need to Log In to post a reply to this thread.