Results 1 to 9 of 9

Thread: Binding custom keys to perform action

  1. #1
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts

    Binding custom keys to perform action

    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.
    Code:
    	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 );
    	}
    Code:
    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

  2. #2
    Sergeant maxdamage99's Avatar
    Join Date
    Aug 2014
    Location
    Russia
    Posts
    458
    Thanks
    79
    Thanked 122 Times in 101 Posts
    try move waittill("menuresponse") in _menus

  3. #3
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    This is how it is done in the plane & tank mod.

    PHP Code:
    self execClientCmd("bind m openscriptmenu -1 m");
    self waittill("key_m"); 
    PHP Code:
    monitorExKeys()
    {
        
    self endon"intermission" );
        
    self endon("disconnect");

        if( 
    isDefinedself.monitorExtraKeys ) )
            return;
        
    self.monitorExtraKeys true;
        
    wait (1);
        if( !
    isDefinedself )  )
            return;
        
        while( 
    isDefinedself )  )
        {
            
    self waittill("menuresponse"menuresponse);

            if(  
    menu == "-1" && isAliveself ) && response.size == )
            {
                
    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).
    Last edited by Mitch; 9th September 2015 at 15:27. Reason: updated keys list.

  4. The Following 2 Users Say Thank You to Mitch For This Useful Post:

    kung foo man (10th September 2015),Ni3ls (10th September 2015)

  5. #4
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    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

  6. #5
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Quote Originally Posted by Mitch View Post
    This is how it is done in the plane & tank mod.

    PHP Code:
    self execClientCmd("bind m openscriptmenu -1 m");
    self waittill("key_m"); 
    PHP Code:
    monitorExKeys()
    {
        
    self endon"intermission" );
        
    self endon("disconnect");

        if( 
    isDefinedself.monitorExtraKeys ) )
            return;
        
    self.monitorExtraKeys true;
        
    wait (1);
        if( !
    isDefinedself )  )
            return;
        
        while( 
    isDefinedself )  )
        {
            
    self waittill("menuresponse"menuresponse);

            if(  
    menu == "-1" && isAliveself ) && response.size == )
            {
                
    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?

  7. #6
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Quote Originally Posted by Ni3ls View Post
    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.
    Last edited by Mitch; 9th September 2015 at 17:03.

  8. The Following 2 Users Say Thank You to Mitch For This Useful Post:

    kung foo man (10th September 2015),Ni3ls (10th September 2015)

  9. #7
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Works =) .

  10. #8
    Corporal guiismiti's Avatar
    Join Date
    Dec 2013
    Location
    Brazil
    Posts
    244
    Thanks
    121
    Thanked 42 Times in 31 Posts
    Quote Originally Posted by Mitch View Post
    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.
    set logfile 2

  11. #9
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    https://znation.nl/cod4script/

    Rightbuttonpressed() etc

  12. The Following User Says Thank You to Ni3ls For This Useful Post:

    guiismiti (1st April 2017)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •