Talk:Scripting
From TF2 Wiki
Contents |
Echoing text to screen issue
- Greeze 15:47, 1 October 2007 (CST)
I'd really like to find a solution to the problem of echoing text to the screen.
Currently, our solution is to use developer 1 before echoing to show text on screen. Unfortunately, that turns on screen echoing for system output as well. Not only that, but using developer 0 hides all text that has been echoed to the screen.
Some have suggested using wait xx before using developer 0 commands. The problem with that is that we could end up with race conditions where one command turns off screen echoing for all other commands. For example:
alias echo1 "developer 1; echo Hello world!; wait 50; developer 0" alias echo2 "developer 1; echo Another hello!; wait 50; developer 0" bind x echo1 bind y echo2
Now, while playing, I press "x" and "Hello world!" is echoed to my screen. Then, 40 ticks later, I press "y". The words "Another hello!" appear on screen for only 10 ticks before echo1 hides all the text.
Has anyone found a graceful solution to this problem?
- I figured out that you could use console filtering and irregular prefix to make sure only your script messages go to the screen. I updated the page with a guide a few months ago, hope it helps people with their script packages! --Ofb 10:29, 8 November 2007 (CST)
Tutorials
- Greeze 14:37, 26 September 2007 (CST)
I think it would be a good idea to add some tutorials to this page, from very basic to advanced.
- Notes about config.cfg, how it works, its location (done)
- autoexec.cfg, how to create, where to create, how it works (done)
- basic binding (done)
- plus(+) and minus(-) commands (done)
- basic aliases (done)
- plus(+) and minus(-) aliases (done)
- executing other cfg files
- Moiax 15:09, 26 September 2007 (CST)
- Thanks, I saw someone posting these commands, but they didn't specify what to actually do with them.
- Just a thought, but we should probably avoid saying things like "left mouse button" as this means different things for different people. I would tend to pick "primary attack" instead.
- StryfeX 15:02, 27 September 2007 (CST)
- Agreed. We should probably come up with a glossary of terms and use that as a standard reference.
- Greeze 15:28, 27 September 2007 (CST)
- Agreed. I've changed it, but the wording might be a little confusing to total beginners. Anyone else want to have a whack at it?
- It might be best off to have a glossary, I'm not familiar enough with scripting any more to even consider starting something like that though. I haven't tried any scripting since the early days of TFC under the original Half-Life
Change Discussion
I removed the following text from the page as, in my testing, nothing got broken. Does anyone know who added that particular note, or what was causing the issue? Essobie 17:41, 4 October 2007 (CST)
- "Note: Currently, calling the command "exec yourconfigfile.cfg" while playing as a spy will break your disguise kit (the disguise kit won't respond to the numbered keys - most likely a bug.)"
- It would appear that the those numbers are hard coded in rather than slot<x> bound - probably to support X-BOX gamepads. You can view the variant interface for yourself by setting tf_disguise_menu_controller_mode 1, and before you ask, yes, it is just as useless. Spoonguard 02:09, 19 October 2007 (CDT)
I added the "lastdisguise" and "lastdisguise random" commands. I also removed the following text since I don't think "disguise random" ever did anything, and at any rate, "lastdisguise random" performs that function --Jethro 12:30, 7 October 2007 (CST)
- disguise random (chooses a random disguise that's neither Spy nor Scout) (no longer works as of 9/29/2007 - Essobie)
Aliasing the Wait command
- Aurora 18:30, 21 November 2007 (BST)
I originally put this in the Scripting Faq, but I decided it's not really a Faq unless someone else has come across it so I will ask it here.
- Q. If I create an alias for the Wait command it reacts differently.
- Example
- I wanted to create an alias to compensate for lag on servers, the TFCSniper script is pretty flimsy depending on how much lag you have and sometimes doesn't work. I created an alias like this:-
alias mediumwait "medwait1" alias medwait1 "wait 100" alias medwait2 "wait 120" alias medwait3 "wait 140"
- This would allow me to change mediumwait to the other aliases in game, after this I altered the tfcsniper script from:-
alias +tfcsniper "+attack2; wait 25; -attack2" alias -tfcsniper "+attack; wait 100; -attack; +attack2; wait 25; -attack2"
- to
alias +tfcsniper "+attack2; wait 25; -attack2" alias -tfcsniper "+attack; mediumwait; -attack; +attack2; wait 25; -attack2"
- Note that I am not actually changing the wait times here, simply referring the same wait 100 to an alias. The problem I got was that the script stopped working; it would go to the sniper scope and flip back to normal view while holding the key. Amending the times in the aliases would give different reactions, but not exactly the same as wait 100, which worked fine if no lag. Having played around with different examples (reload aliases, medheal scripts etc) to see if it was just the tfcsniper script, I've found that whenever I use the aliased wait, it will usually break the script I'm referring from if timing is critical.
use and equip
I found it pretty irritating that you have to use tf_weapon_flaregun if you have the flaregun and tf_weapon_shotgun_pyro if you have the shotgun, while none of the other medic or pyro items have different names for the basic and the unlock. I stumbled across this when I updated my binds so I could pull out weapons without accidentally voting on things and getting my weapon swap eaten.
Another thing was about the equip command:
- Medic
- equip 5 0 0 - syringe gun
- equip 5 0 1 - blutsauger
- equip 5 0 5 - syringe gun
- equip 5 1 0 - medigun
- equip 5 1 2 - kritzkrieg
- equip 5 1 4 - medigun
- equip 5 2 0 - bonesaw
- equip 5 2 3 - ubersaw
- equip 5 2 6 - bonesaw
- Pyro
- equip 7 0 0 - flamethrower
- equip 7 0 1 - flamethrower
- equip 7 0 5 - backburner
- equip 7 1 0 - shotgun
- equip 7 1 2 - shotgun
- equip 7 1 4 - flare gun
- equip 7 2 0 - axe
- equip 7 2 3 - axe
- equip 7 2 6 - axetinquisher
Two ways to pull out any of the basic versions, though one is always "0." The number for the unlocks doesn't seem to follow any pattern. Numbers 0-6 seem to be potentially valid for the third parameter, though unlisted ones don't seem to actually do anything. Anyone know how people figured out the equip command in the first place for medic? --Fyren 23:16, 30 June 2008 (UTC)
- Not that anyone seems to care, but:
- Heavy
- equip 6 0 0 - Sasha
- equip 6 0 1 - Sasha
- equip 6 0 5 - Sasha
- equip 6 0 8 - Natascha
- equip 6 1 0 - shotgun
- equip 6 1 2 - shotgun
- equip 6 1 4 - shotgun
- equip 6 1 7 - sandvich
- equip 6 2 0 - fists
- equip 6 2 3 - fists
- equip 6 2 6 - fists
- equip 6 2 9 - KGB
- Heavy
- Either I was wrong about there being only two ways to pull out the basic weapon or it was changed. Too lazy to recheck pyro and medic. Also, you have to use tf_weapon_lunchbox to pull out the sandvich. --Fyren 06:58, 20 August 2008 (UTC)
List of keys
Article needs to list (or link to a list) of all the the keys that can be bound to and their identifiers. I had a hell of time trying to find out how to bind things to the numpad.--TLAKABM 11:25, 1 July 2008 (UTC)
How are recursive functions written?
(Note: I'm not all to sure how to direct this article so I wanted to put it in the discussion before it's addition.) The script below contains a simple example of how to create a "recursive" alias. (For those whom are unfamiliar, recursion is self application within it's own definition.)
alias "dgJump0" "+jump; wait 10; -jump; wait 38; dgJump0"; bind "j" "dgJump0";
This basically jumps, waits a bit, undoes the jump, waits a bit more, and then calls itself again. The second wait time is important because it is the set time before it calls itself again. (i.e. The time between jumps.) Expanding off of this, here's a toggle to turn the constant jumping on and off.
alias "dgJump" "dgJump0"; alias "dgJump0" "+jump; wait 10; -jump; wait 38; dgJump"; alias "dgJump1" "echo Done jumping."; alias "dgJumpT" "dgJumpT1"; alias "dgJumpT0" "alias dgJump dgJump1; alias dgJumpT dgJumpT1; dgJump"; alias "dgJumpT1" "alias dgJump dgJump0; alias dgJumpT dgJumpT0; dgJump"; bind "j" "dgJumpT";
If you've read the "complex" alias tutorial you'll be able to identify what happens here. This expands to the previous code by using two toggles. (Which, as the author, I'm sure it can be truncated using less text.) Finally, here's an alias that combines plus and minus binds with recursion.
alias "dgPanic" "dgPanic0"; alias "dgPanic0" "+jump; wait 10; -jump; wait 38; dgPanic"; alias "dgPanic1" ""; alias "dgPanicT" "dgPanicT1"; alias "dgPanicT0" "alias dgPanic dgPanic1; alias dgPanicT dgPanicT1"; alias "dgPanicT1" "alias dgPanic dgPanic0; alias dgPanicT dgPanicT0"; alias "+dgPanic" "slot1; wait 10; cl_yawspeed 800; +attack; +right; dgPanicT; dgPanic"; alias "-dgPanic" "slot2; wait 10; cl_yawspeed 210; -attack; -right; dgPanicT; wait 100; taunt"; bind "p" "+dgPanic";
This code is a modified "panic script" made to include recursive jumping. Anyone familiar with most commands could identify what's happening up until "dgPanicT". "dgPanicT" enables jumping, and then "dgPanic" begins jumping. On the release, it simply disables it for reuse. (Author here, knowing that this explanation may need a bit more expanding.)
So, if anyone could give comments as to how understandable this code is, how well it's explained, or if it's even worth mentioning, I would appreciate it. --GutsMan 18:33, 15 July 2008 (EST)
