Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to detect that you have pressed two buttons at once?
#1
Hello everybody,

I am trying to make something that a function will run when you hit two buttons at once.
First I have tried this:
Code:
button_watch()
{
    self endon("disconnect");
    self endon("death");
    for(;;)
    {
        if(self UseButtonPressed() && self MeleeButtonPressed())
        {
            wait .2;
            self giveWeapon( "spas_mp" );
         }
    }
}
But that didn't work.

After I tried this:
Code:
button_watch()
{
    self endon("disconnect");
    self endon("death");
    for(;;)
    {
        if(self UseButtonPressed())
        {
            wait .2;
            if (self.buttonpressed == 1)
            {
                 self giveWeapon( "spas_mp" );
                 self.buttonpressed = 0;
            }
            else
            {
                self.buttonpressed = 3;
            }
        }    
        if(self MeleeButtonPressed())
        {
            wait .2;
            if (self.buttonpressed == 3)
            {
                 self giveWeapon( "spas_mp" );
                 self.buttonpressed = 0;
            }
            else
            {
                self.buttonpressed = 1;
            }
        }
    }
}

onPlayerSpawned()
{
    for(;;)
    {
        self.pressedbutton = undefined;
    }
}
But that didn't give me a spas either.

So what am I doing wrong?
Thanks Smile
Reply

#2
Code:
button_watch()
{
    self endon("disconnect");
    self endon("death");
    for(;;)
    {
        if(self UseButtonPressed() && self MeleeButtonPressed())
        {
            self giveWeapon( "spas_mp" );
         }
         wait .1;
    }
}
[Image: wyipjqo9qon7rc2v1lo.jpg]
Reply

#3
I have tried your code but it still doesn't work.
Reply

#4
which thread did u call?
[Image: wyipjqo9qon7rc2v1lo.jpg]
Reply

#5
Whoops I forgot to post that part of the spawned block, here is the complete one.
Code:
onPlayerSpawned()
{
    self endon("disconnect");

    self.pressedbutton = undefined;
    for(;;)
    {
        self waittill("spawned_player");
        self thread button_watch();
        if(!isdefined(self.hud_rankscroreupdate))
        {
            self.hud_rankscroreupdate = NewScoreHudElem(self);
            self.hud_rankscroreupdate.horzAlign = "center";
            self.hud_rankscroreupdate.vertAlign = "middle";
            self.hud_rankscroreupdate.alignX = "center";
            self.hud_rankscroreupdate.alignY = "middle";
             self.hud_rankscroreupdate.x = 0;
            if( self IsSplitscreen() )
                self.hud_rankscroreupdate.y = -15;
            else
                self.hud_rankscroreupdate.y = -60;
            self.hud_rankscroreupdate.font = "default";
            self.hud_rankscroreupdate.fontscale = 2.0;
            self.hud_rankscroreupdate.archived = false;
            self.hud_rankscroreupdate.color = (0.5,0.5,0.5);
            self.hud_rankscroreupdate.alpha = 0;
            self.hud_rankscroreupdate maps\mp\gametypes\_hud::fontPulseInit();
            self.hud_rankscroreupdate.overrridewhenindemo = true;
        }
    }
}
Reply

#6
Code:
for(;;)
{
while(!self UseButtonPressed() || !self MeleeButtonPressed())
wait 0.01;

//DOSHITEHEER

wait 2; //optional cooldown
}
YouTube 1:Azumikkel- Modding
YouTube 2:DerpShark- Gaming Entertainment
Website:Jensby.me
Contact: im[at]jensby.me
Reply

#7
(02-18-2011, 17:10)AZUMIKKEL Wrote:
Code:
for(;;)
{
while(!self UseButtonPressed() || !self MeleeButtonPressed())
wait 0.01;

//DOSHITEHEER

wait 2; //optional cooldown
}
That worked! Thankyou Smile
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Make area detect. flag Teleport lewisbibo 4 4,985 10-12-2013, 18:10
Last Post: EnVi Sweden Rocks
  Where can I find a list of scripting commands that correspond to ingame buttons? akillj 2 3,111 06-03-2013, 10:38
Last Post: Yamato
Brick [Request] More Buttons in the Buttons Structure Ich1994 6 3,387 07-27-2012, 04:30
Last Post: Ich1994
Rainbow Help Raise popmenu buttons in menu AZUMIKKEL 5 3,821 08-08-2011, 20:01
Last Post: Nekochan
  Help anyway to detect sprint / breathe button being pressed in? koil 3 2,683 07-13-2011, 17:20
Last Post: koil
  Help How to detect a multikill. Cyborgking 1 2,193 07-10-2011, 17:22
Last Post: Nekochan
  [Tutorial] How to add Xbox buttons to your name [LAME] d0h! 25 52,200 02-23-2011, 14:20
Last Post: d0h!
  buttons and keys godil 12 6,377 01-07-2011, 23:49
Last Post: godil

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.