Skip to content

Commit 4e677b9

Browse files
committed
Move "/p freeze" and "/p unfreeze" to JavaScript
1 parent 5084b19 commit 4e677b9

5 files changed

Lines changed: 161 additions & 25 deletions

File tree

data/messages.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,11 @@
490490
"PLAYER_COMMANDS_ARMOR_UPDATED_OTHER": "@success %s (Id:%d)'s armor has been updated to %d.",
491491
"PLAYER_COMMANDS_ARMOR_UPDATED_SELF_ADMIN": "%s (Id:%d) has updated their armor to %d.",
492492
"PLAYER_COMMANDS_ARMOR_UPDATED_SELF": "@success Your armor has been updated to %d.",
493+
"PLAYER_COMMANDS_FREEZE_FYI": "{33AA33}FYI{FFFFFF}: %s (Id:%d) has frozen you.",
494+
"PLAYER_COMMANDS_FREEZE_OTHER_ADMIN": "%s (Id:%d) has frozen %s (Id:%d).",
495+
"PLAYER_COMMANDS_FREEZE_OTHER": "@success %s (Id:%d) has been frozen.",
496+
"PLAYER_COMMANDS_FREEZE_SELF_ADMIN": "%s (Id:%d) has frozen themselves.",
497+
"PLAYER_COMMANDS_FREEZE_SELF": "@success You have been frozen.",
493498
"PLAYER_COMMANDS_HEALTH_STATUS_OTHER": "@usage /p [player] health [0-100]. %s (Id:%d)'s health currently is %.0f.",
494499
"PLAYER_COMMANDS_HEALTH_STATUS_SELF": "@usage /my health [0-100]. Your health currently is %.0f.",
495500
"PLAYER_COMMANDS_HEALTH_UPDATED_OTHER_ADMIN": "%s (Id:%d) has updated %s (Id:%d)'s health to %d.",
@@ -513,6 +518,11 @@
513518
"PLAYER_COMMANDS_SPAWN_WEAPONS_TELEPORT_TARGET" : "@error Sorry, the player can't get weapons now because %s %s.",
514519
"PLAYER_COMMANDS_SPAWN_WEAPONS_WEAPON": "@success %s with ammo multiplier '%d' has been bought.",
515520
"PLAYER_COMMANDS_REQUIRES_VIP": "@error Sorry, this command is only available for VIPs. Check out /vip!",
521+
"PLAYER_COMMANDS_UNFREEZE_FYI": "{33AA33}FYI{FFFFFF}: %s (Id:%d) has unfrozen you.",
522+
"PLAYER_COMMANDS_UNFREEZE_OTHER_ADMIN": "%s (Id:%d) has unfrozen %s (Id:%d).",
523+
"PLAYER_COMMANDS_UNFREEZE_OTHER": "@success %s (Id:%d) has been unfrozen.",
524+
"PLAYER_COMMANDS_UNFREEZE_SELF_ADMIN": "%s (Id:%d) has unfrozen themselves.",
525+
"PLAYER_COMMANDS_UNFREEZE_SELF": "@success You have been frozen.",
516526

517527
"POSITIONING_CURRENT_POSITION": "Your current position is X: %d, Y: %d Z: %d, Rotation: %d",
518528
"POSITIONING_OTHER_USAGE_POS": "{FF9900}Other usage{FFFFFF}: /pos [x] [y] [z]",

javascript/entities/test/mock_player.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class MockPlayer extends Player {
3737

3838
#color_ = Color.WHITE;
3939
#colorOverrides_ = new Map();
40+
#controllable_ = true;
4041
#health_ = 100.0;
4142
#armour_ = 0.0;
4243
#skin_ = 308; // San Fierro Paramedic (EMT)
@@ -213,7 +214,9 @@ export class MockPlayer extends Player {
213214
set rawColor(value) { this.#color_ = value; this.#colorOverrides_.clear(); }
214215

215216
get controllable() { throw new Error('Unable to get whether the player is controllable.'); }
216-
set controllable(value) { /* no need to mock write-only values */ }
217+
set controllable(value) { this.#controllable_ = value; }
218+
219+
get controllableForTesting() { return this.#controllable_; }
217220

218221
get health() { return this.#health_; }
219222
set health(value) { this.#health_ = value; }
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2020 Las Venturas Playground. All rights reserved.
2+
// Use of this source code is governed by the MIT license, a copy of which can
3+
// be found in the LICENSE file.
4+
5+
import { PlayerCommand } from 'features/player_commands/player_command.js';
6+
7+
// Implements the "/my freeze" and "/p [player] freeze" commands, which makes it possible to freeze
8+
// a particular player. This action will be relayed to the player directly.
9+
export class FreezeCommand extends PlayerCommand {
10+
get name() { return 'freeze'; }
11+
12+
// This command is not available to all players, only to administrators.
13+
get playerLevel() { return Player.LEVEL_ADMINISTRATOR; }
14+
15+
// Called when a player executes the command. Will immediately freeze the |target|, and let them
16+
// know about the adminstrative action being taken on them.
17+
async execute(player, target) {
18+
target.controllable = false;
19+
20+
if (player === target) {
21+
this.announce().announceToAdministrators(
22+
Message.PLAYER_COMMANDS_FREEZE_SELF_ADMIN, player.name, player.id);
23+
24+
player.sendMessage(Message.PLAYER_COMMANDS_FREEZE_SELF);
25+
26+
} else {
27+
this.announce().announceToAdministrators(
28+
Message.PLAYER_COMMANDS_FREEZE_OTHER_ADMIN, player.name, player.id, target.name,
29+
target.id);
30+
31+
player.sendMessage(Message.PLAYER_COMMANDS_FREEZE_OTHER, target.name, target.id);
32+
target.sendMessage(Message.PLAYER_COMMANDS_FREEZE_FYI, player.name, player.id);
33+
}
34+
}
35+
}
36+
37+
// Implements the "/my unfreeze" and "/p [player] unfreeze" commands, which do the reverse of the
38+
// freeze command: it makes it possible for the player to move around again.
39+
export class UnfreezeCommand extends PlayerCommand {
40+
get name() { return 'unfreeze'; }
41+
42+
// This command is not available to all players, only to administrators.
43+
get playerLevel() { return Player.LEVEL_ADMINISTRATOR; }
44+
45+
// Called when a player executes the command. Will immediately release the given |target|.
46+
async execute(player, target) {
47+
target.controllable = true;
48+
49+
if (player === target) {
50+
this.announce().announceToAdministrators(
51+
Message.PLAYER_COMMANDS_UNFREEZE_SELF_ADMIN, player.name, player.id);
52+
53+
player.sendMessage(Message.PLAYER_COMMANDS_UNFREEZE_SELF);
54+
55+
} else {
56+
this.announce().announceToAdministrators(
57+
Message.PLAYER_COMMANDS_UNFREEZE_OTHER_ADMIN, player.name, player.id, target.name,
58+
target.id);
59+
60+
player.sendMessage(Message.PLAYER_COMMANDS_UNFREEZE_OTHER, target.name, target.id);
61+
target.sendMessage(Message.PLAYER_COMMANDS_UNFREEZE_FYI, player.name, player.id);
62+
}
63+
}
64+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright 2020 Las Venturas Playground. All rights reserved.
2+
// Use of this source code is governed by the MIT license, a copy of which can
3+
// be found in the LICENSE file.
4+
5+
describe('FreezeCommand', (it, beforeEach) => {
6+
let gunther = null;
7+
let russell = null;
8+
9+
beforeEach(async () => {
10+
const feature = server.featureManager.loadFeature('player_commands');
11+
12+
gunther = server.playerManager.getById(/* Gunther= */ 0);
13+
russell = server.playerManager.getById(/* Russell= */ 1);
14+
russell.level = Player.LEVEL_ADMINISTRATOR;
15+
16+
await feature.registry_.initialize();
17+
await russell.identify();
18+
});
19+
20+
it('should enable administrators to freeze and unfreeze players', async (assert) => {
21+
assert.isTrue(gunther.controllableForTesting);
22+
assert.isTrue(russell.controllableForTesting);
23+
24+
// (1) Russell has the ability to freeze Gunther.
25+
assert.isTrue(await russell.issueCommand('/p gunt freeze'));
26+
assert.isFalse(gunther.controllableForTesting);
27+
28+
assert.equal(russell.messages.length, 2);
29+
assert.includes(
30+
russell.messages[0],
31+
Message.format(Message.PLAYER_COMMANDS_FREEZE_OTHER_ADMIN, russell.name, russell.id,
32+
gunther.name, gunther.id));
33+
34+
assert.equal(
35+
russell.messages[1],
36+
Message.format(Message.PLAYER_COMMANDS_FREEZE_OTHER, gunther.name, gunther.id));
37+
38+
assert.equal(gunther.messages.length, 1);
39+
assert.equal(
40+
gunther.messages[0],
41+
Message.format(Message.PLAYER_COMMANDS_FREEZE_FYI, russell.name, russell.id));
42+
43+
// (2) Russell has the ability to unfreeze Gunther.
44+
assert.isTrue(await russell.issueCommand('/p gunt unfreeze'));
45+
assert.isTrue(gunther.controllableForTesting);
46+
47+
assert.equal(russell.messages.length, 4);
48+
assert.includes(
49+
russell.messages[2],
50+
Message.format(Message.PLAYER_COMMANDS_UNFREEZE_OTHER_ADMIN, russell.name, russell.id,
51+
gunther.name, gunther.id));
52+
53+
assert.equal(
54+
russell.messages[3],
55+
Message.format(Message.PLAYER_COMMANDS_UNFREEZE_OTHER, gunther.name, gunther.id));
56+
57+
assert.equal(gunther.messages.length, 2);
58+
assert.equal(
59+
gunther.messages[1],
60+
Message.format(Message.PLAYER_COMMANDS_UNFREEZE_FYI, russell.name, russell.id));
61+
62+
// (3) Russell has the ability to freeze and unfreeze themselves.
63+
assert.isTrue(await russell.issueCommand('/my freeze'));
64+
assert.isFalse(russell.controllableForTesting);
65+
66+
assert.equal(russell.messages.length, 6);
67+
assert.includes(
68+
russell.messages[4],
69+
Message.format(Message.PLAYER_COMMANDS_FREEZE_SELF_ADMIN, russell.name, russell.id));
70+
71+
assert.equal(russell.messages[5], Message.PLAYER_COMMANDS_FREEZE_SELF);
72+
73+
assert.isTrue(await russell.issueCommand('/my unfreeze'));
74+
assert.isTrue(russell.controllableForTesting);
75+
76+
assert.equal(russell.messages.length, 8);
77+
assert.includes(
78+
russell.messages[6],
79+
Message.format(Message.PLAYER_COMMANDS_UNFREEZE_SELF_ADMIN, russell.name, russell.id));
80+
81+
assert.equal(russell.messages[7], Message.PLAYER_COMMANDS_UNFREEZE_SELF);
82+
});
83+
});

pawn/Elements/AdministratorCommands.pwn

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -499,30 +499,6 @@ lvp_p(playerId, params[]) {
499499
return 1;
500500
}
501501

502-
if (!strcmp(playerParameter, "freeze", true, 6)) {
503-
TogglePlayerControllable(subjectId, 0);
504-
505-
SendClientMessage(playerId, Color::Success, "Player frozen.");
506-
507-
format(g_message, sizeof(g_message), "%s (Id:%d) has frozen %s (Id:%d).",
508-
Player(playerId)->nicknameString(), playerId, Player(subjectId)->nicknameString(), subjectId);
509-
Admin(playerId, g_message);
510-
511-
return 1;
512-
}
513-
514-
if (!strcmp(playerParameter, "unfreeze", true, 8)) {
515-
TogglePlayerControllable(subjectId, 1);
516-
517-
SendClientMessage(playerId, Color::Success, "Player unfrozen.");
518-
519-
format(g_message, sizeof(g_message), "%s (Id:%d) has unfrozen %s (Id:%d).",
520-
Player(playerId)->nicknameString(), playerId, Player(subjectId)->nicknameString(), subjectId);
521-
Admin(playerId, g_message);
522-
523-
return 1;
524-
}
525-
526502
if (!strcmp(playerParameter, "weapon", true, 6) && Player(playerId)->isAdministrator() == true) {
527503
new weaponId = Command->integerParameter(params, 2);
528504
if (WeaponUtilities->isWeaponValid(weaponId) == false) {

0 commit comments

Comments
 (0)