Scriptable Block Trigger

API -

function yourEvent(user, block)

    log('block hit! ' .. block.id .. ' by ' .. user.displayName .. ' at block position: ' .. block.position.x .. ' ' .. block.position.y);
    
    local level = getBackground();
    log('current level is: ' .. level);
    
    if level == 'green_grass_background' then 
    --this would be whatever your background name is!
    
        local cd_ready = helper.checkCooldown('cd');
        local cd_timeLeft = helper.cooldownTimeLeft('cd');
        
        if cd_ready == false then
            log('cannot run yet for another ' .. cd_timeLeft .. ' seconds.');
            return;
        end
        
        
        if block.id == 1 then 
            --remember that this id is specific to the current background level,
            --so you might also want to check the level.
            user.runCommand('!jump' );
        end
        
        helper.setCooldown('cd'); 
        --reset the cooldown timer so we have to wait again!
    
    end
end
 
return function()
    addEvent('scriptableBlocks', 'yourEvent'); --attaches the event to yourEvent()
    
    --vv none of this is actually needed it's just showing what else is possible.
    cd = helper.createCooldown(15, true); --15 seconds, starts ready=true
    local level = getBackground();
    
    local scriptBlocks = getScriptableBlocks();
     --give a list of all blocks on the current level
     
    log('the list of blocks on ' .. level .. ' are:');
    for i,block in pairs(scriptBlocks) do
        log(block.id);
        log(block.position.x .. ' ' .. block.position.y);
    end
    
    --^^ none of this is actually needed it's just showing what else is possible.
    keepAlive(); --this is needed.
end

Events are asynchronous coroutines.

Last updated