Author Topic: [Solved] Trying to make an NPC dialog  (Read 221 times)

ponderitus

  • Newbie
  • *
  • Posts: 25
    • View Profile
[Solved] Trying to make an NPC dialog
« on: April 26, 2017, 04:00:40 am »
does anyone know how to make a dialog where the npc will respond 4 ways based on whether i have neither item, 1 of the required items or both.

none     -   need both
sword  -   need shield
shield  -   need sword
both     -   have both!

ive been able to get it so that if i have neither and then one item it works. but when i try to get both, or either, i either cant get it to work or i get 2 dialogs trying to play at the same time (need this and need both)

ive tried setting things like below, but after this i dont know where im going, or if this even right to begin with
Code: Lua
  1. local shield_search_quest_started = false
  2. local sword_search_quest_started = false
  3. local items_search_quest_started = false
  4.  
  5.   local has_sword = game:has_item("sword")
  6.   if has_sword then
  7.   game:set_value("sword_search_quest_started", true)
  8.   end
  9.  
  10.   local has_shield = game:has_item("shield")
  11.   if has_shield then
  12.   game:set_value("shield_search_quest_started", true)
  13.   end
  14.  
  15.   local has_both = game:has_item("shield" and "sword")
  16.   if has_both then
  17.   game:set_value("items_search_quest_started", true)
  18.   end
  19.  
  20.  -- Guy3
  21. function Guy3:on_interaction()
  22.  
  23.  if game:get_value("sword_search_quest_started") then
  24.     game:start_dialog("Guy3.has_sword")
  25.     else
  26.          game:start_dialog("Guy3.search")
  27.   end
  28. end
  29.  
  30. -- the other 2 dialogs would be
  31. -- "Guy3.has_shield"
  32. -- "Guy3.found"

If anyone can help I'd appreciate it
« Last Edit: April 30, 2017, 01:42:53 am by ponderitus »

llamazing

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Trying to make an NPC dialog
« Reply #1 on: April 26, 2017, 04:48:20 am »
For line 21 on do this instead:
Code: Lua
  1. -- Guy3
  2. function Guy3:on_interaction()
  3.   if has_sword and has_shield then
  4.     game:start_dialog("Guy3.found")
  5.   elseif has_sword and not has_shield then
  6.     game:start_dialog("Guy3.has_sword")
  7.   elseif has_shield and not has_sword then
  8.     game:start_dialog("Guy3.has_shield")
  9.   else
  10.     game:start_dialog("Guy3.search")
  11.   end
  12. end

ponderitus

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Trying to make an NPC dialog
« Reply #2 on: April 27, 2017, 02:32:27 am »
Thank you so much, it would have taken me forever to figure that out. I wish there were more little scripts laying around to work with like this as I'm at a point now where i can kind of read and understand scripts but I'm having trouble writing them. But with other scripts to read that relate I find it easier.

I've been reading a lot of the map scripts from other games but without being able to see them in action it's hard to see exactly what happens at what point, ie, i was trying to get a dialog to show after the npc had reached its destination but couldn't figure out how to get it to appear at any point other than instantly. I have now because I was able to find a guy from one of the solarus games who does the same-ish actions (speaking after an action not before) and see where I'd gone wrong

I can't believe you'd done it and replied within a hour...wish I'd have come back online earlier. I tried another 100 things after I'd posted this. Thanks again

llamazing

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Trying to make an NPC dialog
« Reply #3 on: April 27, 2017, 03:13:52 am »
If you have any other questions, just ask.

Have you seen Christopho's tutorials? They cover some very basic scripting.
https://www.youtube.com/playlist?list=PLzJ4jb-Y0ufxwkj7IlfURcvCxaDCSecJY

ponderitus

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Trying to make an NPC dialog
« Reply #4 on: April 27, 2017, 06:47:28 am »
Cheers, I will be :) I just don't want to flood the message board with questions ALL the time

Yeah I've watched them countless amounts of times, that's how I've got where I am. I'm trying to make sense of the Lua api as well, I've always got it open next to me whilst I'm trying something, as well as the Christopho tutorial (if there is one). I'm more of a visual learner though so it's hard to understand what it's trying to show sometimes or how to implement it without it actually showing me, I'm getting better though. But that's why i love Christopho's tutorials so much, there's so much info in them, much more than the title suggests. It's amazing how far I've got with just them as reference, I can't wait for the next one. Will probably make me realize I've been doing something else wrong for ages :P

It's a shame he's the only person who does any sort of videos. I've tried watching his live coding sessions because I'm sure I'd learn loads through watching that...But I don't speak French so it's hard to understand whats going on (especially in the chat bar) and youtube translations suck.