onKeypressed will keep firing over and over, because of the repeat function(which is dependent on the player's OS keyboard settings, which makes it unreliable for game settings like this, as some players may fire faster than others).
You could simply do something like this:
PHP Code:
function onCreated() {
this.firerate = .1;
}
function onWeaponFired() {
while (keydown(4)) {
FireGun();
sleep(this.firerate);
}
}
function FireGun() {
//shoot stuff
}
However, I have been told using sleep is bad before, so this may get some resistance.