Need Help with a script to remove a weapon from inventory if the weapon has no ammo.
7 replies, posted
[CODE]
for k,v in pairs( ply:GetWeapons() ) do
if v:GetAmmoCount() == 0 then
ply:StripWeapon( v )
end
end
[/CODE]
I am using that currently but it doesn't work. I was wandering if anyone can tell me why that doesn't work. Any help is appreciated.
Well when do you run the code?
GM:PlayerLoadout
PlayerLoadout only gets run when the player's meant to get weapons, which seems to be only at the start of the round - try using something like [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/EntityFireBullets]GM/EntityFireBullets[/url] so it gets called whenever bullets are fired, which is probably more suitable
or in a timer/think
Well, you could do that, but I think it'd be better to only call it when it's actually needed (as in when bullets are fired)
I think there is a problem with the rest of the code too. I'm not sure though
[QUOTE=awesomenessis;50028045]I think there is a problem with the rest of the code too. I'm not sure though[/QUOTE]
Pretty sure StripWeapon's argument is a string, not an entity.
So you'll have to do v:GetClass()
Sorry, you need to Log In to post a reply to this thread.