Prevent Movement While Resting?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
CorbinHillman
Posts: 6
Joined: Wed Jan 16, 2013 7:23 am

Prevent Movement While Resting?

Post 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"
User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

Re: Prevent Movement While Resting?

Post 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,

}
Currently conspiring with many modders on the "Legends of the Northern Realms"project.

"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
CorbinHillman
Posts: 6
Joined: Wed Jan 16, 2013 7:23 am

Re: Prevent Movement While Resting?

Post 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..
User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

Re: Prevent Movement While Resting?

Post 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.
Last edited by msyblade on Wed Jan 16, 2013 9:07 am, edited 1 time in total.
Currently conspiring with many modders on the "Legends of the Northern Realms"project.

"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
CorbinHillman
Posts: 6
Joined: Wed Jan 16, 2013 7:23 am

Re: Prevent Movement While Resting?

Post by CorbinHillman »

alright thanks for the help :)
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Prevent Movement While Resting?

Post 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)
Finished Dungeons - complete mods to play
User avatar
Wanderer
Posts: 113
Joined: Sat Dec 29, 2012 9:08 pm
Location: Lyramion / Twinlake :)

Re: Useful scripts repository

Post 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.
My first LoG-Mod: Abandoned Places 2
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Prevent Movement While Resting?

Post 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?
Finished Dungeons - complete mods to play
CorbinHillman
Posts: 6
Joined: Wed Jan 16, 2013 7:23 am

Re: Prevent Movement While Resting?

Post by CorbinHillman »

I did all of the stuff you told me with the codes but it still lets me move when I am resting..?
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Prevent Movement While Resting?

Post 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
Finished Dungeons - complete mods to play
Post Reply