Skip to content

Commit 5f1adb9

Browse files
remove * from valid options for PlayersArgument, update example scripts
1 parent c0d1c9e commit 5f1adb9

8 files changed

Lines changed: 40 additions & 40 deletions

File tree

Code/ArgumentSystem/Arguments/PlayersArgument.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public class PlayersArgument(string name) : EnumHandlingArgument(name)
1616
$"Player variable (e.g. {PlayerVariableToken.Example}), " +
1717
$"RoleTypeId enum (e.g. ClassD), " +
1818
$"Team enum (e.g. SCPs), " +
19-
$"player id's or name, " +
20-
$"or * for every player";
19+
$"player id's or name";
2120

2221
[UsedImplicitly]
2322
public DynamicTryGet<Player[]> GetConvertSolution(BaseToken token)
@@ -32,11 +31,6 @@ public DynamicTryGet<Player[]> GetConvertSolution(BaseToken token)
3231
},
3332
() =>
3433
{
35-
if (token is SymbolToken { IsJoker: true })
36-
{
37-
return new(() => Player.ReadyList.ToArray());
38-
}
39-
4034
if (!token.CanReturn<PlayerValue>(out var get))
4135
{
4236
return $"{token} does not represent a " +

Code/MethodSystem/Methods/PlayerDataMethods/GetPlayerDataMethod.cs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,47 @@ public class GetPlayerDataMethod : ReturningMethod, IAdditionalDescription, ICan
1313
public override string Description => "Gets player data from the key.";
1414

1515
public string AdditionalDescription =>
16-
"WARNING: This method will error if the key doesn't exist. " +
17-
$"Use {NameOfMethod(typeof(HasPlayerDataMethod))} to verify if a key exists before calling this method.";
16+
"It's recommended to set 'default value' argument for you to not get errors when the key doesn't exist " +
17+
"for a given player!";
1818

1919
public override TypeOfValue Returns => new UnknownTypeOfValue();
2020

2121
public string[] ErrorReasons { get; } =
2222
[
23-
"Key was not found for the player."
23+
"Key %key% was not found for the player %player_name%."
2424
];
2525

2626
public override Argument[] ExpectedArguments { get; } =
2727
[
2828
new PlayerArgument("player"),
29-
new TextArgument("key")
29+
new TextArgument("key"),
30+
new AnyValueArgument("default value")
31+
{
32+
Description = "If the key doesn't exist, this value will be returned.",
33+
DefaultValue = new(null, "no default value - will error when key doesnt exist")
34+
}
3035
];
3136

3237
public override void Execute()
3338
{
3439
var player = Args.GetPlayer("player");
3540
var key = Args.GetText("key");
3641

37-
if (!SetPlayerDataMethod.PlayerData.TryGetValue(player, out var dict) ||
38-
!dict.TryGetValue(key, out var value))
42+
if (SetPlayerDataMethod.PlayerData.TryGetValue(player, out var dict) &&
43+
dict.TryGetValue(key, out var value))
3944
{
40-
throw new ScriptRuntimeError(this, ErrorReasons[0]);
45+
ReturnValue = value;
46+
}
47+
else if (Args.GetAnyValue("default value") is { } defaultValue)
48+
{
49+
ReturnValue = defaultValue;
50+
}
51+
else
52+
{
53+
throw new ScriptRuntimeError(
54+
this,
55+
ErrorReasons[0].Replace("%key%", key).Replace("%player_name%", player.Nickname)
56+
);
4157
}
42-
43-
ReturnValue = value;
4458
}
4559
}

Example Scripts/chaosCoin.ser

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ if $effect is 3
4747
*room = @evPlayer -> roomRef
4848

4949
# explode player if he isnt in a room
50-
if *room is invalid
50+
if {*room -> isInvalid}
5151
Explode @evPlayer
5252
stop
5353
end
@@ -171,7 +171,7 @@ if $effect is 9
171171
end
172172

173173
# gets a random player that is not @evPlayer
174-
@swapPlayer = Take {Except * @evPlayer} 1
174+
@swapPlayer = Take {Except @all @evPlayer} 1
175175
$swapX = @swapPlayer -> posX
176176
$swapY = @swapPlayer -> posY
177177
$swapZ = @swapPlayer -> posZ

Example Scripts/custom roles/seniorGuardOnSpawned.ser

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
-- forRoles senior_guard
33

44
ClearInventory @evPlayer
5+
GiveItem @evPlayer GunFSP9
56
GiveItem @evPlayer KeycardMTFPrivate
6-
GiveItem @evPlayer Radio
77
GiveItem @evPlayer Medkit
88
GiveItem @evPlayer GrenadeHE
9-
GiveItem @evPlayer Ammo9x19 3
9+
GiveItem @evPlayer Radio
1010
GiveItem @evPlayer ArmorCombat
11-
GiveItem @evPlayer GunFSP9
11+
GiveItem @evPlayer Ammo9x19 3

Example Scripts/killStreak.ser

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ if {VarExists @evAttacker} is false
1111
end
1212

1313
# increment killer's streak
14-
$streak = GetPlayerData @evAttacker "streak"
15-
16-
if $streak isnt invalid
17-
$streak = $streak + 1
18-
else
19-
$streak = 1
20-
end
14+
$streak = GetPlayerData @evAttacker "streak" 0
15+
$streak = $streak + 1
2116

2217
# save the new kill streak
2318
SetPlayerData @evAttacker "streak" $streak

Example Scripts/surfaceSmite.ser

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
-- availableFor RemoteAdmin
33
-- description "Kills a random player currently in the Surface Zone."
44

5-
Countdown * 10s "A random person on surface is going to be killed in %seconds% seconds!"
5+
Countdown @all 10s "A random person on surface is going to be killed in %seconds% seconds!"
66
wait 11s
77

88
# 1. Get all players on the surface and limit the selection to 1 random person.
99
@target = Take @surfacePlayers 1
1010

1111
# 2. Check if anyone was actually found to avoid a runtime error.
1212
if {AmountOf @target} isnt 1
13-
Broadcast * 5s "No players found in the Surface Zone!"
13+
Broadcast @all 5s "No players found in the Surface Zone!"
1414
stop
1515
end
1616

1717
# 3. Execute the kill with a custom reason.
1818
Kill @target "The surface is no longer safe."
19-
Broadcast * 5s "Eliminated {@target -> name} from the surface."
19+
Broadcast @all 5s "Eliminated {@target -> name} from the surface."

Example Scripts/zombie infection/onZombieBit.ser

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ if {Chance 50%}
2222
stop
2323
end
2424

25-
*date = GetPlayerData @victim date_of_death_by_infection
26-
27-
if *date is invalid
25+
if {HasPlayerData @victim date_of_death_by_infection} is false
2826
# set the date of death to 1 minute in the future
2927
*date = Date.Offset {Date.Current} add 1m
3028
else
3129
# when was bit before, remove 20 seconds from the date
3230
# so the infection happens faster
31+
*date = GetPlayerData @victim date_of_death_by_infection
3332
*date = Date.Offset *date subtract 20s
3433
end
3534

Example Scripts/zombie infection/zombieInfectionHandler.ser

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ forever
99
over @all with @plr
1010
wait 1ms
1111

12-
*dateOfDeath = GetPlayerData @plr date_of_death_by_infection
13-
14-
# invalid -> infection date not set -> not infected
15-
if *dateOfDeath is invalid
12+
# infection date not set -> not infected
13+
if {HasPlayerData @plr date_of_death_by_infection} is false
1614
continue
1715
end
18-
16+
1917
# if the current date is "lower" than the date of death
2018
# it means that the player is not fully infected
21-
if {Date.Current} < *dateOfDeath
19+
if {Date.Current} < {GetPlayerData @plr date_of_death_by_infection}
2220
continue
2321
end
2422

0 commit comments

Comments
 (0)