Tutorial: Multiple game modes on a single map
Posted: Thu Aug 01, 2013 2:38 pm
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:
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:
2nd: you need to add in the fake console code. It goes in the function "ScriptPostLoad()" and I always add it at the end.ScriptCB_DoFile("ObjectiveCTF")
ScriptCB_DoFile("ObjectiveTDM")
ScriptCB_DoFile("setup_teams")
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):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
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:--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 -^
Hidden/Spoiler:
Then paste 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 -^
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.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
Credits:
[RDH]Zerted (he showed me how to make custom fake console commands, thanks!)
Me, CavalryCaptainMike