What's new

Discussion [Oh N0] Button Processing and Button Combos :)

Z

zy0n

Enthusiast
Messages
900
Reaction score
449
Points
165
Sin$
7
Okay so heres my version of Advanced Button Handling, including button combination monitoring, and automatic instruction creation :smile:

Here are the basic functions:

Code:
initButtons(){
level.buttonName = strToArray("X;Y;A;B;Up;Down;Left;Right;RT;LT;RB;LB;RS;LS", ";");
level.buttonAction = [];
actions = strToArray("+usereload;weapnext;+gostand;+melee;+actionslot 1;+actionslot 2;+actionslot 3;+actionslot4;+attack;+speed_throw;+frag;+smoke;+stance;+breathe_sprint", ";");
foreach(button in level.buttonName ) level.buttonAction[button] = actions[level.buttonAction.size];
}

monitor_PlayerButtons(){
self.buttonPressed = [];
self.buttonPressedCombo = [];
self.comboPressed = [];
foreach ( button in level.buttonName )self thread monitorButtons( button );
}

monitorButtons( button ){
self endon ( "disconnect" );
self endon ( "death" );
self notifyOnPlayerCommand( button, level.buttonAction[button] );
self.buttonPressed[button] = false;
self.buttonPressedCombo[button] = false;
for ( ;; ) {
self waittill( button );
self.buttonPressed[ button ] = true;
self.buttonPressedCombo[ button ] = true;
self notify( "buttonPressed" );
wait .05;
self.buttonPressed[ button ] = false;
self.buttonPressedCombo[ button ] = false;
}
}

monitorCombo( comboID, str, buttons ){
self endon ( "disconnect" );
self endon ( "death" );
self.comboPressed[comboID] = 0;
i=0;
b = strToArray(buttons, ", ");
if(!isDefined(level.comboInstruct[comboID])) self thread comboString( b, comboID, str );
for(;;) {
self waittill("buttonPressed");
if ( self timedPro("combo_"+comboID, 1, true ) ) i = 0;
if ( self.buttonPressedCombo[b[i]] ){
self.buttonPressedCombo[b[i]] = false;
i++;
}
else i = 0;
if (i==b.size) {
i = 0;
self.comboPressed[comboID] = true;
wait .05;
self.comboPressed[comboID] = false;
}
}
}

isComboPressed( comboID )
{
if ( self.comboPressed[ comboID ] ) {
self.comboPressed[ comboID ] = false;
return true;
} else return false;
}

isButtonPressed( buttonID )
{
if (self.buttonPressed[ buttonID ]) {
self.buttonPressed[ buttonID ] = false;
return true;
} else return false;
}

comboString( combo, ID, string ){

level.comboInstruct[ID] = "Press ";
foreach ( button in combo ) level.comboInstruct[ID] += "[{" + level.buttonAction[button] + "}] ";
level.comboInstruct[ID] += string;
}

timedPro( pname, waitTime, reset ){

if ( !isDefined( self.isProcess[pname]["active"]) ){
self.isProcess[pname]["start"] = getTime();
self.isProcess[pname]["active"] = true;
self.isProcess[pname]["wait"] = waitTime*1000;
return false;
} else {
if ( ( getTime() - self.isProcess[pname]["start"] ) > self.isProcess[pname]["wait"] ){
if ( isDefined( reset ) && reset ) self thread killTimedPro( pname );
return true;
}
else return false;
}
}

killTimedPro( pname ){
self.isProcess[pname]["active"] = undefined;
}

strToArray(string, del){
array = [];
values = strTok( string, del);
foreach (value in values) array[array.size] = value;
return array;
}


To use the host must thread initButtons()
Each player must thread monitor_PlayerButtons() in onPlayeSpawned()


Code:
example(){
self thread monitorCombo("TestCombo", "to see if this works", "X, A, B, Y");

for(;;){
if(isComboPressed("TestCombo")){
self thread whatever();
}
wait .05;
}

}

To use the automatic instruction creation
place this within your instruction loop :smile:
and all you have to do is monitorCombo(blah blah) and it will create the instruction and display.

Code:
foreach(inst in level.comboInstruct){
disp setText(inst);
wait 3;
}
 
Top Bottom
Login
Register