A story of persist

Hi!

I have check every files in the HW base to know if we have any function that can save the file called ‘persistx.lua’ (same in the HW2 campaign) and load that one for the next mission, but I haven’t found anything yet.

So, I hope Gearbox will add a function like that, because I need it to make persistence for the campaign.

Thanks :wink:
C’ya

@BitVenom

There must be something like this… I think of the new Raider Retreat mission that references the same persist file as M05. The Raider Retreat files are the ones I would look through if I were you to try to figure out how to add new missions that reference persist .luas.

I found, in my campaign file profile, one persist create at the end of the mission.

Thus this file is automatically generated.

What I would like to know, it is what are the conditions, to be able to load this file, in the following mission.

Finally I wonder if, as in the file rr_oem.campaign , there would be not way to put a new variable considered by the game…

Something like this :

savepersist = "Path to folder/persistx.lua"

And, we have actually this :

usepersist = "player:Campaign//HOMEWORLDCLASSIC//persist5.lua",
usedefaultpersist = 1,

So, game use one persist if the persist5 doesn’t exists. This persist, locate on the rr_oem folder (singleplayerfleet.lua).

It’s just a little feature, but i think it’s more easy to add the ‘savepersist’ additionally to the ‘usepersist’, so we can “trace” the persist … ~

EDIT : I try with my next mission, without this usepersist, to load by default this persist with my previously mission result :

Nothing, persist refuse to load … And i try with the ‘usepersist’, but nothing, won’t work…

[No error in the log :wink: ]

I found way to make this possible. I edit my post to make full “How to” in the few days.

I look forward to it!

any word on that how-to? I’d really like to get my hands dirty on some persistence related stuff.

1 Like

I am waiting Erayser for publish this, because i write it in French, and Erayser make this document in English.

So wait & see …

The following tutorial shows you how to implement and use the “persist.lua” in missions for Homeworld: Remastered. To use it, and in the best way possible, here’s how you should proceed:

NOTE : You need to have at least TWO missions. The first mission creates the wanted persist to use it in the second one.

First of all, make sure to have your two missions. The method is the same everytime you want to implement a persist. The amount of missions in .campaign doesn’t matter.

So basically we have :

  • Mission_1.lua / .level in our “Mission_1” folder
  • Mission_2.lua / .level in our “Mission_2” folder

Let’s start it.
In “Mission_1.lua”, make sure at the end of your mission that ALL small ships (smaller than frigates) are docked in bigger ships such as a mothership, a capital ship, a carrier and so on…

Preview of Mission 5 Gehenna - HWRM

function Rule_dockAllStrikeCraft()
	-- get all player dockable ships
	Player_FillShipsByType("AllPlayerScouts", 0, "Hgn_Scout" )
	Player_FillShipsByType("AllPlayerInterceptors", 0, "Hgn_Interceptor" )
	Player_FillShipsByType("AllPlayerBombers", 0, "Hgn_AttackBomber" )
	Player_FillShipsByType("AllPlayerEliteBombers", 0, "Hgn_AttackBomberElite" )
	Player_FillShipsByType("AllPlayerAssCorvs", 0, "Hgn_AssaultCorvette" )
	Player_FillShipsByType("AllPlayerPulseCorvs", 0, "Hgn_PulsarCorvette" )
	Player_FillShipsByType("AllPlayerMinelayerCorvs", 0, "Hgn_MinelayerCorvette" )
	Player_FillShipsByType("AllPlayerEliteAssCorvs", 0, "Hgn_AssaultCorvetteElite" )
	Player_FillShipsByType("AllPlayerResCollectors", 0, "Hgn_ResourceCollector" )
	
	-- tell all player ships to dock with MS
	if ( SobGroup_Empty ("AllPlayerScouts") == 0) then
		SobGroup_DockSobGroupInstant("AllPlayerScouts", Players_Mothership)
	end
	if ( SobGroup_Empty ("AllPlayerInterceptors") == 0) then
		SobGroup_DockSobGroupInstant("AllPlayerInterceptors", Players_Mothership)
	end
	if ( SobGroup_Empty ("AllPlayerBombers") == 0) then
		SobGroup_DockSobGroupInstant("AllPlayerBombers", Players_Mothership)
	end
	if ( SobGroup_Empty ("AllPlayerEliteBombers") == 0) then
		SobGroup_DockSobGroupInstant("AllPlayerEliteBombers", Players_Mothership)
	end
	if ( SobGroup_Empty ("AllPlayerAssCorvs") == 0) then
		SobGroup_DockSobGroupInstant("AllPlayerAssCorvs", Players_Mothership)
	end
	if ( SobGroup_Empty ("AllPlayerPulseCorvs") == 0) then
		SobGroup_DockSobGroupInstant("AllPlayerPulseCorvs", Players_Mothership)
	end
	if ( SobGroup_Empty ("AllPlayerMinelayerCorvs") == 0) then
		SobGroup_DockSobGroupInstant("AllPlayerMinelayerCorvs", Players_Mothership)
	end
	if ( SobGroup_Empty ("AllPlayerEliteAssCorvs") == 0) then
		SobGroup_DockSobGroupInstant("AllPlayerEliteAssCorvs", Players_Mothership)
	end
	if ( SobGroup_Empty ("AllPlayerResCollectors") == 0) then
		SobGroup_DockSobGroupInstant("AllPlayerResCollectors", Players_Mothership)
	end
	
	Rule_Remove ("Rule_dockAllStrikeCraft")

end

NOTE : Players_Mothership is a variable, is defined as follows:

Players_Mothership = "Players_Mothership"
SobGroup_Create(Players_Mothership)
SobGroup_FillShipsByType( Players_Mothership, "Player_Ships0", "Hgn_MotherShip" )  

And needs to be defined at the very beginning of your mission. Please note that names can be changed (of course), including the ships.

Thanks to that, we know that all of our small ships will be docked in bigger ones, and this to prevent log errors while the player loads the second mission.

Let’s move to the mission 2 .level

In our example : Preview of Level Gehenna

player[0] = {
	id = 0,
	name = "",
	resources = 0,
	raceName = "Hiigaran", -- Or other
	startPos = 0
}

---------------------------------------------------------
function DetermChunk()
	addPoint("PlayerStartPoint", {3473.000000, 0.000000, 13700.000000}, {179.999985, -0.000005, 179.999985})
	...
	...
	...
	...
end

In your Mission_2.lua : Preview Mission Gehenna

function OnInit()
	blabla...    
	
        Rule_Add("Rule_Init")
end

function Rule_Init()

    -- create the groups we need from persistent fleet information
    -- Moved this to Rule_Init so the hyperspace sound effects will play.
    SobGroup_LoadPersistantData("Hgn_Mothership")
	

blabla ...

end

CAUTION : It is necessary to place the “SobGroup_LoadPersistantData” in a different function than “OnInit” so the hyperspace effects will play.
[You will probably be able to use this method to start a recall on the map and then display the player’s fleet…]

Make sure that all persists are properly saved in “Bin\Profiles\ProfileName\Campaign\CampaignName”. If that’s the case you should not have any problem.

1 Like