Gmod TTT Custom player models Sometimes unequips on round start

It happens frequently, but sometimes the player model actually stays. It’ll fix itself after a map change sometimes but it is quite annoying. Is there a fix for this? My current code is this:


ITEM.Name = 'Jeff'
ITEM.Price = 30000
ITEM.Model = 'models/newinfec/newhun.mdl'

function ITEM:OnEquip(ply, modifications)
	if not ply._OldModel then
		ply._OldModel = ply:GetModel()
	end
	
	timer.Simple(2, function() ply:SetModel(self.Model) ply:SetupHands() end)
end

function ITEM:OnHolster(ply)
	if ply._OldModel then
		ply:SetModel(ply._OldModel)
	end
end

function ITEM:PlayerSetModel(ply)
	ply:SetModel(self.Model)
end


You can try this http://forum.facepunch.com/showthread.php?t=1250362&p=41323661&viewfull=1#post41323661
Or

I have googled it, the main answer is to comment out line 271 (which was a fix a few years back. The line 271 fix is already fixed when you get pointshop.) Also, most of the results are from 2013-2014 and is outdated.

Any idea at all? If I can’t figure it out I’ll purchase point shop 2 (or I could wait for pointshop pro) which will hopefully fix it.

Edit: It seems to be doing this to the default Kleiner model as well

Try running a simple timer before setting the model in the PlayerSetModel hook. If that fails, try doing it in the PlayerSpawn hook.

TTT resets the playermodel on TTTBeginRound.
You all should know that.

Just hook into TTTBeginRound and set the playermodel there.

Alright thanks for the reply, I’ll give that a try. I’m trying to recreate the issue but I’m having no success so far. I’ll add the timer whenever it happens again. (It seems to happen when there are other players on the server, currently I’m testing with bots)

Like so? (I’m new to lua, forgive me If I messed up lol)


ITEM.Name = 'Kleiner'
ITEM.Price = 250
ITEM.Model = 'models/player/kleiner.mdl'

function ITEM:OnEquip(ply, modifications)
	if not ply._OldModel then
		ply._OldModel = ply:GetModel()
	end
	
	timer.Simple(1, function() ply:SetModel(self.Model) end)
end

function ITEM:OnHolster(ply)
	if ply._OldModel then
		ply:SetModel(ply._OldModel)
	end
end

function ITEM:PlayerSetModel(ply)
	ply:SetModel(self.Model)
end

hook.Add("TTTBeginRound","resetModel",PlayerSetModel)

Hey, you know how to use hooks! Nice.

You’re close. Pointshop allows you to define hooks that will be called if the player has the item equipped without having to use hook.Add and add your own check. Here’s an example for the TTTBeginRound hook:
[lua]
function ITEM:TTTBeginRound(ply, modifications)
– do stuff here
end
[/lua]



local function SetPlayerModel(ply, model, modifications)
	if IsValid(ply) and ply:Alive() and !ply:IsSpec() then
		if ply.IsGhost and ply:IsGhost() then return end
		ply.PS_OldModel = ply:GetModel()
		ply:SetModel(model)
		if modifications then
			if modifications.skin then
				ply:SetSkin(modifications.skin)
			end
			if modifications.bodygroups then
				for k,v in pairs(modifications.bodygroups) do
					if string.find(model, "dod") then
						ply:SetBodygroup(k-1, v)
					else
						ply:SetBodygroup(k, v)
					end
				end
			end
		end
		ply:SetupHands()
	end
end

function PS_GivePlayerModel(ply, model, modifications)
	timer.Simple(0.01, function()
		SetPlayerModel(ply, model, modifications)
	end)
	hook.Add("TTTBeginRound", ply:SteamID().."_playermodel", function()
		timer.Simple(0.01, function()
			SetPlayerModel(ply, model, modifications)
		end)
	end)
end

function PS_RemovePlayerModel(ply)
	timer.Simple(0.01, function()
		if IsValid(ply) and ply:Alive() and !ply:IsSpec() then
			if ply.IsGhost and ply:IsGhost() then return end
			if ply.PS_OldModel then
				ply:SetModel(ply.PS_OldModel)
				ply:SetupHands()
			end
		end
	end)
	hook.Remove("TTTBeginRound", ply:SteamID().."_playermodel")
end


Use PS_GivePlayerModel on Equip function.
Use PS_RemovePlayerModel on Holster function.

Thanks! I’ll test it out tonight whenever no one is online. How would I go about incorporating that into Equip and Holster in the playershop.lua? Would I just simply make a Hook and call on those functions?
Or literally use the provided code in equip/holster

[editline]15th December 2016[/editline]

Edit: I did as moat said and the models seem to be working now! I added this to the PlayerSetModel


timer.Simple(1, function() ply:SetModel(self.Model) end)

If the issue persists I will update the thread, for now it seems to be working. I appreciate everyone who participated in helping me! I wouldn’t of been able to figure it out without you.