[finally] Hydraulics' Alternative ! v1.1

Started by Sebastian, Sep 25, 2019, 10:20 PM

Previous topic - Next topic

Sebastian

CREDITS:


Hydraulics' Alternative
"  I'm presenting you the future  "

Synced, enabled by a command, actioned by keys
Best alternative to Voodoo's Hydraulics, inspired by SA*
Customizable anti-spam is implemented, to avoid chaos-makers (or not :P )
NUMPAD 8, 5, 4 and 6 are used for Front, Rear, Left and Right leans.
Shift is used to increase vehicle's height.*


[spoiler=Instalation guide]
1.Registering locals, usually in the top of the script
local shift = BindKey( true, 0x10, 0, 0 );
local num8 = BindKey( true, 0x68, 0, 0 );
local num4 = BindKey( true, 0x64, 0, 0 );
local num6 = BindKey( true, 0x66, 0, 0 );
local num5 = BindKey( true, 0x65, 0, 0 );


/*     Hydraulics System done by Sebastian!     */
/*     Don't change the settings - too risky       */

local hyd_top = 2.4, // high level - actioned when pressing SHIFT - set 0 to remove the uppering (safer gameplay)
hyd_z = -0.1, // Centre of Mass Z
hyd_zl = 0.7, // Upper Limit variation -
hyd_lean = 1.4, // front lean
hyd_oplean = -1.4, // rear lean
hyd_side = 0.5, // right lean
hyd_opside = -0.5, // left lean
hyd_mark = -0.001, // trick
hyd_25 = array( 1000, 0 ), // had to do with the UpperLimit variation
hyd_ticks = array( 100, 0 ), // anti-spam of everyplayer
hyd_tickslimit = 600; // interval of time a player can bounce again (in miliseconds)

2. This goes under onPlayerJoin( player ) to reset player's ticks count
function onPlayerJoin( player )
{
hyd_ticks[ player.ID ] = 0;
}

3. This goes under onPlayerCommand( player, cmd, text )
switch( cmd )
{
case "hydraulics":
{
if( !player.Vehicle ) return MessagePlayer( "[#00AAAA]Error - You must be driving a car!", player );
else if( player.VehicleSlot != 0 ) return MessagePlayer( "[#00AAAA]Error - Only the driver can action the hydraulics!", player );

local veh = player.Vehicle,
z = veh.GetHandlingData( 7 );

if( z != hyd_z )
{
veh.ResetHandlingData( 20 );
hyd_25[ veh.ID ] = hyd_zl;
veh.SetHandlingData( 20, hyd_25[ veh.ID ] );
veh.SetHandlingData( 7, hyd_z );

MessagePlayer( "[#00FFFF]Hydraulics were enabled !", player );
}
else
{
hyd_25[ veh.ID ] = 0;
veh.ResetHandlingData( 20 );
veh.ResetHandlingData( 7 );
MessagePlayer( "[#00AAAA]Hydraulics were disabled !", player );
}

veh.AddSpeed( Vector( 0, 0, 0 ) ); // used for the handling rule 24 to take effect
}
break;
}

4. Telling buttons what to do 8) via onKeyDown( player, key )
switch( key )
{
case shift:
case num8:
case num5:
case num4:
case num6:
{
if( !player.Vehicle ) return 0;
else if( player.VehicleSlot != 0 ) return 0;
else if( hyd_25[ player.Vehicle.ID ] == 0 ) return 0;
else if( ( GetTickCount() - hyd_ticks[ player.ID ] ) < hyd_tickslimit ) return 0;

local veh = player.Vehicle,
low = veh.GetHandlingData( 20 ),
val6 = veh.GetHandlingData( 6 ),
val5 = veh.GetHandlingData( 5 );

hyd_ticks[ player.ID ] = GetTickCount();
PlaySound( veh.World, 336, veh.Pos );

switch( key )
{
case shift:
{
if( low < hyd_top ) veh.SetHandlingData( 20, hyd_top );
else veh.SetHandlingData( 20, hyd_25[ veh.ID ] );

veh.AddSpeed( Vector( 0, 0, 0 ) );
}
break;

case num8: // front
case num5: // rear
{
if( low < hyd_top )
{
if( key == num8 ) return veh.SetHandlingData( 6, val6 + hyd_oplean );
else return veh.SetHandlingData( 6, val6 + hyd_lean );
}
else
{
veh.SetHandlingData( 20, hyd_25[ veh.ID ] + hyd_mark );
veh.AddSpeed( Vector( 0, 0, 0 ) );
if( key == num8 ) return veh.SetHandlingData( 6, val6 + hyd_lean );
else return veh.SetHandlingData( 6, val6 + hyd_oplean );
}
}
break;

case num4: // left
case num6: // right
{
if( low < hyd_top )
{
if( key == num4 ) return veh.SetHandlingData( 5, val5 + hyd_side );
else return veh.SetHandlingData( 5, val5 + hyd_opside );
}
else
{
veh.SetHandlingData( 20, hyd_25[ veh.ID ] + hyd_mark );
veh.AddSpeed( Vector( 0, 0, 0 ) );
if( key == num4 ) return veh.SetHandlingData( 5, val5 + hyd_opside );
else return veh.SetHandlingData( 5, val5 + hyd_side );
}
}
break;
}
}
break;
}

5. Last step takes us to onKeyUp( player, key )
switch( key )
{
case num8: // front
case num5: // rear
case num4: // left
  case num6: // right
{
if( !player.Vehicle ) return 0;
else if( player.VehicleSlot != 0 ) return 0;
else if( hyd_25[ player.Vehicle.ID ] == 0 ) return 0;

local veh = player.Vehicle,
low = veh.GetHandlingData( 20 ),
deflow = hyd_25[ veh.ID ];

if( low == ( deflow + hyd_mark ) )
{
veh.SetHandlingData( 20, hyd_top );
if( key == num8 || key == num5 ) return veh.ResetHandlingData( 6 );
else return veh.ResetHandlingData( 5 );
}
else
{
if( key == num8 || key == num5 ) return veh.ResetHandlingData( 6 );
else return veh.ResetHandlingData( 5 );
}
}
break;
}
[/spoiler]


PS: It could be a lot better/more real, but there is some bug happening due vc:mp or vc engine, so I couldn't use the method I've used in this video.
PS2: Not all vehicles will respond properly to this alternative, so be careful. Will try to find what's bothering other vehicles...
PS3: Because I was forced to use handling rule 24 instead of 25, vehicle can be more sensible when highered (after pressing shift). In order to remove the uppering, set hyd_top to 0 and that's it.

Sebastian

#1
UPDATE 2h later !
first topic updated
  • Replaced handling rule 24 with rule 20, because of the advantages
  • Cars now go more lowride when hydraulics are enabled!
  • Considerable less fragility for the cars, which improves a lot the gameplay!

This update requires a total "reinstalation" of the script, since many lines had to be edited.

Sebastian

#2
UPDATE 20mins later !
first topic updated
  • Anti-spam interval of time was decreased to 600 (from 800)
  • Shift key was attached to the numpads, in onKeyDown event
  • Checking if the player is the driver, as normal. Otherwise, there would be a chaos.

It is up to you if you update or not.
Thanks @Matheus for making me aware of the passengers' ability to play with hydraulics too!

MatheuS

Very good! I really liked the system, it looked like even GTA San Andreas.
Now I can make people have sex in the car on my RPG server.
if( !sucess ) tryAgain();
Thanks to the VCMP community. It was the happiest period of my life.

Sebastian

Quote from: MatheuS on Sep 26, 2019, 09:31 AMNow I can make people have sex in the car on my RPG server.

*cough* auto-car-bouncer *cough*
vehicle.SetHandlingData( 7, -1.5 );
LOOP PlaySound( vehicle.World, 338, vehicle.Pos );

MatheuS

Quote from: Sebastian on Sep 26, 2019, 09:55 AM
Quote from: MatheuS on Sep 26, 2019, 09:31 AMNow I can make people have sex in the car on my RPG server.

*cough* auto-car-bouncer *cough*
vehicle.SetHandlingData( 7, -1.5 );
LOOP PlaySound( vehicle.World, 338, vehicle.Pos );

if( !sucess ) tryAgain();
Thanks to the VCMP community. It was the happiest period of my life.

[TDA]Speed

if you got any error of these types AN ERROR HAS OCCURED [the index 'hyd_z' does not exist]
CALLSTACK
due to no arry name copy this and post in the top of main.nut
*fixed by Sebastian*

  hyd_top <- 2.4, // high level - actioned when pressing SHIFT - set 0 to remove the uppering (safer gameplay)
   hyd_z <- -0.1, // Centre of Mass Z
  hyd_zl <- 0.7, // Upper Limit variation -
  hyd_lean <- 1.4, // front lean
  hyd_oplean <- -1.4, // rear lean
  hyd_side <- 0.5, // right lean
  hyd_opside <- -0.5, // left lean
  hyd_mark <- -0.001, // trick
  hyd_25 <- array( 1000, 0 ), // had to do with the UpperLimit variation
  hyd_ticks <- array( 100, 0 ), // anti-spam of everyplayer
  hyd_tickslimit <- 600; // interval of time a player can bounce again (in miliseconds)