View Single Post
  #12  
Old 12-02-2008, 11:36 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by thatdwarf View Post
PHP Code:
function onWeaponFired() {
  
this.on true;
  
doGani();
  
onTimeout();
}

function 
onTimeout() {
  if (
keydown2(getkeycode("f"), true)) {
    
this.delay++;
  }
  if(
this.delay 1) {                //check if semi or auto
    //ammo check here
    
freezeplayer(.1);
    
setani("gunganishere""");
    
temp.angle getangle(vecx(player.dir), vecy(player.dir));
    
setshootparams(STUFF GOES HERE); 
    
setShootCoords();
    
shoot(this.shootcoords[0],this.shootcoords[1], player.zrandom(temp.angle, (temp.angle this.accuracy) * .4),NULLNULL"blueball3""");
    
this.delay 0;
  }
  
setTimer(.1);

The problem is that you're detecting key presses wrong. Try something like this:

PHP Code:
function onTimeOut() {
  
this.delay -= 0.05;
  
  
temp.key_f keydown2(getkeycode("f"), false); // F key is pressed
  
if (key_f && ! this.keydown_f) {
    
this.mode this.mode// Changes mode between 0 and 1
    // player.chat = "Mode:" SPC (this.mode == 0 ? "Semi-Automatic" : "Automatic");
    // The above line would also work instead of the if statements
    
if (this.mode == 0) {
      
player.chat "Mode: Semi-Automatic";
    } else if (
this.mode == 1) {
      
player.chat "Mode: Automatic";
    }
  }
  
this.keydown_f key_f;
  
  
temp.key_s keydown2(getkeycode("s"), false); // S key is pressed
  
if (key_s && (this.mode == || ! this.keydown_s) && this.delay <= 0) {
    
// shoot
    
this.delay 1// replace the one with the shooting speed (seconds)
  
}
  
  
this.keydown_s key_s;
  
setTimer(0.05);

S to shoot, F to change modes. It should be simple to change the controls to your liking. Let me know if that doesn't work or you need it explained better, or need additional help.

Quote:
Originally Posted by DrakilorP2P View Post
Can someone explain why sleep() is so horrible it warrants such a huge text? Does it halt the entire machine or what?
Sorta, it can stop loops/timeouts, and throw stuff out of scope. It's normally best to work around it if possible.
__________________
Reply With Quote