help of this luna.lua

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

user154
Goomba
Goomba
Posts: 1
Joined: Fri Jun 14, 2024 1:44 pm
Pronouns: user144

help of this luna.lua

Postby user154 » Mon Jul 21, 2025 2:27 pm

Hi everyone, I'm working on a custom luna.lua script and could really use some help. I'm trying to handle player crushing by blocks that move using layers and events. The code works fine when blocks move from top to bottom and crush the player. However, when the blocks move from bottom to top, they also crush the player, and I can't figure out how to prevent that. If anyone has a solution or idea, I’d really appreciate it. :(

Code: Select all

local npcList = {650, 1, 2, 3, 4} 

local blockManager = require("blockmanager")
local Routine = require("routine")
local blockIDs = {1, 115, 188} 

local freezeTimer = 0

function handleFallingNPCs()
    for _,v in ipairs(NPC.get(npcList)) do
        if v:mem(0x12C, FIELD_WORD) <= 0 and not v.friendly then
            if v.speedY > 0 then
                for _,p in ipairs(Player.get()) do
                    if math.abs((v.x + v.width/2) - (p.x + p.width/2)) < (v.width/2 + p.width/2) then
                        local npcBottom = v.y + v.height
                        local playerTop = p.y
                        local dist = npcBottom - playerTop

                        if dist >= 0 and dist <= 8 then
                            if not p:mem(0x13E, FIELD_BOOL) then
                                if p.powerup > 1 then
                                    p.powerup = 1
                                    p:mem(0x140, FIELD_WORD, 50)
                                else
                                    p:kill()
                                end
                            end
                        end
                    end
                end
            end
        end
    end
end


function handleFallingBlocks()
    local player = Player(1)

    for _,b in ipairs(Block.getIntersecting(player.x, player.y - 2, player.x + player.width, player.y)) do
        if table.contains(blockIDs, b.id) and not b.isHidden and not b:mem(0x5A, FIELD_BOOL) then
            local bconfig = blockManager.getBlockSettings(b.id)

            
            local layer = b.layerObj
            if layer and layer.speedY > 0 then
                if not player:mem(0x13E, FIELD_BOOL) and freezeTimer <= 0 then
                    if player.powerup > 1 then
                        player.powerup = 1
                        player:mem(0x140, FIELD_WORD, 50)
                    else
                        player:kill()
                    end

                    Defines.levelFreeze = true
                    freezeTimer = 20 
                end
            end
        end
    end
end

function onTick()
    handleFallingNPCs()
    handleFallingBlocks()

    if freezeTimer > 0 then
        freezeTimer = freezeTimer - 1
        if freezeTimer == 0 then
            Defines.levelFreeze = false
        end
    end
end

function table.contains(tbl, val)
    for _,v in ipairs(tbl) do
        if v == val then return true end
    end
    return false
end

ilovehamburgerz
2025 Egg Hunter
2025 Egg Hunter
Posts: 470
Joined: Thu Jul 25, 2024 5:34 am
Flair: i have 0 dollars
Pronouns: he/him

Re: help of this luna.lua

Postby ilovehamburgerz » Tue Jul 22, 2025 5:50 pm

Thats a lot of ends, are you sure it works perfectly with them? That might be your problem.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: help of this luna.lua

Postby Emral » Tue Jul 22, 2025 6:21 pm

Instead of checking for blocks in an area around the player, perhaps it'll yield better results to cancel onPlayerKill and detecting a crush kill there.
The way I would approach this is to check for the memory offsets 0x146 onwards in onPlayerKill, and if certain combinations of them are set for the death (up AND down, left AND right), cancelling the kill event by setting the first variable passed to onPlayerKill to false.
I've done something similar to your current approach as well at some point, but I don't know how much it will help you in this situation. It was part of the episode Subzero Heroes, and I THINK eventually became antizip.lua, which you can find on the forums. But I don't completely recall... Sorry I can't be more specific, it's been a while.
Best of luck. I hope this helps.


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari