forked from cuberite/Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdifficulties.lua
More file actions
119 lines (109 loc) · 4.21 KB
/
difficulties.lua
File metadata and controls
119 lines (109 loc) · 4.21 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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 }
}
local IsEntityBlockedInPeaceful =
{
["cZombie"] = true,
["cZombiePigman"] = true,
["cSpider"] = true,
["cCaveSpider"] = true,
["cEnderman"] = true,
["cEnderDragon"] = true,
["cSkeleton"] = true,
["cGhast"] = true,
["cCreeper"] = true,
["cSilverfish"] = true,
["cBlaze"] = true,
["cSlime"] = true,
["cWitch"] = true,
["cWither"] = true,
["cSilverfish"] = true,
["cGuardian"] = true,
}
function HandleDifficultyCommand ( Split, Player )
if (Split[2] == nil) then
if (#Split == 1) then
SendMessage(Player, cChatColor.LightGray .. "Current world difficulty: " .. GetWorldDifficulty(Player:GetWorld()))
SendMessage(Player, cChatColor.LightGray .. "To change: " .. Split[1] .. " <peaceful|easy|normal|hard>")
else
SendMessage( Player, cChatColor.LightGray .. "Usage: " .. Split[1] .. " <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)
LOGINFO(Player:GetName() .. " set the world difficulty to peaceful.")
SendMessage(Player, cChatColor.LightGray .. "Set the world difficulty to peaceful.")
--Remove mobs which are not allowed in peaceful
Player:GetWorld():ForEachEntity(
function (a_Entity)
if not(a_Entity:IsMob()) then
return
end
if (a_Entity:GetMobFamily() == cMonster.mfHostile) then
a_Entity:Destroy()
end
end
)
elseif (Split[2] == "easy") or (Split[2] == "1") or (Split[2] == "e") then
SetWorldDifficulty(Player:GetWorld(), 1)
LOGINFO(Player:GetName() .. " set the world difficulty to easy.")
SendMessage(Player, cChatColor.LightGray .. "Set the world difficulty to easy.")
elseif (Split[2] == "normal") or (Split[2] == "2") or (Split[2] == "n") then
SetWorldDifficulty(Player:GetWorld(), 2)
LOGINFO(Player:GetName() .. " set the world difficulty to normal.")
SendMessage(Player, cChatColor.LightGray .. "Set the world difficulty to normal.")
elseif (Split[2] == "hard") or (Split[2] == "3") or (Split[2] == "h") then
SetWorldDifficulty(Player:GetWorld(), 3)
LOGINFO(Player:GetName() .. " set the world difficulty to hard.")
SendMessage(Player, cChatColor.LightGray .. "Set the world difficulty to hard.")
else
SendMessage(Player, cChatColor.LightGray .. "Usage: " .. Split[1] .. " <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
function OnSpawningEntity(World, Entity)
if GetWorldDifficulty(World) == 0 then
return IsEntityBlockedInPeaceful[Entity:GetClass()]
end
return false
end