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:20 AM #2
ByteSource
League Champion
Originally posted by GAMER View Post
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!

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 ];
}




Eyy Dude Can You Help Me Out Really Quick
10-22-2012, 05:22 AM #3
Originally posted by iBe
Eyy Dude Can You Help Me Out Really Quick


As long as it's not adding verification to a menu or adding a patch/gamemode into your patch.





:carling:
10-22-2012, 05:23 AM #4
Blackstorm
Veni. Vidi. Vici.
This has been done before in a different way and it isn't a very successful type of button handling.

here's the thread of all the devs arguing about it.. lol

*no advertising intended* You must login or register to view this content.

here's an explanation:

You must login or register to view this content.
10-22-2012, 05:26 AM #5
ByteSource
League Champion
Originally posted by GAMER View Post
As long as it's not adding verification to a menu or adding a patch/gamemode into your patch.





:carling:



Umm Ahh No But It Has Sumthing To DO With My Patch
10-22-2012, 05:29 AM #6
BlurzGoHard
Maggbot timeout!
Originally posted by iBe
Umm Ahh No But It Has Sumthing To DO With My Patch


Bang Bang stare Hahaha what could you possibly need help with Sir. Enzo
10-22-2012, 05:30 AM #7
Originally posted by Blackstorm View Post
This has been done before in a different way and it isn't a very successful type of button handling.

here's the thread of all the devs arguing about it.. lol

*no advertising intended* You must login or register to view this content.

here's an explanation:

You must login or register to view this content.


It's successful depending on the type of way you are using it. For me? It's wonderful. For many advanced mods you may find isButtonPressed pretty useful and it's a pain in the ass when you need that type of handling and it's host only.

Now don't get me wrong dconnor had a good idea, but man was his sloppy! He didn't need all the work in the coding, and since you are monitoring the on and off form every second it works the same way.


Edit: I see what you mean if the buttons release event is missed.... you could just do a simple: waittill("this"); or wait over a time...
10-22-2012, 05:32 AM #8
Blackstorm
Veni. Vidi. Vici.
Originally posted by GAMER View Post
It's successful depending on the type of way you are using it. For me? It's wonderful. For many advanced mods you may find isButtonPressed pretty useful and it's a pain in the ass when you need that type of handling and it's host only.

Now don't get me wrong dconnor had a good idea, but man was his sloppy! He didn't need all the work in the coding, and since you are monitoring the on and off form every second it works the same way.


I guess what they meant if it's being used in a large lobby where lag is pretty much inevitable it can be bad, but we don't have to worry about large lobbies anymore so good job lol Smile
10-22-2012, 05:35 AM #9
BlurzGoHard
Maggbot timeout!
Originally posted by Blackstorm View Post
I guess what they meant if it's being used in a large lobby where lag is pretty much inevitable it can be bad, but we don't have to worry about large lobbies anymore so good job lol Smile


Blackstorm stare whats your skype> my buddy told me you needed something reasigned??
10-22-2012, 05:35 AM #10
Originally posted by Blackstorm View Post
I guess what they meant if it's being used in a large lobby where lag is pretty much inevitable it can be bad, but we don't have to worry about large lobbies anymore so good job lol Smile


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

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo