-
Notifications
You must be signed in to change notification settings - Fork 351
Expand file tree
/
Copy pathgmod_wire_vehicle.lua
More file actions
80 lines (66 loc) · 2.43 KB
/
gmod_wire_vehicle.lua
File metadata and controls
80 lines (66 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
AddCSLuaFile()
DEFINE_BASECLASS( "base_wire_entity" )
ENT.PrintName = "Wire Vehicle Controller"
ENT.WireDebugName = "Vehicle Controller"
if CLIENT then return end -- No more client
function ENT:Initialize()
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
self.Inputs = Wire_CreateInputs( self, { "Throttle", "Steering", "Handbrake", "Engine", "Lock", "Vehicle [ENTITY]" } )
self.Outputs = Wire_CreateOutputs( self, { "Vehicle [ENTITY]" } )
end
function ENT:LinkEnt( pod )
pod = WireLib.GetClosestRealVehicle(pod,self:GetPos(),self:GetPlayer())
if not IsValid(pod) or not pod:IsVehicle() then return false, "Must link to a vehicle" end
if not WireLib.CanTool(self:GetPlayer(), pod, "wire_vehicle") then return false, "You do not have permission to access this vehicle" end
self.Vehicle = pod
WireLib.SendMarks(self, {pod})
WireLib.TriggerOutput(self, "Vehicle", pod)
return true
end
function ENT:UnlinkEnt()
self.Vehicle = nil
WireLib.SendMarks(self, {})
WireLib.TriggerOutput(self, "Vehicle", NULL)
return true
end
function ENT:TriggerInput(iname, value)
if (iname == "Throttle") then
self.Throttle = value
elseif (iname == "Steering") then
self.Steering = value
elseif (iname == "Vehicle") then
self:LinkEnt(value)
elseif not IsValid(self.Vehicle) then
return
elseif (iname == "Handbrake") then
self.Vehicle:Fire("handbrake"..(value~=0 and "on" or "off"), 1, 0)
elseif (iname == "Engine") then
self.Vehicle:Fire("turn"..(value~=0 and "on" or "off"), 1, 0)
if value~=0 then self.Vehicle:Fire("handbrakeoff", 1, 0) end
elseif (iname == "Lock") then
self.Vehicle:Fire((value~=0 and "" or "un").."lock", 1, 0)
end
end
function ENT:Think()
if IsValid(self.Vehicle) then
local delta = CurTime()%1/1000 -- A miniscule constant change
if self.Steering then self.Vehicle:Fire("steer", self.Steering+delta, 0) end
if self.Throttle then self.Vehicle:Fire("throttle",self.Throttle+delta, 0) end
end
self:NextThink(CurTime())
return true
end
function ENT:BuildDupeInfo()
local info = BaseClass.BuildDupeInfo(self) or {}
if self.Vehicle and self.Vehicle:IsValid() then
info.Vehicle = self.Vehicle:EntIndex()
end
return info
end
function ENT:ApplyDupeInfo(ply, ent, info, GetEntByID)
BaseClass.ApplyDupeInfo(self, ply, ent, info, GetEntByID)
self.Vehicle = GetEntByID(info.Vehicle)
end
duplicator.RegisterEntityClass("gmod_wire_vehicle", WireLib.MakeWireEnt, "Data")