player:SetModel Not working?!

Please help me… A couple of things to bare in mind when answering

  1. I AM A HUGE NOOB (I literally just started Gmod lua coding 2 days ago and made my facepunch account about 1 hour ago)
  2. I will probably not understand what you are talking about when it comes to code so please try to explain it!

anyway with that all over here is my problem!

this is the code in my init.lua

**** BIG EDIT****

My actualy player model now works but my first person interface does not (My gun floats in mid air in first person view)

This is my new code:

[lua]function GM:PlayerInitialSpawn( ply )
ply:SetModel( “models/player/odessa.mdl” )
ply:SetTeam( 1 )
end

function GM:PlayerSpawn( ply )
if ply:Team() == 1 then
ply:Give( “weapon_pistol” )
ply:SetModel( “models/player/leet.mdl” )
end
if ply:Team() == 2 then
ply:Give( “weapon_357”)
ply:SetModel( “models/player/odessa.mdl” )
end
if ply:Team() == 3 then
end

//Team Randomiser
ply:SetTeam( math.random( 1, 2 ) )

COS = team.NumPlayers( 1 )
SEA = team.NumPlayers( 2 )
if COS > SEA then
ply:SetTeam( 2 )
elseif SEA > COS then
ply:SetTeam( 1 )
end

if ply:Team() == 1 then
ply:SetModel( “modles/player/alyx.mdl” )
end

end[/lua]

What model are they?

Also look into elseif statements

  1. well I suppose the model is odessa

  2. Thanks I will

Well there are a few things I see wrong.

  1. Your order is messed up in your playerspawn hook. If you are changing the players model depending on what team they are on, you should put your code to change teams ahead of the one to change player models.

Something like this:
[lua]
function GM:PlayerInitialSpawn( ply )
ply:SetModel( “models/player/odessa.mdl” )
ply:SetTeam( 1 )
end

function GM:PlayerSpawn( ply )
ply:SetModel( “models/player/odessa.mdl” )

//Team Randomiser
ply:SetTeam( math.random( 1, 2 ) )

COS = team.NumPlayers( 1 )
SEA = team.NumPlayers( 2 )
if COS > SEA then
ply:SetTeam( 2 )
elseif SEA > COS then
ply:SetTeam( 1 )
end

if ply:Team() == 1 then
ply:SetModel( “modles/player/alyx.mdl” )
end

end
[/lua]

  1. Although this isn’t really wrong… If your only trying to change the player model of that one team you do not need all of those if statements for the other teams.

  2. This isn’t wrong either but you can make some of your code short and get rid of those if statements in some parts:

Something like this:
[lua]
local RDM = math.random( 1, 2 )
if RDM == 1 then
ply:SetTeam( 1 )
elseif RDM == 2 then
ply:SetTeam( 2 )
end
[/lua]

Can easily be shortened to this:
[lua]

//First way
local RDM = math.random( 1, 2 )
ply:SetTeam( rdm ) --sets the team to what ever variable is inside and since your only searchign for either 1 or 2 it makes more sense to just do this

//Second Way
ply:SetTeam( math.random( 1, 2 ) )
[/lua]

Also what exactly is your issue? If its the player in t-model pose thing you might just be using the wrong models. I know there are separate player models with animations that have to be used.

You’re supposed to use PlayerSpawn to handle spawning, PlayerSetModel hook to set the model, PlayerLoadout to handle weapons. PlayerSetModel and PlayerLoadout should be called by PlayerSpawn.

ok bran92don

  1. thanks for the help
  2. You kind of fixed it!
  3. my gun is still floating in mid air but my player model now works (my first person view has no hands)

If the gun is floating in air, then the addon isn’t properly installed, or the game isn’t mounted correctly. mount.cfg has issues with caps, hyphens, and parens at times: (, -, )

https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/setting_up_a_server_with_steamcmd.lua.html

No… I’m just using the regular pistol
(ply:Give( “weapon_pistol”))

also it is not exactly floating there is just no hand holding onto it…

I’m assuming this is a custom gamemode?
If so, this should help you out.

Please use [noparse][lua]CODE HERE[/lua][/noparse] tags, it’s much easier to read.

Jeezy: SetupHands does not work for some reason

RonanZer0: Done thanks

Can you tell if it is coming out of the crotch?

I believe Robot / Rejax came up with these:
https://dl.dropboxusercontent.com/u/26074909/_server/code/weapon_worldmodel_upside_down.lua
https://dl.dropboxusercontent.com/u/26074909/_server/code/weapon_rh_fix.lua

No its as if someone just removed the hand model. This actual gun is in the normal place

Show us the SWEP code… Did you set the worldmodel to w_… and the viewmodel as v_ or c_ ?

Remember what I told you I am a complete noob I know what none of that means

Example from weapon_base:


SWEP.ViewModel		= "models/weapons/v_pistol.mdl"
SWEP.WorldModel		= "models/weapons/w_357.mdl"


When you set the viewmodel, it’ll be a v_… or c_… modelname…

When you set the worldmodel, it’ll be w_…