-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerState.lua
72 lines (51 loc) · 1.47 KB
/
PlayerState.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
-- The table that contains all the player states.
g_PlayerStates = {}
function CreatePlayerState(a_Player)
local self = {}
local SelectedArena = nil
local JoinedArena = nil
do -- The functions for managing the selected arena.
-- Returns true if the player has an arena selected.
function self:HasArenaSelected()
return (SelectedArena ~= nil)
end
-- Changes the arena wich the player has selected.
function self:SelectArena(a_Arena)
if (ArenaStateExists(a_Arena)) then
SelectedArena = a_Arena
return true
end
return false
end
-- Returns the name of the selected arena.
function self:GetSelectedArena()
return SelectedArena
end
end
do -- The functions managing the joined arena.
-- Returns true if the player joined an arena.
function self:HasJoinedArena()
return (JoinedArena ~= nil)
end
-- Changes the arena that the player has joined.
function self:JoinArena(a_Arena)
JoinedArena = a_Arena
end
-- returns the name of the joined arena.
function self:GetJoinedArena()
return JoinedArena
end
end
return self
end
-- This function returns the playerstate of a player. If it doesn't exist it creates it first and then returns it.
function GetPlayerState(a_Player)
local Name = a_Player:GetName()
local PlayerState = g_PlayerStates[Name]
if (PlayerState ~= nil) then
return PlayerState
end
PlayerState = CreatePlayerState(a_Player)
g_PlayerStates[Name] = PlayerState
return PlayerState
end