Fire.LuA
#1
anyone know how to add TNT boxes to this so they can be ignited? also does anyone know how to make railroads work? they dont link together andyou cant put a cart on it



PHP Code:
local FirePlugin = {}
FirePlugin.__index FirePlugin

FireBlocks 
= {}

function 
FirePlugin:new()
   
local t = {}
   
setmetatable(tFirePlugin)
   
local w Lua__cPlugin:new()
   
tolua.setpeer(wt)
   
w:tolua__set_instance(w)
   return 
w
end

function IsForeverBurnableBlockID )
    if( 
BlockID == E_BLOCK_BLOODSTONE then
        
return true
    end
    
return false
end

function IsBurnableBlockID )
    if( 
BlockID == E_BLOCK_LEAVES or BlockID == E_BLOCK_LOG BlockIDthen
        
return true
    end

    
return false
end

function FindBurnableAroundXY)
    
World cRoot:Get():GetWorld()

    
ListBurnables = {}
    if( 
IsBurnableWorld:GetBlock(X-1YZ) ) ) then
        table
.insertListBurnables, { ["x"] = X-1, ["y"] = Y, ["z"] = } )
    
end
    
if( IsBurnableWorld:GetBlock(X+1YZ) ) ) then
        table
.insertListBurnables, { ["x"] = X+1, ["y"] = Y, ["z"] = } )
    
end
    
if( IsBurnableWorld:GetBlock(XY-1Z) ) ) then
        table
.insertListBurnables, { ["x"] = X, ["y"] = Y-1, ["z"] = } )
    
end
    
if( IsBurnableWorld:GetBlock(XY+1Z) ) ) then
        table
.insertListBurnables, { ["x"] = X, ["y"] = Y+1, ["z"] = } )
    
end
    
if( IsBurnableWorld:GetBlock(XYZ-1) ) ) then
        table
.insertListBurnables, { ["x"] = X, ["y"] = Y, ["z"] = Z-} )
    
end
    
if( IsBurnableWorld:GetBlock(XYZ+1) ) ) then
        table
.insertListBurnables, { ["x"] = X, ["y"] = Y, ["z"] = Z+} )
    
end

    
return ListBurnables
end

function FirePlugin:OnDisable()
    
LogPlugin:GetName() .. " v." .. Plugin:GetVersion() .. " is shutting down..." )
end

function FirePlugin:Initialize()
    
self:SetName"Fire" )
    
self:SetVersion)

    
PluginManager cRoot:Get():GetPluginManager()
    
PluginManager:AddHookselfcPluginManager.E_PLUGIN_TICK )
    
PluginManager:AddHookselfcPluginManager.E_PLUGIN_BLOCK_PLACE )
    
PluginManager:AddHookselfcPluginManager.E_PLUGIN_BLOCK_DIG )

    
Log"Initialized " .. self:GetName() .. " v." .. self:GetVersion() )
    return 
true
end

function FirePlugin:OnBlockPlacePacketDataPlayer )

    if( 
PacketData.m_ItemType == E_BLOCK_FIRE or PacketData.m_ItemType == E_ITEM_FLINT_AND_STEEL then
        
if( PacketData.m_Direction > -then
            local X 
PacketData.m_PosX
            local Y 
PacketData.m_PosY
            local Z 
PacketData.m_PosZ

            X
YAddDirectionXYZPacketData.m_Direction )

            --
Since flint and steel doesn't do anything on the server side yet
            if( PacketData.m_ItemType == E_ITEM_FLINT_AND_STEEL ) then
                local World = cRoot:Get():GetWorld()
                World:SetBlock( X, Y, Z, E_BLOCK_FIRE, 0 )
            end

            if( not IsForeverBurnable( World:GetBlock( X, Y-1, Z ) ) ) then
                table.insert( FireBlocks, { ["x"] = X, ["y"] = Y, ["z"] = Z } )
            end
        end
    end

    return false -- dont forbid placing the fire
end

-- To put out fires! :D
function FirePlugin:OnBlockDig( PacketData, Player )
    if( PacketData.m_Direction < 0 ) then
        return false
    end

    local X = PacketData.m_PosX
    local Y = PacketData.m_PosY
    local Z = PacketData.m_PosZ

    X, Y, Z = AddDirection( X, Y, Z, PacketData.m_Direction )

    local World = cRoot:Get():GetWorld()
    if( World:GetBlock( X, Y, Z ) == E_BLOCK_FIRE ) then
        World:SetBlock( X, Y, Z, E_BLOCK_AIR, 0 )
    end

    return false
end

NumTicks = 0
function FirePlugin:Tick( DeltaTime )
    if( NumTicks < 10 ) then    -- Only spread every 10 ticks, to make sure it doesnt happen too fast
        NumTicks = NumTicks + 1
        return
    end
    NumTicks = 0

    World = cRoot:Get():GetWorld()

    NewTable = {}
    for key,val in pairs(FireBlocks) do
        X = val["x"]
        Y = val["y"]
        Z = val["z"]
        Burnables = FindBurnableAround(X, Y, Z)
        if( math.random(10) > 5 ) then
            table.insert( NewTable, val )
        elseif( #Burnables > 0 ) then
            ToBurn = Burnables[ math.random( #Burnables ) ]
            World:SetBlock( ToBurn["x"], ToBurn["y"], ToBurn["z"], E_BLOCK_FIRE, 0 )
            table.insert( NewTable, ToBurn )
            table.insert( NewTable, val )
        else
            World:SetBlock( X, Y, Z, 0, 0 )
        end
    end
    FireBlocks = NewTable
end

Plugin = FirePlugin:new()
cRoot:Get():GetPluginManager():AddPlugin( Plugin ) 
Reply
Thanks given by:
#2
(02-28-2011, 10:06 AM)distroyed123 Wrote: anyone know how to add TNT boxes to this so they can be ignited? also does anyone know how to make railroads work? they dont link together andyou cant put a cart on it

Needs to be implemented into MCServer.
Reply
Thanks given by:
#3
(03-01-2011, 02:47 AM)Tybor Wrote:
(02-28-2011, 10:06 AM)distroyed123 Wrote: anyone know how to add TNT boxes to this so they can be ignited? also does anyone know how to make railroads work? they dont link together andyou cant put a cart on it

Needs to be implemented into MCServer.

ahh ok, didnt know if everything needed to be emplemented
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)