Welcome, Guest. Please login or register.
Did you miss your activation email?
November 23, 2024, 04:31:14 AM
Home Help Login Register
News: Zombie Master 2 discussion

Zombie Master  |  Other  |  Trouble in Terrorist Town  |  Topic: Can someone advice me what is wrong with this code?
Pages: [1]
Author Topic: Can someone advice me what is wrong with this code?  (Read 5251 times)
Mr. Wepz.
Poster

Posts: 65


« on: February 27, 2011, 01:36:13 AM »

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!
Cush
Poster

Posts: 79


« Reply #1 on: February 27, 2011, 01:49:09 AM »


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


Your speech marks are all messed up and ply:Nick() shouldnt have .. before it. This should work -

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 )
« Last Edit: February 27, 2011, 01:52:40 AM by Cush »
Mr. Wepz.
Poster

Posts: 65


« Reply #2 on: February 27, 2011, 01:51:21 AM »

Im gonna give it a try ill hit you back soon :D

Thanks Btw for fast response :D
Cush
Poster

Posts: 79


« Reply #3 on: February 27, 2011, 01:52:42 AM »


Although instead of looping through every player and printing the message whenever someone joins, you can just use PrintMessage on its own and it will print it in the chat for all players automatically.

Like this :


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

hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )
Mr. Wepz.
Poster

Posts: 65


« Reply #4 on: February 27, 2011, 01:56:47 AM »

yeah thats actolly what i needed let me test now, see if it works.

So final it is

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

hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )
end

right?
Cush
Poster

Posts: 79


« Reply #5 on: February 27, 2011, 01:57:32 AM »

Yup, I dont see any reason that wouldnt run.

*EDIT*

Wait, you added an extra 'end' at the end of it, dont need that.
« Last Edit: February 27, 2011, 01:58:36 AM by Cush »
Mr. Wepz.
Poster

Posts: 65


« Reply #6 on: February 27, 2011, 01:59:58 AM »

Ok it works :D

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

hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )

Final code, but how about on disconnect? When somebody leaves or gets kicked etc. same as this only opposite right?
Cush
Poster

Posts: 79


« Reply #7 on: February 27, 2011, 02:01:57 AM »


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

hook.Add( "PlayerDisconnected", "playerDisconnected", PlayerDisconnect )
Mr. Wepz.
Poster

Posts: 65


« Reply #8 on: February 27, 2011, 02:03:31 AM »

Thanks, i must add this on a diff .lua file or can i use the same only below it? so it will end as


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 )

or just new LUA file?
Cush
Poster

Posts: 79


« Reply #9 on: February 27, 2011, 02:04:38 AM »

That would work fine, you can have as many functions and hooks as you want in a single lua file.

The only reason people put stuff in different files is to keep it all organised.
Mr. Wepz.
Poster

Posts: 65


« Reply #10 on: February 27, 2011, 02:05:33 AM »

Ah ok then ill put it in a diffrent lua file, Thank you so much man this really helped ^^ :D
Cush
Poster

Posts: 79


« Reply #11 on: February 27, 2011, 02:06:34 AM »

Nono you should put it in the same file like you had in your post, no point in having two different lua files which only have a couple of lines each.
Mr. Wepz.
Poster

Posts: 65


« Reply #12 on: February 27, 2011, 02:07:14 AM »

Yeah thats true actolly, ill do that, and really thanks again ^^
Pages: [1]
Zombie Master  |  Other  |  Trouble in Terrorist Town  |  Topic: Can someone advice me what is wrong with this code? « previous next »
Jump to:  


Login with username, password and session length

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines
Page created in 0.01 seconds with 18 queries.