Skip to content

Commit

Permalink
Merge pull request #742 from LVPlayground/feature/gravityKey
Browse files Browse the repository at this point in the history
add key to easily swap around gravity in the car
  • Loading branch information
OttoRocket-LVP authored Jun 22, 2020
2 parents 40010bd + 79efe6a commit 8b6424f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions javascript/entities/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions javascript/entities/vehicle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
34 changes: 34 additions & 0 deletions javascript/features/playground/commands/gravity_key.js
Original file line number Diff line number Diff line change
@@ -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.');
}
}
1 change: 1 addition & 0 deletions javascript/features/playground/playground_commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
12 changes: 12 additions & 0 deletions pawn/Driver/Driver.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 =
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions pawn/Interface/Server.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b6424f

Please sign in to comment.