View Single Post
  #6  
Old 06-26-2013, 06:22 PM
defaultaccount defaultaccount is offline
Cassini
Join Date: Feb 2006
Location: HeLLifAX
Posts: 299
defaultaccount is on a distinguished road
Quote:
Originally Posted by callimuc View Post
1st: style your code and please use PHP tags
2nd: you should always do '==' checks and not '=' checks within if() statements and such

now that we fixed this, your code will look like the following which makes it easier for us to read:

PHP Code:
function onKeyPressed() {
  if (
keydown(4)) {
    if (
this.equiped == true) {
      
player.weapon.trigger("WeaponFired");
    }
    else
      
onEquip();
  }
}

function 
onWeaponFired() {
  if (
this.fired) {
    if (
this.equiped == true) {
      if (
this.ammo 0) {
        
this.fired false;
        
setani(this.firenull);
        
this.ammo -= 1;
        
freezeplayer(this.freeze);
        
this.angle getangle(vecx(playerdir),vecy(playerdir));
        
setshootparams(player.account);
        
shoot(player.x+.3player.y+.3player.zthis.angle+random(this.bulletangleabs(this.bulletangle)), 0this.bspeed"pb_bullet1""pb_bullet.png");
        
triggerServer("gui"this.name"Shell");
      }
    }
  }
}

function 
onTimeout() {
  if (
this.fired == false) {
    
this.fired true;
    
setTimer(this.rof);
  }


personally I would do something like:

PHP Code:
/*
Flags I used:
  this.gunEquiped      - boolean - is the weapon currently equiped?
  this.gunShootTimer   - timer between each bullet
  this.gunCurrentShots - amount of bullets which have been fired
  this.gunMaxShots     - max bullets which can be used
  this.playerFreeze    - freezetimer for the player
  
Note:
  you would need to trigger the onEquipGun() and onUnEquipGun() depending on your system,
  this is just a very basic example and not completed. this is not being made secure but
  should work to understand the basics of such a set up and to learn from it
*/

//#CLIENTSIDE
function onCreated() {
    
//automatic gun or not?
  
this.gunAutomatic true;
    
//amount of bullets to shoot
  
this.gunMaxShots 20;
    
//timer between each bullet
  
this.gunShootTimer 0.25;
    
//freeze timer for the player
  
this.playerFreeze 0.1;
}

function 
onKeyPressed() {
    
//D button has not been pressed, so no need for further going
  
if (!keydown(4)) return;
  
    
//equip the weapon and stop going
  
if (this.GunEquiped == false) {
    
this.onEquipGun();
    return;
  }
    
//check if the D button has been pressed and if you shot less bullets then the clip size (in other words: if you can shoot)
    //check the canFireGun() function for the check
  
if (canFireGun() == false ) return;
  
    
//if the gun isnt automatic, shoot once and then stop the function
  
if (this.gunAutomatic == false) {
    
this.shootProjectile();
    return;
  }
    
//else keep going with the automatic shooting
  
while ( canFireGun() == true ) {
    
this.shootProjectile();
    
sleep(this.gunShootTimer);
  }
}

function 
shootProjectile() {
    
//I made it '>=' instead of '==' to have a small failsafe check in there
  
if (this.currentShots >= this.maxShots) {
    
this.onReloadGun();
    return;
  }
  
//your shooting setup in here
    //raise amount of shots being done
  
this.currentShots ++;
    
//freeze the player (based on default movement)
  
freezePlayer(this.playerFreeze);
}

function 
onReloadGun() {
  
//put in your reloading stuff in here
}

public function 
onEquipGun() {
  
//put in your equiping part here
    //set the flag to true
  
this.gunEquiped true;
}

public function 
onUnEquipGun() {
  
//put in your unequiping part here
    //your gun isn't equiped anymore
  
this.gunEquiped false;
}

function 
canFireGun() {
  
temp.toReturn = (keydown(4) == true && this.gunCurrentShots this.gunMaxShots);
  return 
temp.toReturn;


I would still do one main script in a class and then have the weapons linked to that class using this.join("classname"); so once you are doing a change, you dont need to update all weapons (depending on the change)
I tried updating the whole script to what you said, but it doesn't work now. I'm going to just try and add a sleep timer to the original script because it checks for holding d, the script I posted works, but it just doesn't shoot when you hold d. I'd post the whole script the way I updated it but I think someone would use it but look at my post in php by calliumuc

I basically set it to exactly what you posted calliumu but it doesn't shoot, reload or unequip. my old script works for everything except holding d , help me fix it by looking at my first post. It shoots fine it just doesn't work for holding shoot. Sorry but I don't want to completely have to reedit it I just need to add a sleep for the rate it fires, everything else works the way I made it orgionally unequip, shell and clip triggers, fire and the ganis work

I see what your saying about how I made it, the automatic works, but its very unresponsive. I need the wording to make it if D is held.

Last edited by defaultaccount; 06-26-2013 at 08:17 PM..
Reply With Quote