This is the place for discussion and support for LunaLua and related modifications and libraries.
Moderator: Userbase Moderators
Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
|
|
|
|
-
fern
- Bot

- Posts: 56
- Joined: Sat Dec 02, 2017 8:59 pm
Postby fern » Mon Dec 04, 2017 9:26 pm
Is HealthPoint broken? Or am I using it wrong?
I have this code:
Code: Select all HealthPoint.makeNPCInvincible(23);
HealthPoint.setNPCHealth(24, 10);
For the invincible NPC, I believe it only adds three hitpoints, because I get three hits for 8000 points.
For the other one it takes three hits instead of ten. No matter what value I input it takes three hits. Also, it changes the health for all NPCs of that type.
EDIT: It actually makes EVERY NPC take three hits. Is there an alternative or am I using it wrong?
|
|
|
|
|
|
|
|
|
-
Quantix
- Chain Chomp

- Posts: 333
- Joined: Tue Jan 26, 2016 5:04 pm
Postby Quantix » Tue Dec 05, 2017 7:11 am
HealthPoint.lua has been deprecated for a while now. You're better off using pnpc, but I can't go over why right now.
|
|
|
|
|
|
|
|
|
-
fern
- Bot

- Posts: 56
- Joined: Sat Dec 02, 2017 8:59 pm
Postby fern » Tue Dec 05, 2017 1:55 pm
Quantix wrote:HealthPoint.lua has been deprecated for a while now. You're better off using pnpc, but I can't go over why right now.
Thanks, I looked into it and have no idea how it works, I'm new to Lua.
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9891
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Tue Dec 05, 2017 3:33 pm
HealthPoint is very unreliable, as Quantix said. Pnpc doesn't do the HP stuff out of the box, but it helps you set them up per-npc.
Using pnpc is simple:
Code: Select all local pnpc = API.load("pnpc")
local sturdyNPCTable = {
[1] = 3,
[2] = 4
}
function onNPCKill(killObj, killedNPC, killReason)
if sturdyNPCTable[killedNPC.id] then
killedNPC = pnpc.wrap(killedNPC)
if killedNPC.data.hp == nil then
killedNPC.data.hp = sturdyNPCTable[killedNPC.id]
end
killedNPC.data.hp = killedNPC.data.hp - 1
if killedNPC.data.hp ~= 0 then
killObj.cancelled = true
end
end
end
This won't cancel out the score you get from bouncing on NPCs, there is currently no way to do that. However, this does the following:
-onNPCKill runs whenever ANY NPC dies. The sturdyNPCTable narrows it down to only the NPC IDs you want checked. In this example, I check for IDs 1 and 2, which are SMB3 goombas.
-pnpc.wrap gives the NPC a unique identifier which pnpc uses to find the NPC across ticks. This can be used to attach variables to NPCs, like a HP variable which we will attach here.
-if we haven't already, we then initialise the HP variable, count down by 1 every time the NPC is killed, and check if the value is not 0. If the value is not 0 we then cancel the killObj, which makes it so that the NPC does not die.
-You will notice that if we set the initial HP value to 0 or lower, the NPC will never die. The HP variable will count down, but never reach 0. This is a way to make the NPC invincible/unkillable.
Since onNPCKill is called whenever an NPC is killed and pnpc remembers which NPC has how much HP, we can count down the HP value bit by bit every time the NPC dies.
You might have noticed the "killReason" variable which we haven't used. This is the kill type performed on the NPC. You can perform additional checks to exclude certain kill types. Further down on this page is a list for reference: http://wohlsoft.ru/pgewiki/LunaLua_events
Hope this helped!
|
|
|
|
|
|
|
|
|
-
PixelPest
- Link

- Posts: 7111
- Joined: Sun Jul 12, 2015 5:38 pm
- Flair: Tamer of Boom Booms
-
Contact:
Postby PixelPest » Tue Dec 05, 2017 3:39 pm
You can also set the memory field for HP (may only work for bosses) to a lower number when the NPC is spawned
|
|
|
|
|
|
|
|
|
-
fern
- Bot

- Posts: 56
- Joined: Sat Dec 02, 2017 8:59 pm
Postby fern » Tue Dec 05, 2017 5:59 pm
Enjl wrote:HealthPoint is very unreliable, as Quantix said. Pnpc doesn't do the HP stuff out of the box, but it helps you set them up per-npc.
Using pnpc is simple:
Code: Select all local pnpc = API.load("pnpc")
local sturdyNPCTable = {
[1] = 3,
[2] = 4
}
function onNPCKill(killObj, killedNPC, killReason)
if sturdyNPCTable[killedNPC.id] then
killedNPC = pnpc.wrap(killedNPC)
if killedNPC.data.hp == nil then
killedNPC.data.hp = sturdyNPCTable[killedNPC.id]
end
killedNPC.data.hp = killedNPC.data.hp - 1
if killedNPC.data.hp ~= 0 then
killObj.cancelled = true
end
end
end
This won't cancel out the score you get from bouncing on NPCs, there is currently no way to do that. However, this does the following:
-onNPCKill runs whenever ANY NPC dies. The sturdyNPCTable narrows it down to only the NPC IDs you want checked. In this example, I check for IDs 1 and 2, which are SMB3 goombas.
-pnpc.wrap gives the NPC a unique identifier which pnpc uses to find the NPC across ticks. This can be used to attach variables to NPCs, like a HP variable which we will attach here.
-if we haven't already, we then initialise the HP variable, count down by 1 every time the NPC is killed, and check if the value is not 0. If the value is not 0 we then cancel the killObj, which makes it so that the NPC does not die.
-You will notice that if we set the initial HP value to 0 or lower, the NPC will never die. The HP variable will count down, but never reach 0. This is a way to make the NPC invincible/unkillable.
Since onNPCKill is called whenever an NPC is killed and pnpc remembers which NPC has how much HP, we can count down the HP value bit by bit every time the NPC dies.
You might have noticed the "killReason" variable which we haven't used. This is the kill type performed on the NPC. You can perform additional checks to exclude certain kill types. Further down on this page is a list for reference: http://wohlsoft.ru/pgewiki/LunaLua_events
Hope this helped!
You have no idea how much this helped! Just one more question:
Is there a way to "force" a kill animation? I tried forcing it by changing killReason to the specific one I wanted but it didn't work. I also tried setting kill flag off because I didn't know what that meant but it causes the goomba to fly as if was killed with a shell. I'm trying to force the Link sword kill effect when they get stomped.
|
|
|
|
|
|
|
|
|
-
The0x539
- Eerie

- Posts: 751
- Joined: Fri Jan 22, 2016 8:02 pm
Postby The0x539 » Tue Dec 05, 2017 6:00 pm
fern wrote:Enjl wrote:HealthPoint is very unreliable, as Quantix said. Pnpc doesn't do the HP stuff out of the box, but it helps you set them up per-npc.
Using pnpc is simple:
Code: Select all local pnpc = API.load("pnpc")
local sturdyNPCTable = {
[1] = 3,
[2] = 4
}
function onNPCKill(killObj, killedNPC, killReason)
if sturdyNPCTable[killedNPC.id] then
killedNPC = pnpc.wrap(killedNPC)
if killedNPC.data.hp == nil then
killedNPC.data.hp = sturdyNPCTable[killedNPC.id]
end
killedNPC.data.hp = killedNPC.data.hp - 1
if killedNPC.data.hp ~= 0 then
killObj.cancelled = true
end
end
end
This won't cancel out the score you get from bouncing on NPCs, there is currently no way to do that. However, this does the following:
-onNPCKill runs whenever ANY NPC dies. The sturdyNPCTable narrows it down to only the NPC IDs you want checked. In this example, I check for IDs 1 and 2, which are SMB3 goombas.
-pnpc.wrap gives the NPC a unique identifier which pnpc uses to find the NPC across ticks. This can be used to attach variables to NPCs, like a HP variable which we will attach here.
-if we haven't already, we then initialise the HP variable, count down by 1 every time the NPC is killed, and check if the value is not 0. If the value is not 0 we then cancel the killObj, which makes it so that the NPC does not die.
-You will notice that if we set the initial HP value to 0 or lower, the NPC will never die. The HP variable will count down, but never reach 0. This is a way to make the NPC invincible/unkillable.
Since onNPCKill is called whenever an NPC is killed and pnpc remembers which NPC has how much HP, we can count down the HP value bit by bit every time the NPC dies.
You might have noticed the "killReason" variable which we haven't used. This is the kill type performed on the NPC. You can perform additional checks to exclude certain kill types. Further down on this page is a list for reference: http://wohlsoft.ru/pgewiki/LunaLua_events
Hope this helped!
You have no idea how much this helped! Just one more question:
Is there a way to "force" a kill animation? I tried forcing it by changing killReason to the specific one I wanted but it didn't work. I also tried setting kill flag off because I didn't know what that meant but it causes the goomba to fly as if was killed with a shell. I'm trying to force the Link sword kill effect when they get stomped.
cancel the kill event and call the npc's kill method yourself
|
|
|
|
|
|
|
|
|
-
fern
- Bot

- Posts: 56
- Joined: Sat Dec 02, 2017 8:59 pm
Postby fern » Tue Dec 05, 2017 6:10 pm
The0x539 wrote:
cancel the kill event and call the npc's kill method yourself
Here's what I tried writing inside onNPCKill():
Code: Select all if killReason ~= 10 and killedNPC.data.hp == 0 then
killObj.cancelled = true
killReason = 10
killObj.cancelled = false
end
|
|
|
|
|
|
|
|
|
-
The0x539
- Eerie

- Posts: 751
- Joined: Fri Jan 22, 2016 8:02 pm
Postby The0x539 » Tue Dec 05, 2017 6:14 pm
fern wrote:The0x539 wrote:
cancel the kill event and call the npc's kill method yourself
Here's what I tried writing inside onNPCKill():
Code: Select all if killReason ~= 10 and killedNPC.data.hp == 0 then
killObj.cancelled = true
killReason = 10
killObj.cancelled = false
end
the value of killObj.cancelled doesn't matter until the function is done doing its thing
Code: Select all if killReason ~= 10 and killedNPC.data.hp == 0 then
killObj.cancelled = true
killedNPC:harm(10)
end
|
|
|
|
|
|
|
|
|
-
fern
- Bot

- Posts: 56
- Joined: Sat Dec 02, 2017 8:59 pm
Postby fern » Tue Dec 05, 2017 6:54 pm
The0x539 wrote:fern wrote:The0x539 wrote:
cancel the kill event and call the npc's kill method yourself
Here's what I tried writing inside onNPCKill():
Code: Select all if killReason ~= 10 and killedNPC.data.hp == 0 then
killObj.cancelled = true
killReason = 10
killObj.cancelled = false
end
the value of killObj.cancelled doesn't matter until the function is done doing its thing
Code: Select all if killReason ~= 10 and killedNPC.data.hp == 0 then
killObj.cancelled = true
killedNPC:harm(10)
end
Ah, I see. Thanks a lot!
EDIT: I tested this and I get the same as before, which is the NPC skipping that last hit.
|
|
|
|
|
|
|
|
|
-
fern
- Bot

- Posts: 56
- Joined: Sat Dec 02, 2017 8:59 pm
Postby fern » Wed Dec 06, 2017 12:18 am
Ok, I fixed it by using killedNPC:kill(10) instead of harm and not cancelling the death. Thanks for your help guys!
Also, I feel like I've been making too many threads asking for help, should I be using the LunaLua Help thread instead?
|
|
|
|
|
Return to “LunaLua”
Users browsing this forum: No registered users and 2 guests
|