User Tools

Site Tools


developer_center:developer_editor:lucky_block

Table of Contents

Lucky Block

• When the player breaks a specified block, random items will drop in random quantities

Script

local function onPlayerBreakBlock(e) 
    local block = e.blockid 
    if block == 200 then
        local result, id = Item:randomItemID(200, 2001)
        Backpack:addItem(e.eventobjid, id,1)
    end
end
 
ScriptSupportEvent:registerEvent("Block.DestroyBy", onPlayerBreakBlock)

Explaination

This script defines a function onPlayerBreakBlock(e) that is triggered when a player breaks a block. It checks if the block ID is 200. If true, it calls Item:randomItemID(200, 2001) to get a random item ID between 200 and 2001, and then adds 1 item of that type to the player's backpack using Backpack:addItem(e.eventobjid, id, 1).

Finally, ScriptSupportEvent:registerEvent(“Block.DestroyBy”, onPlayerBreakBlock) registers this function to trigger when a block is destroyed.

developer_center/developer_editor/lucky_block.txt · Last modified: 2024/09/09 08:58 by don