summaryrefslogtreecommitdiff
path: root/entities/weapons/gms_wand.lua
blob: cd71e2cf2fb8879e17d1423bf20c80c6a5e5d118 (plain)
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
81
82
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