player.StripWeapon

ISSUE RESOLVED, thanks to the console command “lastinv”.

You’ve got a katana in your hand. A Hunter is several meters away with its back turned. You aim, hold “E”, and right click. Your thrown sword nails the Hunter in the back, and to finish it off, you proceed to whip out your… tool gun?

Basically, my issue is that using player.StripWeapon on a currently selected weapon causes the player to switch to the toolgun if they have it, regardless of what weapon they were carrying before switching to the soon-to-be-stripped weapon. If anyone has a fix for this, could they please share it? Thanks!

I don’t know how to fix the bug itself, but you can fix the issue by using **[Player.SelectWeapon

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Player.SelectWeapon)** after StripWeapon.

The thing is, I don’t want the player to select a specific weapon, and as far as I know, player.SelectWeapon only accepts a specific weapon’s class name.

If there’s some way to force the player to select the weapon they were holding before losing the stripped weapon, that’d be great.

Thanks.

Make a variable and set it to whatever weapon they have every time they change weapon, then set their weapon to that variable

Probably need two variables, anyway it’s that simple

[lua]local wep = ply:GetActiveWeapon():GetClass();
ply:StripWeapon(“the_weapon”);
ply:SelectWeapon(wep);[/lua]

[lua]
local weptab = ply:GetWeapons()
for k,v in pairs(weptab) do
if( v:GetClass() == “gmod_tool” ) then
weptab[k] = weptab[k-1]
end
end
local rand = math.random(1, #weptab)
ply:StripWeapon(“wep_name”)
ply:SelectWeapon(weptab[rand]:GetClass())
[/lua]

That should select a weapon that is not the toolgun if i understand what you want correctly…

This is untested code.

ISSUE RESOLVED, I used the console command “lastinv”.

What if the last weapon they had out was the toolgun?