1
-
2
1
using CounterStrikeSharp . API ;
3
2
using CounterStrikeSharp . API . Core ;
4
3
using CounterStrikeSharp . API . Core . Translations ;
@@ -101,13 +100,6 @@ public void OnRankCommand(CCSPlayerController? player, CommandInfo info)
101
100
102
101
private void ProcessTargetAction ( CCSPlayerController ? player , CommandInfo info , Func < IPlayerServices , long ? , ( string message , string logMessage ) > action , bool requireAmount = true )
103
102
{
104
- TargetResult targets = info . GetArgTargetResult ( 1 ) ;
105
- if ( ! targets . Any ( ) )
106
- {
107
- _moduleServices ? . PrintForPlayer ( player , Localizer . ForPlayer ( player , "k4.phrases.no-target" ) ) ;
108
- return ;
109
- }
110
-
111
103
long ? amount = null ;
112
104
if ( requireAmount )
113
105
{
@@ -119,6 +111,13 @@ private void ProcessTargetAction(CCSPlayerController? player, CommandInfo info,
119
111
amount = parsedAmount ;
120
112
}
121
113
114
+ TargetResult targets = info . GetArgTargetResult ( 1 ) ;
115
+ if ( ! targets . Any ( ) )
116
+ {
117
+ _moduleServices ? . PrintForPlayer ( player , Localizer . ForPlayer ( player , "k4.phrases.no-target" ) ) ;
118
+ return ;
119
+ }
120
+
122
121
foreach ( var target in targets )
123
122
{
124
123
if ( _playerCache . TryGetValue ( target , out var zenithPlayer ) )
@@ -138,8 +137,55 @@ private void ProcessTargetAction(CCSPlayerController? player, CommandInfo info,
138
137
}
139
138
}
140
139
140
+ private void ProcessOfflineTargetAction ( ulong steamID , char operatation , long amount )
141
+ {
142
+ if ( _moduleServices == null )
143
+ return ;
144
+
145
+ Task . Run ( async ( ) =>
146
+ {
147
+ long points = await _moduleServices . GetOfflineData < long > ( steamID , "storage" , "Points" ) ;
148
+ switch ( operatation )
149
+ {
150
+ case '+' :
151
+ points += amount ;
152
+ break ;
153
+ case '-' :
154
+ points -= amount ;
155
+ break ;
156
+ case '=' :
157
+ points = amount ;
158
+ break ;
159
+ }
160
+
161
+ if ( points < 0 )
162
+ points = 0 ;
163
+
164
+ string rank = DetermineRanks ( points ) . CurrentRank ? . Name ?? "k4.phrases.rank.none" ;
165
+ await _moduleServices . SetOfflineData ( steamID , "storage" , new Dictionary < string , object ? > { { "Points" , points } , { "Rank" , rank } } ) ;
166
+ } ) ;
167
+ }
168
+
141
169
public void OnGivePoints ( CCSPlayerController ? player , CommandInfo info )
142
170
{
171
+ if ( ulong . TryParse ( info . GetArg ( 1 ) , out ulong steamId ) )
172
+ {
173
+ if ( ! int . TryParse ( info . GetArg ( 2 ) , out int amount ) || amount <= 0 )
174
+ {
175
+ _moduleServices ? . PrintForPlayer ( player , Localizer . ForPlayer ( player , "k4.phrases.invalid-amount" ) ) ;
176
+ return ;
177
+ }
178
+
179
+ var target = Utilities . GetPlayerFromSteamId ( steamId ) ;
180
+ if ( target == null )
181
+ {
182
+ ProcessOfflineTargetAction ( steamId , '+' , amount ) ;
183
+ Logger . LogWarning ( "{0} ({1}) gave {2} {3} rank points [OFFLINE]" ,
184
+ player ? . PlayerName ?? "CONSOLE" , player ? . SteamID ?? 0 , steamId , amount ) ;
185
+ return ;
186
+ }
187
+ }
188
+
143
189
ProcessTargetAction ( player , info ,
144
190
( zenithPlayer , amount ) =>
145
191
{
@@ -158,6 +204,24 @@ public void OnGivePoints(CCSPlayerController? player, CommandInfo info)
158
204
159
205
public void OnTakePoints ( CCSPlayerController ? player , CommandInfo info )
160
206
{
207
+ if ( ulong . TryParse ( info . GetArg ( 1 ) , out ulong steamId ) )
208
+ {
209
+ if ( ! int . TryParse ( info . GetArg ( 2 ) , out int amount ) || amount <= 0 )
210
+ {
211
+ _moduleServices ? . PrintForPlayer ( player , Localizer . ForPlayer ( player , "k4.phrases.invalid-amount" ) ) ;
212
+ return ;
213
+ }
214
+
215
+ var target = Utilities . GetPlayerFromSteamId ( steamId ) ;
216
+ if ( target == null )
217
+ {
218
+ ProcessOfflineTargetAction ( steamId , '-' , amount ) ;
219
+ Logger . LogWarning ( "{0} ({1}) took {2} rank points from {3} [OFFLINE]" ,
220
+ player ? . PlayerName ?? "CONSOLE" , player ? . SteamID ?? 0 , amount , steamId ) ;
221
+ return ;
222
+ }
223
+ }
224
+
161
225
ProcessTargetAction ( player , info ,
162
226
( zenithPlayer , amount ) =>
163
227
{
@@ -176,6 +240,24 @@ public void OnTakePoints(CCSPlayerController? player, CommandInfo info)
176
240
177
241
public void OnSetPoints ( CCSPlayerController ? player , CommandInfo info )
178
242
{
243
+ if ( ulong . TryParse ( info . GetArg ( 1 ) , out ulong steamId ) )
244
+ {
245
+ if ( ! int . TryParse ( info . GetArg ( 2 ) , out int amount ) || amount <= 0 )
246
+ {
247
+ _moduleServices ? . PrintForPlayer ( player , Localizer . ForPlayer ( player , "k4.phrases.invalid-amount" ) ) ;
248
+ return ;
249
+ }
250
+
251
+ var target = Utilities . GetPlayerFromSteamId ( steamId ) ;
252
+ if ( target == null )
253
+ {
254
+ ProcessOfflineTargetAction ( steamId , '=' , amount ) ;
255
+ Logger . LogWarning ( "{0} ({1}) set {2}'s rank points to {3} [OFFLINE]" ,
256
+ player ? . PlayerName ?? "CONSOLE" , player ? . SteamID ?? 0 , steamId , amount ) ;
257
+ return ;
258
+ }
259
+ }
260
+
179
261
ProcessTargetAction ( player , info ,
180
262
( zenithPlayer , amount ) =>
181
263
{
0 commit comments