Page 1 of 1

[ACS] Real Elevators - Accelerating and Decelerating Lifts

PostPosted: Thu Nov 25, 2021 6:51 pm
by Nero
One of the quality of life things I've always wanted: elevators that would move like the real thing; in other words, they accelerate when they start to move and decelerate when they near their destination.
Ok...that's not that tall an order is it? ... :? ... :shock: ... :ugeek: ... Yes and no.

Anyway, introducing Real Elevators(v0.3.1), a tiny code library that does just what I've always wanted in a nice neat package!
    * Real Elevators is a modder's resource. This code does nothing on its own.

So, how it works: there's more under the hood than this, but the only function - yes function - users need to know about is MoveElevator. This function is called from a script that should be activated by the player, as shown below.
Code: Select allExpand view
    This function is called from implementation scripts to move an elevator.
    It is assumed that it is a player that is the script activator.
    ElevatorId, int, this is the sector id of the elevator control sector(s).
    SkipAccel, bool, if true the elevator will begin moving at full speed but can still decelerate.
    SkipDecel, bool, if true the elevator will move to its final position at full speed.
    TotalDist, int, how far the elevator will move; positive values move up, negative move down.
    MaxSpeed, int, the maximum speed the elevator will move at.
    AccelDist, int, how much of the Total Distance will be used for accelerating AND decelerating; this value is effectively doubled.
    MoveStartBias, int, this value increases or decreases the rate of acceleration for the first half of acceleration; positive increase, negative decrease.
    MoveEndBias, int, this value increases or decreases the rate of deceleration for the last half of deceleration; positive increase, negative decrease.
    JustFloor, bool, if true only the floor of the given sector will be moved; this is for regular lifts and not 3D floor elevators!
function void MoveElevator (int ElevatorId, bool SkipAccel, bool SkipDecel, int TotalDist, int MaxSpeed, int AccelDist, int MoveStartBias, int MoveEndBias, bool JustFloor)
    // . . . stuff that none of us ever have to do again to make an elevator accelerate or decelerate :P

A script using MoveElevator might look like this: the script is called from another which is flagged as an ENTER script, thus the player is the activator of this elevator script, which also handles level transition effects.
Code: Select allExpand view
//Starting Location/Level Selection Elevator
    SetPlayerProperty(0, 1, PROP_TOTALLYFROZEN);
    FadeTo(24, 24, 24, 1.0, 0.0);
    Thing_Move(0, 1043, 1);
    MoveElevator(3000, true, false, -212, 15, 96, 0, 1, false);
    SetPlayerProperty(0, 0, PROP_TOTALLYFROZEN);
    FadeTo(24, 24, 24, 0.0, 0.5);

  • This library should be multiplayer friendly, allowing up to 8 players to be activating and riding elevators at any given time.
  • I originally designed this around elevators made from 3D floors, but I've also tweaked the code to include regular lifts as well.

Most Recent Version:
Old Versions:

  • Load the package you downloaded with ZDL or equivalent.
  • Mod authors are free to do with this as they please, especially integrate into their own stuff, I just ask for credit, thanks!

  • Pretty sure this is done and I won't be updating it any time soon. I'm already using this code in my own stuff and I added multiplayer and regular lifts for the public release, so it seems pretty feature complete to me. Please let me know if you have any problems or suggestions!
  • v0.3! - well I thought I was done but then I had another thought: what if someone wants the elevator to not decelerate? Like what if you want to "break" an elevator mid-transit? It doesn't make sense that it should necessarily come to a nice gradual halt. So deceleration skipping is now a feature. This does mean that the MoveElevator function has received an additional argument.
  • v0.3.1! - found a small bug that broke multiplayer, I should be using ACS_NamedExecuteAlways to call the ElevatorMove script.

Spoiler: "The WHOLE Library if You're Interested - updated to v0.3.1"