forked from Bremaweb/landrush
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfunctions.lua
More file actions
55 lines (46 loc) · 1.14 KB
/
functions.lua
File metadata and controls
55 lines (46 loc) · 1.14 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
local function vertical_level(y)
-- 3 levels of vertical protection
if ( y < -200 ) then
y = -32000
elseif ( y < -60 ) then
y = -200
elseif ( y < 140 ) then
y = -30
else
y = 90
end
return y
end
function landrush.get_chunk(pos)
local N = landrush.config:get("chunkSize")
local x = math.floor(pos.x/N)
local y = vertical_level(pos.y)
local z = math.floor(pos.z/N)
return x..","..y..","..z
end
function landrush.get_chunk_center(pos)
local N = landrush.config:get("chunkSize")
local x = math.floor(pos.x/N)*N + 7.5
local z = math.floor(pos.z/N)*N + 7.5
return {x=x,y=nil,z=z}
end
function landrush.get_owner(pos)
local chunk = landrush.get_chunk(pos)
if landrush.claims[chunk] then
return landrush.claims[chunk].owner
end
end
function landrush.get_distance(pos1,pos2)
if ( pos1 ~= nil and pos2 ~= nil ) then
return math.floor(math.sqrt( (pos1.x - pos2.x)^2 + (pos1.z - pos2.z)^2 ))
end
return 0
end
function landrush.get_timeonline(name)
-- a wrapper for whoison.getTimeOnline
-- since whoison is an optional dependency
if ( landrush.whoison == true ) then
return (whoison.getTimeOnline(name) / 60)
end
return -1
end