Skip to content

Commit

Permalink
add simple savestate system
Browse files Browse the repository at this point in the history
  • Loading branch information
zweek committed Dec 31, 2022
1 parent e22ef1c commit 711fb1d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 53 deletions.
4 changes: 3 additions & 1 deletion src/scripts/kb_act.lst
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"blank" "=========================="
"blank" "QUICKSAVES"
"blank" "SAVES & SAVESTATES"
"blank" "=========================="
"save quicksave" "Create Quicksave"
"load quicksave" "Load Quicksave"
"save quicksave2" "Create Second Quicksave"
"load quicksave2" "Load Second Quicksave"
"save quicksave3" "Create Third Quicksave"
"load quicksave3" "Load Third Quicksave"
"createsavestate" "Create Savestate"
"loadsavestate" "Load Savestate"
"blank" "=========================="
"blank" "RESETTING"
"blank" "=========================="
Expand Down
1 change: 1 addition & 0 deletions src/scripts/vscripts/scripts.rson
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ When: "SERVER && SP"
Scripts:
[
sp/_savegame.gnut
sp/srmm_savestates.nut
_trigger_functions_sp.gnut
_script_movers.gnut
sp/_ai_sp.gnut
Expand Down
1 change: 1 addition & 0 deletions src/scripts/vscripts/sp/_savegame.gnut
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void function InitSaveGame()
FlagInit( "SaveRequires_PlayerIsTitan" )
AddClientCommandCallback( "RestartFromLevelTransition", RestartFromLevelTransition )
AddClientCommandCallback( "RespawnNowSP", RespawnNowSP )
AddCallback_OnClientConnected( SaveStateInit )
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
52 changes: 0 additions & 52 deletions src/scripts/vscripts/sp/cl_sp_hud.gnut
Original file line number Diff line number Diff line change
Expand Up @@ -9,65 +9,13 @@ global function ServerCallback_UpdateDifficulty
global function BeginIntroSequence
global function IntroInProgress

global function RUITimerInit
var rui

struct
{
bool introInProgress = false
} file

// Timer Code
void function RUITimerInit()
{
printt("START TIMER")
//#if CLIENT
WaitFrame()
//thread RUITimerUI_DelayedInit();
//#endif

}

void function RUITimerUI_DelayedInit()
{
// Wait a frame, so no errors :D
WaitFrame();
// Make a text segment.
rui = RuiCreate( $"ui/cockpit_console_text_top_left.rpak", clGlobal.topoCockpitHudPermanent, RUI_DRAW_COCKPIT, 0 )
// Set up text segment? yea sure why not
RuiSetInt( rui, "maxLines", 1 )
RuiSetInt( rui, "lineNum", 1 )
// Position
RuiSetFloat2( rui, "msgPos", <0.57, 0.53, 0.0> )
// Display text
RuiSetString( rui, "msgText", "Time: " )
// Font size
RuiSetFloat( rui, "msgFontSize", 48.0 )
// Alpha cause it cewl
RuiSetFloat( rui, "msgAlpha", 0.9 )
// ????
RuiSetFloat( rui, "thicken", 0.0 )
// Color :3
RuiSetFloat3( rui, "msgColor", <1.0, 0.55, 0.0> )
thread RUIUpdateTimerText();
}

void function RUIUpdateTimerText()
{
while (true)
{
// Wait frame so it doesn't loop when not needed, and overload the CPU
WaitFrame();
// Get the player
entity player = GetLocalClientPlayer();
// Check if player isn't very alive, or just non-existent
if (player == null || !IsValid(player)) {
continue;
}
RuiSetString(rui, "msgText", format("%2i:%1i%.2f", (Time() / 60).tointeger(), (Time() % 60.0 / 10.0).tointeger(), Time() % 10.0));
}
}

void function ClSpHud_Init()
{
if ( IsLobby() )
Expand Down
33 changes: 33 additions & 0 deletions src/scripts/vscripts/sp/srmm_savestates.nut
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
untyped
global function SaveStateInit

struct {
bool savestateExists = false
vector position
vector angles
vector velocity
} file

void function SaveStateInit( entity player )
{
AddClientCommandCallback( "createsavestate", Pressed_CreateSaveState )
AddClientCommandCallback( "loadsavestate", Pressed_LoadSaveState )
}

bool function Pressed_CreateSaveState( entity player, array<string> args )
{
file.position = player.GetOrigin()
file.angles = player.GetAngles()
file.velocity = player.GetVelocity()
file.savestateExists = true
return true
}

bool function Pressed_LoadSaveState( entity player, array<string> args )
{
if (!file.savestateExists || !SRMM_getSetting(SRMM_settings.practiceMode)) return false
player.SetOrigin(file.position)
player.SetAngles(file.angles)
player.SetVelocity(file.velocity)
return true
}

0 comments on commit 711fb1d

Please sign in to comment.