Can Custom FC Commands use ReadDataFile?

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
User avatar
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Can Custom FC Commands use ReadDataFile?

Post by AnthonyBF2 »

I have 1.3 r129 installed and have learned how to make custom buttons with commands on Fake Console list from the help of Zerted.

I'm using the asset scripts to munge a new mission.lvl similar to the retail file.
On each stock mission I have the ability to toss in FC commands, then when I munge, I just copy the new mission.lvl into gamedata\data\_lvl_pc and replace.

Then when I begin the game my commands are there and have already made plenty of stuff work.

Then I'd say not more than 30 minutes later, I had this idea:

On the script for tat2g_eli (Mos Eisley Assault) I decided to try to call in a character while running the game.

The first button I titled "Call Lord Vader" which would run this command:
ReadDataFile("SIDE\\rep.lvl", "rep_hero_cloakedanakin")

While in-game I would click "Call Lord Vader"

Then I would click the 2nd button titled "Assign Lord Vader" with this command
AddUnitClass(IMP, "rep_hero_cloakedanakin")

How ever the game just crashed when I click the command Call Lord Vader, not giving me a chance to "Assign Lord Vader" to a team.

My question is, if possible, how may I call in new characters with FC commands and assign them to a team.

Lua setup:
Hidden/Spoiler:
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
SupportsCustomFCCommands = true

local moreCommands = nil
if AddFCCommands ~= nil then
moreCommands = AddFCCommands
end

AddFCCommands = function()

--
ff_AddCommand(
"Call Lord Vader", --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() ReadDataFile("SIDE\\rep.lvl", "rep_hero_cloakedanakin")
end
)
--
--
ff_AddCommand(
"Assign Lord Vader", --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() AddUnitClass(IMP, "rep_hero_cloakedanakin")
--

if moreCommands ~= nil then
return moreCommands()
end
end

) --end of ff_AddCommand's parameters
end
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
And here is bf2log: (long log, here is important bit)
Hidden/Spoiler:
ifs_sideselect_fnEnter(): Map does not support custom era teams
ifs_sideselect_fnEnter(): The award settings file exists
ifs_sideselect_fnEnter(): Starting to remove award effects...
ifs_sideselect_fnEnter(): Finished removing award effects.
ff_rebuildFakeConsoleList(): Adding in modder's custom commands...
ff_rebuildFakeConsoleList(): Finished adding in modder's custom commands.
fakeconsole_functions: AddCommand: Not adding command: Unlock Vehicles
fakeconsole_functions: AddCommand: Not adding command: Force No Views
fakeconsole_functions: AddCommand: Not adding command: Allow CP Capture
fakeconsole_functions: AddCommand: Not adding command: Not Immune To Mines
fakeconsole_functions: AddCommand: Not adding command: Disable Tumble Recovery
fakeconsole_functions: AddCommand: Not adding command: Allow AI Spawn 1
fakeconsole_functions: AddCommand: Not adding command: Allow AI Spawn 2
fakeconsole_functions: AddCommand: Not adding command: Team Auto-assign On
fakeconsole_functions: AddCommand: Not adding command: Heros SP Rules Off
fakeconsole_functions: AddCommand: Not adding command: Heros SP Scripted Off
fakeconsole_functions: AddCommand: Not adding command: Menu Sounds On
fakeconsole_functions: AddCommand: Not adding command: No Flee Just Die
fakeconsole_functions: AddCommand: Not adding command: Remove Award Effects
fakeconsole_functions: AddCommand: Not adding command: Allow Victory
fakeconsole_functions: AddCommand: Not adding command: AI AutoBalance Off
fakeconsole_functions: AddCommand: Not adding command: AI BlindJetJumps Off
fakeconsole_functions: AddCommand: Not adding command: Hide Team Points
fakeconsole_functions: AddCommand: Not adding command: Remove JetPacks
ifs_fakeconsole: Is runnable: Call Lord Vader function: 0564BF10

Message Severity: 3
C:\Battlefront2\main\RedEngineFL\Memory\RedMemory.cpp(561)
attempted to allocate from invalid heap -1

Message Severity: 3
C:\Battlefront2\main\RedEngineFL\Memory\RedMemory.cpp(538)
Allocating 50444 bytes failed - no free blocks left in Heap -1 ()
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Can Custom FC Commands use ReadDataFile?

Post by [RDH]Zerted »

There's probably some memory pool you also need to add. Look at a different map that uses cloaked anakin and compare the memory pools. My guess is it's something to do with cloth, but I don't know memory pools that well.
User avatar
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Re: Can Custom FC Commands use ReadDataFile?

Post by AnthonyBF2 »

I've added hooded Anakin to tat2g_eli before without changing anything else, simply by calling the string and adding it to a team.

Having as fake console option would be better, it saves MP functionality for that mode.
Having an extra character on your side, then join MP, you spawn as something else, host doesn't have the edits.

I hope the game engine allows stuff like this, but I don't know how else to call characters to a running level.
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Can Custom FC Commands use ReadDataFile?

Post by commanderawesome »

It's totally possible. In fact, one of my projects makes use of this feature.
User avatar
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Re: Can Custom FC Commands use ReadDataFile?

Post by AnthonyBF2 »

Super cool! Is it easy?

I'd love to add buttons for each level to call in unique characters for what ever level it would be.
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Can Custom FC Commands use ReadDataFile?

Post by commanderawesome »

Just follow this tutorial:
viewtopic.php?f=27&t=29399&p=495872
Except add it to setup_teams.lua or make your own .lvl file for it. (see the tutorials "Munge a custom .lvl file" and "Make a custom user script" in the 1.3 patch docs.)
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Can Custom FC Commands use ReadDataFile?

Post by [RDH]Zerted »

Yes, I'd recommend adding custom commands through a user script. That way you don't have to mess with mission.lvl. Here's an example user script that does uses different spawn paths based on which map is being played: viewtopic.php?f=27&t=28821&p=489493&hil ... ls#p489493

v1.3 added the global variables: __thisMapsCode__ and __thisMapsMode__ which will help tell you what map is playing. They're set by the ReadDataFile() call that loads the map. If you're loading sections from different maps, it should end up with the code of the last loaded map.

Why don't you post your memory pool lines. I can't debug that, but someone else probably can. Your unit loading issue should be fixable. Three things to check:
1) Make sure you're not over the unit limit for IMP. The game only supports so many unit classes per team. See the limitations thread in the FAQ.
2) Switch IMP to it's actual number to double check that IMP isn't nil.
3) Try using ReadDataFileInGame() instead of ReadDataFile()
Post Reply