Changed the Fire plugin to use the new plugin structure
git-svn-id: http://mc-server.googlecode.com/svn/trunk@206 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
7c3f98e4ed
commit
dc926282ec
@ -1,15 +1,18 @@
|
|||||||
local FirePlugin = {}
|
local FireBlocks = {} -- List of blocks that are currently burning!
|
||||||
FirePlugin.__index = FirePlugin
|
|
||||||
|
|
||||||
FireBlocks = {}
|
function Initialize( Plugin )
|
||||||
|
|
||||||
function FirePlugin:new()
|
Plugin:SetName( "Fire" )
|
||||||
local t = {}
|
Plugin:SetVersion( 2 )
|
||||||
setmetatable(t, FirePlugin)
|
|
||||||
local w = Lua__cPlugin:new()
|
PluginManager = cRoot:Get():GetPluginManager()
|
||||||
tolua.setpeer(w, t)
|
PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_TICK )
|
||||||
w:tolua__set_instance(w)
|
PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_BLOCK_PLACE )
|
||||||
return w
|
PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_BLOCK_DIG )
|
||||||
|
|
||||||
|
Log( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
|
||||||
|
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function IsForeverBurnable( BlockID )
|
function IsForeverBurnable( BlockID )
|
||||||
@ -53,24 +56,8 @@ function FindBurnableAround( X, Y, Z )
|
|||||||
return ListBurnables
|
return ListBurnables
|
||||||
end
|
end
|
||||||
|
|
||||||
function FirePlugin:OnDisable()
|
|
||||||
Log( self:GetName() .. " v." .. self:GetVersion() .. " is shutting down..." )
|
|
||||||
end
|
|
||||||
|
|
||||||
function FirePlugin:Initialize()
|
function OnBlockPlace( PacketData, Player )
|
||||||
self:SetName( "Fire" )
|
|
||||||
self:SetVersion( 1 )
|
|
||||||
|
|
||||||
PluginManager = cRoot:Get():GetPluginManager()
|
|
||||||
PluginManager:AddHook( self, cPluginManager.E_PLUGIN_TICK )
|
|
||||||
PluginManager:AddHook( self, cPluginManager.E_PLUGIN_BLOCK_PLACE )
|
|
||||||
PluginManager:AddHook( self, cPluginManager.E_PLUGIN_BLOCK_DIG )
|
|
||||||
|
|
||||||
Log( "Initialized " .. self:GetName() .. " v." .. self:GetVersion() )
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function FirePlugin:OnBlockPlace( PacketData, Player )
|
|
||||||
|
|
||||||
if( PacketData.m_ItemType == E_BLOCK_FIRE or PacketData.m_ItemType == E_ITEM_FLINT_AND_STEEL ) then
|
if( PacketData.m_ItemType == E_BLOCK_FIRE or PacketData.m_ItemType == E_ITEM_FLINT_AND_STEEL ) then
|
||||||
if( PacketData.m_Direction > -1 ) then
|
if( PacketData.m_Direction > -1 ) then
|
||||||
@ -79,10 +66,10 @@ function FirePlugin:OnBlockPlace( PacketData, Player )
|
|||||||
local Z = PacketData.m_PosZ
|
local Z = PacketData.m_PosZ
|
||||||
|
|
||||||
X, Y, Z = AddDirection( X, Y, Z, PacketData.m_Direction )
|
X, Y, Z = AddDirection( X, Y, Z, PacketData.m_Direction )
|
||||||
|
local World = cRoot:Get():GetWorld()
|
||||||
|
|
||||||
--Since flint and steel doesn't do anything on the server side yet
|
--Since flint and steel doesn't do anything on the server side yet
|
||||||
if( PacketData.m_ItemType == E_ITEM_FLINT_AND_STEEL ) then
|
if( PacketData.m_ItemType == E_ITEM_FLINT_AND_STEEL ) then
|
||||||
local World = cRoot:Get():GetWorld()
|
|
||||||
World:SetBlock( X, Y, Z, E_BLOCK_FIRE, 0 )
|
World:SetBlock( X, Y, Z, E_BLOCK_FIRE, 0 )
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -96,7 +83,7 @@ function FirePlugin:OnBlockPlace( PacketData, Player )
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- To put out fires! :D
|
-- To put out fires! :D
|
||||||
function FirePlugin:OnBlockDig( PacketData, Player )
|
function OnBlockDig( PacketData, Player )
|
||||||
if( PacketData.m_Direction < 0 ) then
|
if( PacketData.m_Direction < 0 ) then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -115,26 +102,26 @@ function FirePlugin:OnBlockDig( PacketData, Player )
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
NumTicks = 0
|
local NumTicks = 0
|
||||||
function FirePlugin:Tick( DeltaTime )
|
function Tick( DeltaTime )
|
||||||
if( NumTicks < 10 ) then -- Only spread every 10 ticks, to make sure it doesnt happen too fast
|
if( NumTicks < 10 ) then -- Only spread every 10 ticks, to make sure it doesnt happen too fast
|
||||||
NumTicks = NumTicks + 1
|
NumTicks = NumTicks + 1
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
NumTicks = 0
|
NumTicks = 0
|
||||||
|
|
||||||
World = cRoot:Get():GetWorld()
|
local World = cRoot:Get():GetWorld()
|
||||||
|
|
||||||
NewTable = {}
|
local NewTable = {}
|
||||||
for key,val in pairs(FireBlocks) do
|
for key,val in pairs(FireBlocks) do
|
||||||
X = val["x"]
|
X = val["x"]
|
||||||
Y = val["y"]
|
Y = val["y"]
|
||||||
Z = val["z"]
|
Z = val["z"]
|
||||||
Burnables = FindBurnableAround(X, Y, Z)
|
local Burnables = FindBurnableAround(X, Y, Z)
|
||||||
if( math.random(10) > 5 ) then
|
if( math.random(10) > 5 ) then
|
||||||
table.insert( NewTable, val )
|
table.insert( NewTable, val )
|
||||||
elseif( #Burnables > 0 ) then
|
elseif( #Burnables > 0 ) then
|
||||||
ToBurn = Burnables[ math.random( #Burnables ) ]
|
local ToBurn = Burnables[ math.random( #Burnables ) ]
|
||||||
World:SetBlock( ToBurn["x"], ToBurn["y"], ToBurn["z"], E_BLOCK_FIRE, 0 )
|
World:SetBlock( ToBurn["x"], ToBurn["y"], ToBurn["z"], E_BLOCK_FIRE, 0 )
|
||||||
table.insert( NewTable, ToBurn )
|
table.insert( NewTable, ToBurn )
|
||||||
table.insert( NewTable, val )
|
table.insert( NewTable, val )
|
||||||
@ -144,6 +131,3 @@ function FirePlugin:Tick( DeltaTime )
|
|||||||
end
|
end
|
||||||
FireBlocks = NewTable
|
FireBlocks = NewTable
|
||||||
end
|
end
|
||||||
|
|
||||||
Plugin = FirePlugin:new()
|
|
||||||
cRoot:Get():GetPluginManager():AddPlugin( Plugin )
|
|
Loading…
Reference in New Issue
Block a user