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
addhook("die", "onDie")
function onDie(id)
	if Player[id].car then
		local _, i;
		for _, i in pairs(Player[id].car.players) do
			if i == id then
				table.remove(Player[id].car.players, _);
				break;
			end
		end
		Player[id].car = nil;
	end
	if Player[id].carowner then
		Player[id].carowner.owner = 0;
		Player[id].carowner = nil;
	end
end
function getPos(str)
	local x1, x2, f;
	f = string.find(str, "|");
	x1 = string.sub(str, 0, f - 1);
	x2 = string.sub(str, f + 1);
	return tonumber(x1), tonumber(x2);
end
addhook("leave", "onLeave")
function onLeave(id)
	if Player[id].joined == true then return 0 end;
	local _, i;
	if Player[id].car then
		for _, i in pairs(Player[id].car.players) do
			if i == id then
				table.remove(Player[id].car.players, _);
				break;
			end
		end
	end
	for _, i in pairs(Player[id].cars) do
		local car = cars[i];
		RemoveCar(car);
	end
	if Player[id].carowner then
		Player[id].carowner.owner = 0;
	end
	if Player[id].house then
		Player[id].house.owner = 0;
		Player[id].house.allowed = {};
		Player[id].house = nil;
	end
	local x, y;
	for _, i in pairs(Player[id].built) do
		x, y = getPos(_);
		if map_obj[x][y].gfx > 0 then
			freeimage(map_obj[x][y].gfx);
			map_obj[x][y].parent = nil;
		end
	end
	SavePlayer(id);
end
addhook("spawn", "onSpawn")
function onSpawn(id)
	if Player[id].hud > 0 then
		freeimage(Player[id].hud);
	end
	
	Player[id].hud = image("gfx/MafiaRP/hud2.png", hud_x + (115 / 2), hud_y + (200 / 2), 2, id);
	Player[id].hunger = 0;
	Player[id].thirst = 0;
	Player[id].job = "None";
	
	UpdateHud(id);
end
addhook("hit", "onHit")
function onHit(id, source, weapon, hpdmg, apdmg, rawdmg)
	if Player[id].train > 0 then return 1 end;
	if source > 0 then if Player[source].train > 0 then return 1 end end;
	if Player[id].car then return 1 end;
	if Player[id].carowner then
		if source > 0 then
			if Player[source].car then
				if Player[source].car.cid == Player[id].carowner.cid then return 1 end;
			elseif Player[source].carowner then
				if Player[source].carowner.cid == Player[id].carowner.cid then return 1 end;
			end
		end
		Player[id].carowner.health = Player[id].carowner.health - rawdmg;
		checkCarHealth(Player[id].carowner);
		UpdateHud(id);
		return 1;
	end
end