summaryrefslogtreecommitdiff
path: root/entities
diff options
context:
space:
mode:
Diffstat (limited to 'entities')
-rw-r--r--entities/weapons/gms_wand.lua83
1 files changed, 83 insertions, 0 deletions
diff --git a/entities/weapons/gms_wand.lua b/entities/weapons/gms_wand.lua
new file mode 100644
index 0000000..cd71e2c
--- /dev/null
+++ b/entities/weapons/gms_wand.lua
@@ -0,0 +1,83 @@
+
+AddCSLuaFile()
+
+SWEP.Slot = 2
+SWEP.SlotPos = 5
+
+SWEP.Base = "gms_base_weapon"
+SWEP.PrintName = "Wand"
+SWEP.ViewModel = "models/Weapons/v_hands.mdl"
+SWEP.WorldModel = "models/props_c17/tools_wrench01a.mdl"
+
+SWEP.Purpose = "Shortens down weapon crafting time"
+SWEP.Instructions = "Craft weapons faster"
+
+SWEP.HoldType = "knife"
+
+
+function SWEP:Initialize()
+ PrecacheParticleSystem( "vortigaunt_fx.pcf" )
+end
+
+function SWEP:PrimaryAttack()
+ ParticleEffectAttach( "vortigaunt_hand_glow_c", PATTACH_ABSORIGIN_FOLLOW, self, 0 )
+ //ParticleEffectAttach("vortigaunt_hand_glow_c",PATTACH_ABSORIGIN_FOLLOW,self,0)
+ self:throw_attack("models/props/cs_office/Chair_office.mdl")
+
+end
+
+local ShootSound = Sound("Metal.SawbladeStick")
+
+
+function SWEP:throw_attack (model_file)
+ //Get an eye trace. This basically draws an invisible line from
+ //the players eye. This SWep makes very little use of the trace, except to
+ //calculate the amount of force to apply to the object thrown.
+ local tr = self.Owner:GetEyeTrace()
+
+ //Play some noises/effects using the sound we precached earlier
+ self:EmitSound(ShootSound)
+ self.BaseClass.ShootEffects(self)
+
+ //We now exit if this function is not running serverside
+ if (!SERVER) then return end
+
+ //The next task is to create a physics prop based on the supplied model
+ local ent = ents.Create("prop_physics")
+ ent:SetModel(model_file)
+
+
+ //Set the initial position and angles of the object. This might need some fine tuning;
+ //but it seems to work for the models I have tried.
+ ent:SetPos(self.Owner:EyePos() + (self.Owner:GetAimVector() * 16))
+ ent:SetAngles(self.Owner:EyeAngles())
+
+ ent:Spawn()
+
+ ParticleEffectAttach( "vortigaunt_hand_glow_c", PATTACH_ABSORIGIN_FOLLOW, ent, 0 )
+
+
+ //Now we need to get the physics object for our entity so we can apply a force to it
+ local phys = ent:GetPhysicsObject()
+
+ //Check if the physics object is valid. If not, remove the entity and stop the function
+ if !(phys && IsValid(phys)) then ent:Remove() return end
+
+ //Time to apply the force. My method for doing this was almost entirely empirical
+ //and it seems to work fairly intuitively with chairs.
+ phys:ApplyForceCenter(self.Owner:GetAimVector():GetNormalized() * math.pow(tr.HitPos:Length(), 3))
+
+
+ //Now for the important part of adding the spawned objects to the undo and cleanup lists.
+ cleanup.Add(self.Owner, "props", ent)
+
+ undo.Create ("Thrown_SWEP_Entity")
+ undo.AddEntity (ent)
+ undo.SetPlayer (self.Owner)
+ undo.Finish()
+end
+
+SWEP.FixWorldModel = true
+SWEP.FixWorldModelPos = Vector( -1.5, 1, -3 )
+SWEP.FixWorldModelAng = Angle( 90, 90, 0 )
+SWEP.FixWorldModelScale = 1