Trying to make a ghost prop similar to Thruster

Like the title says, I want to have a ghost prop for my swep similar to thruster and dynamite. Just a little preview of where the prop will be placed. I looked at the code for dynamite and thruster and cannot follow it at all. I see that it includes ‘ghostentity.lua’ and I’m guessing I either have to use that or “borrow” code from it but I have no clue what to do.

The SWEP I’m making can spawn 5 different types of props so it must make a ghost for 5 different props depending on which one is selected at the time.

Go on the clientside, spawn the prop half transparent and set the position in think ever time you are supposed to see the ghost.

Thanks, I was wondering if it should go into think. Also I understand the reasoning behind putting it on clientside since you don’t want others to see it but I can’t figure out where to put it. I have gotten a transparent box to show up by putting it in Deploy() but where in cl_init do I put it?

Here’s the code I have in Deploy ATM.



	local vStart = self.Owner:GetShootPos()
	local vForward = self.Owner:GetAimVector()

	local trace = {}
	trace.start = vStart
	trace.endpos = vStart + (vForward * 300)
	trace.filter = self.Owner
		
	local tr = util.TraceLine( trace ) 
		
	if !tr.Hit then return end
		ghostbox = ents.Create ("prop_physics_multiplayer")
		ghostbox:SetModel (PROPLIST[self.CProp].MODEL)
		ghostbox:Fire("SetHealth", BOX_HEALTH, 0)
		ghostbox:SetName("ghostbox")
		ghostbox:CallOnRemove("removeboxformoreboxes",RemoveTheDamnBox,ent)
		ghostbox:SetPos(tr.HitPos + (tr.HitNormal * PROPLIST[self.CProp].OFFSET))
		ghostbox.type = self.CProp
		ghostbox.owner = self.Owner
		ghostbox.steam = self.owner:SteamID()
		ghostbox.team = self.Owner:Team()
		ghostbox:Fire("color", TEAMCOLOR[ghostbox.team], 0)
		ghostbox:Fire("alpha", 100, 0)
		ghostbox:Spawn()
		ghostbox:Activate()


Also when I try and change the position of it in Think() I just get spammed with errors and the box moves to my current position. Here’s the code in think.



	local vStart = self.Owner:GetShootPos()
	local vForward = self.Owner:GetAimVector()

	local trace = {}
	trace.start = vStart
	trace.endpos = vStart + (vForward * 300)
	trace.filter = self.Owner
		
	local tr = util.TraceLine( trace ) 
		
	if !tr.Hit then return end
		ghostbox:SetPos(tr.HitPos + (tr.HitNormal * PROPLIST[self.CProp].OFFSET))


ALSO, since I’m spawning an actual model, it doesn’t allow it to stick into the world. So the moment I deploy, then it spawns the prop and slowly ‘pops’ out of the world since that is what props do in gmod.

Why not just look at garrys code for it?

I find looking at garry’s default tools confusing.
Try looking into some of the wire mod tools. They’re pretty much complete in everything you might want.

I have tried looking into both garrys code and other tools codes such as advanced duplicator and wire. All are extremely confusing.

Garry uses a couple main functions in which he just passes the model, position, and angle. Then in the actual tool he updates the ghost.
I have successfully spawned the ghost prop but I can’t seem to make it move without getting spammed with errors. I’ve follow what garry does with very little luck.

well I got the ghost prop working by using most of Garry’s code in ‘Ghostentity.lua’ but I have one problem still. When I change weapons the ghost prop stays.
I’m not too familiar with all the SWEP functions. Is there one that is called when you change tools?

I was guessing it was SWEP:OnRemove() but that didn’t work.

edit: Duuuh got it. It was SWEP:Holster(). I just had to remove the ghost then return true.