-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
68 lines (51 loc) · 1.98 KB
/
main.lua
File metadata and controls
68 lines (51 loc) · 1.98 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
-- Globals
PLUGIN = {}
LOGPREFIX = ""
WORLDSPAWNPROTECTION = {}
MESSAGE = {}
PLAYERLOCATIONS = {}
function Initialize( Plugin )
PLUGIN = Plugin
Plugin:SetName( "EssentialsSpawn" )
Plugin:SetVersion( 1 )
LOGPREFIX = "[" .. Plugin:GetName() .. "] "
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_BREAKING_BLOCK, OnPlayerBreakingBlock)
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_MOVING, OnPlayerMoving)
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_PLACING_BLOCK, OnPlayerPlacingBlock)
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_PLACING_BLOCK, OnPlayerPlacingBlock)
cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK, OnPlayerRightClick)
cPluginManager:AddHook(cPluginManager.HOOK_EXPLODING, OnExploding)
cPluginManager:AddHook(cPluginManager.HOOK_TAKE_DAMAGE, OnTakeDamage)
cPluginManager:AddHook(cPluginManager.HOOK_SPAWNING_MONSTER, OnSpawningMonster)
cRoot:Get():ForEachWorld(
function (World)
local WorldIni = cIniFile()
WorldIni:ReadFile(World:GetIniFileName())
WORLDSPAWNPROTECTION[World:GetName()] = WorldIni:GetValueSetI("SpawnProtect", "ProtectRadius", 10)
WorldIni:WriteFile(World:GetIniFileName())
end
)
LOG( LOGPREFIX .. "Plugin v" .. Plugin:GetVersion() .. " Enabled!" )
return true
end
function OnDisable()
LOG( LOGPREFIX .. "Plugin Disabled!" )
end
function IsInSpawn(X, Y, Z, WorldName)
local World = cRoot:Get():GetWorld(WorldName)
local SpawnLoc = Vector3d(World:GetSpawnX(), World:GetSpawnY(), World:GetSpawnZ())
local PlayerLoc = Vector3d(X, Y, Z)
-- Get protection radius for the world.
local protectRadius = GetSpawnProtection(WorldName)
if (protectRadius == -1) then
-- There is no spawn for this world, so the player can\'t be in it.
return false
end
if ((SpawnLoc - PlayerLoc):Length() <= protectRadius) then
return true
end
return false
end
function GetSpawnProtection(WorldName)
return WORLDSPAWNPROTECTION[WorldName]
end