[SCRIPT] Safe Ladder - descend ladders without falling

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

[SCRIPT] Safe Ladder - descend ladders without falling

Post by Lark »

[EDIT]

Here is version 1.0 of the safe_ladder.lua and safe_ladder_deploy.lua scripts in the form of a demonstration dungeon in a 5MB download that includes new sounds. I can post the scripts, sounds, and definitions separately if anyone likes. Otherwise, it can be found at:

https://ntg.missouristate.edu/images/la ... erDemo.zip

See the demo, but to use it, simply put the files in the right directory, load definitions as part of your dungeon, add the safe_ladder_deploy.lua one place in your dungeon (I always used the first level), then back on to a ladder to descend it safely (without falling). No big deal for ladders of elevation one, but stack 10 ladders on top of each other and that's quite a fall unless you use this script. Please post ideas, suggestions, improvements, et cetera and be kind! I do this part time for fun and I have a lot yet to learn!

Thanks, -Lark

[END OF EDIT]

I am writing a script that can be used to descend any number of stacked ladders without the party falling. I've tried three different methods, and now have one that basically works (and enough knowledge to fix the second if I so desired). I don't know that it's the best method, but it works in the editor and in an exported dungeon. I'll upload the script/test dungeon soon. However, I've run into a few choices and, while I could implement all or most of them, I thought I'd get people's opinions:
  1. Should the party descend "smoothly", or hesitate slightly on each "step"? (Implemented)
  2. Should the party make sounds as they step on "each rung"? (Implemented)
  3. Should the sound that plays when the party falls one level be played at the bottom of the ladder? (currently works either way).
  4. The party controls are disabled, but should they be "grayed out" until the bottom is reached? (I've not gotten this to work, but I have some good leads from people here.)
  5. The party descends all stacked ladders "safely" by backing onto the top-most ladder and control isn't returned until they reach the foot of the bottom ladder. This is the only way to descend safely. Is this good enough?
  6. What else am I missing?
There is also another script that you include once in your dungeon, and it automatically deploys the "safe ladder" script on all ladders named "<any text>_<sequence number>" as long as too many sequence numbers aren't skipped. What's "too many" can be defined.

Does anyone have any other ideas, comments, et cetera? Thanks, -Lark
Last edited by Lark on Fri Dec 02, 2016 12:56 am, edited 5 times in total.
minmay
Posts: 2789
Joined: Mon Sep 23, 2013 2:24 am

Re: [SCRIPT] Safe Ladder - Opinions?

Post by minmay »

So, if you're trying to add new party actions you should understand how they work in the base game.

The party can occupy one state at a time. Being idle, moving, turning, climbing ladders, climbing stairs, and falling into a pit are all examples of states. Note that falling within a single map, without a pit involved, is NOT a state of its own; the party is considered idle, the movement controls just don't work. This is why you can click on a ladder while falling and the party will start climbing the ladder (ending up with the wrong final world Y position, but it's corrected the next time you move).

Now, here's how ladders work in the base game:
On attempting to climb a ladder (by moving into a LadderComponent or clicking on it)
If the party is overloaded or grappled, or the square above the party contains an enabled PlatformComponent or an enabled party-blocking object (obstacles, monsters, etc.), the party "bumps" upwards, similar to trying to move into a wall. Otherwise, they enter the ladder-climbing state. As soon as the ladder-climbing state is entered, the party's initial world Y position is recorded, the party's GravityComponent is disabled, the party_climb_ladder sound is played, the party's DynamicObstacleComponent ceases occupying their current square and begins occupying the square at the top of the ladder (but the actual party object's elevation HAS NOT CHANGED YET). Oh, and the ladders_climbed statistic is increased by 1.

During the ladder-climbing state
The game does some fancy camera and position work for the "stepping" motion on every frame. The party cannot move, turn, attack, pick up or drop items, etc. while climbing a ladder. However, there isn't some convenient game flag you can set to get that behaviour. Instead, the code for moving, turning, attacking, picking up and dropping items, etc. checks whether the party is currently climbing, falling down a pit, etc.
No combination of GameMode.setGameFlag(), GameMode.setEnableControls(), or even party hooks will give you equivalent behaviour - think about spellcasting for instance.

At the top of a ladder
The party's GravityComponent is still disabled. If the party moves, the GravityComponent is re-enabled at the end of the move. It will be re-enabled immediately if they turn or get teleported or whatever. Attempting to move backwards also re-enables the GravityComponent immediately without resulting in a move. Free-look is disabled at the tops of ladders for some reason.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: [SCRIPT] Safe Ladder - Opinions?

Post by Lark »

minmay: Thank you for the information. That helps and confirms much of what I've discovered and teaches me a few new things. Let me explain what I have working: I place a trigger at the top landing and the top of the ladder during initialization and I also count the ladders blow while ensuring the script is at the top most ladder. The landing trigger only flags a possible descent should the party trip the trigger at the top of the ladder. This is needed because you can't have the party climb up the ladder and have them immediately climb back down without pressing a key! A deactivate of the landing trigger sets off a retarded reset of the descent flag (by .2 seconds) allowing for both a descent if the party steps on the ladder or a reset if the party goes somewhere else yet ends up at the base of the ladder(s) again.

When the party backs onto the top ladder trigger, the safe ladder script activates and, as you said, the party is now simply idle. The script suspends gravity and checks to see that the party is facing the ladder for a proper descent. If not, it enables gravity and exits so the party falls. Otherwise, it disables the party controls, moves the party down a short distance (.05 in world space), enables gravity, and repeats 60 times per ladder playing a step sound every 15 iterations. Just for fun, I also (currently) make the party pause slightly longer (~.1 seconds) simulating hesitating on a rung. I just don't know that I like that part or not, so I ask for people's opinions on that and other things such as do people like the step sounds?

I can acomplish the same thing by using an invisable platform, but if I do, I have to set the platform's position in x, y, elevation at each elevation boundary else the party will fall through the platform at the bottom of the first ladder. It just seamed simpler to just move the party with gravity suspended instead.

Regardless, at the end of the last ladder, I can either skip 15 iterations and have the party fall and make the "party_fall" sound or I can make it completely silent by doing all iterations lowering the party gently to the floor - it even pushes monsters out of the way. I then set the party's position because, as you said, setWorldPosition doesn't actually set the party's position in x, y, elevation. Gravity is then restored, flags reset, an the party finds itself safely on the ground without falling. I'm pretty satisfied with the results, but the only thing I would really like to do is to gray out the party's controls to let the player know that, just like climbing ladders built into the game, they have no control until they descend the entire set of contiguous ladders. I thought I had some leads on that, but now I'm thinking not because of what you have said. Maybe I'll just call this one good and go on to my next idea.

I'd still like to polish it a bit before I post it, but it really works well enough for me now in the editor and in an exported dungeon. Thank you for your help!

Sincerely, -Lark
Eburt
Posts: 69
Joined: Thu Feb 05, 2015 5:44 am

Re: [SCRIPT] Safe Ladder - Opinions?

Post by Eburt »

I'm quite interested in this. I had wanted to do something similar, but never worked on it.
Lark wrote:
  1. Should the party descend "smoothly", or hesitate slightly on each "step"? (Implemented)
  2. Should the party make sounds as they step on "each rung"? (Implemented)
  3. Should the sound that plays when the party falls one level be played at the bottom of the ladder? (currently works either way).
  4. The party controls are disabled, but should they be "grayed out" until the bottom is reached? (I've not gotten this to work, but I have some good leads from people here.)
  5. The party descends all stacked ladders "safely" by backing onto the top-most ladder and control isn't returned until they reach the foot of the bottom ladder. This is the only way to descend safely. Is this good enough?
  6. What else am I missing?
My thoughts:
  1. Hesitating on each step would be nice. I was thinking to use a camera component for this. Your gravity approach is a neat idea. How does it look?
  2. I would play a sound, just like climbing the ladder. In fact, just playing the same sound would be good enough IMO.
  3. I think the falling sound would be out of place.
  4. No strong opinions on the UI, but again it would be nice to have it match the ladder climbing UI.
  5. I think making them descend all is fine. The only issue is if they want to avoid monsters/projectiles - maybe give them the option to "drop" the remainder of the ladder by trying to move or something? I would be happy with your current approach though.
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: [SCRIPT] Safe Ladder - descend ladders without falling

Post by Lark »

Eburt: Thank you for the input. I have modified the original post to include a download link for a demo dungeon of the scripts. I implemented things as you preferred, but they are easily changed in the scripts. Many thanks to Akroma222 and others who helped with various aspects.

Everyone: Please let me know how you like it. I only tested it on one computer, but I tested it exported and across save games. I never tried to save on a ladder itself, but I'm not worried if that works or not.

Have fun, -Lark
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: [SCRIPT] Safe Ladder - descend ladders without falling

Post by Mysterious »

This is really cool and I needed this in my mod so many thanks for the ladder. I don't know why it was not originaly in the Game it's self
User avatar
THOM
Posts: 1280
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: [SCRIPT] Safe Ladder - descend ladders without falling

Post by THOM »

This is a great addition. Yes could have been a feature from the original LoG2...

At least I would like to give some comments:

- sadly climbing down the ladders needs more or less double the time it needs to climb up. Can't it be the same? [well - now it become very fast! (???)]
- If you are half the way up on a stacked long ladder you can't go down, just up. Or jump. It there a possibillity to change the direction?
- just before you land on the floor there is a small cut in the moving-sequence ( a bit like a jump). Can that be fixed somehow?
- If there would be a possibillity for the party to get hurt by just jumping down one elevation, it would mean that ladders become more important. Not just for going up - also for down....

But beside that I'm very impressed by this solution.
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: [SCRIPT] Safe Ladder - descend ladders without falling

Post by Lark »

Thom: Yes, descent time can be the same, longer, or even instantaneously - just change the script to suit you. Unlike some of my past scripts, I've not parameterized this one, so just change the code itself. See the lines of code nextIn = .1 which is the next interval to wait when the party steps on a ladder rung and nextIn = .05 which is the next interval to wait for the next frame to be displayed. Set these values to smaller numbers to have things move more quickly. Halving them will double the descent speed and you can eliminate, shorten, or lengthen the hesitation between "steps" too, the occurance of which is controlled by if (count % 15 * 15) == 15 then. You can wipe out the sounds too. Larger numbers will give you less "rungs" which are further apart, hesitations and sound wise. I didn't try to make them actually match the number or rungs on the ladders, but you easily could.

Could the direction be changed while on a ladder? Yes, I think so using the same techniques, likely with a separate script at each elevation with a clickable trigger, but that's really a different script that I'm not inclined to write this at the moment... maybe later.

I'm not seeing the jumping issue in any of my tests, but just when the script stops and places the party in their final resting spot is controlled by if count > interval then where interval = self.go.map:getModuleHeight() / .05 * below which is number of frames to display before the party lands based on the module height and how many ladders are stacked on each other. (Don't confuse the .05 spacial gaps here with the .05 framerate above.) Perhaps adding a few frames (a fudge factor) to the above statement would help. Mathematically, the script should be correct, but try putting a + 1 or so on the statement above and see if it helps. If you make it too big, the party will descend through the floor, then pop back up to normal.

I didn't write the part where the party falls one level and doesn't get hurt. I suppose you could simulate this with appropriate triggers and a damage tile script, but it's really not in the purview of this script, sorry!

Thanks for the feedback - you have some good ideas, but those are for later versions.

Thanks, -Lark
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: [SCRIPT] Safe Ladder - descend ladders without falling

Post by Lark »

Mysterious wrote:This is really cool and I needed this in my mod so many thanks for the ladder. I don't know why it was not originaly in the Game it's self
Thanks! Glad you like it. I hope to play your mod someday!

See the above post to tweak the speed and operation a bit. Using nextIn = .033 and if (count % 20 * 20) == 20 then between rungs is faster and maybe better... Let me know if anyone wants further tweaking assistance.

Cheers! -Lark
Post Reply