[ACS] Real Elevators - Accelerating and Decelerating Lifts

Post your example zscripts/ACS scripts/etc here.
Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
User avatar
Sarah
Posts: 542
Joined: Wed Sep 06, 2006 12:36 pm
Github ID: Saican
Operating System: Debian-like Linux (Debian, Ubuntu, Mint, etc) 64-bit
Location: Middle of Nowheresville Il.

[ACS] Real Elevators - Accelerating and Decelerating Lifts

Post by Sarah »

: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.2), 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 functions - yes functions - users need to know about are MoveElevator and MoveElevatorObject. This functions are called from a script that should be activated by the player, as shown below.

Code: Select all

/*
    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 all

//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);
}
Using MoveElevatorObject is Even Simpler!
  • The function only has 2 arguments: The TID of the object(s) to move, and the ID of a reference floor.
  • The reference floor is thought of as "below" the objects, and should be part of the elevator.
  • MoveElevatorObject should be called in tandem with MoveElevator.

Code: Select all

function void MoveElevatorObject (int ObjectID, int SectorID) { ACS_NamedExecuteAlways("ElevatorObjectMove", 0, ObjectID, SectorID); } 
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.
  • Objects, such as light sources, can be moved through a second function that can be called in tandem. (v0.3.2)
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.
  • v0.3.1! - found a small bug that broke multiplayer, I should be using ACS_NamedExecuteAlways to call the ElevatorMove script.
  • v0.3.2! - Moving objects that should be attached to the elevator is now possible!
Spoiler: The WHOLE Library if You're Interested - updated to v0.3.2
User avatar
Sarah
Posts: 542
Joined: Wed Sep 06, 2006 12:36 pm
Github ID: Saican
Operating System: Debian-like Linux (Debian, Ubuntu, Mint, etc) 64-bit
Location: Middle of Nowheresville Il.

Re: [ACS] Real Elevators - Accelerating and Decelerating Lif

Post by Sarah »

Real Elevators v0.3.2 - Now Including Objects!

I've added another function, MoveElevatorObject, to Real Elevators to allow "attached" objects to be moved with the elevator.
  • Usage is straightforward.
  • This function should be called in tandem with MoveElevator.
  • There are only 2 arguments, the TID of the object(s) to move, and a reference sector ID.
    • The reference sector ID should be part of the elevator and is thought of as "beneath" the objects (they are sitting on or floating above this floor).
Spoiler: Code for the interested, entire library available above
User avatar
Nash
 
 
Posts: 17283
Joined: Mon Oct 27, 2003 12:07 am
Twitch ID: nashmuhandes
Github ID: nashmuhandes
Location: Kuala Lumpur, Malaysia

Re: [ACS] Real Elevators - Accelerating and Decelerating Lif

Post by Nash »

Bumping this one up because it's a very, VERY useful library. Giving the lifts ease-in/out movement may not sound like much on paper but visually it just adds so much polish to the presentation. Thank you for making this library, Sarah!

Return to “Script Library”