[SOLVED] Issue with bullet script

So, i have 3 weapons ENR.45 SPO-5.56 and the Hellfire12 (name to be determined) and only the SPO fires, the other 2 dont, theyre both in the same spot in the script, and its the same code with the variables cahnges, any ideas?

heres the code, all the variables have been checked and double checked





//Shoot ENR
Movement.prototype.onMouseDown = function(event) {
    if (this.app.root.findByName('ENR.45').enabled === true) {
       // shooting code 
        if (event.button === pc.MOUSEBUTTON_LEFT) {
            // shoot
            if (this.sporounds !== 0) {
                var bullet = this.app.root.findByName('ENRBullet').clone();
                this.app.root.addChild(bullet);
                bullet.reparent(this.app.root);
                bullet.setPosition(this.app.root.findByName('ENRBullet').getPosition());
                bullet.setRotation(this.app.root.findByName('ENRBullet').getRotation());
                bullet.enabled = true;
                console.log(bullet);
                // update magazine
                this.enrrounds = this.enrrounds - 1;
            }
        }
    }
// Function end
};

//Shoot Hellfire
Movement.prototype.onMouseDown = function(event) {
    if (this.app.root.findByName('Hellfire12').enabled === true) {
       // shooting code 
        if (event.button === pc.MOUSEBUTTON_LEFT) {
            // shoot
            if (this.sporounds !== 0) {
                var bullet = this.app.root.findByName('Shells').clone();
                this.app.root.addChild(bullet);
                bullet.reparent(this.app.root);
                bullet.setPosition(this.app.root.findByName('Shells').getPosition());
                bullet.setRotation(this.app.root.findByName('Shells').getRotation());
                bullet.enabled = true;
                console.log(bullet);
                // update magazine
                this.sporounds = this.sporounds - 1;
            }
        }
    }
// Function end
};


//Shoot SPO
Movement.prototype.onMouseDown = function(event) {
    if (this.app.root.findByName('SPO-5.56').enabled === true) {
       // shooting code 
        if (event.button === pc.MOUSEBUTTON_LEFT) {
            // shoot
            if (this.sporounds !== 0) {
                var bullet = this.app.root.findByName('SPOBullet').clone();
                this.app.root.addChild(bullet);
                bullet.reparent(this.app.root);
                bullet.setPosition(this.app.root.findByName('SPOBullet').getPosition());
                bullet.setRotation(this.app.root.findByName('SPOBullet').getRotation());
                bullet.enabled = true;
                console.log(bullet);
                // update magazine
                this.sporounds = this.sporounds - 1;
            }
        }
    }
// Function end
};

Hi @Thebosser.24! Currently you have three functions with the same name. That’s not possible. Only one function is working. You need to add all weapons in the same onMouseDown function (and remove the others).

so how would i go about that

Copy the code that’s inside every onMouseDown function and paste it in the same onMouseDown function.

something like this? --note: i created a checkpoint so if it doesnt work i can fix it–

Movement.prototype.onMouseDown = function(event) {
    if (this.app.root.findByName('ENR.45').enabled === true) {
       // shooting code 
        if (event.button === pc.MOUSEBUTTON_LEFT) {
            // shoot
            if (this.sporounds !== 0) {
                var bullet = this.app.root.findByName('ENRBullet').clone();
                this.app.root.addChild(bullet);
                bullet.reparent(this.app.root);
                bullet.setPosition(this.app.root.findByName('ENRBullet').getPosition());
                bullet.setRotation(this.app.root.findByName('ENRBullet').getRotation());
                bullet.enabled = true;
                console.log(bullet);
                // update magazine
                this.enrrounds = this.enrrounds - 1;
            }
        }
    }

if (this.app.root.findByName('Hellfire12').enabled === true) {
       // shooting code 
        if (event.button === pc.MOUSEBUTTON_LEFT) {
            // shoot
            if (this.sporounds !== 0) {
                var bullet = this.app.root.findByName('Shells').clone();
                this.app.root.addChild(bullet);
                bullet.reparent(this.app.root);
                bullet.setPosition(this.app.root.findByName('Shells').getPosition());
                bullet.setRotation(this.app.root.findByName('Shells').getRotation());
                bullet.enabled = true;
                console.log(bullet);
                // update magazine
                this.sporounds = this.sporounds - 1;
            }
        }
    }

if (this.app.root.findByName('SPO-5.56').enabled === true) {
       // shooting code 
        if (event.button === pc.MOUSEBUTTON_LEFT) {
            // shoot
            if (this.sporounds !== 0) {
                var bullet = this.app.root.findByName('SPOBullet').clone();
                this.app.root.addChild(bullet);
                bullet.reparent(this.app.root);
                bullet.setPosition(this.app.root.findByName('SPOBullet').getPosition());
                bullet.setRotation(this.app.root.findByName('SPOBullet').getRotation());
                bullet.enabled = true;
                console.log(bullet);
                // update magazine
                this.sporounds = this.sporounds - 1;
            }
        }
    }
};
1 Like

IT WORKS
thanks!

1 Like