forked from cuberite/Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
difficulties.lua
101 lines (92 loc) · 3.41 KB
/
difficulties.lua
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
local MobDamages =
{
["cSpider"] = { 2, 2, 3 },
["cEnderman"] = { 4, 7, 10 },
["cZombie"] = { }, -- Handled in OnTakeDamage()
["cSlime"] = { 4, 4, 4 },
["cCaveSpider"] = { 2, 2, 3 },
["cZombiePigman"] = { 5, 9, 13 },
["cSkeleton"] = { 2, 2, 3 },
["cBlaze"] = { 4, 6, 9 }
}
function HandleDifficultyCommand ( Split, Player )
if (Split[2] == nil) then
if (#Split == 1) then
SendMessage(Player, "Current world difficulty: " .. GetWorldDifficulty(Player:GetWorld()))
SendMessage(Player, "To change: /difficulty [peaceful/easy/normal/hard]")
else
SendMessage( Player, "Usage: /difficulty [peaceful/easy/normal/hard]" )
end
return true
end
if (Split[2] == "peaceful") or (Split[2] == "0") or (Split[2] == "p") then
SetWorldDifficulty(Player:GetWorld(), 0)
SendMessage( Player, "World difficulty set to peaceful" )
elseif (Split[2] == "easy") or (Split[2] == "1") or (Split[2] == "e") then
SetWorldDifficulty(Player:GetWorld(), 1)
SendMessage( Player, "World difficulty set to easy" )
elseif (Split[2] == "normal") or (Split[2] == "2") or (Split[2] == "n") then
SetWorldDifficulty(Player:GetWorld(), 2)
SendMessage( Player, "World difficulty set to normal" )
elseif (Split[2] == "hard") or (Split[2] == "3") or (Split[2] == "h") then
SetWorldDifficulty(Player:GetWorld(), 3)
SendMessage( Player, "World difficulty set to hard" )
else
SendMessage( Player, "Usage: /difficulty [peaceful/easy/normal/hard]" )
end
return true
end
function OnTakeDamage(Receiver, TDI)
if (TDI.Attacker == nil) then
return false
end
local Attacker = TDI.Attacker
local WorldDifficulty = GetWorldDifficulty(Attacker:GetWorld())
if Attacker:IsA("cZombie") then
-- The damage value from the zombie is computed from the zombie health. See http://minecraft.gamepedia.com/Zombie
if (WorldDifficulty == 1) then
if (Attacker:GetHealth() >= 16) then TDI.FinalDamage = 2;
elseif (Attacker:GetHealth() >= 11) then TDI.FinalDamage = 3;
elseif (Attacker:GetHealth() >= 6) then TDI.FinalDamage = 3;
else TDI.FinalDamage = 4; end
elseif (WorldDifficulty == 2) then
if (Attacker:GetHealth() >= 16) then TDI.FinalDamage = 3;
elseif (Attacker:GetHealth() >= 11) then TDI.FinalDamage = 4;
elseif (Attacker:GetHealth() >= 6) then TDI.FinalDamage = 5;
else TDI.FinalDamage = 6; end
elseif (WorldDifficulty == 3) then
if (Attacker:GetHealth() >= 16) then TDI.FinalDamage = 4;
elseif (Attacker:GetHealth() >= 11) then TDI.FinalDamage = 6;
elseif (Attacker:GetHealth() >= 6) then TDI.FinalDamage = 7;
else TDI.FinalDamage = 9; end
end
return false
end
local Damages = MobDamages[Attacker:GetClass()]
if (Damages ~= nil) then
TDI.FinalDamage = Damages[WorldDifficulty]
end
end
local IsEntityBlockedInPeaceful =
{
["cZombie"] = true,
["cZombiePigman"] = true,
["cSpider"] = true,
["cEnderman"] = true,
["cEnderDragon"] = true,
["cSkeleton"] = true,
["cGhast"] = true,
["cCreeper"] = true,
["cSilverfish"] = true,
["cBlaze"] = true,
["cSlime"] = true,
["cWitch"] = true,
["cWither"] = true,
["cSilverfish"] = true,
}
function OnSpawningEntity(World, Entity)
if (GetWorldDifficulty(World) == 0) then
return IsEntityBlockedInPeaceful[Entity:GetClass()]
end
return false
end