2013-05-26 15:20:49 -04:00
|
|
|
|
|
|
|
-- ProtectionAreas.lua
|
2013-06-07 12:28:37 -04:00
|
|
|
-- Defines the main plugin entrypoint, as well as some utility functions
|
2013-05-26 15:20:49 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-06 13:10:45 -04:00
|
|
|
--- Prefix for all messages logged to the server console
|
|
|
|
PluginPrefix = "ProtectionAreas: ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--- Called by MCS when the plugin loads
|
|
|
|
-- Returns true if initialization successful, false otherwise
|
2013-05-26 15:20:49 -04:00
|
|
|
function Initialize(a_Plugin)
|
|
|
|
a_Plugin:SetName("ProtectionAreas");
|
|
|
|
a_Plugin:SetVersion(1);
|
|
|
|
|
2013-06-06 13:10:45 -04:00
|
|
|
if (not(InitializeStorage())) then
|
|
|
|
LOGWARNING(PluginPrefix .. "failed to initialize Storage, plugin is disabled");
|
|
|
|
return false;
|
|
|
|
end
|
2013-05-26 15:20:49 -04:00
|
|
|
InitializeHooks(a_Plugin);
|
|
|
|
InitializeCommandHandlers();
|
|
|
|
|
2013-06-07 12:28:37 -04:00
|
|
|
-- We might be reloading, so there may be players already present in the server; reload all of them
|
|
|
|
local function ReloadPlayers(a_World)
|
|
|
|
ReloadAllPlayersInWorld(a_World:GetName());
|
|
|
|
end
|
|
|
|
cRoot:Get():ForEachWorld(ReloadPlayers);
|
2013-05-26 15:20:49 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
end
|
2013-06-07 12:28:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--- Loads a cPlayerAreas object from the DB for the player, and assigns it to the player map
|
|
|
|
function LoadPlayerAreas(a_Player)
|
|
|
|
local PlayerID = a_Player:GetUniqueID();
|
|
|
|
local PlayerX = math.floor(a_Player:GetPosX());
|
|
|
|
local PlayerZ = math.floor(a_Player:GetPosZ());
|
|
|
|
local WorldName = a_Player:GetWorld():GetName();
|
|
|
|
g_PlayerAreas[PlayerID] = g_Storage:LoadPlayerAreas(a_Player:GetName(), PlayerX, PlayerZ, WorldName);
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function ReloadAllPlayersInWorld(a_WorldName)
|
|
|
|
local World = cRoot:Get():GetWorld(a_WorldName);
|
|
|
|
World:ForEachPlayer(LoadPlayerAreas);
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|