[Solved] Trying to make an NPC dialog

Started by ponderitus, April 26, 2017, 04:00:40 AM

Previous topic - Next topic
April 26, 2017, 04:00:40 AM Last Edit: April 30, 2017, 01:42:53 AM by ponderitus
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) Select

local shield_search_quest_started = false
local sword_search_quest_started = false
local items_search_quest_started = false

  local has_sword = game:has_item("sword")
  if has_sword then
  game:set_value("sword_search_quest_started", true)
  end

  local has_shield = game:has_item("shield")
  if has_shield then
  game:set_value("shield_search_quest_started", true)
  end

  local has_both = game:has_item("shield" and "sword")
  if has_both then
  game:set_value("items_search_quest_started", true)
  end

-- Guy3
function Guy3:on_interaction()

if game:get_value("sword_search_quest_started") then
    game:start_dialog("Guy3.has_sword")
    else
         game:start_dialog("Guy3.search")
  end
end

-- the other 2 dialogs would be
-- "Guy3.has_shield"
-- "Guy3.found"


If anyone can help I'd appreciate it

For line 21 on do this instead:
Code (lua) Select
-- Guy3
function Guy3:on_interaction()
  if has_sword and has_shield then
    game:start_dialog("Guy3.found")
  elseif has_sword and not has_shield then
    game:start_dialog("Guy3.has_sword")
  elseif has_shield and not has_sword then
    game:start_dialog("Guy3.has_shield")
  else
    game:start_dialog("Guy3.search")
  end
end

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

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

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.