How to do it?
Posted: Sun Feb 05, 2017 6:39 pm
How do you make an npc's dialogue change based on which character your playing as?
Code: Select all
function onMessageBox(eventObj, msgStr)
if msgStr == "goombaTalk" then
eventObj.cancelled = true --cancels the message from displaying
if player.character == 1 then
Text.showMessageBox("Actual Message")
elseif player.character == 2 then
Text.showMessageBox("Other Message")
Text.showMessageBox("he gets 2")
end
end
end
It didn't work, are supposed to put in the name of the event somewhere?Enjl wrote:Link the dialogue to lua by making it some sort of code. I like to call them stuff like "goombaTalk" for if it's a Goomba, etc...
once you got the message in SMBX set to your code, you make an onMessageBox function:Code: Select all
function onMessageBox(eventObj, msgStr) if msgStr == "goombaTalk" then eventObj.cancelled = true --cancels the message from displaying if player.character == 1 then Text.showMessageBox("Actual Message") elseif player.character == 2 then Text.showMessageBox("Other Message") Text.showMessageBox("he gets 2") end end end
Do you insert a event in the code?Enjl wrote:What event
But what does Msgstr mean? what do i insert instead of goomba talk for the text happen?Enjl wrote:No????? The "eventObj" is the action of displaying the text box after talking to the npc. onMessageBox is activated every time this happens in the game.
Code: Select all
function onMessageBox(eventObj, msgStr)
if msgStr == "ScubaTalk" then
eventObj.cancelled = true
if player.character == 1 then
Text.showMessageBox("Scuba:Hi there MosaicMario! How have you been?")
Text.showMessageBox("MosaicMario:Hey Scuba, It's been awhile, but, i actually had a question.")
Text.showMessageBox("Scuba: Sure! I'll tell you anything!")
Text.showMessageBox("MosaicMario: Well, do you have any important info you can give me?")
Text.showMessageBox("Scuba: Yeah! I heard that in an area you could only reach if you rode a magic carpet, there's a vase with a keyhole, a secert exit!")
Text.showMessageBox("MosaicMario: Hey, Thanks for telling me! See you another time!")
Text.showMessageBox("Scuba: It's Okay! Don't mention it.")
elseif player.character == 2 then
Text.showMessageBox("Scuba:Hi there Rosy! How are you doing?")
Text.showMessageBox("Rosy: Oh, i'd say pretty fine")
Text.showMessageBox("Scuba: Well, did you- wait, are you blushing?")
Text.showMessageBox("Rosy: No, umm... it's just blush, do you have any tips for me?")
Text.showMessageBox("Scuba: Well... Okay, i do. I heard that in the subcon skies, there's a place with a vase that can only be reached with a magic carpet")
Text.showMessageBox("Rosy: Oh, thank you for telling me that... sweetie.")
Text.showMessageBox("Scuba: What?")
Text.showMessageBox("Rosy: Um, nothing.")
Text.showMessageBox("Scuba: Okay, see you another time i guess.")
elseif player.character == 3 then
Text.showMessageBox("Scuba: O-Oh h-hey there B-Berry.")
Text.showMessageBox("Berry: Yoshi!(Hi Scuba!)")
Text.showMessageBox("Scuba: U-Uh did you have a-a question?.")
Text.showMessageBox("Berry: Yoshi!(Yeah, do you know any important information about Subcon Valley?)")
Text.showMessageBox("Scuba: Y-Yeah, i-i know that y-you can find a-a keyhole somewhere i-in the sk-sk-sky.")
Text.showMessageBox("Berry: Yoshi!(Okay, thanks for telling me! See you later!(Why was he hesisting so much?)")
Text.showMessageBox("Scuba: O-Ok S-S-See you u-um, n-never.")
elseif player.character == 4 then
Text.showMessageBox("Scuba: Hey there Hoops! What have you been up too?")
Text.showMessageBox("Hoops: Um? Saving the world?)")
Text.showMessageBox("Scuba: Oh, that's pretty serious i guess, what brings you here?")
Text.showMessageBox("Hoops: Tell me, are you hiding something important?)")
Text.showMessageBox("Scuba: No, why would i hide anything? Infact, let me tell you something, I know that somewhere in the skies in subcon, you can find a vase that could on be reached with a magic carpet, even with a flight wing or such you couldn't reach it!")
Text.showMessageBox("Hoops: Wow, that's good to know, but now if you excuse me, i need to skitdaddle to save the world in time!")
Text.showMessageBox("Scuba: Alright, see you another day!")
elseif player.character == 5 then
Text.showMessageBox("Scuba: Umm, who are you? Did you need something?")
Text.showMessageBox("MosaicLink: Someone told me someone named Scuba would give me some valueable information, i just wasn't expecting you to be a fish.")
Text.showMessageBox("Scuba: Okay, let me give you that information. You may be able to find a vase somewhere in skies that you could only reach with a magic carpet that contains a keyhole.")
Text.showMessageBox("MosaicLink: Well, okay then, bye i guess.")
Text.showMessageBox("Scuba: Okay, bye stranger?")
end
end
end