I'm trying to make it so props can't pick up these weapons: rpg, ar2, and grenade
I've tried a ton of things with this, but nothing works
[lua]
function GM:PlayerCanPickupWeapon(pl, ent)
if pl:Team() != TEAM_HUNTERS then
return true
end
return true
end[/lua]
Can someone please help me with this, I have no clue what I'm doing wrong.
I have a code that gives last prop alive a 357, so I can't completely turn off props getting weapons cause then they can't get the 357
And there are weapons laying around certain maps, I just need to make it so the props can't pick them up, but the hunters can.
Any help is appreciated.
let us take your code apart.
[lua]function GM:PlayerCanPickupWeapon(pl, ent)[/lua]
ok. right hook.
[lua] if pl:Team() != TEAM_HUNTERS then
return true
end
[/lua]
If you're not in TEAM_HUNTERS you can pick weapons up.
[lua] return true
end
[/lua]
aand you can pick it up, regardless of the Team.
Basicly your code is complete useless, since it doesn't do shit.
What you try to do, is an variable in the Metatable Player.
You should do something simmilar to this (PSEUDOCODE)
[lua] // Last Prop Standing
ply.IsLastProp = true // Setting the variable for the player.
ply:Give("weapon_AK47")
[...]
function GM:PlayerCanPickupWeapon(ply, ent)
if ply:Team() == TEAM_PROP and ply.IsLastProp then // If it is an Prop and got the variable true, then let him pick it up.
return true
end
if ply:Team() == TEAM_HUNTERS then // Hunters can pick it up.
return true
end
return false // other Props not.
end
[...]
hook.Add("PlayerSpawn", "CleaningOutmyCloset", function( ply ) ply.IsLastProp = false end) // setting the variable back to false, so that the props aren't keeping the flag.
[/lua]
I'm not sure if the code you provided would have worked, but it helped me figure out what I needed to do.
Just put this in and it worked great.
[lua]
function GM:PlayerCanPickupWeapon(ply, ent)
local prop_alive = {}
for k,ply in pairs( team.GetPlayers(TEAM_PROPS) ) do
if ply:Alive() then table.insert( prop_alive, ply ) end
end
if ply:Team() == TEAM_PROPS && table.Count(prop_alive) == 1 then
return true
end
if ply:Team() == TEAM_HUNTERS then
return true
end
return false
end [/lua]
Thank you for the help!
Sorry, you need to Log In to post a reply to this thread.