Hello, I have been trying to make a join and leave message with chat.addtext and im not so good with the net library this is what i have so far
[code]
if SERVER then
util.AddNetworkString( "PlayerConnectmsg" )
hook.Add( "PlayerConnect", "doSayOnConnect", onConnect )
net.Send( "PlayerConnectmsg" )
net.Broadcast()
end
if CLIENT then
net.Receive( "PlayerConnectmsg", function()
chat.AddText( Color( 255, 255, 255), "Player " .. ply:Nick() .. "(" .. ply:SteamID() .. ") has joined the game." )
end )
end
[/code]
Nothing happens and there are no errors not sure what the problem with it is any help would be great i may have accidentally put something thats not ment to be there but yea im not sure thanks, the code up there is for connect message not sure how to add a disconnect function with that im not so good with the net library
[code]
if SERVER then
util.AddNetworkString( "PlayerConnectmsg" )
hook.Add( "PlayerConnect", "doSayOnConnect", function(name)
net.Start( "PlayerConnectmsg" )
net.WriteString(name)
net.Broadcast()
end)
end
if CLIENT then
net.Receive( "PlayerConnectmsg", function()
local name = net.ReadString()
chat.AddText( Color( 255, 255, 255), "Player "..name.." has joined the game." )
end)
end
[/code]
You can't get SteamID in the connect hook, only name and ip.
[URL="http://wiki.garrysmod.com/page/Net_Library_Usage"]More about the net library[/URL]
As for disconnecting, you can pretty much do the same thing, just with the [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerDisconnected]GM/PlayerDisconnected[/url] hook.
So would i have to change the connect hook to a PlayerInitialSpawn hook k so this would work?
[code]
if SERVER then
util.AddNetworkString( "PlayerConnectmsg" )
hook.Add( "PlayerInitialSpawn", "doSayOnConnect", function(name)
net.Start( "PlayerConnectmsg" )
net.WriteString(name)
net.Broadcast()
end)
end
if CLIENT then
net.Receive( "PlayerConnectmsg", function()
local name = net.ReadString()
chat.AddText( Color( 255, 255, 255), "Player " .. ply:Nick() .. "(" .. ply:SteamID() .. ") has joined the game." )
end)
end
[/code]
now would i be able to call there steam id if i changed the hook ?
There's no need for networking. The client is already notified when a player joins or leaves.
[lua]
hook.Add("ChatText", "joinleave", function(ply, name, txt, type)
if type == "joinleave" then
chat.AddText(Color( 255, 255, 255), txt)
return
end
end)
[/lua]
This of course wouldn't support player based so you [I]can't[/I] get their steamid.
Yea i need something that supports there steam id and works damn :/
[url]http://wiki.garrysmod.com/page/gameevent/Listen[/url]
This will supply all of the data you need
Omg thankyou code_gs :D
[code]
gameevent.Listen( "player_connect" )
hook.Add( "player_connect", "player_connect_example", function( data )
local name = data.name // Same as Player:Nick()
local steamid = data.networkid // Same as Player:SteamID()
local ip = data.address // Same as Player:IPAddress()
local id = data.userid // Same as Player:UserID()
local bot = data.bot // Same as Player:IsBot()
local index = data.index // Same as Player:EntIndex()
// Player has connected; this happens instantly after they join -- do something..
end )
[/code]
i can easily use this example and change it thanks man :D
[editline]14th June 2015[/editline]
Hey just got back put this together do you think this would work?
[code]
gameevent.Listen( "player_connect" )
hook.Add( "player_connect", "player_connect_example", function( data )
local name = data.name // Same as Player:Nick()
local steamid = data.networkid // Same as Player:SteamID()
local ip = data.address // Same as Player:IPAddress()
local id = data.userid // Same as Player:UserID()
local bot = data.bot // Same as Player:IsBot()
local index = data.index // Same as Player:EntIndex()
chat.AddText( Color( 255, 255, 255), "Player " .. data.name .. "("..data.networkid .. ") has joined the game." )
end )
gameevent.Listen( "player_disconnect" )
hook.Add( "player_disconnect", "player_disconnect_example", function( data )
local name = data.name // Same as Player:Nick()
local steamid = data.networkid // Same as Player:SteamID()
local ip = data.address // Same as Player:IPAddress()
local id = data.userid // Same as Player:UserID()
local bot = data.bot // Same as Player:IsBot()
local index = data.index // Same as Player:EntIndex()
chat.AddText( Color( 255, 255, 255), "Player " .. data.name .. "("..data.networkid .. ") has left the game." )
end )
[/code]
[editline]14th June 2015[/editline]
Thanks for all the help finished :D ~FreshPrince
Sorry, you need to Log In to post a reply to this thread.