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.