Permalink
Browse files

Disallowed being able to use effects as tool models

  • Loading branch information...
1 parent 1299a5c commit 78c22fcf1ed1b58a7955aef9d89cd1aa44ce2446 @robotboy655 robotboy655 committed Aug 31, 2015
@@ -15,7 +15,7 @@ function TOOL:LeftClick( trace )
if ( !trace.HitPos ) then return false end
if ( trace.Entity:IsPlayer() ) then return false end
if ( CLIENT ) then return true end
-
+
local ply = self:GetOwner()
-- Get client's CVars
@@ -25,12 +25,15 @@ function TOOL:LeftClick( trace )
local model = self:GetClientInfo( "model" )
local remove = self:GetClientNumber( "remove" ) == 1
+ if ( !util.IsValidModel( model ) ) then return false end
+ if ( !util.IsValidProp( model ) ) then return false end
+
-- If we shot a button change its keygroup
if ( IsValid( trace.Entity ) && trace.Entity:GetClass() == "gmod_dynamite" && trace.Entity:GetPlayer() == ply ) then
trace.Entity:Setup( damage )
trace.Entity:SetShouldRemove( remove )
trace.Entity.delay = delay
-
+
numpad.Remove( trace.Entity.NumDown )
trace.Entity.key = group
trace.Entity.NumDown = numpad.OnDown( ply, group, "DynamiteBlow", trace.Entity, delay )
@@ -40,7 +43,7 @@ function TOOL:LeftClick( trace )
if ( !self:GetSWEP():CheckLimit( "dynamite" ) ) then return false end
local dynamite = MakeDynamite( ply, trace.HitPos, Angle( 0, 0, 0 ), group, damage, model, remove, delay )
-
+
local CurPos = dynamite:GetPos()
local NearestPoint = dynamite:NearestPoint( CurPos - ( trace.HitNormal * 512 ) )
local Offset = CurPos - NearestPoint
@@ -53,21 +56,21 @@ function TOOL:LeftClick( trace )
undo.Finish()
ply:AddCleanup( "dynamite", dynamite )
-
+
return true
-
+
end
function TOOL:RightClick( trace )
return self:LeftClick( trace )
-
+
end
if ( SERVER ) then
function MakeDynamite( pl, Pos, Ang, key, Damage, Model, Remove, delay, Vel, aVel, frozen )
-
+
if ( IsValid( pl ) && !pl:CheckLimit( "dynamite" ) ) then return nil end
local dynamite = ents.Create( "gmod_dynamite" )
@@ -77,13 +80,13 @@ if ( SERVER ) then
dynamite:SetShouldRemove( Remove )
dynamite:Spawn()
dynamite:Activate()
-
+
dynamite:Setup( Damage )
if ( IsValid( pl ) ) then
dynamite:SetPlayer( pl )
end
-
+
local ttable = {
key = key,
pl = pl,
@@ -94,32 +97,32 @@ if ( SERVER ) then
remove = Remove,
delay = delay
}
-
+
table.Merge( dynamite:GetTable(), ttable )
dynamite.NumDown = numpad.OnDown( pl, key, "DynamiteBlow", dynamite, delay )
-
+
if ( IsValid( pl ) ) then
pl:AddCount( "dynamite", dynamite )
end
-
+
DoPropSpawnedEffect( dynamite )
-
+
return dynamite
-
+
end
duplicator.RegisterEntityClass( "gmod_dynamite", MakeDynamite, "Pos", "Ang", "key", "Damage", "model", "remove", "delay", "Vel", "aVel", "frozen" )
-
+
local function BlowDynamite( pl, dynamite, delay )
if ( !IsValid( dynamite ) ) then return end
dynamite:Explode( delay, pl )
-
+
end
numpad.Register( "DynamiteBlow", BlowDynamite )
-
+
end
function TOOL:UpdateGhostDynamite( ent, pl )
@@ -128,7 +131,7 @@ function TOOL:UpdateGhostDynamite( ent, pl )
local tr = util.GetPlayerTrace( pl )
local trace = util.TraceLine( tr )
-
+
if ( !trace.Hit || trace.Entity:IsPlayer() || trace.Entity:GetClass() == "gmod_dynamite" ) then
ent:SetNoDraw( true )
return
@@ -141,7 +144,7 @@ function TOOL:UpdateGhostDynamite( ent, pl )
local Offset = CurPos - NearestPoint
ent:SetPos( trace.HitPos + Offset )
-
+
ent:SetNoDraw( false )
end
@@ -152,17 +155,17 @@ function TOOL:Think()
if ( !IsValid( self.GhostEntity ) || self.GhostEntity:GetModel() != mdl ) then
self:MakeGhostEntity( mdl, Vector( 0, 0, 0 ), Angle( 0, 0, 0 ) )
end
-
+
self:UpdateGhostDynamite( self.GhostEntity, self:GetOwner() )
-
+
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:AddControl( "Header", { Description = "#tool.dynamite.help" } )
-
+
CPanel:AddControl( "ComboBox", { MenuButton = 1, Folder = "dynamite", Options = { [ "#preset.default" ] = ConVarsDefault }, CVars = table.GetKeys( ConVarsDefault ) } )
CPanel:AddControl( "Numpad", { Label = "#tool.dynamite.explode", Command = "dynamite_group" } )
@@ -14,24 +14,27 @@ cleanup.Register( "hoverballs" )
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()
-
+
local model = self:GetClientInfo( "model" )
local key_d = self:GetClientNumber( "keydn" )
local key_u = self:GetClientNumber( "keyup" )
local speed = self:GetClientNumber( "speed" )
local strength = math.Clamp( self:GetClientNumber( "strength" ), 0.1, 20 )
local resistance = math.Clamp( self:GetClientNumber( "resistance" ), 0, 20 )
+ if ( !util.IsValidModel( model ) ) then return false end
+ if ( !util.IsValidProp( model ) ) then return false end
+
-- We shot an existing hoverball - just change its values
if ( IsValid( trace.Entity ) && trace.Entity:GetClass() == "gmod_hoverball" && trace.Entity.pl == ply ) then
-
+
trace.Entity:SetSpeed( speed )
trace.Entity:SetAirResistance( resistance )
trace.Entity:SetStrength( strength )
@@ -40,10 +43,10 @@ function TOOL:LeftClick( trace )
numpad.Remove( trace.Entity.NumUp )
numpad.Remove( trace.Entity.NumBackDown )
numpad.Remove( trace.Entity.NumBackUp )
-
+
trace.Entity.NumDown = numpad.OnDown( ply, key_u, "Hoverball_Up", trace.Entity, true )
trace.Entity.NumUp = numpad.OnUp( ply, key_u, "Hoverball_Up", trace.Entity, false )
-
+
trace.Entity.NumBackDown = numpad.OnDown( ply, key_d, "Hoverball_Down", trace.Entity, true )
trace.Entity.NumBackUp = numpad.OnUp( ply, key_d, "Hoverball_Down", trace.Entity, false )
@@ -52,29 +55,29 @@ function TOOL:LeftClick( trace )
trace.Entity.speed = speed
trace.Entity.strength = strength
trace.Entity.resistance = resistance
-
+
return true
-
+
end
-
+
if ( !self:GetSWEP():CheckLimit( "hoverballs" ) ) then return false end
local ball = MakeHoverBall( ply, trace.HitPos, key_d, key_u, speed, resistance, strength, model )
-
+
local CurPos = ball:GetPos()
local NearestPoint = ball:NearestPoint( CurPos - ( trace.HitNormal * 512 ) )
local Offset = CurPos - NearestPoint
ball:SetPos( trace.HitPos + Offset )
-
+
local const, nocollide
-
+
-- Don't weld to world
if ( trace.Entity != NULL && !trace.Entity:IsWorld() ) then
- const = constraint.Weld( ball, trace.Entity, 0, trace.PhysicsBone, 0, 0, true ) -- Ent1, Ent2, Bone1, Bone2, forcelimit, nocollide, deleteonbreak
+ const = constraint.Weld( ball, trace.Entity, 0, trace.PhysicsBone, 0, 0, true )
- ball:GetPhysicsObject():EnableCollisions( false )
+ if ( IsValid( ball:GetPhysicsObject() ) ) then ball:GetPhysicsObject():EnableCollisions( false ) end
ball.nocollide = true
end
@@ -102,11 +105,11 @@ end
if ( SERVER ) then
function MakeHoverBall( ply, Pos, key_d, key_u, speed, resistance, strength, model, Vel, aVel, frozen, nocollide )
-
+
if ( IsValid( ply ) ) then
if ( !ply:CheckLimit( "hoverballs" ) ) then return end
end
-
+
local ball = ents.Create( "gmod_hoverball" )
if ( !IsValid( ball ) ) then return false end
@@ -127,7 +130,7 @@ if ( SERVER ) then
ball.NumBackDown = numpad.OnDown( ply, key_d, "Hoverball_Down", ball, true )
ball.NumBackUp = numpad.OnUp( ply, key_d, "Hoverball_Down", ball, false )
- if ( nocollide == true ) then ball:GetPhysicsObject():EnableCollisions( false ) end
+ if ( nocollide == true && IsValid( ball:GetPhysicsObject() ) ) then ball:GetPhysicsObject():EnableCollisions( false ) end
local ttable = {
key_d = key_d,
@@ -141,15 +144,15 @@ if ( SERVER ) then
}
table.Merge( ball:GetTable(), ttable )
-
+
if ( IsValid( ply ) ) then
ply:AddCount( "hoverballs", ball )
end
-
+
DoPropSpawnedEffect( ball )
return ball
-
+
end
duplicator.RegisterEntityClass( "gmod_hoverball", MakeHoverBall, "Pos", "key_d", "key_u", "speed", "resistance", "strength", "model", "Vel", "aVel", "frozen", "nocollide" )
@@ -158,16 +161,16 @@ end
function TOOL:UpdateGhostHoverball( ent, pl )
if ( !IsValid( ent ) ) then return end
-
+
local tr = util.GetPlayerTrace( pl )
local trace = util.TraceLine( tr )
if ( !trace.Hit ) then return end
-
+
if ( trace.Entity:IsPlayer() || trace.Entity:GetClass() == "gmod_hoverball" ) then
-
+
ent:SetNoDraw( true )
return
-
+
end
local CurPos = ent:GetPos()
@@ -177,25 +180,25 @@ function TOOL:UpdateGhostHoverball( ent, pl )
ent:SetPos( trace.HitPos + Offset )
ent:SetNoDraw( false )
-
+
end
function TOOL:Think()
if ( !IsValid( self.GhostEntity ) || self.GhostEntity:GetModel() != self:GetClientInfo( "model" ) ) then
self:MakeGhostEntity( self:GetClientInfo( "model" ), Vector( 0, 0, 0 ), Angle( 0, 0, 0 ) )
end
-
+
self:UpdateGhostHoverball( self.GhostEntity, self:GetOwner() )
-
+
end
local ConVarsDefault = TOOL:BuildConVarList()
function TOOL.BuildCPanel( CPanel )
CPanel:AddControl( "Header", { Description = "#tool.hoverball.help" } )
-
+
CPanel:AddControl( "ComboBox", { MenuButton = 1, Folder = "hoverball", Options = { [ "#preset.default" ] = ConVarsDefault }, CVars = table.GetKeys( ConVarsDefault ) } )
CPanel:AddControl( "Numpad", { Label = "#tool.hoverball.up", Command = "hoverball_keyup", Label2 = "#tool.hoverball.down", Command2 = "hoverball_keydn" } )
Oops, something went wrong.

0 comments on commit 78c22fc

Please sign in to comment.