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
Smoke = {}
Smoke.Duration = 20
Smoke.Radius = 15 -- <-- this one is touchable but be careful
Smoke.Static = 1
Smoke.TotalObj = Smoke.Radius*Smoke.Static + 1
Smoke.Table = {}
Smoke.HookFunctions = {}
addhook('projectile_impact','Smoke.HookFunctions.projectile_impact')
Smoke.HookFunctions.projectile_impact = function(id, weapon, x, y, mode, projectileid)
	if mode==100 then
		if weapon == 53 then
			timer(2,'parse','freeprojectile '..projectileid..' '..id)
			if Smoke.Table[projectileid] then
				repeat projectileid = projectileid + 1
					until
					not Smoke.Table[projectileid]
			end
			
			Smoke.Table[projectileid] = {
			SmokeStartx = x,
			SmokeStarty = y,
			Radius = Smoke.Radius,
			TotalObj = 0,
			ImageTable = {},
			Smoke_Dur = Smoke.Duration,
			ProjectId = projectileid,
			Floor = image('gfx/mora/Smoke/Smoke_floor.png',x,y,0)
			}
			parse('equip '..id..' 53')
		end
	end
end
addhook('second','Smoke.HookFunctions.second')
Smoke.HookFunctions.second = function()
	for key, value in pairs(Smoke.Table) do
		
		if value.Smoke_Dur - 1 > 5 then
			for k, v in pairs(value.ImageTable) do
				local rndm = math.random(150,220)
				tween_color(v.image,999,rndm,rndm,rndm)
			end
			value.Smoke_Dur = value.Smoke_Dur - 1
			parse("effect \"smoke\" " .. object(value.Floor,"x") .. " " .. object(value.Floor,"y") .. " 2 2")
		elseif value.Smoke_Dur - 1 == 5 then
			parse("effect \"smoke\" " .. object(value.Floor,"x") .. " " .. object(value.Floor,"y") .. " 2 2")
			value.Smoke_Dur = 3
			tween_alpha(Smoke.Table[key].Floor,5000,0.0)
			for k, v in pairs(value.ImageTable) do
				tween_alpha(v.image,5000,0.0)
			end
			timer(5000,"parse",'lua Smoke.HookFunctions.RemoveSmoke('..value.ProjectId..')')
		end
	end
end
Smoke.HookFunctions.RemoveSmoke = function(projectileid)
	local image_index = Smoke.Table[projectileid].ImageTable
	for k, v in pairs(image_index) do
		freeimage(v.image)
	end
	freeimage(Smoke.Table[projectileid].Floor)
	Smoke.Table[projectileid]=nil
end
addhook('ms100','Smoke.HookFunctions.ms100')
Smoke.HookFunctions.ms100 = function()
	for key, value in pairs(Smoke.Table) do
		if value.TotalObj + 1 <= Smoke.TotalObj then
			value.TotalObj = value.TotalObj + 1
			Smoke.PuffFunction(value.ProjectId)
		end
		
		for k, v in pairs(value.ImageTable) do
			for s, p in pairs(value.ImageTable) do
				if v~=p then
					local x, y = v.X, v.Y
					local x2, y2 = p.X, p.Y
					local d = math.sqrt((x2-x)^2 + (y2-y)^2) -- Calculate distance between the two players
					if (d < v.radius) then
						local a = -(math.atan2(x2-x,y2-y)+math.pi/2)%(2*math.pi) -- Calculate angle between two players and convert it from the CS2D unit circle (from 0 on the Y plane and 90 on the X clockwise to 0 on the X plane and 90 on the Y anticlockwise)
						local nx, ny = x2 + math.cos(a)*v.radius, y2 + math.sin(a)*v.radius -- Calculate position as 30 pixels away from the centre of the second player along the angle calculated above
						if not (tile(math.floor(nx/32), math.floor(ny/32), "wall")) then
							tween_move(v.image,99,nx,ny)
							v.X = nx
							v.Y = ny
						end
					end
				end
			end
		end
	end
end
Smoke.PuffFunction = function(projectileid)
	local SmokeIndex = Smoke.Table[projectileid].ImageTable
	local Sx, Sy = Smoke.Table[projectileid].SmokeStartx+math.random(-3,3), Smoke.Table[projectileid].SmokeStarty+math.random(-3,3)
	local rand_size = 1.5 + math.random(10,100)*0.01
	SmokeIndex[Smoke.Table[projectileid].TotalObj] = {
		X = Sx,
		Y = Sy,
		image = image("gfx/mora/Smoke/Smoke_puff.png",Sx,Sy,3),
		duration = 5,
		radius = rand_size*10 + 10,
		ProjectId = projectileid
	}
			local rndm = math.random(150,220)
			tween_color(SmokeIndex[Smoke.Table[projectileid].TotalObj].image,1500,rndm,rndm,rndm)
			imagealpha(SmokeIndex[Smoke.Table[projectileid].TotalObj].image,0.0)
			imagehitzone(SmokeIndex[Smoke.Table[projectileid].TotalObj].image,1,-(rand_size*10),-(rand_size*10),(rand_size*10)*2,(rand_size*10)*2)
			tween_alpha(SmokeIndex[Smoke.Table[projectileid].TotalObj].image,1500,math.random(50,90)*0.01)
			tween_scale(SmokeIndex[Smoke.Table[projectileid].TotalObj].image,3000,rand_size,rand_size)
	
end
addhook('hitzone','Smoke.HookFunctions.hitzone')
Smoke.HookFunctions.hitzone = function(image_id,player_id,object_id,weapon,impactx,impacty,damage)
	imagealpha(image_id,0.0)
	tween_alpha(image_id,450,math.random(50,90)*0.01)
end