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
function initarray(s,v)
	local asd={}
	for i=1,s do
		asd[i]=v
	end
	return asd
end
function hudtext2(id,tid,color,txt,x,y)
	local toprint = ("©"..color.." "..txt)
	parse('hudtxt2 '..id..' '..tid..' "'..toprint..'" '..x.." "..y)
end
function standardangle(angle)
	if (angle<-90) then angle = (angle + 360)	end
	return math.rad(math.abs( angle + 90 ))-math.pi
end
function cs2dangle(angle) --MUST BE 2*Pi
	angle = math.deg(angle) - 90
	if(angle > 180 ) then angle = angle -360 end
	return angle
end
function doublerad(angle)
	return angle + math.pi
end
function singlerad(angle)
	return angle - math.pi
end
ship_rotation = initarray(32,0)
addhook("startround","setcarsprites")
function setcarsprites()
	ship_sprite = initarray(32,nil)
	for i=1,64 do
		if(i<=32) then
			ship_sprite[i]=image("gfx/car_t.bmp",0,0,1)
		else
			ship_sprite[i]=image("gfx/car_ct.bmp",0,0,1)
		end
		imageblend(ship_sprite[i],0)
	end
end
addhook("always","rotateplayers")
function rotateplayers()
	for p in pairs( player(0,"table") ) do
		if(player(p,"health")>0 ) then
		
			local pl_rot = doublerad( standardangle( player(p,"rot") ) )
			local sp_rot = doublerad( ship_rotation[p] )
		
			if(pl_rot > sp_rot) then
				if(pl_rot - sp_rot <= math.pi) then
					sp_rot = sp_rot + 0.05
				elseif(pl_rot - sp_rot > math.pi) then
					sp_rot = sp_rot - 0.05
				end				
			elseif(pl_rot < sp_rot) then
				if(sp_rot - pl_rot <= math.pi) then
					sp_rot = sp_rot -0.05
				elseif(sp_rot - pl_rot > math.pi) then
					sp_rot = sp_rot + 0.05
				end
			end
		
			if(sp_rot < 0) then sp_rot = sp_rot + (math.pi*2) end --Correct the angle if it is less than 0
			if(sp_rot > math.pi*2) then sp_rot = sp_rot - (math.pi*2) end --Correct the angle if it is more that 2*Pi
			
			sp_rot = singlerad( sp_rot ) --Remove my fancy 2Pi system
		
			local x = player(p,"x") + math.cos(sp_rot)*4
			local y = player(p,"y") + math.sin(sp_rot)*4
			
			if(x >= 0 and y >= 0) then --Make sure we aren't "setposing" outside the map (LEFT AND TOP)
				if(x <= map("xsize")*32 and y <= map("ysize")*32) then --Same here (RIGHT AND BOTTOM)
					parse("setpos "..p.." "..x.." "..y) --Set the position
					
					local sprite_to_show = p
					
					if(player(p,"team") == 2) then sprite_to_show = sprite_to_show + 32 end--If CT, show CT car sprite
					imagepos(ship_sprite[sprite_to_show],x,y,cs2dangle(sp_rot) )--Draw the car
				end
			end
			ship_rotation[p]=sp_rot
		end
	end
end