Im_YouViolateMe

[GSC] My improved button monitoring

Apr 29th, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.89 KB | None | 0 0
  1. /////////////////////////////////////////////////////
  2. /*
  3. YouViolateMe
  4. Improved Button Monitoring now supports getStance
  5. 7/25/2016
  6. */
  7. /////////////////////////////////////////////////////
  8.  
  9. MonitorButtons()
  10. {
  11.     self endon("disconnect");
  12.    
  13.     self notify("stop_listening");
  14.     self notify("stop_notify");
  15.     self thread notifyOnPlayerCommand("dpad_up", ::ActionSlotOneButtonPressed, "stopAS1Notify");
  16.     self thread notifyOnPlayerCommand("dpad_down", ::ActionSlotTwoButtonPressed, "stopAS2Notify");
  17.     self thread notifyOnPlayerCommand("dpad_left", ::ActionSlotThreeButtonPressed, "stopAS3Notify");
  18.     self thread notifyOnPlayerCommand("dpad_right", ::ActionSlotFourButtonPressed, "stopAS4Notify");
  19.     self thread notifyOnPlayerCommand("button_sprint", ::SprintButtonPressed, "stopSprintNotify");
  20.     self thread notifyOnPlayerCommand("button_melee", ::MeleeButtonPressed, "stopMeleeNotify");
  21.     self thread notifyOnPlayerCommand("button_jump", ::JumpButtonPressed, "stopJumpNotify");
  22.     self thread notifyOnPlayerCommand("button_use", ::UseButtonPressed, "stopUseNotify");
  23.     self thread notifyOnPlayerCommand("button_switchweapon", ::ChangeSeatButtonPressed, "stopSeatButtonNotify");
  24.     self thread notifyOnPlayerCommand("button_stance", ::StanceButtonPressed, "stopStanceNotify");
  25.     self thread notifyOnPlayerCommand("button_attack", ::AttackButtonPressed, "stopAttackNotify");
  26.     self thread notifyOnPlayerCommand("button_aim", ::ADSButtonPressed, "stopADSNotify");
  27.     self thread notifyOnPlayerCommand("button_secondaryoffhand", ::SecondaryOffHandButtonPressed, "stopSecondaryOffHandNotify");
  28.     self thread notifyOnPlayerCommand("button_frag", ::FragButtonPressed, "stopFragNotify");
  29.    
  30.     self thread listen("stop_noclip_button_monitoring", ::ToggleNoclip, "dpad_left", undefined, "crouch"); //example for noclip
  31.  
  32.     //add custom button monitoring below if necessary
  33. }
  34.  
  35. ActionSlotOneButtonPressed(){ return self ActionSlotOneButtonPressed(); }
  36. ActionSlotTwoButtonPressed(){ return self ActionSlotTwoButtonPressed(); }
  37. ActionSlotThreeButtonPressed(){ return self ActionSlotThreeButtonPressed(); }
  38. ActionSlotFourButtonPressed(){ return self ActionSlotFourButtonPressed(); }
  39. SprintButtonPressed(){ return self SprintButtonPressed(); }
  40. MeleeButtonPressed(){ return self MeleeButtonPressed(); }
  41. JumpButtonPressed(){ return self JumpButtonPressed(); }
  42. UseButtonPressed(){ return self UseButtonPressed(); }
  43. ChangeSeatButtonPressed(){ return self ChangeSeatButtonPressed(); }
  44. StanceButtonPressed(){ return self StanceButtonPressed(); }
  45. AttackButtonPressed(){ return self AttackButtonPressed(); }
  46. ADSButtonPressed(){ return self ADSButtonPressed(); }
  47. SecondaryOffHandButtonPressed(){ return self SecondaryOffHandButtonPressed(); }
  48. FragButtonPressed(){ return self FragButtonPressed(); }
  49.  
  50. notifyOnPlayerCommand(ButtonNotify, isButtonPushed, stopNotify)
  51. {
  52.     self endon("disconnect");
  53.     self endon("stop_notify");
  54.     self endon(stopNotify);
  55.    
  56.     for(;;)
  57.     {
  58.         if (self [[isButtonPushed]]())
  59.             self notify(ButtonNotify);
  60.        
  61.         wait 0.05;
  62.     }
  63. }
  64.  
  65. listen(endon_event, function, event, event2, stance)
  66. {
  67.     self endon("disconnect");
  68.     self endon("stop_listening");
  69.     self endon(endon_event);
  70.    
  71.     for(;;)
  72.     {
  73.         if (!isDefined(event2))
  74.         {
  75.             if (!isDefined(stance))
  76.                 self waittill(event);
  77.             else
  78.                 self waittill_event_stance(.15, event, stance);
  79.            
  80.             if (self.AllowControls)
  81.                 self [[function]]();
  82.            
  83.             wait .18;
  84.         }
  85.         else
  86.         {
  87.             self waittill_both(.15, event, event2, isDefined(stance) ? stance : undefined);
  88.            
  89.             if (self.AllowControls)
  90.                 self [[function]]();
  91.            
  92.             wait .18;
  93.         }
  94.     }
  95. }
  96.  
  97. waittill_event_stance(time, arg1, stance)
  98. {
  99.     self endon("disconnect");
  100.    
  101.     threads = 0;
  102.    
  103.     while(threads < 2)
  104.     {
  105.         self waittill(arg1);
  106.         threads++;
  107.        
  108.         if (self getStance() == stance)
  109.             threads++;
  110.         else
  111.             threads = 0;
  112.     }
  113.    
  114.     self notify(arg1 + "_" + stance);
  115. }
  116.  
  117. waittill_both(time, arg1, arg2, stance)
  118. {
  119.     self endon("disconnect");
  120.    
  121.     threads = 0;
  122.    
  123.     while(threads < 2)
  124.     {
  125.         firstarg = self waittill_any_return(arg1, arg2);
  126.         threads++;
  127.         self thread timeout(time);
  128.        
  129.         if (firstarg == arg1)
  130.             self thread waitforstring(arg2);
  131.         else if (firstarg == arg2)
  132.             self thread waitforstring(arg1);
  133.        
  134.         msg = self waittill_any_return("button_pushed", "stop_waiting");
  135.        
  136.         if (msg == "stop_waiting")
  137.             threads = 0;
  138.         else if (msg == "button_pushed")
  139.         {
  140.             if (isDefined(stance))
  141.             {
  142.                 if (self getStance() == stance)
  143.                     threads++;
  144.                 else
  145.                     threads = 0;
  146.             }
  147.             else
  148.                 threads++;
  149.         }
  150.     }
  151.    
  152.     self notify(arg1 + "_" + arg2);
  153. }
  154.  
  155. timeout(time)
  156. {
  157.     self endon("disconnect");
  158.     self endon("button_pushed");
  159.    
  160.     wait(time);
  161.     self notify("stop_waiting");
  162.    
  163.     return;
  164. }
  165.  
  166. waitforstring(arg, threads)
  167. {
  168.     self endon("disconnect");
  169.     self endon("stop_waiting");
  170.    
  171.     self waittill(arg);
  172.     self notify("button_pushed");
  173.    
  174.     return;
  175. }
  176.  
  177. ToggleNoclip() //my example function
  178. {
  179.     self.Noclip = !self.Noclip;
  180.     if (self.Noclip)
  181.     {
  182.         self notify("stop_noclip");
  183.         self thread Noclip();
  184.     }
  185.     else
  186.     {
  187.         self unlink();
  188.         self enableweapons();
  189.         self.originObj delete();
  190.         self notify("stop_noclip");
  191.     }
  192. }
  193.  
  194. Noclip()
  195. {
  196.     self endon("stop_noclip");
  197.     self endon("disconnect");
  198.     self.originObj = spawn( "script_origin", self.origin, 1 );
  199.     self.originObj.angles = self.angles;
  200.     self playerlinkto( self.originObj, undefined );
  201.     self disableweapons();
  202.     for(;;)
  203.     {
  204.         if(FragButtonPressed())
  205.         {
  206.             normalized = anglesToForward( self getPlayerAngles() );
  207.             scaled = vectorScale( normalized, 40 );
  208.             originpos = self.origin + scaled;
  209.             self.originObj.origin = originpos;
  210.         }
  211.         else if(MeleeButtonPressed())
  212.         {
  213.             self unlink();
  214.             self enableweapons();
  215.             self.originObj delete();
  216.             self.Noclip = false;
  217.             self notify("stop_noclip");
  218.         }
  219.         wait 0.05;
  220.     }
  221. }
Advertisement
Add Comment
Please, Sign In to add comment