I've been trying to figure this out for ages, and I simply cannot figure it out.
Essentially I've been having a problem with onWeaponFired and the detection of an equipped weapon.
What I want to do is when the player presses D, it 'equips' the weapon (sets ganis) and when they dequip it (pressing S) it'll reset the ganis. However, when I want to use onWeaponFired it'll immediately fire the weapon even though the weapon isn't equipped by pressing D. I've tried many different ways including with booleans, but it doesn't go over very well because pressing D is the same thing as executing onWeaponFired at the same time. Not really sure how I would go about this.
Also, one thing to note is that this isn't a clone of Era or something I just made the weapon for fun and uhh I know Era uses the same equip/dequip system for guns. First you press D, it equips then you press D again and it fires the weapon.
PHP Code:
//#CLIENTSIDE
/*
0 dequipped
1 equipped
*/
function onCreated(){
this.on = false;
this.dPress = 0;
}
function onKeyPressed(code,key){
if (key == "d" && player.weapons[selectedweapon] == this.name && this.dPress == 0){
this.on = true;
player.chat = this.dPress;
gravAni();
this.dPress = 1;
// this.increment += 1;
}
if (key == "s" && player.weapons[selectedweapon] == this.name && this.dPress == 1){
this.on = false;
gravAni();
this.dPress = 0;
player.chat = this.dPress;
}
}
function gravAni(){
if (this.on){
replaceani("idle", "gravgun_idle");
replaceani("walk", "gravgun_walk");
setani("gravgun_idle", NULL);
}else if(!this.on){
replaceani("idle", "idle");
replaceani("walk", "walk");
}
}
function onWeaponFired(){
if( this.on ){ // if equipped, fire
setani("gravgun_fire", NULL);
player.chat = "Fired";
// player.chat = this.dPress;
//sleep(this.increment - );
// player.chat = "Fired for " @ this.increment;
// setani("gravgun_idle", NULL);
}
}
Is there a way to prevent onWeaponFired from being executed this way?