Hello, Ive been trying to edit this lua file that i have which shows a joining and leaving message for people. Here is the code:
[CODE]// client side apple
// Spawn
function player_spawn( data )
local name1 = data:ReadString()
local nickteamcolour1 = team.GetColor(data:ReadShort())
chat.AddText( Color( 255, 0, 255 ), "[Server] ", nickteamcolour1, name1, Color( 255, 255, 255 ), " has joined in the server." )
surface.PlaySound( "garrysmod/save_load1.wav" )
end
usermessage.Hook("player_spawn", player_spawn)
// Disconnect
function player_disconnect( data )
local name3 = data:ReadString()
local nickteamcolour3 = team.GetColor(data:ReadShort())
chat.AddText( Color( 255, 0, 255 ), "[Server] ", nickteamcolour3, name3, Color( 255, 255, 255 ), " has left the server. " )
surface.PlaySound( "garrysmod/save_load2.wav" )
end
usermessage.Hook("player_disconnect", player_disconnect)[/CODE]
I've been trying to find out how I can add ..ply:SteamID() into it so does that mea nI have to replace the "function player_spawn( data )" with "function FirstSpawn( ply )"? Or can I justfunction player_spawn( data )( ply ) and have two things, data and ply?
It is networked from the server; but it doesn't need to be. If you use that system, you'll need to network the SteamID the same way as the other elements ( except via String ). Game-events are shared, and provide enough information for join / disconnect messages: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_redistributable/acecooldev_base/documentation/game_events/game_event_listeners.lua.html[/url]
remove .html to view .lua; html doesn't copy well. Look at player_connect and player_disconnect. For disconnect, the player object may be accessible, for connect it won't be ( it gets fired right when the player connects ), but there is enough for your chat.AddText with name, steamid, etc... On Disconnect you shouldn't have any issues grabbing team, etc ( just make sure the player object is valid first, because it can also be fired if a player connects then immediately disconnects ).
Ok thanks, but I still dont know how to impliment that onto my thing because I want to keep the colors how they are without ruining everything, and also I get what you mean but i really dont know how to do anything in lua so I'm going to have to mess around until it works
Well, you're already grabbing the name via string; you'd simply add another line like "local name3 = data:ReadString()", after the line with data:ReadShort( ), with a new variable name for steamid.
On the server-side code, you'd add a new WriteString with the steamid, after the line with WriteShort... [url]http://wiki.garrysmod.com/page/umsg[/url] although I'd recommend using net instead of umsg but for something like this it doesn't really matter.
So I tried to follow directions and made this:
[CODE]// client side apple
// Spawn
function player_spawn( data )
local name1 = data:ReadString()
local nickteamcolour1 = team.GetColor(data:ReadShort())
chat.AddText( Color( 255, 0, 255 ), "[Server] ", nickteamcolour1, name1, Color( 255, 255, 255 ), " has joined in the server." )
surface.PlaySound( "garrysmod/save_load1.wav" )
end
usermessage.Hook("player_spawn", player_spawn)
// Disconnect
function player_disconnect( data )
local name3 = data:ReadString()
local name4 = ply:SteamID()(ply:ReadString())
local nickteamcolour3 = team.GetColor(data:ReadShort())
chat.AddText( Color( 255, 0, 255 ), "[Server] ", nickteamcolour3, name3, Color( 255, 255, 255 ), " has left the server. Steam ID:" name4 )
surface.PlaySound( "garrysmod/save_load2.wav" )
end
usermessage.Hook("player_disconnect", player_disconnect)[/CODE]
Is that Whart I'm supposed to do?
Not quite..
[QUOTE=Acecool;46270572]Well, you're already grabbing the name via string; you'd simply add another line like "local name3 = data:ReadString()", after the line with data:ReadShort( ), with a new variable name for steamid.
On the server-side code, you'd add a new WriteString with the steamid, after the line with WriteShort... [url]http://wiki.garrysmod.com/page/umsg[/url] although I'd recommend using net instead of umsg but for something like this it doesn't really matter.[/QUOTE]
Basically, just copy and paste the line with data:ReadString( ) on a new line, after the line data:ReadShort( ). Or, in between; but networking data needs to be read in the order it was sent so if you put it in the middle, then you'd need to ensure you write the steamid string in the same place on the server-side of that script.
Post the full script.
I'm not really getting it, also this IS the whole lua file
Is that what you mean?
[CODE]// client side apple
// Spawn
function player_spawn( data )
local name1 = data:ReadString()
local nickteamcolour1 = team.GetColor(data:ReadShort())
chat.AddText( Color( 255, 0, 255 ), "[Server] ", nickteamcolour1, name1, Color( 255, 255, 255 ), " has joined in the server." )
surface.PlaySound( "garrysmod/save_load1.wav" )
end
usermessage.Hook("player_spawn", player_spawn)
// Disconnect
function player_disconnect( data )
local name3 = data:ReadString()
local name4 = data:ReadString() ply:SteamID()
local nickteamcolour3 = team.GetColor(data:ReadShort())
chat.AddText( Color( 255, 0, 255 ), "[Server] ", nickteamcolour3, name3, Color( 255, 255, 255 ), " has left the server. Steam ID:" name4 )
surface.PlaySound( "garrysmod/save_load2.wav" )
end
usermessage.Hook("player_disconnect", player_disconnect)[/CODE]
Sorry if this is frustrating I really dont understand haha
Look for "server side apple"... Nah, just look through all Lua files ( use notepad++ or other tool to search all *.lua files ) for player_disconnect and player_spawn; you should find the code where it sends the message.
Sorry, you need to Log In to post a reply to this thread.