Neat! I'll attach a map with the GUI version of this script.
Development > Galaxy Scripting
Input, a script to capture key and mouse input
- 14 posts
-
Shawn91210 Author
- Battle.net
- Shawn
- #770 NA
- Join date
- Aug 17, 2010
- Location
- United States
- Reputation
- 1
- Posts
- 194
- Projects
- 3
- Teams
- Last login
- Mar 22, 2013
-
avogatro Author
- Battle.net
- avogatro
- #524 EU
- Join date
- Sep 24, 2010
- Location
- Germany
- Reputation
- 0
- Posts
- 234
- Projects
- 2
- Last login
- Apr 27, 2013
Any improvement compare to my 2 month old script? Which activate and deactivate itself for certain interval for every action and every active player?
include "TriggerLibs/NativeLib" trigger gt_WASD_test; bool WASD_w_down(bool testConds, bool runActions) { gv_trigger_stats[EventPlayer()][0]=1; if (gv_c_debug == true){ UIDisplayMessage(PlayerGroupSingle(EventPlayer()), c_messageAreaChat, StringToText("w down")); } TriggerEnable(TriggerGetCurrent(), false); Wait(0.1, c_timeGame); TriggerEnable(TriggerGetCurrent(), true); return true; } bool WASD_a_down(bool testConds, bool runActions) { gv_trigger_stats[EventPlayer()][1]=1; TriggerEnable(TriggerGetCurrent(), false); if (gv_c_debug){ UIDisplayMessage(PlayerGroupSingle(EventPlayer()), c_messageAreaChat, StringToText("a down")); } TriggerEnable(TriggerGetCurrent(), true); return true; } bool WASD_s_down(bool testConds, bool runActions) { gv_trigger_stats[EventPlayer()][2]=1; if (gv_c_debug){ UIDisplayMessage(PlayerGroupSingle(EventPlayer()), c_messageAreaChat, StringToText("s down")); } TriggerEnable(TriggerGetCurrent(), false); Wait(0.1, c_timeGame); TriggerEnable(TriggerGetCurrent(), true); return true; } bool WASD_d_down(bool testConds, bool runActions) { gv_trigger_stats[EventPlayer()][3]=1; if (gv_c_debug){ UIDisplayMessage(PlayerGroupSingle(EventPlayer()), c_messageAreaChat, StringToText("d down")); } TriggerEnable(TriggerGetCurrent(), false); Wait(0.1, c_timeGame); TriggerEnable(TriggerGetCurrent(), true); return true; } bool WASD_jump_down(bool testConds, bool runActions) { gv_trigger_stats[EventPlayer()][4]=1; TriggerEnable(TriggerGetCurrent(), false); gf_WASD_jump(EventPlayer()); Wait(gv_c_jump_period, c_timeGame); TriggerEnable(TriggerGetCurrent(), true); gv_trigger_stats[EventPlayer()][4]=0; return true; } bool WASD_shoot_down(bool testConds, bool runActions) { gv_trigger_stats[EventPlayer()][5]=1; TriggerEnable(TriggerGetCurrent(), false); while ((gv_trigger_stats[EventPlayer()][5] == 1)) { gf_WASD_shoot(EventPlayer()); Wait(0.8, c_timeGame); } TriggerEnable(TriggerGetCurrent(), true); return true; } bool WASD_shoot2_down(bool testConds, bool runActions) { gv_trigger_stats[EventPlayer()][6]=1; TriggerEnable(TriggerGetCurrent(), false); gf_WASD_shoot2(EventPlayer()); Wait(15, c_timeGame); TriggerEnable(TriggerGetCurrent(), true); return true; } bool WASD_w_up(bool testConds, bool runActions) { gv_trigger_stats[EventPlayer()][0]=0; if (gv_c_debug){ UIDisplayMessage(PlayerGroupSingle(EventPlayer()), c_messageAreaChat, StringToText("w up")); } TriggerEnable(TriggerGetCurrent(), false); Wait(0.1, c_timeGame); TriggerEnable(TriggerGetCurrent(), true); return true; } bool WASD_a_up(bool testConds, bool runActions) { gv_trigger_stats[EventPlayer()][1]=0; if (gv_c_debug){ UIDisplayMessage(PlayerGroupSingle(EventPlayer()), c_messageAreaChat, StringToText("a up")); } TriggerEnable(TriggerGetCurrent(), false); Wait(0.1, c_timeGame); TriggerEnable(TriggerGetCurrent(), true); return true; } bool WASD_s_up(bool testConds, bool runActions) { gv_trigger_stats[EventPlayer()][2]=0; if (gv_c_debug){ UIDisplayMessage(PlayerGroupSingle(EventPlayer()), c_messageAreaChat, StringToText("s up")); } TriggerEnable(TriggerGetCurrent(), false); Wait(0.1, c_timeGame); TriggerEnable(TriggerGetCurrent(), true); return true; } bool WASD_d_up(bool testConds, bool runActions) { gv_trigger_stats[EventPlayer()][3]=0; if (gv_c_debug){ UIDisplayMessage(PlayerGroupSingle(EventPlayer()), c_messageAreaChat, StringToText("d up")); } TriggerEnable(TriggerGetCurrent(), false); Wait(0.1, c_timeGame); TriggerEnable(TriggerGetCurrent(), true); return true; } bool WASD_jump_up(bool testConds, bool runActions) { gv_trigger_stats[EventPlayer()][4]=0; TriggerEnable(TriggerGetCurrent(), false); gf_WASD_jump(EventPlayer()); Wait(2.0, c_timeGame); TriggerEnable(TriggerGetCurrent(), true); return true; } bool WASD_shoot_up(bool testConds, bool runActions) { gv_trigger_stats[EventPlayer()][5]=0; TriggerEnable(TriggerGetCurrent(), false); Wait(0.1,c_timeGame); TriggerEnable(TriggerGetCurrent(), true); return true; } bool WASD_shoot2_up(bool testConds, bool runActions) { gv_trigger_stats[EventPlayer()][6]=0; TriggerEnable(TriggerGetCurrent(), false); return true; } bool WASD_test_Func (bool testConds, bool runActions) { // Variable Declarations int lv_player; // Variable Initialization lv_player = 0; return true; } void WASD_InitTriggers () { playergroup lv_pg_active = PlayerGroupActive(); int lv_p = 1; int lv_player ; while ( lv_p <= PlayerGroupCount(lv_pg_active)){ lv_player = PlayerGroupPlayer(lv_pg_active, lv_p); gv_trigger_array [lv_player][0]= TriggerCreate("WASD_w_down"); TriggerAddEventKeyPressed(gv_trigger_array [lv_player][0], lv_player, c_keyW, true, c_keyModifierStateIgnore, c_keyModifierStateIgnore, c_keyModifierStateIgnore); gv_trigger_array [lv_player][1]= TriggerCreate("WASD_w_up"); TriggerAddEventKeyPressed(gv_trigger_array [lv_player][1], lv_player, c_keyW, false, c_keyModifierStateIgnore, c_keyModifierStateIgnore, c_keyModifierStateIgnore); //TriggerEnable(gv_trigger_array [lv_player][1], false); gv_trigger_array [lv_player][2]= TriggerCreate("WASD_a_down"); TriggerAddEventKeyPressed(gv_trigger_array [lv_player][2], lv_player, c_keyA, true, c_keyModifierStateIgnore, c_keyModifierStateIgnore, c_keyModifierStateIgnore); gv_trigger_array [lv_player][3]= TriggerCreate("WASD_a_up"); TriggerAddEventKeyPressed(gv_trigger_array [lv_player][3], lv_player, c_keyA, false, c_keyModifierStateIgnore, c_keyModifierStateIgnore, c_keyModifierStateIgnore); //TriggerEnable(gv_trigger_array [lv_player][3], false); gv_trigger_array [lv_player][4]= TriggerCreate("WASD_s_down"); TriggerAddEventKeyPressed(gv_trigger_array [lv_player][4], lv_player, c_keyS, true, c_keyModifierStateIgnore, c_keyModifierStateIgnore, c_keyModifierStateIgnore); gv_trigger_array [lv_player][5]= TriggerCreate("WASD_s_up"); TriggerAddEventKeyPressed(gv_trigger_array [lv_player][5], lv_player, c_keyS, false, c_keyModifierStateIgnore, c_keyModifierStateIgnore, c_keyModifierStateIgnore); //TriggerEnable(gv_trigger_array [lv_player][5], false); gv_trigger_array [lv_player][6]= TriggerCreate("WASD_d_down"); TriggerAddEventKeyPressed(gv_trigger_array [lv_player][6], lv_player, c_keyD, true, c_keyModifierStateIgnore, c_keyModifierStateIgnore, c_keyModifierStateIgnore); gv_trigger_array [lv_player][7]= TriggerCreate("WASD_d_up"); TriggerAddEventKeyPressed(gv_trigger_array [lv_player][7], lv_player, c_keyD, false, c_keyModifierStateIgnore, c_keyModifierStateIgnore, c_keyModifierStateIgnore); //TriggerEnable(gv_trigger_array [lv_player][7], false); gv_trigger_array [lv_player][8]= TriggerCreate("WASD_jump_down"); TriggerAddEventKeyPressed(gv_trigger_array [lv_player][8], lv_player, c_keySpace, true, c_keyModifierStateIgnore, c_keyModifierStateIgnore, c_keyModifierStateIgnore); //gv_trigger_array [lv_player][9]= TriggerCreate("WASD_jump_up"); //TriggerAddEventKeyPressed(gv_trigger_array [lv_player][9], lv_player, c_keySpace, false, c_keyModifierStateIgnore, c_keyModifierStateIgnore, c_keyModifierStateIgnore); //TriggerEnable(gv_trigger_array [lv_player][9], false); gv_trigger_array [lv_player][10]= TriggerCreate("WASD_shoot_down"); TriggerAddEventMouseClicked(gv_trigger_array [lv_player][10], lv_player, c_mouseButtonLeft, true); gv_trigger_array [lv_player][11]= TriggerCreate("WASD_shoot_up"); TriggerAddEventMouseClicked(gv_trigger_array [lv_player][11], lv_player, c_mouseButtonLeft, false); //TriggerEnable(gv_trigger_array [lv_player][11], false); gv_trigger_array [lv_player][12]= TriggerCreate("WASD_shoot2_down"); TriggerAddEventMouseClicked(gv_trigger_array [lv_player][12], lv_player, c_mouseButtonRight, true); gv_trigger_array [lv_player][13]= TriggerCreate("WASD_shoot2_up"); TriggerAddEventMouseClicked(gv_trigger_array [lv_player][13], lv_player, c_mouseButtonRight, false); TriggerEnable(gv_trigger_array [lv_player][13], false); lv_p+=1; } }
Last edited Mar 10, 2011 by avogatro -
JademusSreg Moderator
- Join date
- May 09, 2010
- Location
- United States
- Reputation
- 20
- Posts
- 285
- Projects
- 1
- Last login
- Jun 19, 2013
In my experience, even disabled triggers to detect player key, button, and movement input generate network traffic. This is why using as few triggers as possible is preferable, as it is the only thing approximating a throttle we have on this issue.
Since the engine cannot perform simultaneous parallel processing of its threads, using multiple triggers when they will just fire in sequence anyway is needless overhead.
My script is intended to capture all player input from keys, mouse buttons, and mouse movement, without any specific implementation. Call me a romantic, but I have a soft spot for modularity. I'd like people to be able to do whatever they want with it, stopping just long enough to configure the constants that regulate the creation triggers, in case they don't need to detect key up or mouse movement.
So it's not an improvement, per se, but rather a script with some similar features but a different and more general purpose, which may also happen to be more conservative toward net traffic.
The only (minor) issue one may have with my script is the overhead cost of the variable memory which, assuming a 32-bit bool implementation, roughly exceeds 6 kb.
-
MotiveMe Author
- Battle.net
- Motive
- #866 NA
- Join date
- Apr 25, 2010
- Location
- United States
- Reputation
- 0
- Posts
- 288
- Projects
- 3
- Team
- Last login
- May 11, 2013
While I have a few issues with Jademus' script (consts, man, consts! 6, 16, 99, magic numbers make me sad), I'm inclined to agree with him in regards to the disabled triggers part.
CortexRP.com Creator
-
JademusSreg Moderator
- Join date
- May 09, 2010
- Location
- United States
- Reputation
- 20
- Posts
- 285
- Projects
- 1
- Last login
- Jun 19, 2013
My attempts at using constants to define array sizes have been met with syntax errors in the past. Also, they are not magic, so much as they should correspond to the highest constant ints for the relevant input types; keys go up to c_keyF12 = 98, for example. I have no other option there. It becomes the user's responsibility to modify them according to its needs.
EDIT: I tried using constants again and was pleasantly surprised. Script updated. Thanks Motive. =D
Last edited Mar 10, 2011 by JademusSreg -
s3rius Moderator
- Battle.net
- serius
- #707 EU
- Join date
- Apr 24, 2010
- Location
- Germany
- Reputation
- 8
- Posts
- 2,317
- Projects
- 1
- Last login
- May 01, 2012
Yea, Jademus' script is much cleaner than yours, avo :)
Though a const int for the player number would be appreciated:
const int MAX_PLAYERS = 16; ... Input[MAX_PLAYERS] playerInput;
-
JademusSreg Moderator
- Join date
- May 09, 2010
- Location
- United States
- Reputation
- 20
- Posts
- 285
- Projects
- 1
- Last login
- Jun 19, 2013
Yes. =)
-
avogatro Author
- Battle.net
- avogatro
- #524 EU
- Join date
- Sep 24, 2010
- Location
- Germany
- Reputation
- 0
- Posts
- 234
- Projects
- 2
- Last login
- Apr 27, 2013
- Beautiful is better than ugly.
- Explicit is better than implicit.
- Simple is better than complex.
- Complex is better than complicated.
- Flat is better than nested.
- Sparse is better than dense.
- Readability counts.
- Special cases aren't special enough to break the rules.
- Although practicality beats purity.
- Errors should never pass silently.
- Unless explicitly silenced.
- In the face of ambiguity, refuse the temptation to guess.
- There should be one and preferably only oneobvious way to do it.
- Although that way may not be obvious at first unless you're Dutch.
- Now is better than never.
- Although never is often better than right now.
- If the implementation is hard to explain, it's a bad idea.
- If the implementation is easy to explain, it may be a good idea.
- NameSpaces are one honking great idea. let's do more of those!
I don't know, if yours faster or not. But most other author use your logic, and their maps are not very fast.
I think, my system generate less traffic, but it is hard to proof.
We need a test with a lot of player. 2 system but same map.
Last edited Mar 11, 2011 by avogatro -
JademusSreg Moderator
- Join date
- May 09, 2010
- Location
- United States
- Reputation
- 20
- Posts
- 285
- Projects
- 1
- Last login
- Jun 19, 2013
My script almost certainly generates less network traffic, a total of 5 input catching triggers versus 14n where n is the number of active players, but it would be positively unscientific for one to be averse to testing such things. Be certain to implement each system in separate maps when conducting the tests, since toggling between the two in the same map via the disabling of triggers is not effective at throttling the network traffic generated by the input detection triggers, in my experience.
Also, your demonstrable wealth of platitudes has awed and humbled me.
-
s3rius Moderator
- Battle.net
- serius
- #707 EU
- Join date
- Apr 24, 2010
- Location
- Germany
- Reputation
- 8
- Posts
- 2,317
- Projects
- 1
- Last login
- May 01, 2012
Event's will probably be queued and sent in packages from one player to another.
Then they'll arrive at the other player who can then use them like the events have been generated on his local pc.
Thus it'll probably not matter very much in terms of net traffic.Two triggers which both use the same trigger event don't necessarily cause a game to transfere the same event twice.
See my awesome drawing skills for what I mean:
http://simplest-image-hosting.net/png-0-unbenannt63
I like your creed there. Filled with truth :)
Last edited Mar 11, 2011 by s3rius -
FuzzYD Author
- Battle.net
- FuzzYD
- #609 NA
- Join date
- Sep 08, 2010
- Location
- Malaysia
- Reputation
- 20
- Posts
- 886
- Projects
- 3
- Last login
- May 25, 2013
Only now do i realize i can use constants to declare array sizes.. it doesnt work if its not a constant right? Are there any cases in which this does not work?
Works AoS2
CoderBoss Bars+
Custom boss barsGXML
Dialog XML parserProject W
CoderRandN Aligning dialog labels -
s3rius Moderator
- Battle.net
- serius
- #707 EU
- Join date
- Apr 24, 2010
- Location
- Germany
- Reputation
- 8
- Posts
- 2,317
- Projects
- 1
- Last login
- May 01, 2012
-
JademusSreg Moderator
- Join date
- May 09, 2010
- Location
- United States
- Reputation
- 20
- Posts
- 285
- Projects
- 1
- Last login
- Jun 19, 2013
Trivial update; MAX_PLAYERS updated to INPUT_MAX_PLAYERS = c_maxPlayers to avoid namespace conflicts.
- 14 posts
JademusSreg ModeratorInput, a script to capture key and mouse input
Photon Cycles, the source files for a luminous lightbikes map
SC2Mapster's IRC channel, where map problems get a beating