Page 1 of 1

Freeze party in place at will (Via mahric)

Posted: Tue Nov 27, 2012 4:53 pm
by msyblade
Still playing mahric's Wine Merchant Basement (I am just enamored with this mod), and he released his source files for us. One little trick I really wanted to get from him was freezing the party in place to allow storyline fleshing, etc. I pm'd him to ask and this is how simple he made it.

create a counter in your dungeon set to 1,call it whatever you like. (I used cMove)

Then, clone your party in your init.lua with an onMove hook for the counter. If the counter is at 0, onMove returns false. connect a plate where you want to stop the party, to decrement the counter. BAM, onMove returns false.Set a timer to increment the cMove counter, for the time you need to do what you want. Then BAM!, party has control again. Here's the party clone script to put in the init.lua (Make sure to reference the counter correctly, or onMove will crash to desktop.

Code: Select all

cloneObject{
   name = "party",
   baseObject = "party",

   onMove = function(self, dir)
      if (cMove:getValue() == 0) then
         return false
      end
         return true
   end,
}
And it's that simple! Thanx again Mahric!

Re: Freeze party in place at will (Via mahric)

Posted: Tue Nov 27, 2012 5:26 pm
by JohnWordsworth
Heh, that's a really nice way of generalising it so that then any part of your dungeon can turn that feature on/off at will.

I don't know for sure, but I expect if you want to prevent the potential crash to Desktop, you could just check for nil before calling the method like so.
SpoilerShow

Code: Select all

cloneObject{
   name = "party",
   baseObject = "party",

   onMove = function(self, dir)
      if (cMove ~= nil and cMove:getValue() == 0) then
         return false
      end

      return true
   end,
}

Re: Freeze party in place at will (Via mahric)

Posted: Tue Nov 27, 2012 6:27 pm
by Komag
I always set variables like that at dungeon start so there is no chance of it being nil, just as a habit

script entity called partyMoveScript

Code: Select all

cMove = 0
function freezeParty()  cMove = 0  end
function thawParty()  cMove = 1  end
- plate triggers timer and freezeParty()
- timer triggeres thawParty() and self (deactivate)

my party object:

Code: Select all

cloneObject{
   name = "party",
   baseObject = "party",
   onMove = function(self, dir)
      if partyMoveScript.cMove == 0 then  return false  end
   end,
}
(you don't need the "return true" part, that's just default)

Re: Freeze party in place at will (Via mahric)

Posted: Tue Nov 27, 2012 8:46 pm
by JohnWordsworth
Ahh, I assumed that cMove was a script_entity. I always do a nil check when accessing script entities from object hooks, as you write one in Notepad++ and the other in the editor and if you get the name wrong say - crash! I do this just incase the script entity has had it's name changed or I've forgot to paste it in. Arguably though, you could say the crash at least tells you if you've forgotten to include partyMoveScript in your dungeon - instead of getting unexpected behaviour from skipping over certain function calls.

Didn't know if you had to return true or not - but it's nice to know you don't have to :).