Custom console scripts

Ask questions, discuss ideas, get answers
Post Reply
exe
Posts: 60
Joined: Wed Feb 08, 2012 10:04 pm

Custom console scripts

Post by exe »

Hello,

lately I've been trying to create own scripts in BF1942 with the console commands and conditionals (if/while). It's pretty basic but I can see some very interesting and new possibilities. The main issue is that I can't seem to run these scripts in the game. If I add code to the vehicle (e. g. alternative fire) it only runs it at the start of a map and just ignores it after that. Is there any kind of event I could use? I know you can also map scripts to F1/F2/F3/F4 via

Code: Select all

console.bindKeyToConsoleScript int string
but this is not really practical when you play because these are also used for the radio commands. Is it possible to remap them maybe?
User avatar
Apache Thunder
Posts: 1210
Joined: Mon Oct 19, 2009 2:48 am
Location: Levelland Texas, USA
Contact:

Re: Custom console scripts

Post by Apache Thunder »

Yep. There are some lines of code in the Common.con file for the Controls folder in your profile. (found in Mods/BF1942/Settings/Profiles/[Name of your chosen profile]/Controls)

Code: Select all

ControlMap.addKeyToTriggerMapping c_GIScript1 IDFKeyboard IDKey_F1 c_CMNonRepetive
ControlMap.addKeyToTriggerMapping c_GIScript2 IDFKeyboard IDKey_F2 c_CMNonRepetive
ControlMap.addKeyToTriggerMapping c_GIScript3 IDFKeyboard IDKey_F3 c_CMNonRepetive
ControlMap.addKeyToTriggerMapping c_GIScript4 IDFKeyboard IDKey_F4 c_CMNonRepetive
(found under the defaultGameControlMap section)


Change those keys to something else if you want console scripts working on different keys then the default ones.
ImageImageImage
I have cameras in your head!
exe
Posts: 60
Joined: Wed Feb 08, 2012 10:04 pm

Re: Custom console scripts

Post by exe »

Works, thanks a lot! I wonder why I didn't think of that. :)
exe
Posts: 60
Joined: Wed Feb 08, 2012 10:04 pm

Re: Custom console scripts

Post by exe »

To get my idea working I need some help again: Is there a way (= console command) to find out my nick name in the game? I know there are a couple of name related commands but none of them gives me the result I want. The closest I found are these:

Code: Select all

player.active
player.name
but they always return the name of the player who joins last and not my name.

When I change my name via

Code: Select all

game.changeplayername string
I can see that the game edits the GeneralOptions.con and writes

Code: Select all

*old name* = *new name*
into the chat, so there has to be some kind of code to get that information.
Waldek
Posts: 49
Joined: Thu Mar 08, 2012 12:09 pm

Re: Custom console scripts

Post by Waldek »

Can I use that method to bind console commands? For example "Hud 0" to NumPad1 key?
exe
Posts: 60
Joined: Wed Feb 08, 2012 10:04 pm

Re: Custom console scripts

Post by exe »

Yes.

There are probably other methods but here's how I got it working:

1. Unpack game.rfa

2. Add these lines

Code: Select all

ControlMap.create defaultGameControlMap
ControlMap.addKeyToTriggerMapping c_GIScript1 IDFKeyboard IDKey_Numpad1 c_CMNonRepetive

console.bindKeyToConsoleScript 1 Bf1942/game/displayHud
to the mod's Init.con found in the game.rfa.


3. Create a displayHud.con in the game.rfa file (same place as Init.con) with this content

Code: Select all

Var v_Hud

game.useHud -> v_Hud

if v_Hud == 0
	game.useHud 1
elseIf v_Hud == 1
	game.useHud 0
endIf
4. Re-pack game.rfa.
Post Reply