I have a problem with function HIT in my "tibia" remake.
Monsters in my remake don't make any damage.
Console: http://i68.tinypic.com/vct576.png
EXPHit
Spoiler
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
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
addhook("hit","EXPhit") function EXPhit(id,source,weapon,hpdmg,apdmg) 	local HP, dmg, wpnName, name = player(id, "health") 	if hpdmg <= 0 or source == 0 then 		PLAYERS[id].HP = HP-hpdmg 		return 	end 	if type(source) == "table" then 		if gettile(PLAYERS[id].x, PLAYERS[id].y).SAFE then return 1 end 		dmg = math.ceil(math.random(10,20)*hpdmg*source.atk/PLAYERS[id].tmp.def/15) 		source, wpnName = 0, source.name 		--print(wpnName .. " deals " .. dmg .. " damage to " .. player(id, "name") .. ".") 	elseif player(source, 'health') > 0 then 		if id == source then return 1 end 		if inarray({400, 401, 402, 403, 404}, PLAYERS[source].Equipment[7]) then message(source, "You may not attack on a horse.") return 1 end 		if gettile(PLAYERS[id].x, PLAYERS[id].y).SAFE or gettile(PLAYERS[source].x, PLAYERS[source].y).SAFE then message(source, "You may not attack someone in a safezone.") return 1 end 		if not PLAYERS[id].Tutorial.hit then 			message(id, "A player is attacking you! You can fight back by swinging your weapon at him.", "255128000") 			PLAYERS[id].Tutorial.hit = true 		end 		local atk = PLAYERS[source].tmp.atk 		local def = PLAYERS[id].tmp.def 		if weapon == 251 then 			dmg = math.ceil(2500/math.random(80,120)) 			wpnName = 'rune' 		elseif weapon == 46 then 			dmg = math.ceil(500/math.random(80,120)) 			wpnName = 'firewave' 		else 			local dmgMul = ((PLAYERS[id].Level+50)*atk/def)/math.random(60,140) 			dmg = math.ceil(20*dmgMul) 			wpnName = PLAYERS[source].Equipment[3] and ITEMS[PLAYERS[source].Equipment[3]].name or 'dagger' 		end 		--print(player(source, "name") .. " deals " .. dmg .. " damage to " .. player(id, "name") .. ".") 	end 	local resultHP = HP-dmg 	if resultHP > 0 then 		sethealth(id,resultHP) 		parse('effect "colorsmoke" ' .. player(id, "x") .. ' ' .. player(id, "y") .. ' 0 0 192 0 0') 	else 		parse('customkill ' .. source .. ' "' .. wpnName .. '" ' .. id) 	end 	PLAYERS[id].HP = resultHP 	return 1 end
monster.lua553:
Spoiler
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
function Monster:hit(id, dmg) 	if not PLAYERS[id].Tutorial.hitm then 		message(id, "A monster is attacking you! You can fight back by swinging your weapon at it.", "255128000") 		PLAYERS[id].Tutorial.hitm = true 	end 	if player(id, 'weapontype') == 41 and (math.abs(math.rad(player(id, 'rot')) - math.atan2(player(id, 'y')-self.y, player(id, 'x')-self.x) + math.pi/2)%(2*math.pi) <= math.pi*2/3) then 		EXPhit(id, self, -1, dmg/4) 		radiussound("weapons/ricmetal" .. math.random(1,2) .. ".wav", self.x, self.y) 	else 		EXPhit(id, self, -1, dmg) 		radiussound("weapons/knife_hit.wav", self.x, self.y) 	end 	return true end
monster.lua451
Spoiler
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
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
addhook("ms100", "MONSTERms100") function MONSTERms100() 	t = t + 1 	if t % 100 == 0 then 		while #MONSTERS < CONFIG.MAXMONSTERS do 			local rand, spawnNo, mapName 			while true do 				rand = math.random(#CONFIG.MONSTERS) 				mapName = CONFIG.MONSTERS[rand].spawn[map'name'] and map'name' or CONFIG.DEFAULTMAP 				spawnNo = math.random(#CONFIG.MONSTERS[rand].spawn[mapName]) 				if math.random(0, 100) < CONFIG.MONSTERS[rand].spawnchance[mapName][spawnNo] then 					break 				end 			end 			local m = deepcopy(CONFIG.MONSTERS[rand]) 			local x, y, tilex, tiley 			local spawn = m.spawn[mapName][spawnNo] 			repeat 				tilex, tiley = math.random(spawn[1][1], spawn[2][1]), math.random(spawn[1][2], spawn[2][2]) 			until not gettile(tilex, tiley).SAFE and 				 not gettile(tilex, tiley).NOMONSTERS and 				 tile(tilex, tiley, "walkable") and 				 tile(tilex, tiley, "frame") ~= 34 			m.x, m.y = math.floor(tilex*32+16), math.floor(tiley*32+16) 			Monster:new(m) 		end 	end 	for _, m in ipairs(MONSTERS) do 		if t % m.atkspd == 0 then 			m.target = nil 			local closest 			for _, p in ipairs(table.shuffle(player(0, 'table'))) do 				if player(p, 'health') > 0 and 					not gettile(PLAYERS[p].x, PLAYERS[p].y).SAFE and 					not gettile(PLAYERS[p].x, PLAYERS[p].y).NOMONSTERS then 					local dist = math.sqrt((player(p, 'x')-m.x)^2 + (player(p, 'y')-m.y)^2) 					if dist < 400 then 						if not closest or dist < closest[2] then 							closest = {p, dist} 						end 					end 				end 			end 			if closest then 				local dist = closest[2] 				if dist < 400 then 					m.target = closest[1] 					if m.spc and math.random(10000) <= m.spc[1] then 						m.spc[2](m, m.target, dist) 					elseif dist <= (m.range or 32) then 						m:hit(m.target, 10) 					end 				end 			end 		end