SWEP ent model

I created a fire extinguisher swep using the swep construction kit. The only issue left is that the swep returns to the original model when dropped… I’ve tried a few different things but none of it seems to be working. Any ideas?


if (SERVER) then
	util.AddNetworkString("rprint_setCSModel")

	function SWEP:OnDrop()
		self:SetModel("models/props/cs_office/fire_extinguisher.mdl")
		net.Start("rprint_setCSModel")
		net.WriteEntity(self)
		net.Send(player.GetAll())
	end
else
	net.Receive("rprint_setCSModel", function()
		local ent = net.ReadEntity()
		ent:SetModel("models/props/cs_office/fire_extinguisher.mdl")
	end)
end

The SWEP will automatically keep setting the model to the SWEP.WorldModel parameter when dropped. You can change this in the

SWEP:DrawWorldModel and

SWEP:DrawWorldModelTranslucent hooks.

And setting it servaide should be good enough right? Or should I set it client and server side

You can’t set it serverside – those are clientside hooks. But your earlier code’s networking was useless, anyway, since SetModel is networked internally.

[editline]28th August 2017[/editline]

The downside is that the physbox will still be of the old worldmodel. You might experiment setting it in a Think hook, as well, to see if that updates the physics.


if (CLIENT) then
	function SWEP:DrawWorldModel()
		self.WorldModel = "models/props/cs_office/fire_extinguisher.mdl"
	end

	function SWEP:DrawWorldModelTranslucent()
		self.WorldModel = "models/props/cs_office/fire_extinguisher.mdl"
	end
end

With this, it is still the original model…

You run SetModel. You should never have to change SWEP.WorldModel.

I meant to add that here as well, it didn’t work either…


if (CLIENT) then
	function SWEP:DrawWorldModel()
		self:SetModel("models/props/cs_office/fire_extinguisher.mdl")
	end

	function SWEP:DrawWorldModelTranslucent()
		self:SetModel("models/props/cs_office/fire_extinguisher.mdl")
	end
end

You still have to call self:DrawModel() after like normal.


if (CLIENT) then
	function SWEP:DrawWorldModel()
		self:SetModel("models/props/cs_office/fire_extinguisher.mdl")
		self:DrawModel()
	end

	function SWEP:DrawWorldModelTranslucent()
		self:SetModel("models/props/cs_office/fire_extinguisher.mdl")
		self:DrawModel()
	end
end

https://gyazo.com/64117ed697ec3c32314d208024591877

Still no luck :frowning:

I’ve figured out a work around, I created an extinguisher ent with the model I want, in swep:OnDrop(). I call a function that spawns this entity and I have a OnEntCreated hook that checks if the last entity created was my extinguisher ent, if it was then I remove the current ent which is the entity created by swep:OnDrop (the old model). In the extinguisher ent on use I just give the player the extinguisher swep.

Everything is working perfectly! :slight_smile:

Anybody have any ideas of a better way to do this? Is this the best way?

I just tested with this code in single-player, then spawning the weapon with the toolgun:


SWEP.Spawnable = true

function SWEP:DrawWorldModel()
	self:SetModel("models/weapons/w_smg1.mdl")
	self:DrawModel()
end

Result:

Like I said, physbox is off since the model is still the prior one serverside, but it shows fine clientside.