Setting NPCs not to interact with specific characters.

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

Moderator: Userbase Moderators

Megaiwer
Koopa
Koopa
Posts: 15
Joined: Sun Jun 07, 2015 6:46 am

Setting NPCs not to interact with specific characters.

Postby Megaiwer » Sat Aug 22, 2020 1:15 pm

Hello. Is there a way to make an NPC not interact with a specific character? For example, MegaMan passes through the NPC like there's nothing there, while Mario could use it normally? Thank you.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9865
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Setting NPCs not to interact with specific characters.

Postby Emral » Sat Aug 22, 2020 1:47 pm

If it's not necessary to work in multiplayer, you can set all NPCs of that ID to friendly depending on what player.character is.

Megaiwer
Koopa
Koopa
Posts: 15
Joined: Sun Jun 07, 2015 6:46 am

Re: Setting NPCs not to interact with specific characters.

Postby Megaiwer » Sat Aug 22, 2020 3:02 pm

Enjl wrote:
Sat Aug 22, 2020 1:47 pm
If it's not necessary to work in multiplayer, you can set all NPCs of that ID to friendly depending on what player.character is.
Really? Could you please tell me how to do so please?

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9865
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Setting NPCs not to interact with specific characters.

Postby Emral » Sat Aug 22, 2020 3:37 pm

Megaiwer wrote:
Sat Aug 22, 2020 3:02 pm
Enjl wrote:
Sat Aug 22, 2020 1:47 pm
If it's not necessary to work in multiplayer, you can set all NPCs of that ID to friendly depending on what player.character is.
Really? Could you please tell me how to do so please?
For instance, if you have a npc-751.lua where you have your npc's code (you can copy the _templates folder's npc-n.lua for that, and rename it), you could have the following within that script file's onTick function:
v.friendly = player.character == CHARACTER_MEGAMAN

Then the NPC will adjust its friendly state so that it will always be friendly when the player is megaman, and always hostile when not. For further granularity you can chain these together:
v.friendly = player.character == CHARACTER_MEGAMAN or player.character == CHARACTER_SAMUS

If you additionally want some of these NPCs to be friendly by default, things get a bit more complex as you have to remember the initial friendly state in a variable. I'll not get into that just yet, because I don't wanna introduce too much unnecessary complexity if you don't even need that option.

MarioLover64
Spike
Spike
Posts: 259
Joined: Fri Apr 26, 2019 6:09 pm

Re: Setting NPCs not to interact with specific characters.

Postby MarioLover64 » Sat Aug 22, 2020 4:15 pm

For multiplayer compatibility, use the nearest player to the npc

Megaiwer
Koopa
Koopa
Posts: 15
Joined: Sun Jun 07, 2015 6:46 am

Re: Setting NPCs not to interact with specific characters.

Postby Megaiwer » Sat Aug 22, 2020 5:36 pm

Enjl wrote:
Sat Aug 22, 2020 3:37 pm
Megaiwer wrote:
Sat Aug 22, 2020 3:02 pm
Enjl wrote:
Sat Aug 22, 2020 1:47 pm
If it's not necessary to work in multiplayer, you can set all NPCs of that ID to friendly depending on what player.character is.
Really? Could you please tell me how to do so please?
For instance, if you have a npc-751.lua where you have your npc's code (you can copy the _templates folder's npc-n.lua for that, and rename it), you could have the following within that script file's onTick function:
v.friendly = player.character == CHARACTER_MEGAMAN

Then the NPC will adjust its friendly state so that it will always be friendly when the player is megaman, and always hostile when not. For further granularity you can chain these together:
v.friendly = player.character == CHARACTER_MEGAMAN or player.character == CHARACTER_SAMUS

If you additionally want some of these NPCs to be friendly by default, things get a bit more complex as you have to remember the initial friendly state in a variable. I'll not get into that just yet, because I don't wanna introduce too much unnecessary complexity if you don't even need that option.
I'm sorry for bothering you but... I think I've done something wrong. (error was caused by not setting any item to the patch of grass. Though it is still weird that MegaMan could still interact with it at all.
Image

Added in 45 minutes 39 seconds:
To test something I set the patch of grass as friendly to every player and used the slide as MegaMan and the vegetable was pulled from the ground. Though Megaman could not interact with the vegetable itself. Somehow MegaMan's slide bypasses the friendly check.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9865
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Setting NPCs not to interact with specific characters.

Postby Emral » Sun Aug 23, 2020 1:35 am

Ah... good find, that does indeed seem to be the case. I'll fix it for the next patch that should be coming out soon.
As for your error message, that looks like there's an uninitialized variable called 'cfg' somewhere. If you still need help with that, I would need to see your code to give more specific advice.

Megaiwer
Koopa
Koopa
Posts: 15
Joined: Sun Jun 07, 2015 6:46 am

Re: Setting NPCs not to interact with specific characters.

Postby Megaiwer » Sun Aug 23, 2020 12:23 pm

Enjl wrote:
Sun Aug 23, 2020 1:35 am
Ah... good find, that does indeed seem to be the case. I'll fix it for the next patch that should be coming out soon.
As for your error message, that looks like there's an uninitialized variable called 'cfg' somewhere. If you still need help with that, I would need to see your code to give more specific advice.
I deleted the script already. I tried to copy the template file and to add the command but it does not seem to be functioning correctly.
Image
First of all, the grass is inside of the ground and is duplicated, and Mega Man can still pick up the vegetables even though the friendly state should prevent it. (I'm really new to this so I probably made a lot of mistakes.)

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9865
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Setting NPCs not to interact with specific characters.

Postby Emral » Sun Aug 23, 2020 3:24 pm

The npc-751 method was because I thought you were talking about custom NPCs. If you just have a piece of grass, just put this in your luna.lua:
function onTick()
for index,myNPC in ipairs(NPC.get(91, player.section)) do
myNPC.friendly = player.character == CHARACTER_MEGAMAN
end
end

Megaiwer
Koopa
Koopa
Posts: 15
Joined: Sun Jun 07, 2015 6:46 am

Re: Setting NPCs not to interact with specific characters.

Postby Megaiwer » Sun Aug 23, 2020 5:16 pm

Enjl wrote:
Sun Aug 23, 2020 3:24 pm
The npc-751 method was because I thought you were talking about custom NPCs. If you just have a piece of grass, just put this in your luna.lua:
function onTick()
for index,myNPC in ipairs(NPC.get(91, player.section)) do
myNPC.friendly = player.character == CHARACTER_MEGAMAN
end
end
Thank you for your answer. However, there's a problem. This command causes the NPC to become friendly to all present characters if MegaMan exists on the map. Mario is unable to pull the vegetable from the ground.
Image

MarioLover64
Spike
Spike
Posts: 259
Joined: Fri Apr 26, 2019 6:09 pm

Re: Setting NPCs not to interact with specific characters.

Postby MarioLover64 » Sun Aug 23, 2020 5:34 pm

how about...

function onTick()
for index,myNPC in ipairs(NPC.get(91, player.section)) do
nearestPlayer = *insert code here*
myNPC.friendly = nearestPlayer == CHARACTER_MEGAMAN
end
end

Megaiwer
Koopa
Koopa
Posts: 15
Joined: Sun Jun 07, 2015 6:46 am

Re: Setting NPCs not to interact with specific characters.

Postby Megaiwer » Sun Aug 23, 2020 6:46 pm

MarioLover64 wrote:
Sun Aug 23, 2020 5:34 pm
how about...

function onTick()
for index,myNPC in ipairs(NPC.get(91, player.section)) do
nearestPlayer = *insert code here*
myNPC.friendly = nearestPlayer == CHARACTER_MEGAMAN
end
end
So I tried to test this with a goomba because the grass patches are broken with MegaMan's slide and unfortunately it did not work.

Image

MarioLover64
Spike
Spike
Posts: 259
Joined: Fri Apr 26, 2019 6:09 pm

Re: Setting NPCs not to interact with specific characters.

Postby MarioLover64 » Sun Aug 23, 2020 6:57 pm

You didn't set nearestPlayer to anyhing

Megaiwer
Koopa
Koopa
Posts: 15
Joined: Sun Jun 07, 2015 6:46 am

Re: Setting NPCs not to interact with specific characters.

Postby Megaiwer » Sun Aug 23, 2020 8:22 pm

MarioLover64 wrote:
Sun Aug 23, 2020 6:57 pm
You didn't set nearestPlayer to anyhing
Could you please explain what am I supposted to set nearestPlayer to? I'm sorry I just don't get that stuff just yet.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9865
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Setting NPCs not to interact with specific characters.

Postby Emral » Mon Aug 24, 2020 12:30 am

Like I initially said, I didn't go too much into multiplayer solutions because it would dramatically make the code more complicated and because barely anyone ever uses multiplayer, especially with how Megaman doesn't really work in multiplayer (planned to fix in the future).

Off the top of my head I'm not sure what the best way to handle this for multiplayer is. Proximity is certainly one approach but it will stop working as soon as both players overlap with the grass. Other potential solutions include "making a copy of megaman in your episode and removing the grass pullup code" or "reprogramming grass in a new npc slot", but I don't think either of these are ideal either. The former may be most appropriate for you because it allows you to make other changes to the character locally, but it's also a bit of a pain to set up, and I'm not 100% sure if you can replace Megaman or if you would have to fall back to replacing Toad.

Megaiwer
Koopa
Koopa
Posts: 15
Joined: Sun Jun 07, 2015 6:46 am

Re: Setting NPCs not to interact with specific characters.

Postby Megaiwer » Mon Aug 24, 2020 7:13 am

Enjl wrote:
Mon Aug 24, 2020 12:30 am
Like I initially said, I didn't go too much into multiplayer solutions because it would dramatically make the code more complicated and because barely anyone ever uses multiplayer, especially with how Megaman doesn't really work in multiplayer (planned to fix in the future).

Off the top of my head I'm not sure what the best way to handle this for multiplayer is. Proximity is certainly one approach but it will stop working as soon as both players overlap with the grass. Other potential solutions include "making a copy of megaman in your episode and removing the grass pullup code" or "reprogramming grass in a new npc slot", but I don't think either of these are ideal either. The former may be most appropriate for you because it allows you to make other changes to the character locally, but it's also a bit of a pain to set up, and I'm not 100% sure if you can replace Megaman or if you would have to fall back to replacing Toad.
I've tried to copy MegaMan's script and remove the veggie pullup code but nothing happened. It seems like SMBX does not see it.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9865
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Setting NPCs not to interact with specific characters.

Postby Emral » Mon Aug 24, 2020 9:01 am

"but it's also a bit of a pain to set up, and I'm not 100% sure if you can replace Megaman or if you would have to fall back to replacing Toad"
I'm not 100% sure what all the things are you need to do, but given that I haven't detailed a method I would've been very surprised if what you tried worked off the bat. The characters are not natively designed to be overwritten.

Megaiwer
Koopa
Koopa
Posts: 15
Joined: Sun Jun 07, 2015 6:46 am

Re: Setting NPCs not to interact with specific characters.

Postby Megaiwer » Mon Aug 24, 2020 11:54 am

By "replacing toad" Do you mean adding modified MegaMan's script as toad in the level folder?


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 3 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari