PDA

View Full Version : Binding custom keys to perform action



Ni3ls
9th September 2015, 13:52
Im working on a small mod that gives u some extras if you reach a killstreak
Im using custom binds to let them active the items.

if(attacker.killstreak == 3 )
{
attacker iprintlnbold("3 killstreak");
attacker giveWeapon("frag_grenade_german_mp");
attacker setWeaponClipAmmo("frag_grenade_german_mp", 2);
}
else if(attacker.killstreak == 5)
{
attacker iprintlnbold("5 killstreak");
killname="mine";
killkey="j";
attacker.dokey=1;
planter = attacker;
attacker thread makebindkill(killname, killkey, planter );
}
else if(attacker.killstreak == 10)
{
attacker iprintlnbold("10 killstreak");
killname="airstrike";
if(attacker.dokey == 1)
{
killkey="k";
attacker.dokey=2;
}
else
{
killkey="j";
attacker.dokey=1;
}
planter = attacker;
attacker thread makebindkill(killname, killkey, planter );
}

makebindkill(killname, key ,planter)
{
planter iprintlnbold("Press ["+key+"] for "+killname);

planter setclientcvar("clientcmd","bind "+key+ " openscriptmenu ks "+killname);
planter openMenu ("clientcmd");
planter closemenu();

planter waittill("menuresponse", menu, response);
if(response == "mine")
{
mine = spawn("script_model", planter.origin);
mine setModel("xmodel/hill400_barrel_black");
mine playsound("MP_bomb_plant");
trigger = spawn( "trigger_radius", planter.origin, 0, 100, 100);
mine thread cleanup(planter,mine, trigger);
mine thread explode(planter,trigger, mine);
}
else if(response == "airstrike")
{
self thread doeAirstrike();
}

The problem is, if I own both items and I select 1, so I press J or K, the other one is not working anymore. Who can see the problem? No errors in developer 1

maxdamage99
9th September 2015, 14:09
try move waittill("menuresponse") in _menus :)

Mitch
9th September 2015, 15:24
This is how it is done in the plane & tank mod.


self execClientCmd("bind m openscriptmenu -1 m");
self waittill("key_m");


monitorExKeys()
{
self endon( "intermission" );
self endon("disconnect");

if( isDefined( self.monitorExtraKeys ) )
return;
self.monitorExtraKeys = true;
wait (1);
if( !isDefined( self ) )
return;

while( isDefined( self ) )
{
self waittill("menuresponse", menu, response);

if( menu == "-1" && isAlive( self ) && response.size == 1 )
{
self notify( "key_" + response );
}
}
}
(run on each player)

But you can also use the supported keys by libcod e.g. space, left/right/up (forward)/down (back) arrows, lean left/right (Q/E) and aim button (left mouse).

Ni3ls
9th September 2015, 16:07
But when I press the button it performs the action. If I have to key binds and I press 1, the other one is not working anymore

Ni3ls
9th September 2015, 16:08
This is how it is done in the plane & tank mod.


self execClientCmd("bind m openscriptmenu -1 m");
self waittill("key_m");


monitorExKeys()
{
self endon( "intermission" );
self endon("disconnect");

if( isDefined( self.monitorExtraKeys ) )
return;
self.monitorExtraKeys = true;
wait (1);
if( !isDefined( self ) )
return;

while( isDefined( self ) )
{
self waittill("menuresponse", menu, response);

if( menu == "-1" && isAlive( self ) && response.size == 1 )
{
self notify( "key_" + response );
}
}
}
(run on each player)

But you can also use the supported keys by libcod e.g. space, left/right/up (forward)/down (back) arrows, lean left/right (Q/E) and aim button (left mouse).

This monitors every key you press right?

Mitch
9th September 2015, 17:01
This monitors every key you press right?

Every key that you bind with 'bind [insert key] openscriptmenu -1 [insert key]'.

Edit: the libcod keys you need to keep checking in a loop like the use / melee functions.

Ni3ls
10th September 2015, 09:56
Works =) .

guiismiti
31st March 2017, 23:37
But you can also use the supported keys by libcod e.g. space, left/right/up (forward)/down (back) arrows, lean left/right (Q/E) and aim button (left mouse).

Which function is this? I'm trying to find it.

Ni3ls
1st April 2017, 06:56
https://znation.nl/cod4script/

Rightbuttonpressed() etc