Skryptowanie

From Team Fortress Wiki
< Scripting
Revision as of 17:14, 13 August 2011 by Nuc (talk | contribs) (translated some sections, there's not much left though)
Jump to: navigation, search

"Skryptowanie" jest użyciem plików konfiguracyjnych do tworzenia nowych bindów oraz aliasów do tworzenia złożonych operacji oraz sekwencji konsolowych komend.

  • Keybind przypisuje przycisk do komendy konsolowej, na przykład: wybieranie slotu broni czy w celu szybkiego napisania wcześniej oskrypotwanego tekstu.
  • Aliasy tworzą nowe komendy poprzez realizowanie paru komend jednocześnie. Aliasu można użyć do np: wykonania skoku i kucnięcia przy użyciu jednego przycisku.

These scripts range in complexity from simple lists of commands to self-referential loops and nested aliases that redefine one another. With enough time and effort, you can use the tools to create almost any behavior available to the client at the press of a single key.

Podstawowe pliki skryptowania

Team Fortress 2 automatycznie czyta kilka plików gry i odtwarza bindy i aliasy w środku. Oto lista tych plików:

  • config.cfg - Jest to domyślny plik konfiguracyjny, który jest edytowany kiedykolwiek gracz zmienia przypisania klawiszy lub opcje grafiki. Nawet jeżeli edytowanie tego pliku jest bezpieczne, najlepiej zostawić go w spokoju.
  • autoexec.cfg - Jest to domyślny plik konfiguracyjny używany do odtwarzania niestandardowych bindów i aliasów. Gracz może tu wpisać swoje bindy do tego pliku jednak często jest tak, że łatwiej jest stworzyć osobny plik .cfg do pozostałych skryptów, które poźniej można odtworzyć w tym pliku.
  • <klasa>.cfg - Każda klasa ma plik konfiguracyjny który automatycznie odtwarza się gdy gracz zaczyna grać jedną z tych klas. Można wpisać tam swoje bindy bezpośrednio do tego pliku, jednak często jest tak, że łatwiej jest stworzyć osobny plik .cfg który później odtwarza się w tym pliku.

Składnia

Lista zasad składni:

  • Żeby jakikolwiek bind czy alias działał poprawnie, musisz użyć tego formatu:
komenda <argument1> <argument2>
  • komenda jest typem skryptu którego chcesz użyć:
  • bind - Używany do przypisania komendy do jakiegoś przycisku
  • alias - Used to execute commands when the alias is executed.
  • exec - Używany do odtworzenia komend automatycznie po załadowaniu pliku konfiguracyjnego.
  • <argument1> może być albo przypisywanym przyciskiem lub nazwą stworzonego aliasu
  • <argument2> może być komendą przypisywaną do przycisku lub komendy odtwarzane przez alias.
  • Aby uruchomić parę komend jednocześnie, musimy postawić cały argument w cudzysłowach oraz oddzielić komendy apostrofem:
alias "walnaslepo" "+attack; wait 500; -attack"
bind "mouse3" "walnaslepo"
  • Podczas odtwarzania, alias zaczyna strzelać z broni gracza, kontynuuje przez 500 fizycznych klatek (jest to 5 sekund jeżeli gracz gra na serwerze który działa na 100 FPS) po czym przestaje strzelać. Alias jest przypisany aby rozpocząć strzelanie po wciśnięciu kółka myszy.
  • To enclose something in quotes that already has quotes in it, you have to escape the internal quotes by using two consecutive quotes ("") in place of each one.
alias "saysomestuff" "say ""Some Stuff..."""
  • When you type saysomestuff in the console, you will speak "Some Stuff..." in the chat. Without the internal quotes, the chat window will only show "Some".

Przypisywanie klawiszy

Team Fortress 2 pozwala skryptom oraz aliasom do bycia przypisanym do jakiegokolwiek przycisku na klawiaturze. Przyciks który chcesz przypisać jest wpisywany po komendzie bind oraz przed akcją którą chcesz aby twój przycisk wykonywał, tak jak w sekcji u góry. Większość nazw przycisków można łatwo odgadnąć, jak litery alfabetu czy cyfry ("bind a" przypisuje "a", "bind 5" przypisuje do "5" itd. Pozostałe przyciski wymagają od użytkownika wpisania specyficznych nazw. Wiele z nich nie są łatwe do odgadnięcia. Lista takich nazw znajduje się poniżej:

Lista nazw przycisków

  • Keyboard Keys: Nazwy przycisków
  • Lewy Shift: SHIFT
  • Lewy Control: CTRL
  • Lewy Alt: ALT
  • Prawy Shift: RSHIFT
  • Prawy Control: RCTRL
  • Prawy Alt: RALT
  • Tab: TAB
  • Backspace: BACKSPACE
  • ---
  • Insert: INS
  • Scroll Lock: SCROLLLOCK
  • Pause/Break: NUMLOCK
  • ---
  • Home: HOME
  • End: END
  • Delete: DEL
  • Page Up: PGUP
  • Page Down: PGDN
  • ---
  • Strzałka w górę: UPARROW
  • Strzałka w dół: DOWNARROW
  • Strzałka w lewo: LEFTARROW
  • Strzałka w prawo: RIGHTARROW
  • Przyciski klawiatury numerycznej: Nazwy przycisków
  • 0: KP_INS
  • 1: KP_END
  • 2: KP_DOWNARROW
  • 3: KP_PGDN
  • 4: KP_LEFTARROW
  • 5: KP_5
  • 6: KP_RIGHTARROW
  • 7: KP_HOME
  • 8: KP_UPARROW
  • 9: KP_PGUP
  • Enter: KP_ENTER
  • ".": KP_DEL
  • "+": KP_PLUS
  • "-": KP_MINUS
  • "*": KP_MULTIPLY
  • "/":KP_SLASH
  • Kierunki kółka myszy: Nazwy przycisków
  • Kółko myszy w GÓRĘ: MWHEELUP
  • Kółko myszy w DÓŁ: MWHEELDOWN

Używając nazw przycisków powyżej możesz dodać ten przykładowy skrypt do jednego z plików konfiguracyjnych: <bind KP_ENTER "voicemenu 0 1"> Po wciśnięciu Enter na KLAWIATURZE NUMERYCZNEJ, gra uaktywni komendę głosową mówiącą "Dźięki!".

Podstawowe komendy

Większość komend przyjmuje tylko jeden argument, zazwyczaj cyfrę.

bind "q" "sv_alltalk 1"

Wiele przydatnych komend przyjmuje więcej niż jeden argument. Parę przykładów:

  • disguise X Y - przebiera Szpiega za inną klasę. Zamiast X wpisujemy numer klasy od 1-9, a zamiast Y wpisujemy 1 lub 2, wybierając drużynę za którą chcemy się przebrać.
  • voicemenu X Y - Odtwarza komendę głosową. Zamiast X wpisujemy numer menu komend dźwiękowych. Y za to jest pozycją komendy w tym menu komend głosowych.

Przykład: "voicemenu 1 1" jest komendą ostrzegającą drużynę przed Szpiegiem, więc:

bind "t" "voicemenu 1 1"

Ta komenda zmusi twoją postać do wykrzyknięcia "Szpieg!" po wciśnięciu przycisku.

Incrementvar

This command cycles through a range of specified values whenever it executes and applies those values to another command. This has the form of:

command "<argument1>" "incrementvar <argument2> X Y Z"
  • X and Y represent the range of values you want to execute with <argument2>.
  • Z is the size of the step you want to make while you cycle through the range.

If you wanted a value range of 1 through 10 and you wanted to increment your value by 2 each time the command was executed, you'd make X Y Z into 1 10 2. Then each time it executes, <argument2> will execute with an incrementing value of 2, 4, 6, 8, 10, 2, 4, 6, 8, 10... and so forth.

Here is a real example of incrementvar in action:

bind "n" "incrementvar net_graphpos 1 3 1"

This binds the key "n" to cycle to the next position in the 3 available net_graph positions.

Komendy + i -

Komendy tego typu mają dwa stany. Po wciśnięciu przypisanego przycisku +komenda jest uruchamiana i kontynuuje. Po puszczeniu przycisku, -komenda jest uruchamiana i kontynuuje.

Przykład:

bind "c" "+duck"

Ta +komenda jest przypisana do "c", więc kiedykolwiek ten przycisk jest użyty, gracz kuca. Jeżeli przycisk zostaje puszczony +duck zmienia się na -duck i gracz przestaje kucać.

W skrócie, jeżeli komenda lub alias jest przypisany do przycisku, + mówi grze aby utrzymywać komendę w stanie uruchomienia dopóki przycisk nie zostanie puszczony. Zato jeżeli komenda lub alias jest przypisany do przycisku, - mówi grze aby utrzymać komendę wyłączoną gdy przycisk nie jest używany.

Jeżeli alias ma + przed sobą, alias zostanie użyty kiedykolwiek ten przycisk jest wciśnięty. Komenda - zrobi odwrotnie.

Komenda wait

Jeżeli chcesz aby gra opóźniła działanie komendy przy użyciu aliasu, lub jeżeli chcesz uniknąć crashy klienta wywołanymi przez uruchamianie komend zbyt szybko, użyj komendy wait.

Wait mówi grze aby opóźniła następną komendę o jedną fizyczną klatkę. Coś w jakby pełny obrót zegara według zasad TF2. Komenda ta akceptuje liczby jak "wait 50", które mówią grze aby odczekała 50 fizycznych klatek zanim alias kontynuuje działanie. "wait 100" oznacza sekundę opóźnienia na serwerze który działa przy 100 klatkach na sekundę. Niektóre serwery zabraniają użycia komendy wait. Podczas grania na takich serwerach, komendy wait będą ignorowane wystawiając klienta używającego niektórych skryptów na crashe klienta. Skrypt używający pętli oddzielonymi komendami wait zawiesi wszystkie pętle od razu po uruchomieniu.

Aliasy

Alias jest zmienną która przechowuje serie komend które mogą być odtworzone jako grupa. Prosty alias będzie wyglądać tak:

alias "nazwaAliasu" "komenda1; command2; command3"

Oznacza to że można odtwarzać komendy poprzez przypisany klawisz:

bind "przycisk" "nazwaAliasu"

Po wciśnięciu przycisku, komenda1, komenda3, komenda3 zostaną odtworzone w porządku w jakim są wpisane.

Złożone Aliasy

Aliasy mogą odtwarzać każdą komendę z innymi aliasami włącznie. W dodatku alias może odtworzyć alias aby zmienić ustawienia komend poprzedniego aliasu. To pozwala użytkownikowi na tworzenie zmiennych aliasów, tu mamy bardzo łatwy do wykonania przykład: bind "key" namescroll
alias namescroll "imie1"
alias imie1 "setinfo name "imieK1"; alias namescroll imie2"
alias imie2 "setinfo name "imieK2"; alias namescroll imie3"
alias imie3 "setinfo name "imieK3"; alias namescroll imie2"

Jest to trudne to przeczytania więc rozłamiemy to na parę części:

  • Pierwsza linia przypisuje "przycisk" do aliasu o nazwie "namescroll", który musimy jeszcze zdefiniować.
  • Druga linia tworzy alias "namescroll" który odtwarza komendę "imie1"
  • Trzecia linia definiuje alias "imie1" jako 2 komendy.
  • Pierwsza komenda ustawia twoje imię jako The first command sets your in-game name to "ImieK1"
  • Druga komenda redefiniuje alias "namescroll" jako alias do odtworzenia aliasu ImieK2 The second command redefines the alias "namescroll" as an alias for executing the alias "secondname"
  • Czwarta linia definiuje "imie2" tym samym sposobem. Inne (tym razem drugie) imię jest używane w grze, co redefiniuje "namescroll" do jako następny alias "imieK3"
  • The fifth line defines "thirdname" just like the two before it, but with a twist. It redefines the "namescroll" alias as executing the "firstname" alias.

This completes a loop. Each press of the key executes a command and redefines the alias bound to the key, so that when it is next pressed it will execute a different command. If there were no loop, then the alias "namescroll" wouldn't always have another alias to execute with each keypress.

Alias Loops

Aliases can be used in conjunction with the Wait command to create looping aliases.


Warning:Not having the wait in place, or being on a server with wait disabled will cause this example to crash TF2.
alias "Loop" "echo Looping every 150 ticks.;wait 150;Loop"
Loop

Lets break this down into components:
Line 1
The echo displays a message to the console, just so you know it works.
The wait makes it wait 150 ticks between iterations
Loop calls the alias again, restarting at the echo.

Line 2
Loop starts the looping alias.

You can also create loops of alias commands, like this example:

alias "Loop1" "echo Loop 1;wait 150;Loop2"
alias "Loop2" "echo Loop 2;wait 150;Loop1"

Loop1 calls Loop2 which in turn calls Loop1, etc...
This method can also be used for breaking a loop without clearing the loop alias:

alias "Loop1" "echo Loop1;wait 150;Loop2"
alias "Loop2" "Loop1"

This would create a loop, then

alias "Loop2"

would break it, by clearing the Loop2 alias.

You can use these for button presses(Via the +/- prefixes covered earlier) like this:

alias "Loop2" "Loop1"
alias "Loop1" "echo Loop1;wait 150;Loop2"
alias "+Loop" "alias Loop2 Loop1;Loop2"
alias "-Loop" "alias Loop2"
bind "<Key>" "+Loop"

In order of what it's doing:
Make Loop2 point to Loop1
Make Loop1 echo 'Loop1' to the console, wait 150, then call Loop2
make +Loop point Loop2 to Loop1 and run Loop2
make -Loop clear Loop2's link, breaking the loop

Useful Script Commands

There are literally hundreds of different arguments for your script that can make them do almost anything. Here's a list of a few of them.

Komendy głosowe

Komendy głosowe rozkazują twojej postaci aby powiedzieć coś. Jest to często używane w grze jako droga przekazywania informacji (np. Potrzebny tu zasobnik!) lub po prostu dla zabawy (np. Pootis pootis pootis).

Komendy głosowe używane są poprzez ta składnię;

voicemenu <numer_menu> <numer_komendy>

<numer_menu> jest jednym z trzech menu w których są komendy głosowe, <numer_komendy> jest jedną z siedmiu z nich w jednym z trzech menu.

Argumeny komend głosowych

  • 0 <numer_komendy>
    0: Medyk
    1: Dzięki
    2: Dalej!
    3: Naprzód
    4: Idź w lewo
    5: Idź w prawo
    6: Tak
    7: Nie
  • 1 <numer_komendy>
    0: Nadchodzą
    1: Szpieg
    2: Potrzebne działo
    3: Potrzebny teleporter
    4: Potrzebny zasobnik
    5: Działko przed nami
    6: Użyj UberCharge
    7: (Tylko medyk) ÜberCharge gotowy
  • 2 <numer_komendy>
    0: Pomocy
    1: Okrzyk
    2: Zadowolenie
    3: Niezadowolenie
    4: Pozytywne nastawienie
    5: Negatywne nastawienie
    6: Dobry strzał
    7: Dobra robota

Szybkie przebieranie Szpiega

With these quick and easy commands, you can bind keys to specific disguises instead of having to flip through the disguise menu.

Disguise commands are used with the following syntax;

disguise <class_number> <team_number>

Where <class_number> is the number of the class you wish to disguise as, and <team_number> the number of the team you wish to disguise as.

Argumenty przebrań Szpiega

  • 1 <class_number>
    1: Scout
    2: Sniper
    3: Soldier
    4: Demoman
    5: Medic
    6: Heavy
    7: Pyro
    8: Spy
    9: Engineer
  • 2 <team_number>
    1: BLU team
    2: RED team
    -1: Opposite team
    -2: Same team

Szybkie budowanie Inżyniera

Similar to the Spy's quick disguise, this allows the Engineer to bypass his PDA interface and instantly destroy an existing building type while simultaneously pulling up blueprints to place a new building of the same type.

Building commands are used with the following syntax:

build <building_number>
destroy <building number>

Where <building_number> is the number of the building you wish to destroy or pull up blueprints for.

Argumenty szybkiego budowania

  • Number: Building/Destroying
    0: Dispenser
    1: Teleporter Entrance
    2: Sentry Gun/Minisentry
    3: Teleporter Exit

An example of how to implement the above syntax is as follows:

alias sentry "destroy 2; build 2"
alias dispenser "destroy 0; build 0"
alias entrance "destroy 1; build 1"
alias exit "destroy 3; build 3"
bind f1 sentry
bind f2 dispenser
bind f3 entrance
bind f4 exit

In this example buildings are bound to the f1-f4 keys so they do not interfere with weapon selection keys. When activated, the script will instantly and irreversibly destroy an existing building of the listed type while pulling up the Engineer's blueprints of the destroyed building's same type, ready to deploy. The script will still function if only one or two building types are used (in case you only want to map sentry quickbuilding to a single key).

Automatyczne wezwanie Medyka

The Medic can control his autocall threshold through keybinds. The command is:

hud_medicautocallersthreshold <percentage>

The percentage is the percent health below which the autocall is triggered; 0 will show nothing, while 150 will show all nearby allies (since 150% is the maximum possible health).

This command can be used to make the popular "Medic Radar" script: This set of aliases and commands will temporarily boost the Medic's autocall threshold to 150% (a fully-overhealed player)for as long as they hold a key down, allowing him to see where all of his teammates are by their Medic autocall speech bubbles in the event he finds himself alone.

 alias "autocall_default" "hud_medicautocallersthreshold "75""
alias "autocall_all" "hud_medicautocallersthreshold "150""
alias "+radar" "autocall_all"
alias "-radar" "autocall_default"
bind mouse3 "+radar"

The default autocall value, or the autocall threshold when this command is not in use, can be adjusted to any desired number (in the example it is listed as 75% health) and the keybind to activate it can be changed as well (the example is bound to mouse3).

Skrypty warte uwagi

Istnieje parę skryptów wpływających na rozgrywkę, niektóre z nich zostały naprawione. Pozostałe dalej mogą być używane.

Naprawione skrypty

Pistol Scripts

Originally, the Pistol could be fired almost as fast as the human hand could press a key. Realizing this, some people created scripts that made the Pistol fire as rapidly as possible as long as you held down the fire button. This not only allowed the Scout and Engineer to fire faster than most people could manage, but it was easier to aim because you weren't mashing any keys.

Valve eventually leveled the playing field. They patched the Pistol to have a lower max firing rate, which was reached by default whenever a player held down the attack key. The Pistol scripts were no longer necessary.

Targe Turn Scripts

Originally, the keyboard commands to turn your viewpoint left and right were not treated the same as the mouse commands. The Chargin' Targe was the first weapon to create a restriction on how quickly you could turn your viewpoint, therefore Valve put a limit on mouse turn-speed but forgot to apply the same restriction to the keyboard command that resulted in the same action.

Players made scripts that rebound keys whenever a player charged, allowing them to turn at full speed. The most sophisticated examples temporarily rebound the mouse x-axis inputs to the keyboard turn commands, then unbound them when the player attacked at the end of the charge.

Valve eventually capped the keyboard turn commands as they did with the mouse commands, thus conferring no advantage to individuals who used the script.

However, it is still possible to write a script that will toggle Sensitivity between insanely high values when charging and normal value when the player performs an attack. It is also possible to turn easily while using a gamepad's analog sticks.

Air Crouching Scripts

Originally, you could crouch as many times as you liked in a single jump. By binding a script to crouch and uncrouch as rapidly as possible, you could exploit the engine and make it difficult to properly register shots on jumping targets.

Valve patched it so you could only crouch twice in a single jump.

Current Scripts

Weapon Hiding Scripts

There are a large number of scripts which toggle the weapon display option depending on which weapon slot is selected for a class. Players often make their guns invisible to clear up the screen, but make items like melee weapons, PDAs, watches and so forth visible because these models indicate important information. For example, the Spy relies heavily on his visible model to determine when he is cloaked, when his Cloak is disturbed, and when the Dead Ringer activates. Other classes use the melee animations to judge when their attacks will hit.

Sentry Jumping Scripts

Since the Engineer update, Engineers have been able to pack up and carry their Sentry Guns. Simultaneously, the Wrangler allowed Engineers to Sentry jump with their Sentry rockets. With extremely fast inputs, it was discovered that a player could Sentry jump and successfully pack up their Sentry before they were launched away.

While a human can repeat this feat, it's difficult and sometimes inconsistent. Some players made scripts which could reliably execute the commands in the right order at the right speed. They can make a Sentry jump while carrying their Sentry every time.

Gunslinger Scripts

Since it can be troublesome to destroy then rebuild a Combat Mini-Sentry in the heat of battle through the PDA, some players have scripted the destruction and rebuilding of their Mini-Sentry with the click of one or two mouse buttons.

Sensitivity and Control Scripts

Some players prefer different mouse sensitivities and control schemes for some classes (for example, changing from Demo, which doesn't require fine aiming, to Sniper, which encourages low sensitivity for precise aiming so a hand twitching inadvertently won't ruin your aim too much). These scripts alter their control schemes and mouse settings on a per class or even per weapon basis.

Charge Dash Scripts

Since timing the charge and jump can be difficult, some may use a quick script that binds the two actions to a button so that the charge dash will do the maximum amount of distance possible. The user is still required to swing their melee weapon normally to end the charge though.

Quickscope Scripts

Many players find it difficult to scope in, and fire right after to get a quick head shot. There are scripts that will zoom in, and fire just by clicking one mouse button. It may be harder to aim for some people, because you must aim outside of the scope, but it speeds up how fast you fire if you can aim well.

See Also

External Links