aboutsummaryrefslogtreecommitdiff
path: root/gamemode/itemsystem/items/spell_teleport.lua
blob: 629495542b09d84a73ab9a8d51f656be75a49b70 (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
ITEM.Name 			= "Teleport"
ITEM.Class 			= "weapon"
ITEM.Desc 			= "Right click to set target location, left click to open a portal there."
ITEM.Model 			= "models/props_debris/wood_board02a.mdl"
ITEM.Icon 			= Material("wintersurvival2/hud/ws2_icons/icon_spellteleport.png")
ITEM.HoldType		= "magic"

//Load some nessessary stuff
game.AddParticles("particles/particletest.pcf")
PrecacheParticleSystem("firetest")


ITEM.Recipe		= {
	Resources = {
		["Plank"] = 2,
		["Rope"] = 1,
		["Sap"] = 1,
	},
	Tools = {},
}

ITEM.CD = 0.25

ITEM.savedpoint = nil

function ITEM:DoTeleport(score,pl,self)
	print("DoTeleport called!")
	if(self.savedpoint == nil) then return end
    print("Fully successfull teleport callback:")
	print(pl)
	local aim = pl:GetAimVector()

	local D = ents.Create("ws_teleporter")


	D:SetPos(pl:GetShootPos()+aim*200)
	D:SetOwner(pl)
	D:SetAngles(aim:Angle())
	D:Spawn()
	D.endpoint = self.savedpoint
	pl:EmitSound(Sound("physics/flesh/flesh_impact_hard.wav"),100,math.random(90,110))
end

local teleportfunc = function(score, pl, self)
	print("teleportfunc called!")
	if(self.savedpoint == nil) then return end
    print("Fully successfull teleport callback:")
	print(pl)
	local aim = pl:GetAimVector()

	local D = ents.Create("ws_teleporter")


	D:SetPos(pl:GetShootPos()+aim*200)
	D:SetOwner(pl)
	D:SetAngles(aim:Angle())
	D:Spawn()
	D.endpoint = self.savedpoint
	pl:EmitSound(Sound("physics/flesh/flesh_impact_hard.wav"),100,math.random(90,110))
end

function ITEM:OnSecondary(pl,tr)
	print("Endpoint set?")
	ParticleEffect("firetest",pl:GetPos(),pl:GetAngles(),pl)
    self.savedpoint = pl:GetPos()
end

function ITEM:OnPrimary(pl,tr)
	if(CLIENT) then return end
	print("Attempting to cast...")
	pl:Cast("Gateway",teleportfunc,self)
end