-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.lua
More file actions
74 lines (62 loc) · 2.1 KB
/
Copy pathPlayer.lua
File metadata and controls
74 lines (62 loc) · 2.1 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
--[[ Player data wrapper - created by Zonz
This module wraps player data into fields to make code look nicer.
Player fields:
player.x - getPlayerX()
player.y - getPlayerY()
player.name - getAccountName()
player.money - getMoney()
player.isMember - isAccountMember()
player.isMounted - isMounted()
player.isSurfing - isSurfing()
player.isOutside - isOutside()
player.pokedexOwned - getPokedexOwned()
player.pokedexSeen - getPokedexSeen()
player.pokedexEvolved - getPokedexEvolved()
Player functions:
player.isOnCell(x, y) - Equivalent to player.x == x and player.y == y
player.isInRectangle(x1, y1, x2, y2) - player.x >= x1 and player.y >= y1 and player.x <= x2 and player.y <= y2
player.mount(item) - Attempts to use a mount and returns true if successful
]]
local callbacks =
{
x = getPlayerX,
y = getPlayerY,
name = getAccountName,
money = getMoney,
isMember = isAccountMember,
isMounted = isMounted,
isSurfing = isSurfing,
isOutside = isOutside,
pokedexOwned = getPokedexOwned,
pokedexSeen = getPokedexSeen,
pokedexEvolved = getPokedexEvolved,
}
local player = {}
function player.isOnCell(x, y)
return getPlayerX() == x and getPlayerY() == y
end
function player.isInRectangle(x1, y1, x2, y2)
if type(x1) == "table" then
return getPlayerX() >= x1[1] and getPlayerY() >= x1[2] and getPlayerX() <= x1[3] and getPlayerY() <= x1[4]
end
return getPlayerX() >= x1 and getPlayerY() >= y1 and getPlayerX() <= x2 and getPlayerY() <= y2
end
function player.mount(item)
return player.isOutside and not player.isMounted and not player.isSurfing and hasItem(item) and useItem(item)
end
setmetatable(player, {
__index = function(self, key)
if callbacks[key] then
return callbacks[key]()
end
return nil
end,
__newindex = function(self, key, value)
assert(callbacks[key] == nil, "Player fields are read only. (Tried to set " .. tostring(key) .. " to " .. tostring(value) .. ")")
rawset(self, key, value)
end,
})
-- Set global variable
_G.player = player
-- Return the table like an actual lib would
return player