-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshapes.lua
61 lines (36 loc) · 1.17 KB
/
shapes.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
function InitShape()
local Shape = g_Config.General.Shape
if (not Shape) then
LOGWARNING("[LimitWorld] No shape defined. Using circle")
Shape = 'circle'
end
local ShapeFunction = nil
if (Shape == 'circle') then
ShapeFunction = ShapeCircle
elseif (Shape == "square") then
ShapeFunction = ShapeSquare
else
LOGWARNING("Unknown shape. Using circle")
ShapeFunction = ShapeCircle
end
g_PosCheckIsInside = ShapeFunction
end
function ShapeCircle(a_World, a_X, a_Z)
local WorldSpawn = Vector2d(math.floor(a_World:GetSpawnX() / 16), math.floor(a_World:GetSpawnZ() / 16))
local Pos = Vector2d(a_X, a_Z)
local DistanceVec = Pos - WorldSpawn
local Distance = DistanceVec:Length()
if (Distance < g_Config.General.MaxRange) then
-- Coordinates are still inside the world limit
return true
end
return false
end
function ShapeSquare(a_World, a_X, a_Z)
local WorldSpawn = Vector3d(math.floor(a_World:GetSpawnX() / 16), 0, math.floor(a_World:GetSpawnZ() / 16))
local Cuboid = cCuboid(
-g_Config.General.MaxRange, 0, -g_Config.General.MaxRange,
g_Config.General.MaxRange, 0, g_Config.General.MaxRange
)
return Cuboid:IsInside(a_X, 0, a_Z)
end