Not able to run command inside plugin
#11
It does use it here: https://github.com/cuberite/WorldEdit/bl...ns.lua#L33

WorldEdit's function also works with explicit blocktypes and metas.
Reply
Thanks given by:
#12
OK, its now all working.
Here is the final code for anyone wanting /setblock in cuberite.
I will make a github with the full /fill and /setblock plugin when its done.
Until then, you can use this:

VanillaFill/main.lua:
Code:
PLUGIN = nil

function Initialize(Plugin)
    Plugin:SetName("VanillaFill")
    Plugin:SetVersion(1)

    -- Hooks

    PLUGIN = Plugin -- NOTE: only needed if you want OnDisable() to use GetName() or something like that

    -- Command Bindings
    cPluginManager.BindCommand("/setblock", "vanillafill.setblock", setblock, " ~ Changes a block at X Y Z.");
--    cPluginManager.BindCommand("/fill", "vanillafill.fill", fill, " ~ Fills an area from X Y Z to X2 Y2 Z2.");

    LOG("Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion())
    return true
end

function OnDisable()
    LOG(PLUGIN:GetName() .. " is shutting down...")
end

-- This segment is a bit of stripped-down code from the WorldEdit Plugin (github.com/cuberite/WorldEdit)

-- Returns the block type (and block meta) from a string. This can be something like "1", "1:0", "stone" and "stone:0".
-- If a string with a percentage sign is given it will take the second half of the string (With "40%1:0" it uses only "1:0")
function GetBlockTypeMeta(a_BlockString)
    g_DefaultMetas = {
    [E_BLOCK_CHEST]              = 2,
    [E_BLOCK_ENDER_CHEST]        = 2,
    [E_BLOCK_FURNACE]            = 2,
    [E_BLOCK_LADDER]             = 2,
    [E_BLOCK_LIT_FURNACE]        = 2,
    [E_BLOCK_NETHER_PORTAL]      = 1,
    [E_BLOCK_TORCH]              = 1,
    [E_BLOCK_TRAPPED_CHEST]      = 2,
    [E_BLOCK_REDSTONE_TORCH_ON]  = 1,
    [E_BLOCK_REDSTONE_TORCH_OFF] = 1,
    [E_BLOCK_WALLSIGN]           = 2,
    [E_BLOCK_WALL_BANNER]        = 2
}

    if (a_BlockString:find("%%")) then
        local ItemInfo = StringSplit(a_BlockString, "%")
        if (#ItemInfo ~= 2) then
            return false
        end

        a_BlockString = ItemInfo[2]
    end

    local BlockID = tonumber(a_BlockString)

    -- Check if it was a normal number
    if (BlockID) then
        return BlockID, g_DefaultMetas[BlockID] or 0, true
    end

    -- Check for block meta
    local HasMeta = string.find(a_BlockString, ":")

    -- Check if it was a name.
    local Item = cItem()
    if (not StringToItem(a_BlockString, Item)) then
        return false
    else
        if (HasMeta or (Item.m_ItemDamage ~= 0)) then
            return Item.m_ItemType, Item.m_ItemDamage
        else
            return Item.m_ItemType, g_DefaultMetas[Item.m_ItemType] or 0, true
        end
    end
end


function setblock(Split, Player)
    if (#Split ~= 5) then
        -- There was more or less than four arguments (excluding the "/explode" bit)
        -- Send the proper usage to the player and exit
        Player:SendMessage("Usage: /setblock X Y Z [blocktype]")
        return true
    end

    outVector3 = Vector3i(tonumber(Split[2]), tonumber(Split[3]), tonumber(Split[4]))
    Player:SendMessage("Setting block " .. Split[2] .. " "  .. Split[3] .. " " .. Split[4] .. " to type " .. Split[5])
    local type, meta = GetBlockTypeMeta(Split[5])
    Player:GetWorld():SetBlock(outVector3, type, meta)

    return true
end
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)