Wow, that worked immediately. Thanks, Hoeloe! To be honest, I wasn't wanting this to actually spawn an NPC... I want to use it to check for tiles between an NPC and the player, as a kind of vision thing. Like in that MaGLX2 Snake demo.Hoeloe wrote: ↑4 years ago You might find this easier to do with vectors.
From what it looks like, you're trying to spawn an NPC part way between the player and some other object, right?
Doing this with vectors is pretty simple:
Is the basic gist.Code: Select all
local direction = vector(player.x-ax, player.y-ay):normalize() NPC.spawn(id, player.x + dist*direction.x, player.y + dist*direction.y, player.section)
LunaLua Help
Re: LunaLua Help
- Joseph Staleknight
- ABCDs in Katamari Damacy when
- Posts: 506
- Joined: 14 years ago
- Location: :uo!ʇɐɔoך
Re: LunaLua Help
Is there a way to extend the health of a non-boss enemy in Lua? For example, if I wanted an unusually tough Goomba, how would I make its health more than 1 HP?
E: And to clarify, Trying to do so on the NPC Config text doc doesn't work. I've tried that.
E: And to clarify, Trying to do so on the NPC Config text doc doesn't work. I've tried that.
- Emral
- Posts: 941
- Joined: 10 years ago
- https://enjl.talkhaus.com/
Re: LunaLua Help
NPC code guide specifies that the health variable only works on bosses I believe, yeah. Thing is, those are the only NPCs that make use of the hp offset, so it makes sense.Joseph Staleknight wrote: ↑4 years ago Is there a way to extend the health of a non-boss enemy in Lua? For example, if I wanted an unusually tough Goomba, how would I make its health more than 1 HP?
E: And to clarify, Trying to do so on the NPC Config text doc doesn't work. I've tried that.
You can add more HP to regular enemies using pnpc and onNPCHarm. When an NPC is hit in onNPCHarm you can check if it has the ID you want and then save a variable after wrapping the npc. It looks something like this:
Code: Select all
local pnpc = require("pnpc")
function onNPCHarm(eventObj, killedNPC, killReason, culpritOrNil)
-- ID CHECK
-- KILL REASON CHECK
killedNPC = pnpc.wrap(killedNPC)
if killedNPC.data.hp == nil then
killedNPC.data.hp = 5
end
killedNPC.data.hp = killedNPC.data.hp - 1
if killedNPC.data.hp > 0 then
eventObj.cancelled = true
end
end
I do things. You can find them on my talkhaus site. https://enjl.talkhaus.com/
Here is another link. This one lets you draw.
https://enjl.talkhaus.com/draw.html
Here is another link. This one lets you draw.
https://enjl.talkhaus.com/draw.html
- Joseph Staleknight
- ABCDs in Katamari Damacy when
- Posts: 506
- Joined: 14 years ago
- Location: :uo!ʇɐɔoך
Re: LunaLua Help
Yep, that did the trick. Thank you!
EDIT: I just found a problem with the code--apparently, NPCs frozen by the Ice Flower disregard the HP of the toughened NPC. I set the NPC in question to be vulnerable to only other NPCs, so when I throw a different NPC at it, it decrements health as it should. However, when I throw a frozen NPC it completely bypasses the hit NPC's health! How does that even work?
EDIT: I just found a problem with the code--apparently, NPCs frozen by the Ice Flower disregard the HP of the toughened NPC. I set the NPC in question to be vulnerable to only other NPCs, so when I throw a different NPC at it, it decrements health as it should. However, when I throw a frozen NPC it completely bypasses the hit NPC's health! How does that even work?
- Emral
- Posts: 941
- Joined: 10 years ago
- https://enjl.talkhaus.com/
Re: LunaLua Help
Frozen NPCs are a different ID and the act of freezing an NPC is an ID change. The NPC will return to obeying the laws of its HP once thawed. You could add HP for ice cubes by checking them in onNPCHarm and then decrementing HP only if the NPC's ai1 value is a valid multi-hp ID.
I do things. You can find them on my talkhaus site. https://enjl.talkhaus.com/
Here is another link. This one lets you draw.
https://enjl.talkhaus.com/draw.html
Here is another link. This one lets you draw.
https://enjl.talkhaus.com/draw.html
- Joseph Staleknight
- ABCDs in Katamari Damacy when
- Posts: 506
- Joined: 14 years ago
- Location: :uo!ʇɐɔoך
Re: LunaLua Help
I do agree about frozen NPCs being a different ID entirely. However, I think I was a bit unclear on the actual question I had. What I meant to say was:
- I have a toughened non-boss enemy I'm going to call "Target".
- And I have an NPC to throw at Target to damage him. I'll call that one "Projectile".
- If Projectile is a regular NPC, then Target takes damage according to the code, which I want.
- On the other hand, if Projectile is a frozen NPC, then Projectile insta-kills Target, which I don't want.
- Instead, I want Projectile to damage Target equally whether or not Projectile's frozen.
- Emral
- Posts: 941
- Joined: 10 years ago
- https://enjl.talkhaus.com/
Re: LunaLua Help
The ice block doesn't die so it damages target every frame. You need to store a 2nd varaible for an invincibility timer, or kill the culprit if it exists and is an ice block npc. (if culpritOrNil and culpritOrNil.__type == "NPC" and culpritOrNil.id == ICEBLOCKIDREPLACETHIS)Joseph Staleknight wrote: ↑4 years ago I do agree about frozen NPCs being a different ID entirely. However, I think I was a bit unclear on the actual question I had. What I meant to say was:
- I have a toughened non-boss enemy I'm going to call "Target".
- And I have an NPC to throw at Target to damage him. I'll call that one "Projectile".
- If Projectile is a regular NPC, then Target takes damage according to the code, which I want.
- On the other hand, if Projectile is a frozen NPC, then Projectile insta-kills Target, which I don't want.
- Instead, I want Projectile to damage Target equally whether or not Projectile's frozen.
I do things. You can find them on my talkhaus site. https://enjl.talkhaus.com/
Here is another link. This one lets you draw.
https://enjl.talkhaus.com/draw.html
Here is another link. This one lets you draw.
https://enjl.talkhaus.com/draw.html
- Joseph Staleknight
- ABCDs in Katamari Damacy when
- Posts: 506
- Joined: 14 years ago
- Location: :uo!ʇɐɔoך
- ItsFuntime
- THE JACK OF ALL TRADES
- Posts: 39
- Joined: 5 years ago
- First name: Jared
- Pronouns: Eccentric Man
- Location: Your closet
Re: LunaLua Help
Okay, imagine when you're trying to make a bonus room where you get one shot and you have to toss an ice block to one of the question blocks, and you want to a sound to play when the ice block successfully hits a question block. How do know when the ice block successfully hits that question block?
Here's the code for the scenario:
Edit: Here is an image of the debug I encountered:
Here's the code for the scenario:
Hey, this is Jared Funtime! I hope your feet are doing okay!
Find me on:
- ItsFuntime
- THE JACK OF ALL TRADES
- Posts: 39
- Joined: 5 years ago
- First name: Jared
- Pronouns: Eccentric Man
- Location: Your closet
Re: LunaLua Help
Sorry for the double post, but here is rare footage of the glitchy footage (click the pic in the spoiler to play!):ItsFuntime wrote: ↑4 years ago Okay, imagine when you're trying to make a bonus room where you get one shot and you have to toss an ice block to one of the question blocks, and you want to a sound to play when the ice block successfully hits a question block. How do know when the ice block successfully hits that question block?
Here's the code for the scenario:Edit: Here is an image of the debug I encountered:
Hey, this is Jared Funtime! I hope your feet are doing okay!
Find me on:
Re: LunaLua Help
None of that is really valid to do. First off, don't use onLoopSection, use onTick and check for the player's section.
Second, don't load libraries inside functions unless you have a REALLY good reason. Just load what you need at the top of the file.
Third and most importantly, you can't grab a list of blocks and use it later expecting it to stay up to date. Same is true of NPCs, BGOs, etc. You must grab a new list every time you want to use them, otherwise you're just asking for errors like this as you attempt to access invalid memory.
Second, don't load libraries inside functions unless you have a REALLY good reason. Just load what you need at the top of the file.
Third and most importantly, you can't grab a list of blocks and use it later expecting it to stay up to date. Same is true of NPCs, BGOs, etc. You must grab a new list every time you want to use them, otherwise you're just asking for errors like this as you attempt to access invalid memory.
- Emral
- Posts: 941
- Joined: 10 years ago
- https://enjl.talkhaus.com/
Re: LunaLua Help
Fourth: Capitalization matters.
I do things. You can find them on my talkhaus site. https://enjl.talkhaus.com/
Here is another link. This one lets you draw.
https://enjl.talkhaus.com/draw.html
Here is another link. This one lets you draw.
https://enjl.talkhaus.com/draw.html
- ItsFuntime
- THE JACK OF ALL TRADES
- Posts: 39
- Joined: 5 years ago
- First name: Jared
- Pronouns: Eccentric Man
- Location: Your closet
Re: LunaLua Help
Okay, I took your advice, Hueylou, and I changed the code around, and now, whenever a bonus block gets hit, it calls an event called "Bonus Block Hit", which sets "getPrize" to "true". Now, when the ice block dies, the floor gets covered with a layer of invisible triggers (REEEEEEE) that finish the bonus game once and for all. And right now, the think the bonus game is all set for now! Thanks~! :DHoeloe wrote: ↑4 years ago None of that is really valid to do. First off, don't use onLoopSection, use onTick and check for the player's section.
Second, don't load libraries inside functions unless you have a REALLY good reason. Just load what you need at the top of the file.
Third and most importantly, you can't grab a list of blocks and use it later expecting it to stay up to date. Same is true of NPCs, BGOs, etc. You must grab a new list every time you want to use them, otherwise you're just asking for errors like this as you attempt to access invalid memory.
Only one problemo...each block has the same contents in order, and the content identities are in the same order. I just want the table of contents to have its pages become randomized when Mario enters the room, so that the bonus room will be ready for Klonoa to try out. How would you randomize a table in LunaLua?
Well, you're not wrong. I mean...Enjl wrote:Fourth: Capitalization matters.
Hey, this is Jared Funtime! I hope your feet are doing okay!
Find me on:
Re: LunaLua Help
In programming, there is an actual difference between "function" and "Function". As far as the program is concerned, these are as different as "local" and "kjsadkjfkjafsjksakjfjlkjalsk" - totally different.ItsFuntime wrote: ↑4 years agoWell, you're not wrong. I mean...Enjl wrote:Fourth: Capitalization matters.
As for randomising the blocks, you can use either onStart (to randomise at the start of the level) or onLoadSection# (substituting # for the section number, to randomise when the section is entered).
Then, you can create a list of items you want, loop over the blocks using Block.get(id), and then use RNG.irandomEntry on the list of items to select random items to place in them, adjusting the block contents as you do.
- ItsFuntime
- THE JACK OF ALL TRADES
- Posts: 39
- Joined: 5 years ago
- First name: Jared
- Pronouns: Eccentric Man
- Location: Your closet
Re: LunaLua Help
Well then! I have randomized the list and now Klonoa can have his little fun and acquire a cool prize whenever he enters the room! Thanks!
Now, about the Toad NPCs...I wonder if you could make a custom NPC that acts like the Toads, such as rewarding a player with a mushroom, or dying on contact from the bad guys...
Edit: Never mind that. Nerf my question!
Now, about the Toad NPCs...I wonder if you could make a custom NPC that acts like the Toads, such as rewarding a player with a mushroom, or dying on contact from the bad guys...
Edit: Never mind that. Nerf my question!
Hey, this is Jared Funtime! I hope your feet are doing okay!
Find me on: