-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHooks.lua
182 lines (123 loc) · 3.83 KB
/
Hooks.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
-- This file implements all the hook handlers.
function OnTakeDamage(a_Receiver, a_TDI)
-- The receiver isn't an player. Don't even bother
if (not a_Receiver:IsPlayer()) then
return false
end
local Receiver = tolua.cast(a_Receiver, "cPlayer")
local ReceiverName = Receiver:GetName()
local ReceiverState = GetPlayerState(Receiver)
-- The player hasn't joined an arena. Lets bail out.
if (not ReceiverState:HasJoinedArena()) then
return false
end
if ((a_TDI.Attacker == nil) or (a_TDI.DamageType ~= dtRangedAttack)) then
return true
end
-- The attacker isn't an projectile wich means it can't be an snowball.
if (not a_TDI.Attacker:IsProjectile()) then
return true
end
local Projectile = tolua.cast(a_TDI.Attacker, "cProjectileEntity")
if (Projectile:GetProjectileKind() ~= cProjectileEntity.pkSnowball) then
return true
end
local Succes = false
local World = Projectile:GetWorld()
local CreatorID = Projectile:GetCreatorUniqueID()
World:DoWithEntityByID(CreatorID,
function(a_Creator)
if (not a_Creator:IsPlayer()) then
return true
end
local Attacker = tolua.cast(a_Creator, "cPlayer")
local AttackerName = Attacker:GetName()
local AttackerState = GetPlayerState(Attacker)
-- Don't let other players who are not in an arena affect playing people.
if (not AttackerState:HasJoinedArena()) then
return true
end
if (ReceiverState:GetJoinedArena() ~= AttackerState:GetJoinedArena()) then -- Wut?? Somebody from another arena attacked this player. Let's stop it.
return true
end
local Arena = ReceiverState:GetJoinedArena()
local ArenaState = GetArenaState(Arena)
ArenaState:HitPlayer(Attacker, Receiver)
Succes = true
end
)
return Succes
end
function OnPlayerDestroyed(a_Player)
local State = GetPlayerState(a_Player)
-- The player didn't join an arena. We can just leave.
if (not State:HasJoinedArena()) then
return false
end
local ArenaState = GetArenaState(State:GetJoinedArena())
State:JoinArena(nil)
-- Remove the player from the team he was on.
ArenaState:LeaveArena(a_Player:GetName())
end
function OnPlayerMoving(a_Player)
-- Get the playerstate.
local State = GetPlayerState(a_Player)
-- Check if the player has joined any arena's.
if (not State:HasJoinedArena()) then
return false
end
-- Heal and feed the player.
a_Player:Heal(20)
a_Player:Feed(20, 20)
end
function OnBlockInteraction(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace)
if (a_BlockFace == BLOCK_FACE_NONE) then
return false
end
local State = GetPlayerState(a_Player)
if (not State:HasJoinedArena()) then
return false
end
-- Resend the block.
a_Player:GetWorld():SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player)
return true
end
function OnSpawnedEntity(a_World, a_Entity)
if (not a_Entity:IsProjectile()) then
return false
end
local Projectile = tolua.cast(a_Entity, "cProjectileEntity")
local ProjectileType = Projectile:GetProjectileKind()
if (not ProjectileType == cProjectileEntity.pkSnowball) then
return false
end
local PlayerState;
local World = Projectile:GetWorld()
local CreatorID = Projectile:GetCreatorUniqueID()
World:DoWithEntityByID(CreatorID,
function(a_Creator)
if (a_Creator == nil) then
return false
end
if (not a_Creator:IsPlayer()) then
return false
end
PlayerState = GetPlayerState(a_Creator)
end
)
if (not PlayerState) then
return false
end
if (not PlayerState:HasJoinedArena()) then
return false
end
local JoinedArena = PlayerState:GetJoinedArena()
-- Weird. The playerstate says we joined an arena but the arena doesn't exist. Lets "leave" that arena.
if (not ArenaStateExists(JoinedArena)) then
PlayerState:JoinArena(nil)
return false
end
local ArenaState = GetArenaState(JoinedArena)
ArenaState:AddStatsShotsFired()
return false
end