wiremod-svn-archive/wire/lua/entities/gmod_wire_speedometer/init.lua

61 lines
1.6 KiB
Lua
Raw Normal View History

2007-02-04 01:16:06 +00:00
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
ENT.WireDebugName = "Speedo"
local MODEL = Model("models/jaanus/wiretool/wiretool_speed.mdl")
function ENT:Initialize()
self.Entity:SetModel( MODEL )
self.Entity:PhysicsInit( SOLID_VPHYSICS )
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
self.Entity:SetSolid( SOLID_VPHYSICS )
self.Outputs = Wire_CreateOutputs(self.Entity, { "Out", "MPH", "KPH" })
2007-02-04 01:16:06 +00:00
end
function ENT:Setup( xyz_mode, AngVel )
2007-02-04 01:16:06 +00:00
self.XYZMode = xyz_mode
self.AngVel = AngVel
self:SetModes( xyz_mode,AngVel )
local outs = {}
2007-02-04 01:16:06 +00:00
if (xyz_mode) then
outs = { "X", "Y", "Z" }
2007-02-04 01:16:06 +00:00
else
outs = { "Out", "MPH", "KPH", }
end
if (AngVel) then
table.Add(outs, {"AngVel_P", "AngVel_Y", "AngVel_R" } )
2007-02-04 01:16:06 +00:00
end
Wire_AdjustOutputs(self.Entity, outs)
2007-02-04 01:16:06 +00:00
end
function ENT:Think()
self.BaseClass.Think(self)
if (self.XYZMode) then
local vel = self.Entity:WorldToLocal(self.Entity:GetVelocity()+self.Entity:GetPos())
Wire_TriggerOutput(self.Entity, "X", -vel.y)
Wire_TriggerOutput(self.Entity, "Y", vel.x)
Wire_TriggerOutput(self.Entity, "Z", vel.z)
else
local vel = self.Entity:GetVelocity():Length()
Wire_TriggerOutput(self.Entity, "Out", vel)
Wire_TriggerOutput(self.Entity, "MPH", vel / 17.6)
Wire_TriggerOutput(self.Entity, "KPH", vel * 0.09144)
2007-02-04 01:16:06 +00:00
end
if (self.AngVel) then
local ang = self.Entity:GetPhysicsObject():GetAngleVelocity()
Wire_TriggerOutput(self.Entity, "AngVel_P", ang.y)
Wire_TriggerOutput(self.Entity, "AngVel_Y", ang.z)
Wire_TriggerOutput(self.Entity, "AngVel_R", ang.x)
end
2007-02-04 01:16:06 +00:00
self.Entity:NextThink(CurTime()+0.04)
return true
end