Can someone advice me what is wrong with this code?

Alright so i was doing some LUA scripting with a friend of mine who helped me but after all we dint got it working and he dont know what he did wrong to, he said “ply isent defined” or something like that but idk if thats true… He said it should work,

Basicly what we were trying to do is that when people connect to the server and enter the game it says “player [name] joined the server with steamid [id]” in chat…
Better way to ban ppl there steam id’s with ULX,

function FirstSpawn( ply )
for k,v in pairs( player.GetAll() ) do
v:PrintMessage( HUD_PRINTTALK, “…ply:Nick()…” joined, his SteamID is: "…ply:SteamID() )

end

hook.Add( “PlayerInitialSpawn”, “playerInitialSpawn”, FirstSpawn )

function FirstSpawn( ply )
for k,v in pairs( player.GetAll() ) do
v:PrintMessage( HUD_PRINTTALK, “…ply:Nick()…” joined, his SteamID is: "…ply:SteamID() )

end

hook.Add( “PlayerInitialSpawn”, “playerInitialSpawn”, FirstSpawn )

I hope you guys can help cuz my friend said it may had to do with TTT but im not sure of that.

Thanks!

What file have you put them in?

Also, I would recommend you use the OnConnect and OnDisconnect hooks.

  • snip didnt read post -

Also, with your code it prints everyones steam id everytime someone joins

You need to end the for loop, just as you end a function.

[editline]27th February 2011[/editline]

Not true - it goes through all players, but it prints the details of the player that joined.

Try this: (I’m on iPhone so it may fail)

[Lua]
function PrintNameFirst (ply)
ply:PrintMessage( HUD_PRINTTALK, ply:Nick()…" Has Joined The Server, Their SteamID is “…ply:SteamID()…”.
"
end

hook.Add( “PlayerInitialSpawn” , “PlyNamePrint” , PrintNameFirst )
[/Lua]

It’s worth a try, but hopefully it works.

Ah wait i got it working now

function FirstSpawn( ply )
PrintMessage( HUD_PRINTTALK, ply:Nick()… " joined, his SteamID is: " …ply:SteamID() )
end

hook.Add( “PlayerInitialSpawn”, “playerInitialSpawn”, FirstSpawn )

But how about on disconnect (when somebody RDMes and leave so we can easilly ban them to) (soz for bad english :3)

[editline]27th February 2011[/editline]

nvm got it working for disconnect to, Thank you very much all for ur help and time ^^

[Lua]
function PrintNameFirst (ply)
ply:PrintMessage( HUD_PRINTTALK, ply:Nick()…" Has Joined The Server, Their SteamID is “…ply:SteamID()…”.
"
end

hook.Add( “PlayerInitialSpawn” , “PlyNamePrint” , PrintNameFirst )

function PrintNameFirstDisc (ply)
ply:PrintMessage( HUD_PRINTTALK, ply:Nick()…" Has Left The Server, Their SteamID is “…ply:SteamID()…”.
"
end

hook.Add( “PlayerDisconnected” , “PlyNamePrint” , PrintNameFirstDisc )
[/Lua]

Hope this works.

I got it working btw. (Thanks for helping me tho Great job all ^^) But i dont know if you guys know about when the round starts in TTT u and ur inno a music/sound plays and when traitor another sound/music players (diff from eatchother) I have end round music working But when selected i wanna play a sound to, you guys have any ideas that can help me out?

RTM, that code would only print the SteamID of the player who joins to themself.

[lua]
function FirstSpawn( ply )
PrintMessage( HUD_PRINTTALK, ply:Nick()… " joined, his SteamID is: " …ply:SteamID() )
end

hook.Add( “PlayerInitialSpawn”, “playerInitialSpawn”, FirstSpawn )

function PlayerDisconnect( ply )
PrintMessage( HUD_PRINTTALK, ply:Nick()… " has disconnected, his SteamID is: " …ply:SteamID() )
end

hook.Add( “PlayerDisconnected”, “playerDisconnected”, PlayerDisconnect )[/lua]

Yeah i got same code as above :smiley:
(Thanks for helping me tho :D)
But how about the music what plays when selected as innocent or traitor (detective is innocent I guess for TTT) Thats the last thing i need to fix then everything is complete ^^

Yeah I know, I was the one that put it up for you in your thread on the TTT forums.

[lua]
resource.AddFile(“sound/innocent.mp3”)
resource.AddFile(“sound/traitor.mp3”)

local function PlaySounds()
for k,v in pairs( player.GetAll() ) do
if v:GetTraitor() then
v:SendLua(‘surface.PlaySound(“traitor.mp3”)’)
elseif !v:GetTraitor() then
v:SendLua(‘surface.PlaySound(“innocent.mp3”)’)
else
end
end
end

hook.Add(“TTTBeginRound”, “Sounds”, PlaySounds)[/lua]

That should work, I think.

EDIT

I changed it a bit, the original one would have played innocent music for spectators.

Ok ill give it a try

EDIT: The code dont work the sound wont play when selected as traitor, edited the code, just for testing purpose

resource.AddFile(“sound/begininnocent.mp3”)

local function PlaySounds()
for k,v in pairs( player.GetAll() ) do
if v:GetTraitor() then
v:SendLua(‘surface.PlaySound(“begininnocent.mp3”)’)
else
v:SendLua(‘surface.PlaySound(“innocent.mp3”)’)
end
end
end

hook.Add(“TTTBeginRound”, “Sounds”, PlaySounds)

What do you mean? Is it playing for innocent but not traitor? Are there any errors in the console?

Also the bit where you set it to play ‘begininnocent.mp3’ is the file that will be played when you are traitor.

I know, i have a test server just for me alone and when u spawn you spawn as traitor, ofc with the command
“ttt_minimum_players 1”
“ttt_debug_preventwin 1” (testing purpose)

then you spawn as traitor when the round starts, i just look a .mp3 file from my music folder for testing purpose to but thats 10MB but i think size dont matter or does it?

Edit ok see the code as this

resource.AddFile(“sound/begintraitor.mp3”)

local function PlaySounds()
for k,v in pairs( player.GetAll() ) do
if v:GetTraitor() then
v:SendLua(‘surface.PlaySound(“begintraitor.mp3”)’ )
else
v:SendLua(‘surface.PlaySound(“innocent.mp3”)’)
end
end
end

hook.Add(“TTTBeginRound”, “Sounds”, PlaySounds)

but that dont work for me atleast :frowning:

[editline]27th February 2011[/editline]

Oh dear i was wrong and it works, i used another mp3 file and it works , im so sorry it was my own fault >.>

Thanks again! :smiley: