Post here for help and support regarding LunaLua and SMBX2's libraries and features.
Moderator: Userbase Moderators
|
|
|
|
-
DrMekar
- Eerie

- Posts: 781
- Joined: Sat Apr 08, 2017 7:16 am
- Flair: CUSTOM CHARACTER CREATOR
-
Contact:
Postby DrMekar » Fri Jan 08, 2021 3:18 pm
So, I'm finally trying to code my own NPC, though unfortunatly, I can't seem to find the error here:
Code: Select all function bulbulNPC.onNPCHarm(eventObj, v, killReason, culprit)
if v.id ~= npcID then return end
if killReason ~= HARM_TYPE_JUMP and killReason ~= HARM_TYPE_SWORD then return end
v:transform(1)
SFX.play(82)
eventObj.cancelled = true
--if killReason == HARM_TYPE_ PROJECTILE_USED or killReason == HARM_TYPE_SPINJUMP then return end
end
After being jumped on or hit with Sword the NPC should transform to a faster version of itself, so as a PH, I just went
with NPC-1 for the start, so instead of transforming, it just dies. The SFX also isen't working.
Any help would be apperiated.
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9865
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Fri Jan 08, 2021 4:28 pm
Did you register the onNPCHarm event?
|
|
|
|
|
|
|
|
|
-
DrMekar
- Eerie

- Posts: 781
- Joined: Sat Apr 08, 2017 7:16 am
- Flair: CUSTOM CHARACTER CREATOR
-
Contact:
Postby DrMekar » Fri Jan 08, 2021 4:51 pm
Yep.
Code: Select all --Register events
function bulbulNPC.onInitAPI()
npcManager.registerEvent(npcID, bulbulNPC, "onTickNPC")
--npcManager.registerEvent(npcID, bulbulNPC, "onTickEndNPC")
--npcManager.registerEvent(npcID, bulbulNPC, "onDrawNPC")
registerEvent(bulbulNPC, "onNPCHarm", "onNPCKill")
end
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9865
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Fri Jan 08, 2021 5:05 pm
DrMekar wrote: ↑Fri Jan 08, 2021 4:51 pm
Yep.
Code: Select all --Register events
function bulbulNPC.onInitAPI()
npcManager.registerEvent(npcID, bulbulNPC, "onTickNPC")
--npcManager.registerEvent(npcID, bulbulNPC, "onTickEndNPC")
--npcManager.registerEvent(npcID, bulbulNPC, "onDrawNPC")
registerEvent(bulbulNPC, "onNPCHarm", "onNPCKill")
end
Nop.
Why are you registering it under the name onNPCKill? That's not what it's called.
|
|
|
|
|
|
|
|
|
-
DrMekar
- Eerie

- Posts: 781
- Joined: Sat Apr 08, 2017 7:16 am
- Flair: CUSTOM CHARACTER CREATOR
-
Contact:
Postby DrMekar » Fri Jan 08, 2021 5:10 pm
Enjl wrote: ↑Fri Jan 08, 2021 5:05 pm
DrMekar wrote: ↑Fri Jan 08, 2021 4:51 pm
Yep.
Code: Select all --Register events
function bulbulNPC.onInitAPI()
npcManager.registerEvent(npcID, bulbulNPC, "onTickNPC")
--npcManager.registerEvent(npcID, bulbulNPC, "onTickEndNPC")
--npcManager.registerEvent(npcID, bulbulNPC, "onDrawNPC")
registerEvent(bulbulNPC, "onNPCHarm", "onNPCKill")
end
Nop.
Why are you registering it under the name onNPCKill? That's not what it's called.
Oh, that was it. Thanks.
I wasn't sure if I should delete it or if it was needed.
It does shows the wrong effect though, when turning into the Goomba.
Last edited by DrMekar on Sat Jan 09, 2021 7:34 am, edited 1 time in total.
|
|
|
|
|
|
|
|
|
-
DrMekar
- Eerie

- Posts: 781
- Joined: Sat Apr 08, 2017 7:16 am
- Flair: CUSTOM CHARACTER CREATOR
-
Contact:
Postby DrMekar » Sat Jan 09, 2021 7:34 am
So, I've created NPC-943, which is the Bulbul, after being hit once, so for some reason, NPC-942 still turns into the Goomba, instead of the desired one.
Do I need to register it somewhere, since NPC-943 also isen't a Basegame NPC as of yet?
|
|
|
|
|
|
|
|
|
-
Emral
- Cute Yoshi Egg

- Posts: 9865
- Joined: Mon Jan 20, 2014 12:58 pm
- Flair: Phoenix
Postby Emral » Sat Jan 09, 2021 9:34 am
DrMekar wrote: ↑Sat Jan 09, 2021 7:34 am
So, I've created NPC-943, which is the Bulbul, after being hit once, so for some reason, NPC-942 still turns into the Goomba, instead of the desired one.
Do I need to register it somewhere, since NPC-943 also isen't a Basegame NPC as of yet?
Can you provide any useful information for debugging? All relevant up-to-date code would be nice. From your description it sounds like you have a v:transform(1) call somewhere but I doubt that's the problem because that's ridiculously easy to find and debug.
|
|
|
|
|
|
|
|
|
-
DrMekar
- Eerie

- Posts: 781
- Joined: Sat Apr 08, 2017 7:16 am
- Flair: CUSTOM CHARACTER CREATOR
-
Contact:
Postby DrMekar » Sat Jan 09, 2021 9:42 am
Enjl wrote: ↑Sat Jan 09, 2021 9:34 am
DrMekar wrote: ↑Sat Jan 09, 2021 7:34 am
So, I've created NPC-943, which is the Bulbul, after being hit once, so for some reason, NPC-942 still turns into the Goomba, instead of the desired one.
Do I need to register it somewhere, since NPC-943 also isen't a Basegame NPC as of yet?
Can you provide any useful information for debugging? All relevant up-to-date code would be nice. From your description it sounds like you have a v:transform(1) call somewhere but I doubt that's the problem because that's ridiculously easy to find and debug.
Code: Select all -Custom local definitions below
--Register events
function bulbulNPC.onInitAPI()
npcManager.registerEvent(npcID, bulbulNPC, "onTickNPC")
--npcManager.registerEvent(npcID, bulbulNPC, "onTickEndNPC")
--npcManager.registerEvent(npcID, bulbulNPC, "onDrawNPC")
registerEvent(bulbulNPC, "onNPCHarm")
end
function bulbulNPC.onTickNPC(v)
--Don't act during time freeze
if Defines.levelFreeze then return end
local data = v.data
--If despawned
if v.despawnTimer <= 0 then
--Reset our properties, if necessary
data.initialized = false
return
end
--Initialize
if not data.initialized then
--Initialize necessary data.
data.initialized = true
end
--Depending on the NPC, these checks must be handled differently
if v:mem(0x12C, FIELD_WORD) > 0 --Grabbed
or v:mem(0x136, FIELD_BOOL) --Thrown
or v:mem(0x138, FIELD_WORD) > 0 --Contained within
then
--Handling
return
end
v.speedX = v.speedX * 0.92
v.speedY = v.speedX * 1.2
--Execute main AI. This template just jumps when it touches the ground.
if v.collidesBlockBottom then
v.speedX = -1.3
end
end
function bulbulNPC.onNPCHarm(eventObj, v, killReason, culprit)
if v.id ~= npcID then return end
if killReason ~= HARM_TYPE_JUMP and killReason ~= HARM_TYPE_SWORD then return end
v:transform(943)
SFX.play(82)
eventObj.cancelled = true
--if killReason == HARM_TYPE_ PROJECTILE_USED or killReason == HARM_TYPE_SPINJUMP then return end
end
--Gotta return the library table!
return bulbulNPC
Here's the Main Code. I don't have another transform call anywhere.
[size=85][color=green]Added in 22 seconds:[/color][/size]
[quote=Enjl post_id=382456 time=1610202854 user_id=284]
[quote=DrMekar post_id=382452 time=1610195642 user_id=13373]
So, I've created NPC-943, which is the Bulbul, after being hit once, so for some reason, NPC-942 still turns into the Goomba, instead of the desired one.
Do I need to register it somewhere, since NPC-943 also isen't a Basegame NPC as of yet?
[/quote]
Can you provide any useful information for debugging? All relevant up-to-date code would be nice. From your description it sounds like you have a v:transform(1) call somewhere but I doubt that's the problem because that's ridiculously easy to find and debug.
[/quote]
[code]-Custom local definitions below
--Register events
function bulbulNPC.onInitAPI()
npcManager.registerEvent(npcID, bulbulNPC, "onTickNPC")
--npcManager.registerEvent(npcID, bulbulNPC, "onTickEndNPC")
--npcManager.registerEvent(npcID, bulbulNPC, "onDrawNPC")
registerEvent(bulbulNPC, "onNPCHarm")
end
function bulbulNPC.onTickNPC(v)
--Don't act during time freeze
if Defines.levelFreeze then return end
local data = v.data
--If despawned
if v.despawnTimer <= 0 then
--Reset our properties, if necessary
data.initialized = false
return
end
--Initialize
if not data.initialized then
--Initialize necessary data.
data.initialized = true
end
--Depending on the NPC, these checks must be handled differently
if v:mem(0x12C, FIELD_WORD) > 0 --Grabbed
or v:mem(0x136, FIELD_BOOL) --Thrown
or v:mem(0x138, FIELD_WORD) > 0 --Contained within
then
--Handling
return
end
v.speedX = v.speedX * 0.92
v.speedY = v.speedX * 1.2
--Execute main AI. This template just jumps when it touches the ground.
if v.collidesBlockBottom then
v.speedX = -1.3
end
end
function bulbulNPC.onNPCHarm(eventObj, v, killReason, culprit)
if v.id ~= npcID then return end
if killReason ~= HARM_TYPE_JUMP and killReason ~= HARM_TYPE_SWORD then return end
v:transform(943)
SFX.play(82)
eventObj.cancelled = true
--if killReason == HARM_TYPE_ PROJECTILE_USED or killReason == HARM_TYPE_SPINJUMP then return end
end
--Gotta return the library table!
return bulbulNPC
[/code]
Here's the Main Code. I don't have another transform call anywhere.
Last edited by DrMekar on Sat Jan 09, 2021 1:01 pm, edited 1 time in total.
|
|
|
|
|
|
|
|
|
-
DrMekar
- Eerie

- Posts: 781
- Joined: Sat Apr 08, 2017 7:16 am
- Flair: CUSTOM CHARACTER CREATOR
-
Contact:
Postby DrMekar » Sat Jan 09, 2021 1:01 pm
I just had a new idea. Since I can't figure out why it does that, I may aswell do everything in one NPC.
I have already finished the GFX:

FRAMES 1-4 (Normal State)
FRAMES 5-8 (After Being Jumped On or Hit With A Sword)
FRAME 9 (If Within Frames 5-8, Regenerating Health and Returning To Frames 1-4, after about 5 Seconds.)
FRAMES 10-13 (After Being Jumped On or Hit With A Sword In Frames 5-8 Or Hit With A Projectile In Frames 1-4)
FRAME 14 (If Within Frames 10-13, Regenerating Health and Returning To Frames 5-8, after about 5 Seconds.)
FRAMES 15-16 (After Being Jumped On or Hit With A Sword In Frames 10-13 Or Hit With A Projectile In Frames 5-8)
FRAME 17 (If Within Frames 15-16, Regenerating Health and Returning To Frames 10-13, after about 5 Seconds.)
The Important Part here is of course that the NPC actually regenerates Life.
|
|
|
|
|
|
|
|
|
-
DrMekar
- Eerie

- Posts: 781
- Joined: Sat Apr 08, 2017 7:16 am
- Flair: CUSTOM CHARACTER CREATOR
-
Contact:
Postby DrMekar » Sat Jan 16, 2021 10:42 am
'K...
Thanks for leaving me alone with the problem.
|
|
|
|
|
Return to “LunaLua Help”
Users browsing this forum: No registered users and 1 guest
|