Stripweapon

can anyone help?



function DropPhysGun()
if ply:Team(TEAM_POLICE) then
return false
else
ply:StripWeapon("taser")
end
end


it Should Strip the Players taser if they are not Police
but it doesent work

any Help?

I’m probably wrong, but shouldn’t that be
[lua]if(ply:Team() == TEAM_POLICE) then[/lua]

dident Work

snip

[Lua]
function DropPhysGun()
if(ply:Team() == TEAM_POLICE) then
return false
else
ply:StripWeapon(“taser”)
end
end
concommand.Add( “strip”, DropPhysGun )
[/Lua]
I have added concommand.add and when I enter strip in console it says

attempt to index global “ply”(a nil value)

[lua]function DropPhysGun(ply, com, args)
if(ply:Team() == TEAM_POLICE) then
return false
else
ply:StripWeapon(“taser”)
end
end
concommand.Add( “strip”, DropPhysGun )
[/lua]

That will fix your last error message. Not sure about the stripweapon function though, as I don’t have access to the gmod wiki,

Oops yeah, I missed the lack of arguments

is there an better way then useing timer.Create to make it exec every second?

No, a timer is a pretty solid way to do it.

timer.Create(“someStuff”, 1, 0, function() Msg(“oh hi”) end)

It’s probably not going to work because that function isn’t being called when you attempt to drop your physgun. You would need to do this:

[lua]function DPS()
if ( ply:Team() == TEAM_POLICE ) then
return false
else
ply:StripWeapon(“taser”)
end
end
hook.Add(“PhysgunDrop”, “PGD”, DPS)
[/lua]

now I get the same error with the timer every time the Timer Exec the Function it
spam the host console with attempt to index local “ply” (a nil value)

[LUA]
function DPS(ply, com, args)
if ( ply:Team() == TEAM_POLICE ) then
return false
else
ply:StripWeapon(“taser”)
end
end
hook.Add(“PhysgunDrop”, “PGD”, DPS)

concommand.Add( “strip”, DPS )
timer.Create( “striptaser”, 1, 0, DPS)
[/LUA]

You should read up on timers and concommands. If you want to execute a function with arguments, it will have to look like this in your case:

[lua]timer.Create( “striptaser”, 1, 0, DPS, ply) [/lua]

Furthermore, you can’t simply put the timer anywhere. There is no specification of a player entity ply. Either cycle through all the players and create a unique timer for them, or hook it to an event.

same error timer error lua/autorun/server/stripweapon.lua:2: attempt to index…

Did you read what I just posted?

You can’t just put the timer anywhere and don’t specify the player. Like I said; either cycle through the player list or hook it to an event that automatically gives you a player entity.

could you give an example?

[lua]for k, v in pairs(player.GetAll()) do
if ( v:Team() == TEAM_POLICE ) then
return false
else
v:StripWeapon(“taser”)
end
end

[/lua]

Sorry for the lack of formatting

Thanks! =)