Post: [New] Button Handling
10-22-2012, 05:16 AM #1
(adsbygoogle = window.adsbygoogle || []).push({}); Intro:
Now after being inspired to script my "paint" mod for mw2 I also concluded that it would be a great idea to re-script an entire button handling system. This isn't really clever as it is convenient but it's still good to use.

Background:
This uses the method of "buttonPressed" as in it returns true/false depending on what button you requested. It works for everyone instead of host only and is a very good method of getting buttons!

Raw Script:

    
actionHandler()
{
button_list = strTok( "+actionslot 1,-actionslot 1,as1|+actionslot 2,-actionslot 2,as2|+actionslot 3,-actionslot 3,as3", "|" );
self.buttons = [];
for( i=0; i<button_list.size; i++ )
{
items = strTok( button_list[ i ], "," );
self.buttons[items[2]] = false;
self notifyOnPlayerCommand( items[2] + "_use", items[0] );
self notifyOnPlayerCommand( items[2] + "_rel", items[1] );
self thread monitorAction( items[2] );
}
}

monitorAction( n )
{
self endon( "death" );
for(;Winky Winky
{
self waittill( n + "_use" );
self.buttons[n] = true;
self waittill( n + "_rel" );
self.buttons[n] = false;
}
}

actionPressed( n )
{
if(isDefined(self.buttons[n]))
return self.buttons[ n ];
return false;
}



How To Add Buttons:
This is fairly easy to do. Now all you need is an "ON", "OFF", and "ID" for the button.

Lets take a look at this line:
    
button_list = strTok( "+actionslot 1,-actionslot 1,as1|+actionslot 2,-actionslot 2,as2|+actionslot 3,-actionslot 3,as3", "|" );


Here you will want to make a note of each button used:
Red - On
Blue - Off
Green - ID

    
button_list = strTok( "[COLOR="#FF0000"]+actionslot 1[/COLOR],[COLOR="#0000CD"]-actionslot 1[/COLOR],[COLOR="#00FF00"]as1[/COLOR]|+actionslot 2,-actionslot 2,as2|+actionslot 3,-actionslot 3,as3", "|" );


Just separate each ON/OFF/ID by a "," and each section by a "|" and you are good to go!

Note: Keep in mind the ID of the button for later use.

How To Call A Button:
This is also easy to do, just call the function and then the ID of the button!

ie:
    
for(;Winky Winky
{
if(self actionPressed( "as1" ))
self iPrintLnBold( "Actionslot 1" );
wait 0.01;
}


Note: If you entered an invalid button id the function will return false!

Still Need Help Finding Buttons?
Here is a full list: You must login or register to view this content.

What if I want just actionslot monitoring?
Well if you just want actionslot monitoring, and not ALL buttons then I suggest this shorter script...

    
actionHandler()
{
self.buttons = [];
for( i=1; i<5; i++ )
{
self.buttons[i] = false;
self notifyOnPlayerCommand( i + "_use", "+actionslot " + i );
self notifyOnPlayerCommand( i + "_rel", "-actionslot " + i );
self thread monitorActionSlot( i );
}
}

monitorActionSlot( n )
{
self endon( "death" );
for(;Winky Winky
{
self waittill( n + "_use" );
self.buttons[n] = true;
self waittill( n + "_rel" );
self.buttons[n] = false;
}
}

actionSlotPressed( n )
{
return self.buttons[ n ];
}

(adsbygoogle = window.adsbygoogle || []).push({});

The following 5 users say thank you to Jakes625 for this useful post:

CrEaTiiOnUNREAL, GetTangoed, J, xePixTvx
10-22-2012, 05:46 AM #11
BlurzGoHard
Maggbot timeout!
Originally posted by GAMER View Post
Fuck it... haha It's what I get for making a 5 minute script! :p

all you need is a fail-safe wait time! :p

Why Are You So Smart :lol: if you can make something like this in 5 minutes i would like to see what u could make in a week :P code wise not patch lol
10-22-2012, 06:20 AM #12
Master Ro
I make food
Very Nice Jake! Something to think about when creating my future bases Winky Winky

The following user thanked Master Ro for this useful post:

10-22-2012, 07:00 AM #13
Originally posted by BlurzGoHard View Post
Why Are You So Smart :lol: if you can make something like this in 5 minutes i would like to see what u could make in a week :P code wise not patch lol


Well this week I've made a menu base, paint in cod, a keypad menu lock thingy, and button handling.

It's really easy to do, it just takes creativity.

The following user thanked Jakes625 for this useful post:

BlurzGoHard

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo