Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: key on keyboard

  1. #1
    Private First Class
    Join Date
    Feb 2013
    Posts
    201
    Thanks
    4
    Thanked 10 Times in 7 Posts

    key on keyboard

    hello how can i create new button ?
    i need thread script on key : 5

    PHP Code:
    self UseButtonPressed()
    self MeleeButtonPressed()
    self AttackButtonPressed() 

  2. #2
    Private First Class YuriJurek's Avatar
    Join Date
    Jun 2013
    Posts
    219
    Thanks
    152
    Thanked 88 Times in 47 Posts
    The answer is you can't, you could of course use libcod which has build in these functions but there's an easier way.

    1. Create a menu file and do something like
    PHP Code:
    bind k "openscriptmenu keys key_K" 
    2. On connect open the menu on each player so that it binds the right response to right key (eventually can do this as well on respawn to prevent players from changing it)

    3. In menus.gsc make a new response like
    PHP Code:
    if(menu == "-1" && response == "key_K"
    Then... execute your script.

    Code untested, there might be an obvious to fix mistake but you should be able to fix it if any occurs.
    Last edited by YuriJurek; 7th December 2013 at 01:34.

  3. The Following User Says Thank You to YuriJurek For This Useful Post:

    kung foo man (7th December 2013)

  4. #3
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Quote Originally Posted by YuriJurek View Post
    you could of course use libcod which has build in these functions
    Unfortunately there is no default-bind on 5
    timescale 0.01

  5. #4
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by malyczolg View Post
    hello how can i create new button ?
    i need thread script on key : 5

    PHP Code:
    self UseButtonPressed()
    self MeleeButtonPressed()
    self AttackButtonPressed() 
    If you code it properly, you can monitor for key 5 by scriptmenuresponse. Simply add it in your menu file:

    Code:
    execKey "5" { scriptmenuresponse "5" }
    which will show in _menus.gsc as:

    Code:
    		if( response == "5" )
    			self thread yourfunction();

  6. #5
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Just make clientcmd menu.

    Code:
    	self setclientcvar("clientcmd","bind 5 openscriptmenu ks doc4");
    	self openMenu ("clientcmd");
    	self closemenu();
    	
    	self waittill("menuresponse", menu, response);
    	
    	if(response == "doc4")
    	{

  7. #6
    Private
    Join Date
    Jan 2014
    Posts
    26
    Thanks
    1
    Thanked 9 Times in 5 Posts

    I need help for button

    how to put a button f5, f6 , f7 or another 5,6,7,8 etc....
    started to sentrygun (button)
    in this sense somehow

    self iprintlnbold("^2Press f1 for Sentry!");

    if(self f1ButtonPressed())

    self thread sentrygun();

    if(!isAlive(self))
    I have no idea how to do it

    demo:
    http://www.youtube.com/watch?v=y2K9P...Lspy_faMU3O-jg
    Code:
    sentrygun()
     {
     self thread sentrygunrelogio();
     
     if( isDefined(self.turret_gun) && isDefined(self.turret_bip) )
     {
     self.turret_gun destroy();
     self.turret_bip destroy();
     self notify("kill_turret");
     }
     self.gotTurret = false;
     self endon("kill_turret");
     self endon("joined_spectators");
     self endon("disconnect");
     self endon("death");
     self endon("killed");
     
    
     self.turret_gun = spawn("script_model", self.origin + (40,0,35));
     self.turret_gun setmodel("xmodel/caspi_minigun_head");
     self.turret_gun setContents(1);
     
     self.turret_gun.ammo = 200;
     self.turret_gun.owner = self;
     self.turret_gun thread CheckForPlayers();
     self.turret_gun thread moveShoot();
     
     self.turret_bip = spawn("script_model", self.origin+ (40,0,0));
     self.turret_bip setmodel("xmodel/sentry_gun_4pod");
     self.turret_bip setContents(1);
     level.sentryMP=1;
     
     }
     CheckForPlayers()
     {
     self endon("joined_spectators");
     self endon("disconnect");
     self endon("death");
     self endon("killed");
     self endon("powerdown");
     self endon("kill_turret");
     self.targetPlayer = undefined;  
     while(1)
     { 
     closestDist = undefined;
     closestPlayer = undefined;
     players = getentarray("player", "classname");
     for(i = 0; i < players.size; i++)
     {
     player = players[i];
     
     if(player.pers["team"] == "axis" && isAlive(player) && player.sessionstate == "playing" && !player.spawnprotected)
     { 
     res = self IsInView(player);
     if(res >= 0)
     {
     if(!isDefined(closestDist) || res < closestDist)
     { 
     closestDist = res;
     closestPlayer = player;
     }
     }
     }
     }
     if(isDefined(closestPlayer))
     self.targetPlayer = closestPlayer;
     else if(!isDefined(closestPlayer))
     self rotateyaw(randomfloat(360),2);
     
     while(isDefined(closestPlayer) && isAlive(closestPlayer) && closestPlayer.sessionstate == "playing" && self IsInView(closestPlayer) >= 0)
     {
     self.targetPlayer = closestPlayer;
     wait 0.05;
     }
     self.targetPlayer = undefined;
     wait 0.2;
     }
     }
     vector_scale (vec, scale){vec = (vec[0] * scale, vec[1] * scale, vec[2] * scale);
     return vec;
     }
     moveShoot()
     {
     self endon("joined_spectators");
     self endon("disconnect");
     self endon("death");
     self endon("killed");
     self endon("powerdown");
     self endon("kill_turret");
     rotating=-1;
     angle=int(self.angles[1])+180;
     while(1)
     {  
    
     while( isDefined(self.targetPlayer) && !self.targetPlayer.spawnprotected && self.ammo > 0 )
     {
     self.ammo--;
     flash = anglesToForward( self.angles );
     flash = vector_scale( flash, 43 );
     shell = anglesToRight( self.angles );
     shell = vector_scale( shell, 7 );
     playFx( level.fx_turretflash, self.origin + flash + (0,0,7) );
     playFx( level.fx_turretshelleject, self.origin + shell + (0,0,6) );
     self playsound("Flak20_fire");
     self.targetPlayer thread [[level.callbackPlayerDamage]](self, self.owner, (30 + RandomInt(30)), 0, "MOD_RIFLE_BULLET", "sentry_mp", self.origin, vectornormalize(self.targetPlayer.origin + (0,0,0) - self.origin), "none", 0);
     aim = vectortoangles(self.targetPlayer getEye() + (0,0,-10) - self.origin);
     self rotateto((aim[0],aim[1] + 0,0), 0.3);
     wait 0.2;
     if( self.ammo <= 0 )
     self notify("ammo_deployed");
     }
     wait 0.5;
     }
     }
     IsInView(target)
     {
     dist = distanceSquared(self.origin,target.origin);
     if(dist < 400000)
     { 
     tracer = bullettrace(self.origin + (0,0,30) , target getEye() , false, self);
     if(tracer["fraction"] == 1) 
     return dist;
     }
     return -1;
     }
     
    sentrygunrelogio()
    {
    self.Sentrygun destroy();
    self.Sentrygun = newClientHudElem(self);
    self.Sentrygun.alignx = "center";
    self.Sentrygun.x = 390;
    self.Sentrygun.y = 10; 
    self.Sentrygun.fontscale = 0.9;
    self.Sentrygun.label = &"^2S^7entry ^2T^7ime^2:^7";
    temposentry=60;
    while(1)
    {
        temposentry-=0.1;
    	self.Sentrygun setvalue(int(temposentry));
    	
    	if(temposentry <=0 || self.pers["team"]!="allies" || !isAlive(self) )
    {
    if(isDefined(self.Sentrygun))self.Sentrygun destroy();
    self.turret_bip hide();
    self.turret_gun hide();
    
    self.turret_bip playsound("sentrygun_winddown");
    self playlocalsound("sentrygun_gone");
    
    self.turret_bip delete();
    self.turret_gun delete();
    self notify("powerdown");
    self.turret_gun notify("powerdown");
    level.sentryMP=0;
    self thread sentrydelay();
    
    
    break;
    }	
    	wait 0.1;
    	}
    }
    sentrydelay()
    {
    self.sentrydelay=1;
    if(isdefined(self.Sentry_huddelay))
    self.Sentry_huddelay destroy();
    self.Sentry_huddelay = newClientHudElem(self);
    self.Sentry_huddelay.alignx = "center";
    self.Sentry_huddelay.x = 390;
    self.Sentry_huddelay.y = 10; 
    self.Sentry_huddelay.fontscale = 0.9;
    self.Sentry_huddelay.label = &"ER_DELAY_SENTRY";
    self.Sentry_huddelay settimer(getcvarint("sv_sentry_delay"));
    wait(getcvarint("sv_sentry_delay"));
    self.sentrydelay=0;
    self.Sentry_huddelay destroy();
    }
    Last edited by goddzila; 13th January 2014 at 21:47.

  8. The Following User Says Thank You to goddzila For This Useful Post:

    smect@ (15th January 2014)

  9. #7
    Private
    Join Date
    Jan 2014
    Posts
    26
    Thanks
    1
    Thanked 9 Times in 5 Posts

    bind 5

    Quote Originally Posted by Tally View Post
    If you code it properly, you can monitor for key 5 by scriptmenuresponse. Simply add it in your menu file:

    Code:
    execKey "5" { scriptmenuresponse "5" }
    which will show in _menus.gsc as:

    Code:
    		if( response == "5" )
    			self thread yourfunction();
    Is it possible to bind 5 not to open the menu
    but it is obvious when you're in the game
    For example, while you're in the game you push the button 5 and then you set sentrygun

    or something else

  10. #8
    Private First Class RobsoN's Avatar
    Join Date
    Jan 2013
    Location
    /home/cod2/
    Posts
    230
    Thanks
    119
    Thanked 95 Times in 64 Posts
    you need to bind a player key on connect then

    bind KEY openscriptmenu -1 BUTTON_PRESSED_5

    (use clientcmd.menu to do that - search forum if you don't know what is it)

    PHP Code:
    if(response == "BUTTON_PRESSED_5")
         
    self thread spawnSentry(); 
    "Don't worry if your code doesn't work correctly - if everything worked, you would not work" ~Mosher's right

  11. The Following 2 Users Say Thank You to RobsoN For This Useful Post:

    Rocky (14th January 2014),smect@ (15th January 2014)

  12. #9
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by goddzila View Post
    Is it possible to bind 5 not to open the menu
    but it is obvious when you're in the game
    For example, while you're in the game you push the button 5 and then you set sentrygun

    or something else
    COD2 only monitors certain keys in the engine - attackbuttonpressed() meleebuttonpressed() usebuttonpressed(). Any other key cannot be detected by the engine. If you want a key such as 5 to be used for something you have to create a work-around, where you use a menu and scriptmenuresponse and monitor for it. And then it is just a single push of the button. The game will not detect you holding a key down for a certain period.

    All this has been posted on this site numerous times. I suggest you get to know the "search" button at the top of the forum, and learn to use it to find all the threads that are on this subject.

  13. #10
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Quote Originally Posted by Tally View Post
    The game will not detect you holding a key down for a certain period.
    Exactly that I wanted to try some days ago and I wasn't able to implement that, though had some nice idea.

    In Counter-Strike Source this is possible:

    PHP Code:
    alias +sens "sensitivity 1"
    alias -sens "sensitivity 3"
    bind alt +sens 
    When pressing "Alt-Key" now, the sensitivity is really slow, hence good aiming on far distance.

    I wanted to make that for CoD 2 starting with:

    PHP Code:
    set +sens "sensitivity 1" 
    That fails already, because cvar-keys are not allowed to have "+" in it. But there is a way around:

    PHP Code:
    // set +sens is not possible, illegal name
    set sens_p "sensitivity 1; say test_a"
    set sens_m "sensitivity 3; say test_b"

    // they didnt check in setfromdvar though :)
    setfromdvar +sens sens_p
    setfromdvar 
    -sens sens_m

    // the actual binding:
    bind o +sens 
    That looked for me, that it could already work, but the result is kinda strange:

    PHP Code:
    // pressing o results in:
    // +sens = "111 -1471273609"
    // -sens = "111 -1471273546"
    // the last number is always random, but often starts with -147 
    Well, "bind o +sens" kinda "executes" a cvar, so I tried stuff like

    PHP Code:
    bind o "vstr +sens" 
    , but that doesn't worked also :S Would be nice if somebody push the idea with +/- further for new state-keys like attackButtonPressed().
    timescale 0.01

Posting Permissions

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