Quote:
Originally Posted by thatdwarf
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.z, random(temp.angle, (temp.angle + this.accuracy) * .4),NULL, NULL, "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 = 1 - 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 == 1 || ! 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
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.