スクリプト作成

出典: LFS Manual
2017年2月23日 (木) 15:06時点におけるSkylinekakkoii (トーク | 投稿記録)による版 (英最新版のコピー&一部翻訳)
ナビゲーションに移動検索に移動

by AndroidXP

はじめに

2006年12月のパッチVのリリースの際に、LFSの開発者は新しいスクリプトシステムを公開しました。これは、ほとんどのFPSシューティングゲームで実装されているものと非常に似ています。

一般的に、このシステムはタスクを自動化するのに便利です。 Generally, it allows the automation of common tasks, customisation of options on a per-car basis as well as simple toggles to change the binding of keys (and more). This guide is aimed to give you a general understanding of the LFS script system as well as a few examples for simple scripts.

使用方法

基本

スクリプトファイルは拡張子に.lfsおり、LFS\data\scriptフォルダ内に入っています。

これらのファイルを編集するには、まずメモ帳などのテキストエディタで開きます。

もちろん、新しいファイルを作成することもできます。新規作成する際には、正しい拡張子で保存するよう注意してください。

フォルダ内を整理するために、サブディレクトリ内にスクリプトを保存しておくことも可能です。

In general, each line in the script file represents a command that is executed by LFS, going from top to bottom. The only exception are empty lines, and lines that start with "//", which are treated as comments and thus ignored. Basically you can imagine the system as LFS reading each line, writing it into the chat window and hitting return. Of course it is not exactly like that, but it should give you the general idea.

予約済みのファイル名

While you can generally name new script files however you want, a few names have a special meaning to LFS. All affected files already exist in the script folder when you first install the patch, so as long as you don't move or overwrite any files everything will be fine.

  • autoexec.lfs
Like the name suggests, this script is executed automatically every time LFS starts and is thus the ideal place to initialize your scripts.
  • CAR.lfs
"CAR" being replaced with one of the three-letter car shortcuts (see here or below), these scripts are executed everytime the corresponding car is selected in the garage - for example if you select the XR GT Turbo, LFS will execute "XRT.lfs". They are usually used for car specific settings, like a custom FOV or force feedback strength.
  • road.lfs, sequential.lfs, paddle.lfs
Even though these filenames are neither reserved nor automatically executed, they are worth mentioning as by default they are run from inside the CAR.lfs scripts. Their main purpose are custom settings that should apply to cars with a certain shifter type. Road.lfs is the equivalent to cars with a H-gate shifter, sequential.lfs to a sequential stick shifter and paddle.lfs to having paddles. If you have a wheel that supports such shifter types (like the Logitech G25 for example), then these script files are handy to automatically change the shifter setup so it fits the currently selected car.
To match the cars to their gearbox, they should be assigned as following:
Road: UF1, XFG, XRG, XRT, RB4, FXO, LX4, LX6, FZ5, FZR, UFR, RAC
Sequential: FBM, FOX, FO8, MRT, XFR, XRR, FXR
Paddle: BF1

コマンド

以下に掲載しているコマンドはよく使われるものの抜粋です。

全てのコマンドのリストは、LFS\docs\Commands.txt で確認できます。

Options & Miscellaneous

/run        [scriptname]    - スクリプトを実行する(data\script\scriptname.lfs),
                              例:"/run myScript", "/run myFolder\myScript"
/say        [message]       - チャットを入力するのと同じです
/echo       [text]          - テキストを表示する(ローカル画面のみ)
/fov        [degrees]       - 視野
/ff         [0-200]         - フォースフィードバックの強度
/wheel_turn [degrees]       - コントローラーの回転角を指定する
/autoclutch [0-1]           - オートクラッチのON/OFF切り替え
/shifter    [auto/sequential/shifter]    - シフターの種類
/view       [fol/heli/cam/driver/custom] - 視点の選択
/view       [save/reload]  - 現在のカスタム視点を保存/リロードする

Binding & Executing Commands

Binding
/axis   [axis]   [function] - e.g. "/axis 2 throttle"   (to unbind, use -1)
/invert [0/1]    [function] - e.g. "/invert 1 brake"    
/button [button] [function] - e.g. "/button 5 shift_up" (to unbind, use -1)
/key    [key]    [function] - e.g. "/key Q handbrake"
/ctrlf  [num]    [text]     - change shortcut text, e.g. "/ctrlf 1 hello"
/altf   [num]    [text]     - change shortcut text, e.g. "/altf 1 bye"

Simulating key presses
/press [key]                - simulate key press
/shift [key]                - SHIFT + key
/ctrl  [key]                - CTRL + key
/alt   [key]                - ALT + key

Parameter reference

Function names for the /button and /key commands
steer_left, steer_right, steer_fast, steer_slow
throttle, brake, shift_up, shift_down
clutch, handbrake, left_view, right_view, rear_view
horn, flash, reset, pit_speed, tc_disable, zoom_in, zoom_out
reverse, gear_1 - gear_7, ctrl_f1 - ctrl_f12, ignition

To find out the number for a controller button, go to Options > Controls
and press the button in question. You will see the button # and currently
assigned function in the middle right part of the screen.

Function names for the /axis and /invert commands
steer, combined, throttle, brake
lookh, lookp, lookr
clutch, handbrake, shiftx, shifty

Parameters for the key press commands (press / shift / ctrl / alt)
Letters A to Z
Numbers 0 to 9
F1 to F12
up, down, left, right
space, enter, esc, tab
less, more (< >) or (, .) depending on your locale

On a general note: as you might have noticed from the command listing, it is currently impossible to bind other script commands to a button; for example, "/button 1 /say hello" wouldn't work. Luckily we can use the text shortcut keys (Ctrl+F1-F12, Alt+F1-F12) for this, so we can use "/ctrlf 1 /say hello" (which binds "/say hello" to Ctrl+F1) and then "/button 1 ctrl_f1" (binds the press of Ctrl+F1 to button #1). However, this also means that you have to give away a few of your shortcut keys for the scripts, which shouldn't really be a problem, considering there are 32 available shortcuts total (24 bindable via scripts).

"F9 > F10 > F11 > F12 > Off" 切り替え

Shortcut keys used: Ctrl+F12

The basic idea of this script is, that we want to have one button (for example on the wheel) cycling through the F9-F12 menus. To accomplish this, we need five scripts plus an entry in autoexec.lfs.

For this script we will use the Ctrl+F12 text shortcut for our cycle, and bind button #0 (whichever button that is on your controller) to execute it. The multiple usage of the /press command ensures that the menu is properly displayed, in case a menu was already opened manually beforehand. For example, if the F11 menu is already open and we would run viewF11.lfs without pressing the F9 key in it, it would just close the F11 menu instead, which is something we definitely don't want to happen in the heat of a race.

It will work like this:

  1. Button 0 -> Ctrl+F12 -> viewF9 -> press F9 + rebind Ctrl+F12 to run viewF10
  2. Button 0 -> Ctrl+F12 -> viewF10 -> press F10 + rebind Ctrl+F12 to run viewF11
  3. Button 0 -> Ctrl+F12 -> viewF11 -> press F11 + rebind Ctrl+F12 to run viewF12
  4. Button 0 -> Ctrl+F12 -> viewF12 -> press F12 + rebind Ctrl+F12 to run viewOff
  5. Button 0 -> Ctrl+F12 -> viewOff -> turn off menu + rebind Ctrl+F12 to run viewF9
...

viewF9.lfs

/press F10
/press F9
/ctrlf 12 /run viewF10

viewF10.lfs

/press F9
/press F10
/ctrlf 12 /run viewF11

viewF11.lfs

/press F9
/press F11
/ctrlf 12 /run viewF12

viewF12.lfs

/press F9
/press F12
/ctrlf 12 /run viewOff

viewOff.lfs

/press F10
/press F9
/press F9
/ctrlf 12 /run viewF9

autoexec.lfs

/button 0 ctrl_f12
/ctrlf 12 /run viewF9

Indicator Control

Shortcut keys used: Ctrl+F10, Ctrl+F11

This example shows a simple way to comfortably control the indicators with two buttons. You need three scripts and a few entries to autoexec.lfs, shortcut keys used are Ctrl+F10 and F11. The indicators will work as follows; first press of left button activates left indicator, second press deactivates it. Vice versa for the right button. Switching between left and right is possible. For ease of use, the script will output green arrows indicating the currently selected mode into the chat area.

By using the same logic and adding another script, it is also easy to implement the control of the hazards by a third button.

indicateLeft.lfs

/press 7
/ctrlf 11 /run indicateStop
/ctrlf 10 /run indicateRight
/echo ^2‹ ‹ ‹

indicateRight.lfs

/press 8
/ctrlf 10 /run indicateStop
/ctrlf 11 /run indicateLeft
/echo ^2› › ›

indicateStop.lfs

/press 0
/ctrlf 10 /run indicateRight
/ctrlf 11 /run indicateLeft
/echo ^8Off

autoexec.lfs

/button 16 ctrl_f11
/button 18 ctrl_f10 
/ctrlf 10 /run indicateRight
/ctrlf 11 /run indicateLeft

オートシフター設定 (Logitech G25/G27 ユーザー向け)

Shortcut keys used: None

To automatically adjust the controller bindings for the shift mechanism used by the currently selected car, all you have to do is modify the existing road.lfs, sequential.lfs and paddle.lfs as shown below.

Optionally you can also add re-bindings of whatever you want to use the free shifter/paddle buttons for. For example, when using the shifter unit, my right paddle acts as handbrake and the left one as horn, whereas when using the paddles, pulling the sequential stick is the handbrake and pushing sounds the horn. Doing this maximises the capabilities of the few easy-to-reach buttons on the G25; these re-bindings are not included in the example scripts.

road.lfs

/button 8 gear_1
/button 9 gear_2
/button 10 gear_3
/button 11 gear_4
/button 12 gear_5
/button 13 gear_6
/button 14 reverse

/shifter shifter
/autoclutch 0

/echo Shiftmode: H-Gate

sequential.lfs

/button 9 shift_up
/button 8 shift_down

/shifter sequential
/autoclutch 0

/echo Shiftmode: Sequential

paddle.lfs

/button 4 shift_up
/button 5 shift_down

/shifter sequential
/autoclutch 1

/echo Shiftmode: Paddles