--save real Freecam function
RealFreeCamFn = ScriptCB_Freecamera
--overwrite Freecam to prevent cheaters from using it to find other people
--REDEFINE FREE CAM FUNCTION (Thanks Zerted)
ScriptCB_Freecamera = function(...)
print("\nSOMEONE'S CHEATING!!!")
print("\tKilling the player.")
ScriptCB_PlayerSuicide(0)
return RealFreeCamFn(unpack(arg))
end
I'd like to do the same for executing a fake console command, but I can't find a working function that I can overwrite like I did with ScriptCB_Freecamera.
Does anyone know of a function I can use to accomplish this?
1) You can remove fake console completely by adding ifs_pausemenu.lua to the script in your mission.req and it will use a default pause menu with no freecam or fake console buttons.
2) If you want fake console to exist but clean out the buttons you can find fakeconsole_functions.lua somewhere on Gametoast, clean out the contents that builds buttons then put it in data_mod/common/scripts then add fakeconsole_functions to the script section of your mission.req and your mod will use that one instead of the regular script - just like pause menu trick.
Are those the only options? I want it to be usable up to a certain point during the match (the functions will get overwritten in a call to OnTimerExpire).
The function call you want to intercept is to ff_AddCommand(<show>, <description>, <command>, <now>). The <now> parameter is a function which when called, returns true if that command should be displayed in the Fake Console list. Simply intercept that argument and replace it with your own function that always returns false until you want the commands displayed. Despite the documentation saying ff_AddCommand doesn't return anything, make sure your function returns whatever the call to the real ff_AddCommand returns. It's always possible some other mod also intercepted calls to ff_AddCommand and that mod could be relying on a new return value. This super easy to implement advice could save someone a ton of time debugging.
Here's the original implementation of ff_AddCommand for reference. It's defined in fakeconsole_functions.lua (added by v1.3).
Hidden/Spoiler:
[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 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)
--
function ff_AddCommand( show, description, command, now )
--check input
if show == nil then
print("fakeconsole_functions: AddCommand: Show is nil")
return
elseif description == nil then
--removes all spaces from the show string and prevent 'empty' names
local name = string.gsub(show, " ", "")
if name == "" then
name = "blank"
end
description = "mods.fakeconsole.description." .. name
end
--check to see if command is valid at this current time
if now ~= nil then
if not now() then
print("fakeconsole_functions: AddCommand: Not adding command: ", show)
return --don't add this command to the list
end
end
--add the given command into FakeConsole's table of commands
table.insert( gConsoleCmdList, {ShowStr=show, info=description, run=command,} )
end[/code]
If you can accomplish something without replacing a file then I suggest doing it without replacing the file. That way any future mods that come along will still be compatible with your mod.