Tutorial: Multiple game modes on a single map

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
CalvaryCptMike
Captain
Captain
Posts: 476
Joined: Sat Feb 19, 2011 3:10 pm
Projects :: Nothing--absolutely nothing
Location: Freed by alien robots, now living on Mars
Contact:

Tutorial: Multiple game modes on a single map

Post by CalvaryCptMike »

Combining several gamemodes into one mission Tutorial.


This tutorial shows you how to put several very similar gamemodes (such as CTF and TDM) into one mission. The finished product should like something like this:
You start a mission, "Dagobah: Deathmatch or Capture the Flag", once the mission finishes loading you will go into the fake console.
Hidden/Spoiler:
Image
at the top there will be two options, "Play TDM" and "Play CTF". You can click on either one. Once you do, exit the fake console, the gamemode you selected will start, and you can spawn and play like normal. Let's start:

1st: Take the script dag1c_2flag (for example). At the top of the script, you need to add the line "ScriptCB_DoFile("ObjectiveTDM")" like so:
ScriptCB_DoFile("ObjectiveCTF")
ScriptCB_DoFile("ObjectiveTDM")
ScriptCB_DoFile("setup_teams")
2nd: you need to add in the fake console code. It goes in the function "ScriptPostLoad()" and I always add it at the end.
function ScriptPostLoad()

SoundEvent_SetupTeams( REP, 'rep', CIS, 'cis' )

--Capture the Flag for stand-alone multiplayer
-- These set the flags geometry names.
--GeometryName sets the geometry when hte flag is on the ground
--CarriedGeometryName sets the geometry that appears over a player's head that is carrying the flag
SetProperty("flag1", "GeometryName", "com_icon_cis_flag")
SetProperty("flag1", "CarriedGeometryName", "com_icon_cis_flag_carried")
SetProperty("flag2", "GeometryName", "com_icon_republic_flag")
SetProperty("flag2", "CarriedGeometryName", "com_icon_republic_flag_carried")

--This makes sure the flag is colorized when it has been dropped on the ground
SetClassProperty("com_item_flag_carried", "DroppedColorize", 1)

--This is all the actual ctf objective setup
ctf = ObjectiveCTF:New{teamATT = ATT, teamDEF = DEF, textATT = "game.modes.CTF", textDEF = "game.modes.CTF2", hideCPs = true, multiplayerRules = true}
ctf:AddFlag{name = "flag1", homeRegion = "Team1FlagCapture", captureRegion = "Team2FlagCapture"}
ctf:AddFlag{name = "flag2", homeRegion = "Team2FlagCapture", captureRegion = "Team1FlagCapture"}
ctf:Start()

EnableSPHeroRules()

--fc game mode selection start -v
--tell v1.3 to expect custom FC commands

SupportsCustomFCCommands = true

--make sure we don't wipe out someone else's custom commands
local moreCommands = nil
if AddFCCommands ~= nil then
moreCommands = AddFCCommands
end

--v1.3 will automatically call this for you at the proper times
AddFCCommands = function()
--Add your custom commands here using ff_AddCommand() as show below

--YOUR COMMANDS WILL GO HERE

--process someone else's custom FC commands
if moreCommands ~= nil then
return moreCommands()
end
end

--fc game mode selection start -^
--fc game mode selection start -^
--fc game mode selection start -^


end
3rd: Now for the fun part, select all the code that controls the gamemode and press 'Ctrl X.' Paste it into a separate Lua file, and add these lines (the highlighted ones):
--CTF -V
ff_AddCommand(
"Play Regular 2-Flag CTF", --name of the command, should be unique
nil, --command description. If nil, defaults to mods.fakeconsole.description.<name without spaces> (example: mods.fakeconsole.description.MyEnemyAITeleport)
function() --this function does whatever it is you want your command to do
SoundEvent_SetupTeams( REP, 'rep', CIS, 'cis' )

--Capture the Flag for stand-alone multiplayer
-- These set the flags geometry names.
--GeometryName sets the geometry when hte flag is on the ground
--CarriedGeometryName sets the geometry that appears over a player's head that is carrying the flag
SetProperty("flag1", "GeometryName", "com_icon_cis_flag")
SetProperty("flag1", "CarriedGeometryName", "com_icon_cis_flag_carried")
SetProperty("flag2", "GeometryName", "com_icon_republic_flag")
SetProperty("flag2", "CarriedGeometryName", "com_icon_republic_flag_carried")

--This makes sure the flag is colorized when it has been dropped on the ground
SetClassProperty("com_item_flag_carried", "DroppedColorize", 1)

--This is all the actual ctf objective setup
ctf = ObjectiveCTF:New{teamATT = ATT, teamDEF = DEF, textATT = "game.modes.CTF", textDEF = "game.modes.CTF2", hideCPs = true, multiplayerRules = true}
ctf:AddFlag{name = "flag1", homeRegion = "Team1FlagCapture", captureRegion = "Team2FlagCapture"}
ctf:AddFlag{name = "flag2", homeRegion = "Team2FlagCapture", captureRegion = "Team1FlagCapture"}
ctf:Start()

end

) --end of ff_AddCommand's parameters
--CTF -^
4th: Now copy that and paste it into the file we were originally working on, right in the spot that says "--YOUR COMMANDS WILL GO HERE". Okay, if you're doing everything right, your code should look like this:
Hidden/Spoiler:
ScriptCB_DoFile("ObjectiveCTF")
ScriptCB_DoFile("ObjectiveTDM")
ScriptCB_DoFile("setup_teams")

---------------------------------------------------------------------------
-- FUNCTION: ScriptInit
-- PURPOSE: This function is only run once
-- INPUT:
-- OUTPUT:
-- NOTES: The name, 'ScriptInit' is a chosen convention, and each
-- mission script must contain a version of this function, as
-- it is called from C to start the mission.
---------------------------------------------------------------------------

--PostLoad, this is all done after all loading, etc.
function ScriptPostLoad()

--fc game mode selection start -v
--tell v1.3 to expect custom FC commands
SupportsCustomFCCommands = true

--make sure we don't wipe out someone else's custom commands
local moreCommands = nil
if AddFCCommands ~= nil then
moreCommands = AddFCCommands
end

--v1.3 will automatically call this for you at the proper times
AddFCCommands = function()
--Add your custom commands here using ff_AddCommand() as show below

--CTF -V

ff_AddCommand(
"Play Regular 2-Flag CTF", --name of the command, should be unique
nil, --command description. If nil, defaults to mods.fakeconsole.description.<name without spaces> (example: mods.fakeconsole.description.MyEnemyAITeleport)
function() --this function does whatever it is you want your command to do
SoundEvent_SetupTeams( REP, 'rep', CIS, 'cis' )

--Capture the Flag for stand-alone multiplayer
-- These set the flags geometry names.
--GeometryName sets the geometry when hte flag is on the ground
--CarriedGeometryName sets the geometry that appears over a player's head that is carrying the flag
SetProperty("flag1", "GeometryName", "com_icon_cis_flag")
SetProperty("flag1", "CarriedGeometryName", "com_icon_cis_flag_carried")
SetProperty("flag2", "GeometryName", "com_icon_republic_flag")
SetProperty("flag2", "CarriedGeometryName", "com_icon_republic_flag_carried")

--This makes sure the flag is colorized when it has been dropped on the ground
SetClassProperty("com_item_flag_carried", "DroppedColorize", 1)

--This is all the actual ctf objective setup
ctf = ObjectiveCTF:New{teamATT = ATT, teamDEF = DEF, textATT = "game.modes.CTF", textDEF = "game.modes.CTF2", hideCPs = true, multiplayerRules = true}
ctf:AddFlag{name = "flag1", homeRegion = "Team1FlagCapture", captureRegion = "Team2FlagCapture"}
ctf:AddFlag{name = "flag2", homeRegion = "Team2FlagCapture", captureRegion = "Team1FlagCapture"}
ctf:Start()

end

) --end of ff_AddCommand's parameters
--CTF -^

--process someone else's custom FC commands
if moreCommands ~= nil then
return moreCommands()
end
end

--fc game mode selection start -^

end
5th: Now take the code below and copy it:
--TDM -v

ff_AddCommand(
"Play Regular TDM", --name of the command, should be unique
nil, --command description. If nil, defaults to mods.fakeconsole.description.<name without spaces> (example: mods.fakeconsole.description.MyEnemyAITeleport)
function() --this function does whatever it is you want your command to do

TDM = ObjectiveTDM:New{teamATT = 1, teamDEF = 2,
multiplayerScoreLimit = 1000,
textATT = "game.modes.tdm",
textDEF = "game.modes.tdm2", hideCPs = true, multiplayerRules = true, isCelebrityDeathmatch = false}
TDM:Start()

AddAIGoal(1, "Deathmatch", 1000)
AddAIGoal(2, "Deathmatch", 1000)
end

) --end of ff_AddCommand's parameters

--TDM -^
Then paste it:
ScriptCB_DoFile("ObjectiveCTF")
ScriptCB_DoFile("ObjectiveTDM")
ScriptCB_DoFile("setup_teams")

---------------------------------------------------------------------------
-- FUNCTION: ScriptInit
-- PURPOSE: This function is only run once
-- INPUT:
-- OUTPUT:
-- NOTES: The name, 'ScriptInit' is a chosen convention, and each
-- mission script must contain a version of this function, as
-- it is called from C to start the mission.
---------------------------------------------------------------------------

--PostLoad, this is all done after all loading, etc.
function ScriptPostLoad()

--fc game mode selection start -v
--tell v1.3 to expect custom FC commands
SupportsCustomFCCommands = true

--make sure we don't wipe out someone else's custom commands
local moreCommands = nil
if AddFCCommands ~= nil then
moreCommands = AddFCCommands
end

--v1.3 will automatically call this for you at the proper times
AddFCCommands = function()
--Add your custom commands here using ff_AddCommand() as show below

--CTF -V

ff_AddCommand(
"Play Regular 2-Flag CTF", --name of the command, should be unique
nil, --command description. If nil, defaults to mods.fakeconsole.description.<name without spaces> (example: mods.fakeconsole.description.MyEnemyAITeleport)
function() --this function does whatever it is you want your command to do
SoundEvent_SetupTeams( REP, 'rep', CIS, 'cis' )

--Capture the Flag for stand-alone multiplayer
-- These set the flags geometry names.
--GeometryName sets the geometry when hte flag is on the ground
--CarriedGeometryName sets the geometry that appears over a player's head that is carrying the flag
SetProperty("flag1", "GeometryName", "com_icon_cis_flag")
SetProperty("flag1", "CarriedGeometryName", "com_icon_cis_flag_carried")
SetProperty("flag2", "GeometryName", "com_icon_republic_flag")
SetProperty("flag2", "CarriedGeometryName", "com_icon_republic_flag_carried")

--This makes sure the flag is colorized when it has been dropped on the ground
SetClassProperty("com_item_flag_carried", "DroppedColorize", 1)

--This is all the actual ctf objective setup
ctf = ObjectiveCTF:New{teamATT = ATT, teamDEF = DEF, textATT = "game.modes.CTF", textDEF = "game.modes.CTF2", hideCPs = true, multiplayerRules = true}
ctf:AddFlag{name = "flag1", homeRegion = "Team1FlagCapture", captureRegion = "Team2FlagCapture"}
ctf:AddFlag{name = "flag2", homeRegion = "Team2FlagCapture", captureRegion = "Team1FlagCapture"}
ctf:Start()

end

) --end of ff_AddCommand's parameters
--CTF -^

----RIGHT HERE

--process someone else's custom FC commands
if moreCommands ~= nil then
return moreCommands()
end
end

--fc game mode selection start -^

end
And there you go! Munge and start SWBFII. Open your map, open the fake console, choose your gamemode, and play away! This feature is MP compatible too. You could even add more complex modes, like mini-campaign levels or other random stuff. I did in my 3.5 mod. It lets you add random little modes without having to worry about the mission limit.

Credits:
[RDH]Zerted (he showed me how to make custom fake console commands, thanks!)
Me, CavalryCaptainMike
Post Reply