Talk:Scripting
From TF2 Wiki
Contents |
Scripting GUI library
Cryzbl 07:24, 2 April 2009 (UTC) Hello, I'm new to this site but I've read this page a long time ago and I found it very very helpful. But one thing I never liked was how the echo to screen thing works here. It's annoying and has issues, I solved all of these problems and submitted something you could call a library to fpsbanana: http://www.fpsbanana.com/scripting/4177 Thoughts?
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)
- It should be noted that with the addition of sv_allow_wait_command in the 2009-05-21 update that such recursive aliases could cause the client to freeze as it would continue to loop without delay. A simple solution is to alias wait to disable them:
alias "+panic" "cl_yawspeed 800; +right; use tf_weapon_flamethrower; +attack; alias panic- panic+; panic+" alias "-panic" "cl_yawwpeed 210; -right; -attack; alias panic-" alias "panic+" "+jump; wait 10; -jump; wait 38; panic-" alias "panic-" "" alias "wait" "alias panic+; alias wait; echo WAIT DISABLED ON THIS SERVER" wait
- If sv_allow_wait_command is set, then wait is interpreted normally changing nothing. However if unset, wait is interpreted as the alias, which deletes panic+ ending the recursion, notifies the user, and deletes the wait alias so this is only done once. The explicit following call to wait performs this check when the file is loaded. In regards to cleaning up the script, the toggle aliases are unnecessary as a key will simply be bound to +panic. Setting the recalling alias to another that is empty is also unnecessary as it can itself be set to empty within another as demonstrated in -panic and wait. -- Vaeden 06:39, 26 May 2009 (UTC)
Showing Scores
--Omegaman 03:58, 21 December 2008 (UTC)
Hello all, I'm afraid that I've done something stupid and I don't know where else to ask. I accidentally set the tab key to run a bind, not remembering that it is supposed to show the scores. Does anyone know the console command to show the scores? Thank you for the help.
--Omegaman 22:41, 21 December 2008 (UTC)
EDIT: I found it. It's +showscores, for anyone who is interested.
Question about countering scripts
Hi. I'm pretty new to this wiki thing, and I'm not quite sure if this is the right place for me to ask, but there's something I need help with. I want to run one of the Scout scripts found in the community script page (namely, "Total Weapon Interface Redesign"). I placed this script in the scout.cfg file, but it affects the rest of the classes, too. The article says I have to "counter" this in the other cfg files, how do I go about doing this? Thanks in advance! Sembregall 02:53, 3 February 2009 (UTC)
- The method I use to 'counteract' scripts is to write out an autoconfig.cfg file, with the default controls scripted in it. After that, I simply add 'exec autoconfig.cfg' to the beginning of each of my class configuration files. This 'resets' your controls to default when you change classes, and then applies your class-specific scripts.
- Hope that helps. - Balphezar 23:10, 2 April 2009 (UTC)
- I've added a clarification in the wiki, as I was confused as well. - Axon 23:51, 9 April 2009 (UTC)
New weapon commands
Does anyone know how to find the commands to use the new weapons released in each main update?
I'm looking for the names like tf_weapon_lunchbox_drink etc.
A full/relative path to a tf2 file with the names in would be nice, or simply a method to find out the names so we can keep the USE section updated.
- Open team fortress 2/tf/bin/client.dll in a HEX editor and search for "tf_weapon_" -- Vaeden 04:26, 26 May 2009 (UTC)
FaN
Does anyone know the weapon name for the Force-A-Nature? --Matthew0505 08:07, 3 June 2009 (UTC)
- Same as the scatter gun (tf_weapon_scattergun) -- Vaeden 21:14, 6 June 2009 (UTC)
