multi hit npcs

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

Moderator: Userbase Moderators

lolcode
Hoopster
Hoopster
Posts: 41
Joined: Sat Jul 11, 2020 7:55 pm

multi hit npcs

Postby lolcode » Fri Jul 17, 2020 6:45 am

how do i make npcs have more than 1 hp

lolcode
Hoopster
Hoopster
Posts: 41
Joined: Sat Jul 11, 2020 7:55 pm

Re: multi hit npcs

Postby lolcode » Sun Aug 09, 2020 12:57 am

HELP!

Cedur
Link
Link
Posts: 7073
Joined: Tue Jun 28, 2016 10:14 am
Flair: I'm gone, for chess and minesweeper
Pronouns: he/him

Re: multi hit npcs

Postby Cedur » Sun Aug 09, 2020 3:22 pm

Apologies for your question being completely unnoticed, I passed it to Discord

MrDoubleA
Edward
Edward
Posts: 394
Joined: Mon Aug 20, 2018 7:02 am
Flair: How much munchers?

Re: multi hit npcs

Postby MrDoubleA » Sun Aug 09, 2020 3:52 pm

It's not all too hard to do! Put this into your luna.lua file:

Code: Select all

local multiHitNPCs = {
    [1] = 2,
    [2] = 3,
}

function onNPCHarm(eventObj,npc,reason,culprit)
    if not multiHitNPCs[npc.id] or (reason == HARM_TYPE_LAVA or reason == HARM_TYPE_OFFSCREEN) then return end
    
    local data = npc.data
    
    if npc:mem(0x156,FIELD_WORD) > 0 then
        eventObj.cancelled = true
        return
    end
    
    data.health = (data.health or multiHitNPCs[npc.id]) - 1
    
    if data.health > 0 then
        npc:mem(0x156,FIELD_WORD,20) -- Invincibility time
        eventObj.cancelled = true
    end
end
... and replace that list in "multiHitNPCs". For example, if you wanted red goombas (ID 2) to take 3 hits and green koopas (ID 4) to take 2 hits, you'd do:

Code: Select all

local multiHitNPCs = {
    [2] = 3,
    [4] = 2,
}
Last edited by MrDoubleA on Mon Aug 10, 2020 5:55 am, edited 3 times in total.

lolcode
Hoopster
Hoopster
Posts: 41
Joined: Sat Jul 11, 2020 7:55 pm

Re: multi hit npcs

Postby lolcode » Sun Aug 09, 2020 10:55 pm

MrDoubleA wrote:
Sun Aug 09, 2020 3:52 pm
It's not all too hard to do! Put this into your luna.lua file:

Code: Select all

local multiHitNPCs = {
    [1] = 2,
    [2] = 3,
}

function onNPCHarm(eventObj,npc,reason,culprit)
    if not multiHitNPCs[npc.id] or npc:mem(0x156,FIELD_WORD) > 0 or (reason == HARM_TYPE_LAVA or reason == HARM_TYPE_OFFSCREEN) then return end
    
    local config = NPC.config[v.id]
    local data = v.data
    
    data.health = (data.health or config.health) - 1
    
    if data.health > 0 then
        npc:mem(0x156,FIELD_WORD,20) -- Invincibility time
        eventObj.cancelled = true
    end
end
... and replace that list in "multiHitNPCs". For example, if you wanted red goombas (ID 2) to take 3 hits and green koopas (ID 4) to take 2 hits, you'd do:

Code: Select all

local multiHitNPCs = {
    [2] = 3,
    [4] = 2,
}
thanks

Added in 48 minutes 1 second:
classic boss time

Added in 2 hours 41 minutes 48 seconds:
it kinda didnt work

MrDoubleA
Edward
Edward
Posts: 394
Joined: Mon Aug 20, 2018 7:02 am
Flair: How much munchers?

Re: multi hit npcs

Postby MrDoubleA » Mon Aug 10, 2020 5:20 am

My bad! The type in it should be fixed now.


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 3 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari