Entity Jitter

Issue
Printers jitter when carrying them w/ a gravity gun.

Code
cl_init


include("shared.lua")
local LabelBackgroundColor = ENT.Label_BG
local LabelTextColor = ENT.Label_TextColor

function ENT:Initialize()
end

function ENT:Draw()
	self.Entity:DrawModel()
	local Pos = self:GetPos()
	local Ang = self:GetAngles()
	local owner = self:Getowning_ent()
	owner = (IsValid(owner) and owner:Nick()) or "Disconnected"
	txt1 = self.PrintName
	txt2 = "$" .. self:GetNWInt("Amount")
	txt3 = self:GetNWInt("Health")
	opacity1 = txt3 / 2
	surface.SetFont("HUDNumber5")
	local TextWidthLabel = surface.GetTextSize(txt1)
	local TextWidthOwner = surface.GetTextSize(owner)
	Ang:RotateAroundAxis(Ang:Up(), 90)
	cam.Start3D2D(Pos + Ang:Up() * 3.5, Ang, 0.09)
	draw.WordBox(6, -TextWidthLabel * 0.5 - 5, -50, txt1, "HUDNumber5", LabelBackgroundColor, LabelTextColor)
	cam.End3D2D()
	cam.Start3D2D(Pos + Ang:Up() * 3.5, Ang, 0.06)
	draw.WordBox(6, -TextWidthOwner * 0.5, 0, owner, "HUDNumber5", LabelBackgroundColor, LabelTextColor)
	cam.End3D2D()
	Ang:RotateAroundAxis(Ang:Forward(), 90)
	cam.Start3D2D(Pos + Ang:Up() * 7.3, Ang, 0.07)
	draw.RoundedBox(0, -24 - 100, -22, 70, 42, LabelBackgroundColor)
	draw.RoundedBox(0, -24 - 95, -22, 60, 42, Color(255, 0, 0, 255))
	draw.RoundedBox(0, -24 - 95, -22, 60, 42, Color(0, 255, 0, opacity1))

	if self:GetNWBool("Upgraded") then
		surface.SetDrawColor(255, 255, 255, 255)
		surface.SetMaterial(Material("icon16/star.png"))
		surface.DrawTexturedRect(-124, 22, 16, 16)
		draw.SimpleText("Upgraded", "Trebuchet18", -106, 22, Color(255, 255, 255, 255))
	end

	draw.RoundedBox(0, -40, -22, 164, 42, LabelBackgroundColor)
	draw.RoundedBox(0, -35, -22, 154, 42, Color(50, 100, 50, 255))
	draw.SimpleText(txt3, "HUDNumber5", -89, 0, Color(0, 0, 0, 255), 1, 1)
	draw.SimpleText(txt2, "HUDNumber5", 43, 0, Color(0, 0, 0, 255), 1, 1)

	if self:GetNWBool("CoolantToggle") then
		draw.RoundedBox(0, -124, -44, 248, 15, LabelBackgroundColor)
		draw.RoundedBox(0, -119, -44, 238, 15, Color(180, 180, 180, 255))
		draw.RoundedBox(0, -119, -44, ((238 / 100) * self:GetNWInt("Coolant")), 15, Color(0, 255, 255, 255))
		draw.SimpleText("Coolant left: " .. self:GetNWInt("Coolant"), "DermaDefault", -59, -37, Color(0, 0, 0), 1, 1)
	end

	cam.End3D2D()
end

function ENT:Think()
end

init


AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")

-- EDIT DEEZ & NOTHING ELSE --            -- if you want..
local function SetValues(ent)
	ent.printTime = 10 -- Default print time.
	ent.minPrint = 8 -- Minimum print amount.
	ent.maxPrint = 16 -- Maximum print amount.
	ent.upgradedExtra = ent.maxPrint * 0.2 -- The additional income received on upgraded printers.
	ent.printerColor = Color(189, 99, 39, 255) -- The color of the printer prop.
	ent.coolantSystem = false -- Toggles the coolant system.
	ent.coolantLoss = 0.5 -- The Percentage loss for each print of the coolant is enabled.
end

------------------------------
local PrintMore

function ENT:Initialize()
	self:SetModel("models/props_lab/reciever01a.mdl")
	self:PhysicsInit(SOLID_VPHYSICS)
	self:SetMoveType(MOVETYPE_VPHYSICS)
	self:SetSolid(SOLID_VPHYSICS)
	local phys = self:GetPhysicsObject()
	phys:Wake()
	SetValues(self)
	self:SetColor(self.printerColor)
	self.damage = 500
	self.IsMoneyPrinter = true
	self:SetNWInt("Amount", 0)
	self:SetNWInt("Health", 500)
	self:SetNWBool("Upgraded", false)

	if self.coolantSystem then
		self:SetNWInt("Coolant", 100)
		self:SetNWBool("CoolantToggle", true)
	end

	timer.Simple(0.1, function()
		PrintMore(self)
	end)
end

function ENT:OnTakeDamage(dmg)
	self.damage = (self.damage or 500) - math.ceil(dmg:GetDamage())

	if self.damage < 0 then
		self.damage = 0
	end

	self:SetNWInt("Health", self.damage)
end

function ENT:StartTouch(hitEnt)
	if self:GetNWBool("CoolantToggle") then
		if hitEnt.IsCoolant then
			self.Coolant = hitEnt
			local amount = self:GetNWInt("Coolant") + 100

			if amount > 100 then
				amount = 100
			end

			self:SetNWInt("Coolant", amount)
			self.Coolant:Remove()
		end
	end

	if (hitEnt.IsUpgrade) then
		if (not self:GetNWBool("Upgraded")) then
			self:SetNWBool("Upgraded", true)
			hitEnt:Remove()
		end
	end
end

function ENT:Use(activator)
	if (activator:IsPlayer() and self:GetNWInt("Amount") > 0) then
		activator:addMoney(self:GetNWInt("Amount"))
		DarkRP.notify(activator, 0, 4, "You have collected $" .. self:GetNWInt("Amount") .. " from a " .. self.PrintName)
		self:SetNWInt("Amount", 0)
	end
end

function ENT:Destruct()
	local vPoint = self:GetPos()
	local effectdata = EffectData()
	effectdata:SetStart(vPoint)
	effectdata:SetOrigin(vPoint)
	effectdata:SetScale(1)
	util.Effect("Explosion", effectdata)
	DarkRP.notify(self:Getowning_ent(), 1, 4, "Your " .. self.PrintName .. " has exploded!")
end

function ENT:BurstIntoFlames()
	DarkRP.notify(self:Getowning_ent(), 0, 4, "Your " .. self.PrintName .. " has burst into flames!")
	self.burningup = true
	local burntime = math.random(8, 18)
	self:Ignite(burntime, 0)

	timer.Simple(burntime, function()
		self:Fireball()
	end)
end

function ENT:Fireball()
	if not self:IsOnFire() then
		self.burningup = false

		return
	end

	local dist = math.random(20, 280) -- Explosion radius
	self:Destruct()

	for k, v in pairs(ents.FindInSphere(self:GetPos(), dist)) do
		if not v:IsPlayer() and not v:IsWeapon() and v:GetClass() ~= "predicted_viewmodel" and not v.IsMoneyPrinter then
			v:Ignite(math.random(5, 22), 0)
		elseif v:IsPlayer() then
			local distance = v:GetPos():Distance(self:GetPos())
			v:TakeDamage(distance / dist * 100, self, self)
		end
	end

	self:Remove()
end

PrintMore = function(ent)
	if not IsValid(ent) then return end
	if ent.damage <= 0 then return end

	timer.Simple(ent.printTime / 2, function()
		if not IsValid(ent) then return end
		ent:CreateMoney()
	end)
end

function ENT:CreateMoney()
	if not IsValid(self) then return end
	if self:IsOnFire() then return end

	if self:GetNWBool("CoolantToggle") then
		local coolantLeft = self:GetNWInt("Coolant") - self.coolantLoss
		self:SetNWInt("Coolant", coolantLeft)

		if coolantLeft <= 0 then
			self:SetNWInt("Coolant", 0)
			self.damage = self.damage - 5
			self:SetNWInt("Health", self.damage)
			self.sparking = true

			timer.Simple(0.3, function()
				self.sparking = false
			end)
		end
	end

	local PrintAmount = math.random(self.minPrint, self.maxPrint)

	if self:GetNWBool("Upgraded") then
		PrintAmount = PrintAmount + math.ceil(self.upgradedExtra)
	end

	local TotalAmount = self:GetNWInt("Amount") + PrintAmount
	self:SetNWInt("Amount", TotalAmount)

	if self.damage < 500 then
		self.damage = self.damage + 1
		self:SetNWInt("Health", self.damage)
	end

	timer.Simple(self.printTime / 2, function()
		PrintMore(self)
	end)
end

function ENT:Think()
	if self.damage then
		if (self.damage <= 0) then
			if not self:IsOnFire() then
				self.damage = 0
				self:SetNWInt("Health", 0)
				self:BurstIntoFlames()
			end
		end
	end

	if self:WaterLevel() > 0 then
		self:Destruct()
		self:Remove()

		return
	end

	if not self.sparking then return end
	local effectdata = EffectData()
	effectdata:SetOrigin(self:GetPos())
	effectdata:SetMagnitude(1)
	effectdata:SetScale(1)
	effectdata:SetRadius(2)
	util.Effect("Sparks", effectdata)
end

function ENT:OnRemove()
	if self.sound then
		self.sound:Stop()
	end
end

shared


ENT.Label_BG = Color(150, 150, 150)
ENT.Label_TextColor = color_black
ENT.PrintName = "Tier One Printer"
---------------
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.Author = "Koolaidmini"
ENT.Spawnable = true
ENT.AdminSpawnable = true

function ENT:SetupDataTables()
	self:NetworkVar("Int", 0, "price")
	self:NetworkVar("Entity", 0, "owning_ent")
end

I do not own this code. I do however have the right to modify it without removing any credit/license.
This printer does not include credit/licence & was not removed. All credit goes to Koolaidmini

I see nothing that would cause the jittering with this specific entity. Maybe just server lag overall?

Server lag does not seem to be the issue.
Maybe the slight jitter is normal & can’t be improved?

Can you show us a video or gif of what is happening? In my experience, the grav gun doesn’t like anything that isn’t a physics prop, especially if the server has a low tick rate.

Sure making a GIF right now!

The GIF was to big for Imgur, sorry.

Done.
https://mega.nz/#!gVEEFYCC!op1Lps17jnJwf9u7uHJpC0zZf9kiZaYQyGS8KZaqsc0

Yeah, nobody is going to download a 226 MB gif, better make a video and upload it to youtube.

True! 226mb is alot for people with slow internet.
Let me upload a smaller gif (;

being a smartass is a great way to get help dude

Then don’t help?

Don’t need your help when other people who aren’t in a bad mood will help me :stuck_out_tongue:

haha then you mark my reply as dumb, real mature! XD

That’s normal grav gun behaviour. It barely jitters

yeah, I marked it dumb because insulting people trying to help you is a dumb thing to do

I guess you felt the same way, seeing as you edited your post.

I honestly don’t know what you are on about, but it’s making me laugh! Thanks bud (:

Honestly I don’t want your help either.



									if not stop then
										v:Kill()
									end
								end
							end
						end
					end
				end
			end
		end
	end
end)


If you feel me. (;

Doesn’t this:

Seem just a slight bit insult-ish?

First you imply his internet speed is shit, then you tell him to just not help you when he gets (unsurprisingly) annoyed with you saying that, then you just tell him to completely f*ck off because ‘you don’t want his help’. Don’t mean to be rude, but if you want help you probably shouldn’t be saying stuff like that to people that could actually help you with the problem.

Also, I don’t know what the solution is, sorry :frowning:

You are sad. You waist your time trying to do what? Insult me? lol good luck bud