• Radar Gun
    1 replies, posted
I'm trying to fix up this radar gun I found on garrysmod.org ([url]http://www.garrysmod.org/downloads/?a=view&id=111797[/url] this one) The problem is it displays the speed to the entire server, and its very inaccurate. I've modified it a bit, but I can't figure out how to get it to display client side only. I've been working on this for a few hours trying different things. When I try to add the init.lua portion to cl_init.lua part i get this error. [code] [ERROR] addons/darkrpmodification-master/lua/weapons/radargun/cl_init.lua:8: Tried to use invalid object (type IPhysicsObject) (Object was NULL or not of the right type) 1. GetVelocity - [C]:-1 2. unknown - addons/darkrpmodification-master/lua/weapons/radargun/cl_init.lua:8 [/code] init.lua [lua] AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include('shared.lua') SWEP.ViewModel = "models/weapons/v_RPG.mdl" SWEP.WorldModel = "models/Weapons/w_IRifle.mdl" function SWEP:PrimaryAttack() self.Weapon:EmitSound("npc/combine_gunship/gunship_ping_search.wav") local tr = util.GetPlayerTrace(self.Owner) local Trace = util.TraceLine(tr) if Trace.HitNonWorld then TargetEnt = Trace.Entity:GetPhysicsObject() MPH = 23.392857142857142857142857142857 local X = math.abs(TargetEnt:GetVelocity().x) / MPH local Y = math.abs(TargetEnt:GetVelocity().y) / MPH local Z = math.abs(TargetEnt:GetVelocity().z) / MPH Speed = X + Y + Z if Speed - math.abs(math.ceil(Speed)) < math.abs(math.floor(Speed)) then Speed = math.ceil(Speed) else Speed = math.floor(Speed) end --PrintMessage(HUD_PRINTTALK ,"Object speed is: "..tostring(math.floor(X + Y + Z)).." MPH" ) end end function SWEP:SecondaryAttack() end [/lua] cl_init.lua [lua] include("shared.lua"); include("init.lua"); SWEP.PrintName = "Radar Gun" SWEP.Slot = 0 SWEP.SlotPos = 6 SWEP.DrawAmmo = false SWEP.DrawCrosshair = true print("Object speed is: "..tostring(math.floor(X + Y + Z)).." MPH") --I added in attempt to fix it. [/lua] shared.lua [lua] SWEP.Author = "Fatman55" SWEP.Contact = "Fatman55 At Facepunch" SWEP.Purpose = "To check if you are speeding" SWEP.Instructions = "Fire to check speed" SWEP.Spawnable = true; SWEP.AdminSpawnable = true; SWEP.Category = "Custom" SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" [/lua]
Check if the physics object is valid and print the speed to self.Owner
Sorry, you need to Log In to post a reply to this thread.