Skip to content
Permalink
Browse files
Merge pull request #742 from LVPlayground/feature/gravityKey
add key to easily swap around gravity in the car
  • Loading branch information
OttoRocket-LVP committed Jun 22, 2020
2 parents 40010bd + 79efe6a commit 8b6424f35412c3a6cd5312b1372e91060fd9fc66
Showing 6 changed files with 53 additions and 0 deletions.
@@ -61,6 +61,9 @@ export class Player extends Supplementable {
// https://wiki.sa-mp.com/wroot/index.php?title=SetPlayerTeam
static kNoTeam = 255;

// Default gravity value
static kDefaultGravity = 0.008;

// Constants applicable to the `Player.specialAction` property.
static kSpecialActionNone = 0;
static kSpecialActionCrouching = 1; // read-only
@@ -26,6 +26,7 @@ export class Vehicle extends Supplementable {
static kVehicleKeysNos = 32;
static kVehicleKeysBlinkerRight = 64;
static kVehicleKeysBlinkerLeft = 128;
static kVehicleKeysGravity = 256;

// Constants that indicate the seat a player is occupying in the vehicle. Values above 1 are
// possible. They indicate passenger seats in the rear seat or further beyond. (E.g. for a bus.)
@@ -0,0 +1,34 @@
// Copyright 2020 Las Venturas Playground. All rights reserved.
// Use of this source code is governed by the MIT license, a copy of which can
// be found in the LICENSE file.

import Command from 'features/playground/command.js';
import { CommandBuilder } from 'components/command_manager/command_builder.js';

// Command: /gravitykey [player]
export default class GravityKeyCommand extends Command {
get name() { return 'gravitykey'; }
get defaultPlayerLevel() { return Player.LEVEL_MANAGEMENT; }

build(commandBuilder) {
commandBuilder
.parameters([{ name: 'target', type: CommandBuilder.PLAYER_PARAMETER, optional: true }])
.build(GravityKeyCommand.prototype.onGravityKeyCommand.bind(this));
}

// Turn on or off the ability to use indicators.
async onGravityKeyCommand(player, target) {
const subject = target || player;

if (subject.syncedData.vehicleKeys & Vehicle.kVehicleKeysGravity) {
subject.syncedData.vehicleKeys &= ~ Vehicle.kVehicleKeysGravity;
subject.gravity = Player.kDefaultGravity;

player.sendMessage(Message.COMMAND_SUCCESS, subject.name + ' can\'t switch gravity anymore.');
return;
}

subject.syncedData.vehicleKeys |= Vehicle.kVehicleKeysGravity;
player.sendMessage(Message.COMMAND_SUCCESS, subject.name + ' will now able to switch gravity.');
}
}
@@ -74,6 +74,7 @@ class PlaygroundCommands {
'features/playground/commands/fancy.js',
'features/playground/commands/flap.js',
'features/playground/commands/fly.js',
'features/playground/commands/gravity_key.js',
'features/playground/commands/indicators.js',
'features/playground/commands/jetpack.js',
'features/playground/commands/kickflip.js',
@@ -22,6 +22,7 @@ native ReportTrailerUpdate(vehicleid, trailerid);
#define VEHICLE_KEYS_BINDING_NOS KEY_FIRE
#define VEHICLE_KEYS_BINDING_BLINKER_RIGHT KEY_LOOK_RIGHT
#define VEHICLE_KEYS_BINDING_BLINKER_LEFT KEY_LOOK_LEFT
#define VEHICLE_KEYS_BINDING_GRAVITY KEY_ANALOG_UP

// Number of milliseconds a player has to be spraying in order to collect a spray tag.
new const kSprayTagTimeMs = 2000;
@@ -53,6 +54,9 @@ new g_vehicleTrailerId[MAX_VEHICLES];
// The four blinker objects for the player. 0/1 = RIGHT 2/3 = LEFT
new DynamicObject: g_blinkerObjects[MAX_PLAYERS][4];

// The current player gravity (positive or negative)
new Float: g_playerGravity[MAX_PLAYERS];

// Returns whether the given |modelId| is a remote controllable vehicle.
IsModelRemoteControlVehicle(modelId) {
switch (modelId) {
@@ -91,6 +95,7 @@ public OnPlayerConnect(playerid) {
g_lastTakenDamageIssuerId[playerid] = -1;
g_lastTakenDamageTime[playerid] = 0;
g_sprayTagStartTime[playerid] = 0;
g_playerGravity[playerid] = 0.008;
g_isDisconnecting[playerid] = false;

// Proceed with legacy processing.
@@ -281,6 +286,7 @@ public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
AddVehicleComponent(vehicleId, 1010);
}

// Vehicle keys (7): Blinkers
new const bool: pressedBlinkerRight =
PRESSED(VEHICLE_KEYS_BINDING_BLINKER_RIGHT) && vehicleKeys & VEHICLE_KEYS_BLINKER_RIGHT;
new const bool: pressedBlinkerLeft =
@@ -295,6 +301,12 @@ public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {

SetBlinker(playerid, vehicleId, leftBlinker, rightBlinker);
}

// Vehicle keys (8): Gravity
if(PRESSED(VEHICLE_KEYS_BINDING_GRAVITY) && vehicleKeys & VEHICLE_KEYS_GRAVITY) {
g_playerGravity[playerid] *= -1;
SetPlayerGravity(playerid, g_playerGravity[playerid]);
}
}

LegacyPlayerKeyStateChange(playerid, newkeys, oldkeys);
@@ -44,9 +44,11 @@ native ReportPlayerTeleport(playerId, timeLimited);
#define VEHICLE_KEYS_NOS 32
#define VEHICLE_KEYS_BLINKER_RIGHT 64
#define VEHICLE_KEYS_BLINKER_LEFT 128
#define VEHICLE_KEYS_GRAVITY 256

native IsCommunicationMuted();
native bool: SpawnPlayerInHouse(playerId);
native SetPlayerGravity(playerid, Float:value);

// -------------------------------------------------------------------------------------------------
// We override the GivePlayerMoney native as it's used to record intentional changes in a player's

0 comments on commit 8b6424f

Please sign in to comment.