Thx alot, this will help w/ Code console, but does anyone know how to make a selectable command appear when you click on the "Fake Console" Menu?
Re: FC addon?
Posted: Sun Aug 14, 2011 1:27 pm
by DarthD.U.C.K.
from the 1.3 patches documentation:
AAA-v1.3patch\docs\howtos\"Make Custom User Scripts.txt"
Hidden/Spoiler:
Overview
* The UnOfficial v1.3 patch r102+ supports up to 11 custom user scripts. User scripts are loaded and processed at the start of game_interface.lua. This allows the scripts to control or adjust almost everything that happens ingame. For instance, you can create a script that does a few FakeConsole commands at the start of any map or a script that changes the server name to reflect the amount of people on the server.
* The UnOfficial v1.3 patch r129+ supports an unlimited number of custom user scripts. These scripts must start at number 11 and increment that number one at a time. If there is a break in the numbering, such as: user_script_12, user_script_13, user_script_15, and user_script_16, then when the game sees script 14 missing, it will stop checking for other scripts. Thus user_script_15 and user_script_16 won't be loaded.
Requirements
* SWBF2 mod tools
* v1.3 patch r141+ installed
* Basic understanding of Lua
* Basic understanding of how the game works
How To Do It:
1) First, you will need to read and understand the 'Munge A Custom LVL File.txt' document
2) Next, you need to pick a user script slot. The open slots start at 11 and must go up one at a time. Check your "GameData\data\_LVL_PC folder" and see which 'user_script_##.lvl' files you have. If the script name in the req file doesn't match the lvl file name, the script won't work.
x) If you are using a v1.3 patch below version r141, then only slots 0-10 are available.
X) This guide will use slot eleven: "11". If you plan to distribute your scripts to others, it is best to include the source code. This will allow each person to adjust the code for the amount of user scripts that person already has.
3) Configure your map to munge the custom lvl: "user_script_11.lvl" (see the custom lvl doc for help)
4) user_script_11.lvl must, at the very least, contain the lua script: "user_script_11". When your custom lvl is processed by the game, it will load only this script. You can always include more scripts or resources in the lvl if you need them, but the expected script (user_script_11) must load them (use ScriptCB_DoFile() or ReadDataFile()).
5) After you munge your user_script_11.lvl, copy it to the folder: "GameData\Data\_LVL_PC"
6) Thats it! Run your game and check its debug output. You should see it saying it found and loaded your script each time you load a map/level.
More Info
* For an example user script that runs a few FakeConsole commands when you play a single-player map (easy to remove the SP part), see "user_script_example.zip" in the "code eamples" folder of the v1.3 patch.
* You can use these scripts to better configure a dedicated server or enforce rules, such as 'no vehicles' by using the FakeConsole command 'Lock Vehicles' or a snipers only rule by listening in on AddUnitClass() and canceling any non-sniper units from being added to the team!
Re: FC addon?
Posted: Sun Aug 14, 2011 1:44 pm
by Fiodis
Not to hijack the OP's thread, but I've got a somewhat similar question: to what extent is it possible to modify the Fake Console commands already built into it? Can I, for instance, remove a few things from the list that I don't want people cheating with, or rename a few others and give them new functions?
EDIT - As I've received a few misguided PMs on this, I'll clarify further: I know you can add custom commands to Fake Console. Duck posted the tutorial right above me; I can hardly miss it. I want to see if it's possible to alter the ones already on it. Are those hardwired into the exe?
Re: FC addon?
Posted: Sun Aug 14, 2011 6:31 pm
by Maveritchell
Sure it's possible to alter the ones already added. If you remember (and you may well not), I removed the ability to use the "Add Jetpacks" command in "The Big 'L'" (since the map was so dependent on moving across gaps) - it was still selectable, but I simply gave the command a null value in the script. All I did to let this happen was to search through the .lvl file that the Fake Console scripts are contained in, find the name of the function Zerted used to add jetpacks, and simply give it a value of "zero."
Theoretically you could rewrite them so that an addon map uses a different script when a button is pressed, but it would be no different than using a user script or entering code in the code console.
Re: FC addon?
Posted: Sun Aug 14, 2011 8:24 pm
by Noobasaurus
Maveritchell wrote: I removed the ability to use the "Add Jetpacks" command in "The Big 'L'"
I knew it!
Re: FC addon?
Posted: Sun Aug 14, 2011 8:28 pm
by THEWULFMAN
Maveritchell wrote: I removed the ability to use the "Add Jetpacks" command in "The Big 'L'"
Yeah, I noticed. Although at the time I had no grasp of how. I didn't mind not having it, except with that first fan. Still its satisfying to do it without cheats.
Re: FC addon?
Posted: Sun Aug 14, 2011 9:01 pm
by Noobasaurus
THEWULFMAN wrote:
Maveritchell wrote: I removed the ability to use the "Add Jetpacks" command in "The Big 'L'"
Yeah, I noticed. Although at the time I had no grasp of how. I didn't mind not having it, except with that first fan. Still its satisfying to do it without cheats.
I can't do it without cheats...I needed high jump and whatnot to get it done. I also gave myself a huge shield.
Hidden/Spoiler:
See how much I fail at battlefront?
Re: FC addon?
Posted: Mon Aug 15, 2011 3:51 am
by THEWULFMAN
Noobasaurus wrote:
Hidden/Spoiler:
See how much I fail at battlefront?
I refuse to cheat when playing campaigns, I still haven't beat Death Watch Bunker so don't feel bad.
Ontopic:
I definitely will look into adding a couple commands to the FC, it would be handy to be able to be able to turn unit shields on and off for certain mods.
Re: FC addon?
Posted: Mon Aug 15, 2011 6:46 am
by Fiodis
Maveritchell wrote:I removed the ability to use the "Add Jetpacks" command in "The Big 'L'" (since the map was so dependent on moving across gaps) - it was still selectable, but I simply gave the command a null value in the script. All I did to let this happen was to search through the .lvl file that the Fake Console scripts are contained in, find the name of the function Zerted used to add jetpacks, and simply give it a value of "zero."
Theoretically you could rewrite them so that an addon map uses a different script when a button is pressed, but it would be no different than using a user script...
Heh, I didn't notice at the time. So if rewriting a default function Zerted included is no different than making a custom user script, would we have to follow the same process for making a custom user script, with a unique .lvl file, etc.? Or could we just put the code in our map's lua? I'd imagine it'd be the latter, since I don't remember The Big "L" having any sort of special script .lvl included - though, I admit, I didn't really poke around in that map folder too much.
Re: FC addon?
Posted: Mon Aug 15, 2011 9:17 am
by Maveritchell
Fiodis wrote:So if rewriting a default function Zerted included is no different than making a custom user script, would we have to follow the same process for making a custom user script, with a unique .lvl file, etc.? Or could we just put the code in our map's lua? I'd imagine it'd be the latter, since I don't remember The Big "L" having any sort of special script .lvl included - though, I admit, I didn't really poke around in that map folder too much.
I shouldn't have said "no different;" all I really meant was that it's just one more way of injecting code into the game. A custom user script (I believe) is an always-run script that's read through the 1.3 patch. Using the code console is at-will, although you have to type it in. In the case of modifying one of Zerted's functions, you'd be able to run it at-will as well, although it could only be run through a .lua in which the function has been rewritten. Whether that means you munge a .lvl file with the script embedded and then load it through other scripts or whether you simply add it directly into a mission script (the latter is what I did) is functionally irrelevant.
Re: FC addon?
Posted: Mon Aug 15, 2011 3:01 pm
by Fiodis
Maveritchell wrote:In the case of modifying one of Zerted's functions, you'd be able to run it at-will as well, although it could only be run through a .lua in which the function has been rewritten. Whether that means you munge a .lvl file with the script embedded and then load it through other scripts or whether you simply add it directly into a mission script (the latter is what I did) is functionally irrelevant.
Thanks, that suits my intentions perfectly.
Re: FC addon?
Posted: Tue Aug 16, 2011 4:59 pm
by Bonecrusher16O
To add to my Night's question, At the end of the "Make Custom User Scripts" txt Its says to "Run your game and check its debug output". How does one do this???
Re: FC addon?
Posted: Tue Aug 16, 2011 10:26 pm
by Fiodis
Run the BF2_Modtools.exe as you would to get an error log. Then look into the error log.
Info on how to get an error log is in the FAQ thread.
Re: FC addon?
Posted: Mon Aug 29, 2011 7:47 pm
by [RDH]Zerted
Fiodis wrote:I want to see if it's possible to alter the ones already on it. Are those hardwired into the exe?
The ones hardwired into the exe are everything that shows up when using the debug version of the game. Everything else I created and added through Lua code. Anything done in Lua can be modified somehow, it's just a real pain to get at a few things.
Maveritchell wrote:All I did to let this happen was to search through the .lvl file that the Fake Console scripts are contained in, find the name of the function Zerted used to add jetpacks, and simply give it a value of "zero."
You got lucky on that one. Most of the commands don't have named functions.
I thought I had described this somewhere already... v1.3 was designed to allow modders to add their own FC commands. This is different from using user scripts. I think it would be easier to provide an example than write up a long tutorial trying to explain exactly how everything works. Read through the code and comments before asking me questions on it. I suggest putting the code in PostScriptLoad(). If the player doesn't have v1.3, the code won't hurt anything. Check the debug output if the custom commands aren't working. Note: the steps might change for v1.4, but I will do my best to support the format shown below.
The following code is untested; it might have a typo or two.
Hidden/Spoiler:
[code]--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
--SP version of the mp_lobby button
--attempts to teleport all enemy AI units to player 0's location
ff_AddCommand(
"My Enemy AI Teleport", --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
local toPlayer = GetCharacterUnit( 0 )
local team = GetCharacterTeam( 0 )
if toPlayer == nil then return end
--determine the other team
team = uf_GetOtherTeam( team )
if team == nil then return end
--teleports player to toPlayer
local miniFun = function( player, unit, toPlayer, value )
if (unit == nil) or (toPlayer == nil) then return end --check input
local to = GetEntityMatrix( toPlayer )
SetEntityMatrix( unit, to )
end
uf_applyFunctionOnTeamUnits( miniFun, toPlayer, value, {team} )
end,
function() --this function returns ture when you want the command displayed in the FC menu
return not ScriptCB_InNetGame() --only shows command in singleplayer
end
) --end of ff_AddCommand's parameters
--process someone else's custom FC commands
if moreCommands ~= nil then
return moreCommands()
end
end[/code]More info on ff_AddCommand()
[code]-- Description ----
Adds a command to the FakeConsole table
Note: You cannot just call this function anytime to add a command, it must be called while the FC list is being populated for display
-- Parameters ----
show - String to display in the command list
description - A description of the command. Will be generated off of 'show' if value is nil
command - Function to run when this command is clicked
now - Function which describes if this command should be added to the list. Returns a true value if should be added to the list
-- Returns ----
(nothing)
ff_AddCommand( show, description, command, now )
[/code]
If you guys start adding commands to FakeConsole, please let me know what you're adding. I might be able to put them in v1.4. I always wanted a list of commands specific to each map (spawn as locals, repair turrets/droids, enable/disable specific CPs, stop trash compactor, freeze bridge, unlock door, etc...), but I never had the time to make them.
Re: FC addon?
Posted: Mon Aug 29, 2011 8:25 pm
by CalvaryCptMike
Thankyou Zerted! This will be very useful.
Re: FC addon?
Posted: Thu Sep 01, 2011 9:03 pm
by RedFaceofAwesomeness
Thanks for the lua codes I'll see what I can do with it!