I believe I would use Player.SetArmor, but where should I put the code to do it? Sorry for being a noob.
[lua]
function GM:PlayerLoadout( ply )
ply:SetHealth(100)
ply:SetArmor(100)
end
[/lua]
Should work. ;D
[QUOTE=z3r0killz;29564116][lua]
function GM:PlayerLoadout( ply )
ply:SetHealth(100)
ply:SetArmor(100)
end
[/lua]
Should work. ;D[/QUOTE]
Thanks. also, where should I put the code? like which file, and near what point?
that code isnt going to work for what you want, use this
[lua]
for k, v in pairs(player.GetAll()) do
if(v:team() == INSERT_TEAM_NAME_HERE) then
v:SetArmor( 100 )
end
end
[/lua]
just put it in any server side file
[QUOTE=c-unitV2;29564594]that code isnt going to work for what you want, use this
[lua]
for k, v in pairs(player.GetAll()) do
if(v:team() == INSERT_TEAM_NAME_HERE) then
v:SetArmor( 100 )
end
end
[/lua]
just put it in any server side file[/QUOTE]
I didn't know what he meant/wanted >.<
Thanks to both of you!
z3r0killz
You also can't code.
That code will never be called, only on initialize when there are no players in the server unless hosted by himself.
[lua]
function GM:PlayerLoadout( ply )
if ply:team() == TEAM_NAME_HERE then
ply:SetArmor(100)
end
end
[/lua]
you guys are dumb, use my code except call it on whichever hook you would like
[QUOTE=c-unitV2;29586473]you guys are dumb, use my code except call it on whichever hook you would like[/QUOTE]
The OP obviously wanted complete code, why not just give him what he asked for, its easy enough...
Besides your code still fails, putting that in any playerspawn/loadout hook would set everyone's armor. Plus its ply.Team not ply.team.
Put this in any serverside darkrp file (do a ctrl+f directory search with notepad++ for PlayerSpawn and throw it under that function)
[lua]
hook.Add("PlayerSpawn", "drparmor", function(ply)
if (ply:Team() == TEAM_DERP) then
ply:SetArmor(1e12);
end
end);
[/lua]
@wrongpeople for the love of the lua God please stop answering lua questions if you have no idea what the shit you're talking about.
Again, thanks.
You can use slight's method, or edit sv_gamemode_functions.lua on GM:PlayerLoadout or spawn, search "Team_Police" and you need to add teams.
[QUOTE=Slight;29586861]The OP obviously wanted complete code, why not just give him what he asked for, its easy enough...
Besides your code still fails, putting that in any playerspawn/loadout hook would set everyone's armor. Plus its ply.Team not ply.team.
Put this in any serverside darkrp file (do a ctrl+f directory search with notepad++ for PlayerSpawn and throw it under that function)
[lua]
hook.Add("PlayerSpawn", "drparmor", function(ply)
if (v:Team() == TEAM_DERP) then
v:SetArmor(1e12);
end
end);
[/lua]
@wrongpeople for the love of the lua God please stop answering lua questions if you have no idea what the shit you're talking about.[/QUOTE]
v:team() was a typo, and how do you figure my code will set everyone armor to 100? Because it will not. Also v is nil in your code, now stop saying a how much i fail and go fix your code
Slight was the only one that was right, which is sad as there were so many attempts at a simple script. FYI it would be better to use PlayerLoadout but playerspawn works.
How was my code wrong sintwins? besides the team typo?
[QUOTE=c-unitV2;29593703]How was my code wrong sintwins? besides the team typo?[/QUOTE]
Well it didn't have a hook attached to it so it would only be run when the script was loaded so how can it be expected to work?
[QUOTE=sintwins;29593794]Well it didn't have a hook attached to it so it would only be run when the script was loaded so how can it be expected to work?[/QUOTE]
I told him to call it in whichever hook he would like
[QUOTE=c-unitV2;29593835]I told him to call it in whichever hook he would like[/QUOTE]
c-unit, if you do it with player.GetAll() it will sets EVERYONE'S in this team armor. Meaning that it isn't ran on one person, but everyone on server with that team gets that.
which is why i added the if(v:Team() == team) check?
c-unit, your code basically sets the armor for everybody in that team again to 100 as soon as one player of the team spawns. And that's not what Bertolet wanted, as far as I can guess.
Also, he asked where he should put the code in - I doubt that an answer without at least "a hook" helps him. I would go even farther and say that it doesn't help him at all as it can be a bit tricky for inexperienced coders to find the right hook.
[lua]hook.Add("PlayerSpawn", "Armor", function( p )
for k, v in pairs(player.GetAll()) do
v.ArmorVar = 0
end
if(p.ArmorVar == 0) then
if(p:Team() == TEAM_POLICE) then
p:SetArmor( 100 )
p.ArmorVar = 1
end
else
return;
end
end)
hook.Add("PlayerDeath", "Armor", function(p, wep, attacker)
if(p.ArmorVar == 1) then
p.ArmorVar = 0
end
end)[/lua]
Untested, what do the other facepunchers think?
Why do that when you just need to set the player's armor when they spawn?
Bloat.
It's way easier. In fact, it's five lines easy.
[lua]
hook.Add('PlayerLoadout', 'GimmeSomeArmor', function(ply)
if ply:Team() == REPLACE_ME_WITH_TEAM then
ply:SetArmor(REPLACE_ME_WITH_ARMOR)
end
end)[/lua]
[QUOTE=c-unitV2;29596191][lua]hook.Add("PlayerSpawn", "Armor", function( p )
for k, v in pairs(player.GetAll()) do
v.ArmorVar = 0
end
if(p.ArmorVar == 0) then
if(p:Team() == TEAM_POLICE) then
p:SetArmor( 100 )
p.ArmorVar = 1
end
else
return;
end
end)
hook.Add("PlayerDeath", "Armor", function(p, wep, attacker)
if(p.ArmorVar == 1) then
p.ArmorVar = 0
end
end)[/lua]
Untested, what do the other facepunchers think?[/QUOTE]
Oh god. Basicly, what your code does, is that when ANYBODY spawn, EVERYONE'S armor resets. EVERY PLAYER'S ARMOR WILL RESET.
--> You only want to set armor of the SPAWNING one.
[lua]hook.Add("PlayerLoadout", "armortheCPs", function( ply )
if
ply:Team() == "TEAM_POLICE" or
ply:Team() == "TEAM_SWAT"
then
ply:SetArmor( 100 )
end
end)[/lua]
Where is the player.setarmor?
Sorry, you need to Log In to post a reply to this thread.