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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
-- Freezing Arrow
-- Sin: X direction
-- Cos: Y direction
--[[addhook("always", "temphud")
function temphud()
	local livingplayers = player(0, "tableliving")
	for i = 1, #livingplayers do
		local id = livingplayers[i]
		local rad = math.rad(player(id, "rot"))
		parse("hudtxt2 ".. id .." 4 \"Angle: ".. string.sub(player(id, "rot"), 1, 7) .. " Sin(a): ".. string.sub(math.sin(rad), 1, 7) .. " Cos(a): ".. string.sub(math.cos(rad), 1, 7) .." Tan(a):" .. string.sub(math.tan(rad), 1, 7).. "\" 100 100")
	end
end]]
arrowList = {}
addhook("attack", "arrowattack")
function arrowattack(id, mode)
	local flight_time = 2000
	local distance = 800
	-- arrow speed = distance / (flight_time / 1000) [pixels per second]
	
	-- weapon id
	if player(id, "weapontype") == 69 then
		local playerX = player(id, "x")
		local playerY = player(id, "y")
		
		local playerrot = player(id, "rot")
		local playerrotRad = math.rad(playerrot)
		
		local start_posX = playerX + 24 * math.sin(playerrotRad)
		local start_posY = playerY + 24 * -(math.cos(playerrotRad))
		
		local arrowID = image("gfx/freezingarrow/icantdrawarrows.png", start_posX, start_posY, 1)
		
		if player(id, "team") == 1 then	-- if T
			arrowList[arrowID] = false
		else
			arrowList[arrowID] = true
		end
		
		msg("Arrow id: ".. arrowID)
		
		local final_posX = playerX + distance * math.sin(playerrotRad)
		local final_posY = playerY + distance * -(math.cos(playerrotRad))
		
		tween_rotate(arrowID, 0, playerrot)
		tween_move(arrowID, flight_time, final_posX, final_posY)
		
		timer(flight_time, "removeArrow", arrowID)
	end
end
function removeArrow(arrowID)
	arrowList[arrowID] = nil
	freeimage(arrowID)
	freetimer("removearrow", arrowID)
end
farrow_hit_buildings = {
	[1] = true,
	[3] = true,
	[4] = true,
	[5] = true,
	[7] = true,
	[8] = true,
	[9] = true,
	[11] = true,
	[12] = true,
	
	[13] = true,	-- leave teleporter at TRUE if you want the arrow to teleport
	[14] = false,	-- exit must stay FALSE
	
	[15] = true,
	
	[22] = true,	-- teleport orange
	[23] = true,	-- teleport blue
	
	[30] = true,	-- NPC
	
}
farrow_hitreg_resolution = 3	-- every 3 frames => 60ms
farrow_hitreg_counter = 0
addhook("always", "arrowhitreg")
function arrowhitreg()
	farrow_hitreg_counter = farrow_hitreg_counter + 1
	
	if farrow_hitreg_counter < farrow_hitreg_resolution then
		return
	else
		farrow_hitreg_counter = 0
	end
	
	for arrowID, team in pairs(arrowList) do	-- team: T=false | CT=true
		msg("Checking arrowID: ".. arrowID)
		if checkArrowHit(arrowID, team) then
			removeArrow(arrowID)
		end
	end
end
-- return:
--		true = remove arrow
--		false = dont remove arrow, nothing was hit
function checkArrowHit(arrowID, team)
	local arrowX, arrowY = object(arrowID, "x"), object(arrowID, "y")
	
	if type(arrowX) ~= "number" or type(arrowY) ~= "number" then
		msg("ArrowX/Y is NaN!")
		return true	-- this seems to be the only way to remove arrow
	end
	
	-- MAP WALLS
	
	local arrowTileX, arrowTileY = math.floor(arrowX / 32), math.floor(arrowY / 32)
	
	if tile(arrowTileX, arrowTileY, "wall") then
		return true
	end
	
	local playerList = true
	if game("sv_friendlyfire") == 1 then
		playerList = player(0, "tableliving")
	elseif team == false then
		playerList = player(0, "team2living")	-- only CT
	elseif team == true then
		playerList = player(0, "team1living") -- only T
		--playerList = player(0, "table".. (team and 2 or 1) .."living")
	end
	
	-- PLAYERS
	
	if playerList then
		for i = 1, #playerList do
			if farrow_distance(player(playerList[i], "x"), player(playerList[i], "y"), arrowX, arrowY) < 15 then
				msg("Arrow hits player ".. playerList[i])
				
				farrow_hitPlayer(playerList[i])
				return true
			end
		end
	else
		msg("Playerlist is empty!")
	end
	
	-- OBJECTS
	
	local objectList = closeobjects(arrowX, arrowY, 32)
	if type(objectList) == "table" then
		for i = 1, #objectList do
			if arrowID ~= objectList[i] then
				local objectID = objectList[i]
				local objectName = object(objectID, "typename")
				local objectType = object(objectID, "type")
				
				if farrow_hit_buildings[objectType] then
					if objectType == 13 or objectType == 22 or objectType == 23 then
						-- teleporter logic
					else
						
						msg("Hit object: ".. objectName)
						return true
					end
				end
			end
		end
	else
		msg("ObjectList is not a table!")
	end
end
farrow_freezeTime = 3000
farrow_freezeSpeedmod = -15
function farrow_hitPlayer(id)
	local freezeID = image("gfx/sprites/full_light.bmp", 0, 0, (id+200))
	tween_rotate(freezeID, 140, 45)
	imagealpha(freezeID, 0.4)	-- opacity
	imagecolor(freezeID, 100, 180, 250)	-- image color
	
	timer(farrow_freezeTime, "freeimage", freezeID)	-- remove freeze image
	timer(farrow_freezeTime, "parse", ("speedmod ".. id .." ".. player(id, "speedmod")))	-- remove slow
	
	parse("speedmod ".. id .." ".. farrow_freezeSpeedmod)
end
function farrow_distance(x1, y1, x2, y2)
	return math.sqrt( (x2-x1)^2 + (y2-y1)^2 )
end