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
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
addhook("die","EXPdie")
function EXPdie(victim,killer,weapon,x,y)
	local PVP = gettile(PLAYERS[victim].x, PLAYERS[victim].y).PVP
	if not PVP then
		if not PLAYERS[victim].Tutorial.die then
			message(victim, "You are dead. Try your best not to die, you'll drop some of your equipment and money if you do.", "255128000")
			PLAYERS[victim].Tutorial.die = true
		end
		local money = math.min(getmoney(victim), math.floor(PLAYERS[victim].Level*math.random(50,150)/10*CONFIG.PLAYERMONEYRATE))
		if money ~= 0 then
			addmoney(victim, -money)
			spawnitem(1337, player(victim, "tilex"), player(victim, "tiley"), money)
		end
		if PLAYERS[victim].Level >= 5 then
			local previtems = {}
			for i, v in ipairs(CONFIG.SLOTS) do
				if PLAYERS[victim].Equipment[i] and math.random(10000) <= CONFIG.PLAYERDROPRATE then
					dropitem(victim, i, true)
				end
			end
		end
		PLAYERS[victim].HP, PLAYERS[victim].x, PLAYERS[victim].y = 85, nil, nil
	else
		PLAYERS[victim].HP, PLAYERS[victim].x, PLAYERS[victim].y = 5, PVPZONE[PVP][3][1], PVPZONE[PVP][3][2]
		if addmoney(victim, -100) then
			spawnitem(1337, player(victim, "tilex"), player(victim, "tiley"), 100)
		end
	end
	local x = player(victim, 'x')
	local y = player(victim, 'y')
	parse('effect "colorsmoke" ' .. x .. ' ' .. y .. ' 64 64 192 0 0')
	radiussound("weapons/c4_explode.wav", x, y)
	local newitems, previtems = {}, {}
	for i, v in ipairs(CONFIG.SLOTS) do
		previtems[i] = PLAYERS[victim].Equipment[i]
		newitems[i] = 0
	end
	updateEQ(victim, newitems, previtems)
	
end