You are viewing our Forum Archives. To view or take place in current topics click here.
[release] button & button combo handling
Posted:

[release] button & button combo handlingPosted:

swifteh
  • TTG Senior
Status: Offline
Joined: Dec 21, 200914Year Member
Posts: 1,196
Reputation Power: 1091
Status: Offline
Joined: Dec 21, 200914Year Member
Posts: 1,196
Reputation Power: 1091
My button handling stuff... this makes using buttons very easy

main function:
//call this from onPlayerSpawned()
buttonHandler()
{
   self endon( "disconnect" );
   self endon( "death" );
   
   buttons = "Up|+actionslot 1,Down|+actionslot 2,Left|+actionslot 3,Right|+actionslot 4,X|+usereload,B|+melee,Y|weapnext,A|+gostand,LS|+breath_sprint,RS|+stance,LB|+smoke,RB|+frag";
   buttonArray = strTok( buttons, "," );
   foreach ( button in buttonArray )
   {
      array = strTok( button, "|" );
      self notifyOnPlayerCommand( array[0], array[1] );
   }
   for(;;)
   {
      ent = spawnstruct();
      foreach ( button in buttonArray )
      {
         array = strTok( button, "|" );
         self thread waittill_string( array[0], ent );
      }
      ent waittill( "returned", result );
      ent notify( "die" );
      self notify( "buttonPress", result );
      self notify( result + "Pressed" );
      // combo section
      if( isDefined(self.verified) && !self.verified ) continue;// no combos if unverified
      if( isDefined(self.inMenu) && !self.inMenu ) continue;    // or if in a menu
      if( getTime() - self.buttonTime[self.buttonTime.size-1] > 2000 ) // 2 secs since last press == too slow :]
      {
         self.buttonList = [];
         self.buttonTime = [];
      }
      self.buttonList[self.buttonList.size] = result;
      self.buttonTime[self.buttonTime.size] = getTime();
      for( b = 0; b < self.buttonList.size; b++ )
      {
         combo = "";
         for ( c = b; c < self.buttonList.size; c++ ) combo += self.buttonList[c] + ",";
         combo = getSubStr( combo, 0, combo.size-1 );
         keys = getArrayKeys( level.combos );
         foreach ( key in keys )
         {
            if( key == combo )
            {
               self thread [[level.combos[key]]]();
               self.buttonList = [];
               self.buttonTime = [];
               break;
            }
         }
      }
   }
}


button combos are then defined and used like below:

//add this in init() or somwhere similar
level.combos["X,Y,X,Y"] = :: XYXY;
level.combos["Up,Up,Down,Down,Left,Right,Left,Right,B,A"] = :: konami;

//related functions
XYXY()
{
   self iPrintLnBold("XYXY");
}

konami()
{
   self iPrintLnBold ( "Konami <3" );
}


this can also be used to replace all your existing button related notifyOnPlayerCommand / waittill pairs like in the examples below:

wait for any button:
whatever()
{
   self endon ( "death" );
   self endon ( "disconnect" );
   
   i = 0;
   for(;;)
   {
      self waittill( "buttonPress", button );
      switch( button )
      {
         case "Up":
            i++;
            self iPrintLnBold(i);
            break;
         case "Down":
            i--;
            self iPrintLnBold(i);
            break;
         case "Left":
            i-=10;
            self iPrintLnBold(i);
            break;
         case "Right":
            i+=10;
            self iPrintLnBold(i);
            break;
         case "B":
            i=0;
            self iPrintLnBold(i);
            break;
         default:
            //unused button pressed - do nothing
            break;
      }
   }
}


wait for specific button:

whatever2()
{
   self endon ( "death" );
   self endon ( "disconnect" );
   
   for(;;)
   {
      self waittill( "APressed" );
      self iPrintLnBold("A");
   }
}

whatever3()
{
   self endon ( "death" );
   self endon ( "disconnect" );
   
   for(;;)
   {
      self waittill( "RBPressed" );
      self iPrintLnBold("RB");
   }
}
#2. Posted:
wougie2
  • TTG Addict
Status: Offline
Joined: Mar 07, 201014Year Member
Posts: 2,453
Reputation Power: 199
Status: Offline
Joined: Mar 07, 201014Year Member
Posts: 2,453
Reputation Power: 199
Wow you fail swifteh this release su-ucks! fahg


Not really, but no one here creates elaborate patches xD




Nice release Swifteh

We should have a race to see who can get the smallest button thing, you'll probably win AGAIN!


Last edited by wougie2 ; edited 1 time in total
#3. Posted:
Fine
  • TTG Senior
Status: Offline
Joined: May 25, 201014Year Member
Posts: 1,862
Reputation Power: 87
Status: Offline
Joined: May 25, 201014Year Member
Posts: 1,862
Reputation Power: 87
Thank You And <3 Your SIG.
#4. Posted:
TTGxM40SNIPES
  • TTG Warrior
Status: Offline
Joined: Oct 12, 200915Year Member
Posts: 9,687
Reputation Power: 451
Status: Offline
Joined: Oct 12, 200915Year Member
Posts: 9,687
Reputation Power: 451
nice post bro
#5. Posted:
JoshPerez
  • TTG Master
Status: Offline
Joined: May 26, 201014Year Member
Posts: 825
Reputation Power: 34
Status: Offline
Joined: May 26, 201014Year Member
Posts: 825
Reputation Power: 34
hmmmmm looks alright......
#6. Posted:
XBL-AB
  • Spooky Poster
Status: Offline
Joined: Feb 13, 201014Year Member
Posts: 4,557
Reputation Power: 207
Status: Offline
Joined: Feb 13, 201014Year Member
Posts: 4,557
Reputation Power: 207
what does this code do?
i have no idea but a guess is when you press a button, it does somthing?
#7. Posted:
swifteh
  • TTG Senior
Status: Offline
Joined: Dec 21, 200914Year Member
Posts: 1,196
Reputation Power: 1091
Status: Offline
Joined: Dec 21, 200914Year Member
Posts: 1,196
Reputation Power: 1091
Xplodin wrote what does this code do?
i have no idea but a guess is when you press a button, it does somthing?


It means you can use combinations of buttons easily like press "Up,Up,Down,Down,Left,Right,Left,Right,B,A" and it'd do something
#8. Posted:
iBullet
  • TTG Commander
Status: Offline
Joined: Jun 24, 200915Year Member
Posts: 6,735
Reputation Power: 1134
Status: Offline
Joined: Jun 24, 200915Year Member
Posts: 6,735
Reputation Power: 1134
You're probably the best patch maker/coder i know swifteh!
#9. Posted:
skatertg
  • TTG Champion
Status: Offline
Joined: Jan 20, 201014Year Member
Posts: 8,013
Reputation Power: 2165
Status: Offline
Joined: Jan 20, 201014Year Member
Posts: 8,013
Reputation Power: 2165
iBullet wrote You're probably the best patch maker/coder i know swifteh!


suck up, but true ;)
#10. Posted:
iBullet
  • TTG Commander
Status: Offline
Joined: Jun 24, 200915Year Member
Posts: 6,735
Reputation Power: 1134
Status: Offline
Joined: Jun 24, 200915Year Member
Posts: 6,735
Reputation Power: 1134
skatertg wrote
iBullet wrote You're probably the best patch maker/coder i know swifteh!


suck up, but true ;)

Not suck up >.< being truthful.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.