[ACS] Real Elevators - Accelerating and Decelerating Lifts

Post your example zscripts/ACS scripts/etc here.

[ACS] Real Elevators - Accelerating and Decelerating Lifts

Postby Nero » Thu Nov 25, 2021 6:51 pm

:mrgreen:
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), a tiny code library that does just what I've always wanted in a nice neat package!

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.
    
    Args:
    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
script "LEVELELEVATORSTART" (void)
{
    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);
        delay(15);
    SetPlayerProperty(0, 0, PROP_TOTALLYFROZEN);
    FadeTo(24, 24, 24, 0.0, 0.5);
}


Features:
  • 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.

Download:
Most Recent Version:
Old Versions:

Usage:
  • 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!

Updates:
  • 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.

Spoiler: "The WHOLE Library if You're Interested - updated to v0.3"
User avatar
Nero
Royal Boredom....Why can't I do this in Windows?
 
Joined: 06 Sep 2006
Location: Middle of Nowheresville Il.

Return to Script Library

Who is online

Users browsing this forum: bjork and 1 guest