PHP Code:
function onWeaponFired() {
if (! this.isEquipped()) {
return this.equip(); // it's not already equipped, so equip it
}
// it's already equipped
this.fire();
}
function GraalControl.onKeyCode(temp.code, temp.key) {
if (temp.key == "s" && this.isEquipped()) {
// pressed "s" while equipped, unequip it
this.unequip();
}
}
Just do something like this.
Also, note that this is incorrect:
PHP Code:
player.weapons[selectedweapon] == this.name
weapons is an array of weapon objects, not weapon names. The only reason it works is because the weapon object is coerced into a string, which is then compared to the current weapon's name.
The correct way would be to do
PHP Code:
player.weapons[selectedweapon] == this
However, the
best way would just be to do
PHP Code:
player.weapon == this
(
player.weapon always refers to the currently selected weapon)