Text Lua Help

I downloaded these two scripts from another post and wanted to use them to show when a player joins the server and when a player leaves the server. However, these two scripts only show when a player joins, but when a player leaves, nothing happens. Anyone know what’s going on?


//Don't touch the line below this, or your script won't work anymore ~ Mr. Apple
AddCSLuaFile( "cl_player_join.lua"  )


--[[ 
    This makes it so that it shows players disconnecting and connecting. Aswell it allows people to type !join to join the group.
	
--]]
function fPlayerDisconnect( ply )
local name = ply:Nick()
local steamid = ply:SteamID()
		umsg.Start("disconnect_play")
		umsg.String(name)
		umsg.String(steamid)
		umsg.End()
end
hook.Add( "PlayerDisconnected", "playerdisconnected", fPlayerDisconnect )

function fPlayerConnect( ply )
local name = ply:Nick()
local steamid = ply:SteamID()
		umsg.Start("connect_play")
		umsg.String(name)
		umsg.String(steamid)
		umsg.End()
end
hook.Add( "PlayerInitialSpawn", "playerconnected", fPlayerConnect )

function ISaid( ply, saywhat )
local name = ply:Nick()
		umsg.Start("join_group")
		umsg.String(saywhat)
		umsg.String(name)
		umsg.End()
		umsg.Start("join_group2", ply)
		umsg.String(saywhat)
		umsg.String(name)
		umsg.End()
end
hook.Add( "PlayerSay", "ISaid", ISaid )


// I don't like placing things in the first line, ever. So here's my first line

usermessage.Hook("connect_play", function(data)
local name1 = data:ReadString()
local steamid1 = data:ReadString()
chat.AddText(Color(158, 195, 79), name1.." has connected. (ID: "..steamid1..")")
end)

usermessage.Hook("disconnect_play", function(data)
local name2 = data:ReadString()
local steamid2 = data:ReadString()
chat.AddText(Color(158, 195, 79), name2.." has left the server. (ID: "..steamid1..")")
end)

usermessage.Hook("join_group", function(data)
local saywhat = data:ReadString()
local name3 = data:ReadString()
if saywhat == "!join" then
chat.AddText(Color(204, 230, 255), "Player " ..name3.." has joined our Steam group via !join.")
end
end)

usermessage.Hook("join_group2", function(data)
local saywhat = data:ReadString()
local name3 = data:ReadString()
if saywhat == "!join" then
gui.OpenURL("http://steamcommunity.com/groups/SourceGamin")
end
end)

Sorry for asking but can i ask where you got this from? :slight_smile:

I got it from here:

Update:

I just figured out that only sometimes it doesn’t show people connect or disconnect, but other times it does. This is very strange.

think i found the issue… maybe… i dont know but look at this:

usermessage.Hook(“disconnect_play”, function(data)
local name2 = data:ReadString()
local steamid2 = data:ReadString()
chat.AddText(Color(158, 195, 79), name2…" has left the server. (ID: “…steamid1…”)")
end)

Look at the “local steamid2” and the (ID: “…steamid1…”)")… I thin you have to edit the “…steamid1…” so its “…steamid2…”

Im not sure because Im not the best lua coder in the world… aka im newbie :p… see if it works and tell me :smiley:

EDIT: sorry I Dont know how you put that code line into a table like “pros” do so it look nice :(((

That doesn’t seem to be it, I just get lua errors.

then you didn’t do it right because i just downloaded it to my server and had the same problem as you had but I just wrote (ID: “…steamid2…”)") insted of (ID: “…steamid1…”)")

 EDIT: copy/paste this into your cl_player_join.lua

usermessage.Hook(“connect_play”, function(data)
local name1 = data:ReadString()
local steamid1 = data:ReadString()
chat.AddText(Color(158, 195, 79), name1…" has connected. (ID: “…steamid1…”)")
end)

usermessage.Hook(“disconnect_play”, function(data)
local name2 = data:ReadString()
local steamid2 = data:ReadString()
chat.AddText(Color(158, 195, 79), name2…" has left the server. (ID: “…steamid2…”)")
end)

usermessage.Hook(“join_group”, function(data)
local saywhat = data:ReadString()
local name3 = data:ReadString()
if saywhat == “!join” then
chat.AddText(Color(204, 230, 255), “Player " …name3…” has joined our Steam group via !join.")
end
end)

usermessage.Hook(“join_group2”, function(data)
local saywhat = data:ReadString()
local name3 = data:ReadString()
if saywhat == “!join” then
gui.OpenURL(“http://steamcommunity.com/groups/SourceGamin”)
end
end)

use [lua] tags please

I just put that on my server and it shows whenever I join. With the old script, it stops showing once a few people join. No one is on right now so I will test if it still works in a few hours and let you know.

[editline]29th June 2013[/editline]

Someone joined my server, left, and it said no message. I think this script is mostly broken. Try getting people to join and leave 5 times. See how many times the script actually works.

Anyone got anything else that works?

Dude… I just install it on my server without editing anything except that part and it works 100%

And you are sure you have it like “thefolder”/lua/autorun/ “cl_player_join” & cl_“something”

Yes, it always shows for me that players join, but it only shows leaving players like 20 percent of the time.

Nevermind.