03-02-2011, 10:11 AM
PHP Code:
local MapPlugin = {}
MapPlugin.__index = MapPlugin
local MapSize = 200
function MapPlugin:new()
local t = {}
setmetatable(t, MapPlugin)
local w = Lua__cPlugin:new()
tolua.setpeer(w, t)
w:tolua__set_instance(w)
return w
end
function MapPlugin:OnDisable()
LOG( Plugin:GetName() .. " v." .. Plugin:GetVersion() .. " is shutting down..." )
end
function MapPlugin:Initialize()
self:SetName( "TinyMap" )
self:SetVersion( 1 )
PluginManager = cRoot:Get():GetPluginManager()
PluginManager:AddHook( self, cPluginManager.E_PLUGIN_PLAYER_MOVE)
end
function MakeObsidian(X, Y, Z)
local World = cRoot:Get():GetWorld();
World:SetBlock(X, Y, Z, E_BLOCK_OBSIDIAN, 0);
World:SetBlock(X, Y+1, Z, E_BLOCK_OBSIDIAN, 0);
World:SetBlock(X, Y+2, Z, E_BLOCK_OBSIDIAN, 0);
World:SetBlock(X, Y+3, Z, E_BLOCK_OBSIDIAN, 0);
World:SetBlock(X, Y+4, Z, E_BLOCK_OBSIDIAN, 0);
World:SetBlock(X, Y+5, Z, E_BLOCK_OBSIDIAN, 0);
end
function MapPlugin:OnPlayerMove( Player )
Server = cRoot:Get():GetServer()
local PlayerName = Player:GetName()
local X = math.floor(Player:GetPosX())
local Y = math.floor(Player:GetPosY())
local Z = math.floor(Player:GetPosZ())
if(X>MapSize) then
MakeObsidian(X, Y, Z)
Player:TeleportTo(MapSize,Y,Z);
Log(X..','..Y..','..Z);
end
if(Z>MapSize) then
MakeObsidian(X, Y, Z)
Player:TeleportTo(X,Y,MapSize)
Log(X..','..Y..','..Z);
end
--
if(X<-MapSize) then
MakeObsidian(X, Y, Z)
Player:TeleportTo(X,Y,-MapSize)
Log(X..','..Y..','..Z);
end
if(Z<-MapSize) then
MakeObsidian(X, Y, Z)
Player:TeleportTo(X,Y,-MapSize)
Log(X..','..Y..','..Z);
end
end
Plugin = MapPlugin:new()
cRoot:Get():GetPluginManager():AddPlugin( Plugin )
If you read the code, basically it prevents players from going beyond the "limit" of the mapsize you set in the first bits of the plugin. The default "mapsize" is 200x200 which will allow you to run a ridiculous amount of players on a server with only 128mb ram due to the incredibly small footprint of MCServer and the fact that ram usage is due to chunks loaded and nothing else!
I also added the it creates a 6 block tall single block tower of obsidian where the player tries to go beyond the barrier, which will have the eventual effect of creating an impenetrable wall around your "map" beyond which noone can travel.
Obviously you could set admin permissions to allow them to go beyond, but I'm not going to use that, I just wanted something to keep everyone in the one area quickly and easily, and this does the job just fine
The obsidian wall in action!