FA:S 2 weapons work on sandbox gamemode but not my gamemode

Hello, I’m having a problem as described in the title. FA:S 2 weapons work fine when I change the +gamemode “” in my server start.bat to sandbox, but when I try the weapons with my gamemode, the view models of the guns are invisible, and when I try and drop a weapon the model just freezes in mid air, and cannot be picked up. The gun can still be shot, though; the bullets seem to shoot from above the player’s head. If you know what might be causing this then please share with me how I can fix this issue.

Thank you

Are you changing it to your gamemode name, or are you actually changing it to “+gamemode “””?
And what is your gamemode derived from? Could you post some code from it, if you haven’t gotten far?

I am changing it to +gamemode “sandbox”
I have gotten sort of far in my gamemode, so I can’t necessarily post all of it, and apparently I don’t have DeriveGamemode( “sandbox” ) in the shared folder, so I guess whatever it defaults to. I will try deriving it to sandbox and see what happens.

[editline]1st October 2014[/editline]

Now the “q” menu can be accessed, and the view models of the weapons still are not visible.

[editline]1st October 2014[/editline]

Just tried DeriveGamemode( “base” ), and I’m getting the same results I was getting with not having DeriveGamemode() at all.

I also just tried removing this from my code to no success:


local oldhands = ply:GetHands()
if ( IsValid( oldhands ) ) then oldhands:Remove() end*/
  

  local hands = ents.Create( "gmod_hands" )
  if ( IsValid( hands ) ) then
    ply:SetHands( hands )
    hands:SetOwner( ply )

    -- Which hands should we use?
    local cl_playermodel = ply:GetInfo( "cl_playermodel" )
    local info = player_manager.TranslatePlayerHands( cl_playermodel )
    if ( info ) then
      hands:SetModel( info.model )
      hands:SetSkin( info.skin )
      hands:SetBodyGroups( info.body )
    end

    -- Attach them to the viewmodel
    local vm = ply:GetViewModel( 0 )
    hands:AttachToViewmodel( vm )

    vm:DeleteOnRemove( hands )
    ply:DeleteOnRemove( hands )

    hands:Spawn()

Tried changing player model to Kliener, no success.

This is how I am giving the player the weapon:


function GM:ShowSpare1 ( ply )
ply:Give("fas2_m1911")
end

Surely some hero will be able to help me through this issue!

Try removing everything from all files in your gamemode, except for deriving from “base” and the PlayerSpawn function where you give him the weapon. And make sure to set his playermodel.

That was a great idea, why didn’t I think of that! Yes, the weapons are working with deriving from base, so I will slowly try to figure out what is causing the issue, and then report back.

Thanks for the help RonanZer0

[editline]3rd October 2014[/editline]

Ok, I’ve located the issue. This is the bit of code that was causing the weapons to not show up:


function GM:PostDrawViewModel( vm, ply, weapon )

  if ( weapon.UseHands || !weapon:IsScripted() ) then
    local hands = LocalPlayer():GetHands()
    if ( IsValid( hands ) ) then hands:DrawModel() end

  end

end

So it was the hands fix after all… I’ll do some more testing and report back.

[editline]3rd October 2014[/editline]

Well, it seems that that bit of code isn’t really necessary. If I take this out of my init.lua:


local oldhands = ply:GetHands()
if ( IsValid( oldhands ) ) then oldhands:Remove() end
  

  local hands = ents.Create( "gmod_hands" )
  if ( IsValid( hands ) ) then
    ply:SetHands( hands )
    hands:SetOwner( ply )

    -- Which hands should we use?
    local cl_playermodel = ply:GetInfo( "cl_playermodel" )
    local info = player_manager.TranslatePlayerHands( cl_playermodel )
    if ( info ) then
      hands:SetModel( info.model )
      hands:SetSkin( info.skin )
      hands:SetBodyGroups( info.body )
    end

    -- Attach them to the viewmodel
    local vm = ply:GetViewModel( 0 )
    hands:AttachToViewmodel( vm )

    vm:DeleteOnRemove( hands )
    ply:DeleteOnRemove( hands )

    hands:Spawn()
	end

Then the hands won’t show up at all, as expected, since that is the hands fix.

But if I take this out of my cl_init.lua:


function GM:PostDrawViewModel( vm, ply, weapon )

  if ( weapon.UseHands || !weapon:IsScripted() ) then
    local hands = LocalPlayer():GetHands()
    if ( IsValid( hands ) ) then hands:DrawModel() end

  end

end

then the hands still show up, and I haven’t had any errors yet. I’m going to go ahead and mark this thread as SOLVED.

Thanks again for your help RonanZer0, it may seem like you didn’t do much, but I was really stuck with this issue, and you made me realize that all I had to do was take everything out and slowly put stuff back in. You are my hero for today!