@@ -47,7 +47,7 @@ public void PlayerGoToStage(CCSPlayerController? player, CommandInfo command)
4747 return ;
4848
4949 int stage = Int32 . Parse ( command . ArgByIndex ( 1 ) ) - 1 ;
50- if ( stage > CurrentMap . Stages - 1 )
50+ if ( stage > CurrentMap . Stages - 1 && CurrentMap . Stages > 0 )
5151 stage = CurrentMap . Stages - 1 ;
5252
5353 // Must be 1 argument
@@ -84,7 +84,6 @@ public void PlayerGoToStage(CCSPlayerController? player, CommandInfo command)
8484 player . PrintToChat ( $ "{ PluginPrefix } { ChatColors . Red } Invalid stage provided. Usage: { ChatColors . Green } !s <stage>") ;
8585 }
8686
87- // Test command
8887 [ ConsoleCommand ( "css_spec" , "Moves a player automaticlly into spectator mode" ) ]
8988 public void MovePlayerToSpectator ( CCSPlayerController ? player , CommandInfo command )
9089 {
@@ -94,31 +93,210 @@ public void MovePlayerToSpectator(CCSPlayerController? player, CommandInfo comma
9493 player . ChangeTeam ( CsTeam . Spectator ) ;
9594 }
9695
96+ /*
97+ #########################
98+ Reaplay Commands
99+ #########################
100+ */
97101 [ ConsoleCommand ( "css_replaybotpause" , "Pause the replay bot playback" ) ]
98102 [ ConsoleCommand ( "css_rbpause" , "Pause the replay bot playback" ) ]
99103 public void PauseReplay ( CCSPlayerController ? player , CommandInfo command )
100104 {
101- if ( player == null
102- || player . Team != CsTeam . Spectator
103- || CurrentMap . ReplayBot . Controller == null
104- || ! CurrentMap . ReplayBot . IsPlaying
105- || CurrentMap . ReplayBot . Controller . Pawn . SerialNum != player . ObserverPawn . Value ! . ObserverServices ! . ObserverTarget . SerialNum )
105+ if ( player == null || player . Team != CsTeam . Spectator )
106106 return ;
107107
108- CurrentMap . ReplayBot . Pause ( ) ;
108+ foreach ( ReplayPlayer rb in CurrentMap . ReplayBots )
109+ {
110+ if ( ! rb . IsPlayable || ! rb . IsPlaying || ! playerList [ player . UserId ?? 0 ] . IsSpectating ( rb . Controller ! ) )
111+ continue ;
112+
113+ rb . Pause ( ) ;
114+ }
109115 }
110116
111117 [ ConsoleCommand ( "css_replaybotflip" , "Flips the replay bot between Forward/Backward playback" ) ]
112118 [ ConsoleCommand ( "css_rbflip" , "Flips the replay bot between Forward/Backward playback" ) ]
113119 public void ReverseReplay ( CCSPlayerController ? player , CommandInfo command )
114120 {
115- if ( player == null
116- || player . Team != CsTeam . Spectator
117- || CurrentMap . ReplayBot . Controller == null
118- || ! CurrentMap . ReplayBot . IsPlaying
119- || CurrentMap . ReplayBot . Controller . Pawn . SerialNum != player . ObserverPawn . Value ! . ObserverServices ! . ObserverTarget . SerialNum )
121+ if ( player == null || player . Team != CsTeam . Spectator )
122+ return ;
123+
124+ foreach ( ReplayPlayer rb in CurrentMap . ReplayBots )
125+ {
126+ if ( ! rb . IsPlayable || ! rb . IsPlaying || ! playerList [ player . UserId ?? 0 ] . IsSpectating ( rb . Controller ! ) )
127+ continue ;
128+
129+ rb . FrameTickIncrement *= - 1 ;
130+ }
131+ }
132+
133+ [ ConsoleCommand ( "css_pbreplay" , "Allows for replay of player's PB" ) ]
134+ public void PbReplay ( CCSPlayerController ? player , CommandInfo command )
135+ {
136+ if ( player == null )
137+ return ;
138+
139+ int maptime_id = playerList [ player ! . UserId ?? 0 ] . Stats . PB [ playerList [ player . UserId ?? 0 ] . Timer . Style ] . ID ;
140+ if ( command . ArgCount > 1 )
141+ {
142+ try
143+ {
144+ maptime_id = int . Parse ( command . ArgByIndex ( 1 ) ) ;
145+ }
146+ catch { }
147+ }
148+
149+ if ( maptime_id == - 1 || ! CurrentMap . ConnectedMapTimes . Contains ( maptime_id ) )
150+ {
151+ player . PrintToChat ( $ "{ PluginPrefix } { ChatColors . Red } No time was found") ;
152+ return ;
153+ }
154+
155+ for ( int i = 0 ; i < CurrentMap . ReplayBots . Count ; i ++ )
156+ {
157+ if ( CurrentMap . ReplayBots [ i ] . Stat_MapTimeID == maptime_id )
158+ {
159+ player . PrintToChat ( $ "{ PluginPrefix } { ChatColors . Red } A bot of this run already playing") ;
160+ return ;
161+ }
162+ }
163+
164+ CurrentMap . ReplayBots = CurrentMap . ReplayBots . Prepend ( new ReplayPlayer ( ) {
165+ Stat_MapTimeID = maptime_id ,
166+ Stat_Prefix = "PB"
167+ } ) . ToList ( ) ;
168+
169+ Server . NextFrame ( ( ) => {
170+ Server . ExecuteCommand ( $ "bot_quota { CurrentMap . ReplayBots . Count } ") ;
171+ } ) ;
172+ }
173+
174+ /*
175+ ########################
176+ Saveloc Commands
177+ ########################
178+ */
179+ [ ConsoleCommand ( "css_saveloc" , "Save current player location to be practiced" ) ]
180+ public void SavePlayerLocation ( CCSPlayerController ? player , CommandInfo command )
181+ {
182+ if ( player == null || ! player . PawnIsAlive || ! playerList . ContainsKey ( player . UserId ?? 0 ) )
183+ return ;
184+
185+ Player p = playerList [ player . UserId ?? 0 ] ;
186+ if ( ! p . Timer . IsRunning )
187+ {
188+ p . Controller . PrintToChat ( $ "{ PluginPrefix } { ChatColors . Red } Cannot save location while not in run") ;
189+ return ;
190+ }
191+
192+ var player_pos = p . Controller . Pawn . Value ! . AbsOrigin ! ;
193+ var player_angle = p . Controller . PlayerPawn . Value ! . EyeAngles ;
194+ var player_velocity = p . Controller . PlayerPawn . Value ! . AbsVelocity ;
195+
196+ p . SavedLocations . Add ( new SavelocFrame {
197+ Pos = new Vector ( player_pos . X , player_pos . Y , player_pos . Z ) ,
198+ Ang = new QAngle ( player_angle . X , player_angle . Y , player_angle . Z ) ,
199+ Vel = new Vector ( player_velocity . X , player_velocity . Y , player_velocity . Z ) ,
200+ Tick = p . Timer . Ticks
201+ } ) ;
202+ p . CurrentSavedLocation = p . SavedLocations . Count - 1 ;
203+
204+ p . Controller . PrintToChat ( $ "{ PluginPrefix } { ChatColors . Green } Saved location! { ChatColors . Default } use !tele { p . SavedLocations . Count - 1 } to teleport to this location") ;
205+ }
206+
207+ [ ConsoleCommand ( "css_tele" , "Teleport player to current saved location" ) ]
208+ public void TeleportPlayerLocation ( CCSPlayerController ? player , CommandInfo command )
209+ {
210+ if ( player == null || ! player . PawnIsAlive || ! playerList . ContainsKey ( player . UserId ?? 0 ) )
120211 return ;
121212
122- CurrentMap . ReplayBot . FrameTickIncrement *= - 1 ;
213+ Player p = playerList [ player . UserId ?? 0 ] ;
214+
215+ if ( p . SavedLocations . Count == 0 )
216+ {
217+ p . Controller . PrintToChat ( $ "{ PluginPrefix } { ChatColors . Red } No saved locations") ;
218+ return ;
219+ }
220+
221+ if ( ! p . Timer . IsRunning )
222+ p . Timer . Start ( ) ;
223+
224+ if ( ! p . Timer . IsPracticeMode )
225+ {
226+ p . Controller . PrintToChat ( $ "{ PluginPrefix } { ChatColors . Red } Timer now on practice") ;
227+ p . Timer . IsPracticeMode = true ;
228+ }
229+
230+ if ( command . ArgCount > 1 )
231+ try
232+ {
233+ int tele_n = int . Parse ( command . ArgByIndex ( 1 ) ) ;
234+ if ( tele_n < p . SavedLocations . Count )
235+ p . CurrentSavedLocation = tele_n ;
236+ }
237+ catch { }
238+ SavelocFrame location = p . SavedLocations [ p . CurrentSavedLocation ] ;
239+ Server . NextFrame ( ( ) => {
240+ p . Controller . PlayerPawn . Value ! . Teleport ( location . Pos , location . Ang , location . Vel ) ;
241+ p . Timer . Ticks = location . Tick ;
242+ } ) ;
243+
244+ p . Controller . PrintToChat ( $ "{ PluginPrefix } Teleported #{ p . CurrentSavedLocation } ") ;
245+ }
246+
247+ [ ConsoleCommand ( "css_teleprev" , "Teleport player to previous saved location" ) ]
248+ public void TeleportPlayerLocationPrev ( CCSPlayerController ? player , CommandInfo command )
249+ {
250+ if ( player == null || ! player . PawnIsAlive || ! playerList . ContainsKey ( player . UserId ?? 0 ) )
251+ return ;
252+
253+ Player p = playerList [ player . UserId ?? 0 ] ;
254+
255+ if ( p . SavedLocations . Count == 0 )
256+ {
257+ p . Controller . PrintToChat ( $ "{ PluginPrefix } { ChatColors . Red } No saved locations") ;
258+ return ;
259+ }
260+
261+ if ( p . CurrentSavedLocation == 0 )
262+ {
263+ p . Controller . PrintToChat ( $ "{ PluginPrefix } { ChatColors . Red } Already at first location") ;
264+ }
265+ else
266+ {
267+ p . CurrentSavedLocation -- ;
268+ }
269+
270+ TeleportPlayerLocation ( player , command ) ;
271+
272+ p . Controller . PrintToChat ( $ "{ PluginPrefix } Teleported #{ p . CurrentSavedLocation } ") ;
273+ }
274+
275+ [ ConsoleCommand ( "css_telenext" , "Teleport player to next saved location" ) ]
276+ public void TeleportPlayerLocationNext ( CCSPlayerController ? player , CommandInfo command )
277+ {
278+ if ( player == null || ! player . PawnIsAlive || ! playerList . ContainsKey ( player . UserId ?? 0 ) )
279+ return ;
280+
281+ Player p = playerList [ player . UserId ?? 0 ] ;
282+
283+ if ( p . SavedLocations . Count == 0 )
284+ {
285+ p . Controller . PrintToChat ( $ "{ PluginPrefix } { ChatColors . Red } No saved locations") ;
286+ return ;
287+ }
288+
289+ if ( p . CurrentSavedLocation == p . SavedLocations . Count - 1 )
290+ {
291+ p . Controller . PrintToChat ( $ "{ PluginPrefix } { ChatColors . Red } Already at last location") ;
292+ }
293+ else
294+ {
295+ p . CurrentSavedLocation ++ ;
296+ }
297+
298+ TeleportPlayerLocation ( player , command ) ;
299+
300+ p . Controller . PrintToChat ( $ "{ PluginPrefix } Teleported #{ p . CurrentSavedLocation } ") ;
123301 }
124302}
0 commit comments