[Solved ]Trying to make an NPC disappear

Started by ponderitus, April 30, 2017, 02:02:35 AM

Previous topic - Next topic
April 30, 2017, 02:02:35 AM Last Edit: May 02, 2017, 10:53:26 PM by ponderitus
Hi guys, I've been trying to make a sensor which on activated a dialog will load from an NPC who will then walk off and vanish, I've tried to make it a save game variable so that the sensor and the NPC are gone forever after this. I can't seem to get my NPC to disappear when the map reloads, I realize the below will make him disappear when the sensor is activated again (which is what it is doing). Can anyone show me how to make it do what I need it to do. I tried lots of things but I can't seem to get it to work

Code ( lua) Select

local meeting_quest_1 = false

function meeting_sensor:on_activated()
   if game:get_value("meeting_quest_1") then
   worker_npc:remove()
   else
      game:start_dialog("meeting.1")
      hero:freeze()
      local path_movement = sol.movement.create("path")
      path_movement:set_path({ 2, 2, 2, 2, 2, 1, 1, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0 })
      path_movement:set_ignore_obstacles(true)
      worker_npc:is_traversable()
      path_movement:set_speed(64)
      path_movement:start(worker_npc, function()
      worker_npc:remove()
      game:set_value("meeting_quest_1", true)
      hero:unfreeze() 
      end)
   end
end


I kept getting these errors when i tried to get it working outside the sensor:on_activated
Error: attempt to index global 'worker_npc' (a nil value)
Error: attempt to index global 'meeting_sensor' (a nil value)
but as those are names of entities on my map...isnt that enough to use them just as : worker_npc:remove() ?

as in
Code ( lua) Select

map:on_started(function()
if game:get_value("meeting_quest_1") then
worker_npc:remove()


i also forgot that i needed to change the dialog to a function with
Code ( lua) Select

game:start_dialog("meeting.1", function()
   if answer == 2 then -- No
   game:start_dialog("meeting.1")

To get the NPC to disappear when the map reloads, you should use the map:on_started() event.

I think you want something like this:
Code (lua) Select
function map:on_started(destination)
   if game:get_value("meeting_quest_1") then
      worker_npc:remove()
   end
end

function meeting_sensor:on_activated()
   if not game:get_value("meeting_quest_1") then
      game:start_dialog("meeting.1")
      hero:freeze()
      local path_movement = sol.movement.create("path")
      path_movement:set_path({ 2, 2, 2, 2, 2, 1, 1, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0 })
      path_movement:set_ignore_obstacles(true)
      worker_npc:is_traversable()
      path_movement:set_speed(64)
      path_movement:start(worker_npc, function()
         worker_npc:remove()
         game:set_value("meeting_quest_1", true)
         hero:unfreeze() 
      end)
   end
end


you can probably delete line 1 as well because that doesn't look like it is doing anything.

That's perfect, Once again amazing! I managed to get the extra dialog in myself. I did try using map:on_started() but i didn't put destination inside the brackets though, that wasn't my only mistake :P You're so good at these things.