Obligatory "I ruined everything!" thread
#1
Star 
Current wiki CONFIG revision: r593
Current wiki API revision: !!mixed!!


So. I'm planning to fill wiki up-to-date, but for easy furthermore corrections and additions I encourage YOU, developers, to post any //tolua_export changes you do in the code in following format:
Quote:r100500 I removed cRoot class from lua export.

Feel free to post configuring-related changes as well (if you're too lazy to write them into wiki)
Reply
Thanks given by:
#2
I don't get it, are we supposed to post in this thread?
Reply
Thanks given by:
#3
Yes. Post any changes you make to API and .ini keys/values there, please. This will help.
Reply
Thanks given by:
#4
Rev 598, big change Smile

Added hook names with HOOK prefix (but kept the E_PLUGIN_ -prefixed names for compatibility)
Added three hooks: HOOK_PRE_CRAFTING, HOOK_CRAFTING_NO_RECIPE and HOOK_POST_CRAFTING
Added two new objects: cCraftingGrid and cCraftingRecipe

Crafting is now fully customizable in plugins, example code:
Code:
function Initialize( Plugin )
    ...
    PluginManager = cRoot:Get():GetPluginManager()
    PluginManager:AddHook(Plugin, cPluginManager.HOOK_PRE_CRAFTING)
    PluginManager:AddHook(Plugin, cPluginManager.HOOK_CRAFTING_NO_RECIPE)
    PluginManager:AddHook(Plugin, cPluginManager.HOOK_POST_CRAFTING)
end


function OnPreCrafting(Player, Grid, Recipe)
    LOG("Test: Pre-crafting for player " .. Player:GetName() .. ".")
    return false
end


function OnCraftingNoRecipe(Player, Grid, Recipe)
    LOG("Test: Crafting-no-recipe for player " .. Player:GetName() .. ".")
    return false
end


function OnPostCrafting(Player, Grid, Recipe)
    LOG("Test: Post-crafting for player " .. Player:GetName() .. ".")
    local Item = Recipe:GetResult();
    -- Mess with the result, have fun:
    Recipe:SetResult(Item.m_ItemID + 1, Item.m_ItemCount + 1, Item.m_ItemHealth);
    return true
end
Reply
Thanks given by: Taugeshtu
#5
Rev 602 has a new hook, HOOK_BLOCK_TO_PICKUP, that is called each time a player breaks a block and it can modify the pickups that they receive. It is called when MCServer has already decided what the standard pickups should be, and the hook can add / modify / remove them.
Hook parameters: BlockType, BlockMeta, cPlayer, cItem (equipped), cItems (pickups)

Example code that makes grass drop 4 diamonds:
Code:
PluginManager:AddHook(Plugin, cPluginManager.HOOK_BLOCK_TO_PICKUP)
...
function OnBlockToPickup(BlockType, BlockMeta, Player, EquippedItem, Pickups)
    if (BlockType == E_BLOCK_GRASS) then
        Pickups:Clear()
        Pickups:Add(E_ITEM_DIAMOND, 4, 0)
        return true
    end
    return false
end
Reply
Thanks given by:
#6
Could you please describe when crafting hooks are called?
If I'll change recipe output in HOOK_PRE_CRAFTING - will crafting operation return changed item?
Reply
Thanks given by:
#7
HOOK_PRE_CRAFTING is not called yet, it's not implemented

EDIT:
SORRY!! it is implementedTongue
Reply
Thanks given by:
#8
PRE_CRAFTING: before the built-in recipes are checked. If it returns true, builtins are not checked and no other crafting hooks are called
CRAFTING_NO_RECIPE: called only when no built-in recipe is found. Return value is ignored by MCServer (but if there are multiple plugins hooked, the first one returning true breaks the chain of calls, no other plugin will be called, just like with all the other hooks)
POST_CRAFTING: called after the built-in recipes are checked and a recipe was found. Return value ignored, but returning true means no more plugins are called for that hook.
Reply
Thanks given by:
#9
Rev 620: Added cWorld:ForEachEntity and cWorld:ForEachEntityInChunk API functions. I have no idea if they work correctly, though - didn't do any testing. And additionally, I have no idea if there's a way for Lua to convert a cEntity into the more specific class, such as cPlayer, cPassiveMob or whatever. We might need to add these when needed.
Reply
Thanks given by: Taugeshtu
#10
Rev 622: Added HOOK_UPDATING_SIGN and HOOK_UPDATED_SIGN hooks. They both receive the same arguments:
cWorld - the world where the sign is
x, y, z - the block coords of the sign
line1, line2, line3, line4 - the four lines of text in the sign

HOOK_UPDATING_SIGN is called before the sign text is updated. If the hook returns true, the sign text won't get updated. The hook can also return up to four texts, after the "false", those values will override the lines of text that the sign will receive. For example, the following Lua code flips the lines - the last line will become the first etc.:
Code:
function OnUpdatingSign(World, BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4)
    return false, Line4, Line3, Line2, Line1
end

HOOK_UPDATED_SIGN is called after the sign text is updated, it is just a notification. Plugins cannot change the text anymore. When the callback returns true, no more plugins will be called with the notification (not recommended).
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)