Page 1 of 2

Prevent Movement While Resting?

Posted: Wed Jan 16, 2013 7:33 am
by CorbinHillman
I am making my first map and am slightly familiar with the coding but I haven't found out if there is a way to prevent the player from moving while they are resting just in a part because I want it to have the feeling of being "knocked out"

Re: Prevent Movement While Resting?

Posted: Wed Jan 16, 2013 7:55 am
by msyblade
Not sure if this will work, but it is close.

Make a counter in your dungeon called cMove, then insert this script to your init.lua
SpoilerShow

Code: Select all

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

   onMove = function(self, dir)
      if (cMove:getValue() == 0) then
         return false
      end
         return true
   end,
onRest = function(party)
 cMove: decrement()

end,
onWakeUp = function(party)
cMove: increment()

end,

}

Re: Prevent Movement While Resting?

Posted: Wed Jan 16, 2013 8:38 am
by CorbinHillman
I put the code in my init.lua but I don't know what to do with the counter.. this is my current code...
SpoilerShow
function RestPhase()
party:shakeCamera(1,.5)
hudPrint("Oomph...")
playSound("damage_human_male")
party:rest()
end
I want the blackout to last about 5 seconds..

Re: Prevent Movement While Resting?

Posted: Wed Jan 16, 2013 9:03 am
by msyblade
you simply place the counter anywhere and rename it to cMove. Not sure how to get the 5 seconds for you right now, im tired (waaay past bedtime), if it doesn't work, post what happened/went wrong, and one of the gentlemen around here will have you fixed up before long.

ps. you can now use hidden plates to decrement the cMove and freeze party for dialogue etc, and a timer to increment cMove to release them at will.

Re: Prevent Movement While Resting?

Posted: Wed Jan 16, 2013 9:06 am
by CorbinHillman
alright thanks for the help :)

Re: Prevent Movement While Resting?

Posted: Wed Jan 16, 2013 12:21 pm
by Komag
Personally, I like to keep my hooks as drop dead simple as possible and do all coding in the dungeon, so I would do something like this:
in objects.lua:

Code: Select all

cloneObject{
   name = "party",
   baseObject = "party",
   onWakeUp = function(party)
      oomphScript.toWake()
   end,
}
in dungeon place script entity called oomphScript:

Code: Select all

knockedOut = false
function restPhase()
  party:shakeCamera(1,.5)
  hudPrint("Oomph...")
  partyHurt()
  party:rest()
  knockedOut = true
  koTimer:activate()
end

function toWake()
  if knockedOut then
    return false
  end
end

function koOff()
  knockedOut = false
  party:wakeUp(false)
  hudPrint("Uuugh, what happened?")
end

function hurtSounds()
  for i=1,4 do
    if party:getChampion(i):getEnabled() and
       party:getChampion(i):isAlive() then
       party:getChampion(i):playDamageSound()
    end
  end
end
You'll need to place a timer called koTimer in the dungeon and set to around 20s (since sleep time is 5X speed of wake time), and connect it to the oomphScript to koOff(), and also connect it to itself to deactivate itself.

(most of this code is untested, just written off the cuff, so there may be mistakes)

Re: Useful scripts repository

Posted: Wed Jan 16, 2013 1:03 pm
by Wanderer
Hey Komag you are great. Simple but perfect functions.
But I have a problem with the Human Male sound when get hurt, it seems it is a female sound. Can it be that there is a bug in the sound files? Or is it only me and I hear a female where is a male sound? :mrgreen:

Edit: But this issue has nothing to do with your functions, even when I play the Human Male sound directly, it seems that it is a female voice.

Re: Prevent Movement While Resting?

Posted: Wed Jan 16, 2013 5:34 pm
by Komag
Thanks! I moved this out of the script repository (we just have scripts there, no comments).

I don't know if maybe your sound files have a problem, or maybe it's just you and your opinion of the sounds. Did you try the female sound also? Does it maybe sound "more" female than the male sound to you?

Re: Prevent Movement While Resting?

Posted: Thu Jan 17, 2013 1:56 am
by CorbinHillman
I did all of the stuff you told me with the codes but it still lets me move when I am resting..?

Re: Prevent Movement While Resting?

Posted: Thu Jan 17, 2013 2:12 am
by Komag
hmm, I didn't test it myself, and now I can't remember if the hook needs another "return" in front of the script.function

you can always also put the code right in the hook, to check if oomphScript.knockedOut then return false