Page 1 of 1

multi hit npcs

Posted: Fri Jul 17, 2020 6:45 am
by lolcode
how do i make npcs have more than 1 hp

Re: multi hit npcs

Posted: Sun Aug 09, 2020 12:57 am
by lolcode
HELP!

Re: multi hit npcs

Posted: Sun Aug 09, 2020 3:22 pm
by Cedur
Apologies for your question being completely unnoticed, I passed it to Discord

Re: multi hit npcs

Posted: Sun Aug 09, 2020 3:52 pm
by MrDoubleA
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,
}

Re: multi hit npcs

Posted: Sun Aug 09, 2020 10:55 pm
by lolcode
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

Re: multi hit npcs

Posted: Mon Aug 10, 2020 5:20 am
by MrDoubleA
My bad! The type in it should be fixed now.