If you're going to be doing this kind of stuff, I always have to recommend learning how it works and not asking people to write it for you. I understand you're nooby at programming, but we all were once.
I'm going to try and break it down for you as easily as possible.
PlayerSpawn is an event. It's called whenever a Player spawns in the map alive (not as a spectator). It returns one variable, the Player entity of the spawned player.
Player:Name() gets the Player object's Steam name. You might not want to do this, actually, and instead opt for
Player:SteamID(), which can never change.
Entity:SetHealth(number health) does what it says. It sets an Entity's health (in this case a Player's) to the number you pass it.
Player:SetArmor(number armor), again, does exactly what it says. It sets a Player's armor to whatever you give it.
Hooking events, as I said, is rather simple. In your case, you'd want to place code for hooking things in some Lua file in /lua/autorun/server/ in your server's files. This is because all of these functions exist on the SERVER side of the Lua instance, so it's all SERVER sided calls.
The code for hooking PlayerSpawn would look something like this.
hook.Add("PlayerSpawn", "DoSomething", function(ply)
-- your code here
end)
If you wanted to print a message to the server console with a player's name every time someone spawns, it'd look like this.
hook.Add("PlayerSpawn", "PrintPlayerNameOnSpawn", function(ply)
if not IsValid(ply) then return end
print(ply:Name() .. " has spawned!")
end)
In that code is also an example of using Player objects. The "callback" function you give the hook accepts one parameter, that parameter being the Player who spawned. I assigned a name to that variable, ply, but really it could be anything.
The line:
if not IsValid(ply) then return end
can be summarized as "If the player object I got isn't actually a player (bug/disconnect?), stop running".
Moving onto conditionals, like what you're asking, is very simple. If I wanted to print a message only when a player with a certain name spawns, like you're asking, it's also very easy to do.
hook.Add("PlayerSpawn", "PrintPlayerNameOnOneGuy'sSpawn", function(ply)
if not IsValid(ply) then return end
if ply:Name() == "Some Guy" then
print("Some Guy has spawned!")
end
end)
Again, however,
names can change. I would recommend using a SteamID instead, which is static. That would look something like this.
hook.Add("PlayerSpawn", "PrintPlayerNameOnOneGuy'sSpawn", function(ply)
if not IsValid(ply) then return end
if ply:SteamID() == "STEAM_0:1:44419830" then
print("Bytewave has spawned!")
end
end)
The way to use the methods you want to call is just like calling ply:SteamID() or ply:Name(), except you'll ahve to pass in a parameter. That looks something like this.
ply:SetHealth(100) -- give the player 100 HP
ply:SetArmor(100) -- give the player 100 Armor
The rest should be fairly easy to figure out; I've given you the pieces to the puzzle, now put them together.
