wiremod-svn-archive/wire/lua/weapons/gmod_tool/stools/wire_gps.lua

146 lines
4.1 KiB
Lua
Raw Normal View History

TOOL.Category = "Wire - Detection"
2007-02-04 01:16:06 +00:00
TOOL.Name = "GPS"
TOOL.Command = nil
TOOL.ConfigName = ""
if ( CLIENT ) then
language.Add( "Tool_wire_gps_name", "GPS Tool (Wire)" )
language.Add( "Tool_wire_gps_desc", "Spawns a gps for use with the wire system." )
language.Add( "Tool_wire_gps_0", "Primary: Create/Update GPS" )
language.Add( "sboxlimit_wire_gpss", "You've hit gpss limit!" )
language.Add( "undone_wiregps", "Undone Wire GPS" )
end
if (SERVER) then
CreateConVar('sbox_maxwire_gpss', 10)
end
TOOL.Model = "models/jaanus/wiretool/wiretool_speed.mdl"
cleanup.Register( "wire_gpss" )
function TOOL:LeftClick( trace )
if trace.Entity && trace.Entity:IsPlayer() then return false end
// If there's no physics object then we can't constraint it!
if ( SERVER && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end
if (CLIENT) then return true end
local ply = self:GetOwner()
// If we shot a wire_gps do nothing
if ( trace.Entity:IsValid() && trace.Entity:GetClass() == "gmod_wire_gps" && trace.Entity.pl == ply ) then
trace.Entity:Setup()
return true
end
if ( !self:GetSWEP():CheckLimit( "wire_gpss" ) ) then return false end
if (not util.IsValidModel(self.Model)) then return false end
if (not util.IsValidProp(self.Model)) then return false end // Allow ragdolls to be used?
local Ang = trace.HitNormal:Angle()
Ang.pitch = Ang.pitch + 90
wire_gps = MakeWireGPS( ply, Ang, trace.HitPos )
local min = wire_gps:OBBMins()
wire_gps:SetPos( trace.HitPos - trace.HitNormal * min.z )
/*local const, nocollide
2007-02-04 01:16:06 +00:00
// Don't weld to world
if ( trace.Entity:IsValid() ) then
const = constraint.Weld( wire_gps, trace.Entity, 0, trace.PhysicsBone, 0, true, true )
2007-02-04 01:16:06 +00:00
// Don't disable collision if it's not attached to anything
wire_gps:GetPhysicsObject():EnableCollisions( false )
wire_gps.nocollide = true
end*/
local const = WireLib.Weld(wire_gps, trace.Entity, trace.PhysicsBone, true)
2007-02-04 01:16:06 +00:00
undo.Create("WireGPS")
undo.AddEntity( wire_gps )
undo.AddEntity( const )
undo.SetPlayer( ply )
undo.Finish()
ply:AddCleanup( "wire_gpss", wire_gps )
ply:AddCleanup( "wire_gpss", const )
ply:AddCleanup( "wire_gpss", nocollide )
return true
end
if (SERVER) then
function MakeWireGPS( pl, Ang, Pos, nocollide, Vel, aVel, frozen )
if ( !pl:CheckLimit( "wire_gpss" ) ) then return false end
local wire_gps = ents.Create( "gmod_wire_gps" )
if (!wire_gps:IsValid()) then return false end
wire_gps:SetAngles( Ang )
wire_gps:SetPos( Pos )
wire_gps:SetModel( Model("models/jaanus/wiretool/wiretool_speed.mdl") )
wire_gps:Spawn()
wire_gps:Setup()
wire_gps:SetPlayer(pl)
if ( nocollide == true ) then wire_gps:GetPhysicsObject():EnableCollisions( false ) end
local ttable = {
pl = pl,
}
table.Merge(wire_gps:GetTable(), ttable )
pl:AddCount( "wire_gpss", wire_gps )
return wire_gps
end
duplicator.RegisterEntityClass("gmod_wire_gps", MakeWireGPS, "Ang", "Pos", "nocollide", "Vel", "aVel", "frozen")
end
function TOOL:UpdateGhostWireGPS( ent, player )
if ( !ent ) then return end
if ( !ent:IsValid() ) then return end
local tr = utilx.GetPlayerTrace( player, player:GetCursorAimVector() )
local trace = util.TraceLine( tr )
if (!trace.Hit) then return end
if (trace.Entity && trace.Entity:GetClass() == "gmod_wire_gps" || trace.Entity:IsPlayer()) then
ent:SetNoDraw( true )
return
end
local Ang = trace.HitNormal:Angle()
Ang.pitch = Ang.pitch + 90
local min = ent:OBBMins()
ent:SetPos( trace.HitPos - trace.HitNormal * min.z )
ent:SetAngles( Ang )
ent:SetNoDraw( false )
end
function TOOL:Think()
if (!self.GhostEntity || !self.GhostEntity:IsValid() || self.GhostEntity:GetModel() != self.Model ) then
self:MakeGhostEntity( self.Model, Vector(0,0,0), Angle(0,0,0) )
end
self:UpdateGhostWireGPS( self.GhostEntity, self:GetOwner() )
end
function TOOL.BuildCPanel(panel)
panel:AddControl("Header", { Text = "#Tool_wire_gps_name", Description = "#Tool_wire_gps_desc" })
end