Automatic Weapon

Dyhego

Member
Hello everyone!

could you help me create a way for the character to shoot with an automatic weapon? in the style of Cadillacs and Dinosaurs that the characters have automatic weapons and can walk around shooting as well. Would any script have to be used for this?
 
Well, I managed to make the character give automatic shots, but I don't know if this way is correct, because when I hold the button it doesn't release several shots and only shots in a row and it doesn't work as an automatic weapon. follows even scripts. (The programming scripts I ended up taking from another project, because I don't know how to program)


The problem is that the bullets don't run out ...

Code:
name	sarawinter3
health	500
mp 		100
speed	8
type	none
grabdistance 30
shootnum  1
animationscript	data/scripts/sarawinter.c
atchain 1
running	17	3	3	1	1
load	m4
icon	data/chars/sarawinter/lifebar.gif


anim	attack
	delay	9
	custknife	bullet
	bbox	11 8 43 72
	offset	30 77
	frame	data/chars/sarawinter/m4_atk1.gif
	sound	data/sounds/fuzilshoot.wav
	offset	28 76
	@cmd	shoot "bullet" 48 50 1
	frame	data/chars/sarawinter/m4_atk2.gif
	sound	data/sounds/fuzilshoot.wav
	offset	28 69
	@cmd	shoot "bullet" 48 50 1
	frame	data/chars/sarawinter/m4_atk3.gif
	sound	data/sounds/fuzilshoot.wav
	offset	28 76
	@cmd	shoot "bullet" 48 50 1
	frame	data/chars/sarawinter/m4_atk4.gif
	sound	data/sounds/fuzilshoot.wav
	offset	28 69
	@cmd	shoot "bullet" 48 50 1
	frame	data/chars/sarawinter/m4_atk5.gif
		
anim	idle
	bbox	9 7 37 69
	offset	30 77
	frame	data/chars/sarawinter/m4_atk1.gif
		
anim	walk
	loop	1
	offset	23 80
	frame	data/chars/sarawinter/m4_wlk1.gif
	offset	22 80
	frame	data/chars/sarawinter/m4_wlk2.gif
	frame	data/chars/sarawinter/m4_wlk3.gif
	offset	32 80
	frame	data/chars/sarawinter/m4_wlk4.gif
	offset	30 80
	frame	data/chars/sarawinter/m4_wlk5.gif
	offset	25 80
	frame	data/chars/sarawinter/m4_wlk6.gif
	offset	27 79
	frame	data/chars/sarawinter/m4_wlk7.gif
	offset	29 81
	frame	data/chars/sarawinter/m4_wlk8.gif
	offset	29 78
	frame	data/chars/sarawinter/m4_wlk9.gif
	offset	30 77
	frame	data/chars/sarawinter/m4_wlk10.gif
	offset	29 79
	frame	data/chars/sarawinter/m4_wlk11.gif
	offset	25 79
	frame	data/chars/sarawinter/m4_wlk12.gif
		
#|edited by openBor Stats v 0.67

Scripts
sarawinter.c
Code:
#include "data/scripts/common/spawn.c"
#include "data/scripts/common/key.c"
#include "data/scripts/common/shoot.c"
#include "data/scripts/common/commons.c"
#include "data/scripts/common/slam.c"
#include "data/scripts/common/player.c"

void call()
{
	//int r = rand()%500+500;
	////**************8%possiblility*******************
	//if (r <=80){
		spawn01 ("SFire", 30 ,390 ,30);
		spawn01 ("SFire", -60, 380, 0);
		spawn01 ("SFire", -20, 400, -30);
		spawn01 ("SFire" ,100 , 390, -30);
		spawn01 ("SFire", -45, 410, 10);
		spawn01 ("SFire" ,30 ,420, -25);
		spawn01 ("SFire", 110, 390, 15);
		spawn01 ("SFire" ,-80, 380, -30);
		spawn01 ("SFire" ,55, 390, 0);
		spawn01 ("SFire" ,-80 ,330 ,0);
	//}
}


Shoot.c
Code:
void shoot(void Shot, float dx, float dy, float dz)
{ // Shooting projectile
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");

   if (Direction == 0){ //Is entity facing left?                  
      dx = -dx; //Reverse X direction to match facing
   }

   projectile(Shot, x+dx, z+dz, y+dy, Direction, 0, 0, 0);
}


void tosser(void Bomb, float dx, float dy, float dz, float Vx, float Vy, float Vz)
{ // Tossing bomb with desired speed
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   int x = getentityproperty(self, "x");
   int y = getentityproperty(self, "a");
   int z = getentityproperty(self, "z");
   void Shot;

   if (Direction == 0){ //Is entity facing left?                  
      dx = -dx; //Reverse X direction to match facing
   }

   Shot = projectile(Bomb, x+dx, z+dz, y+dy, Direction, 0, 1, 0);
   tossentity(Shot, Vy, Vx, Vz);
   changeentityproperty(Shot, "speed", Vx); 
}


 
Looks like we'll have to do this one step at a time. First looping part.
For automatic shooting, you need script to loop animation if certain key is held, attack1 key in this case. I usually use this function:
Code:
void keyint(void Ani, int Frame, void Key, int Hflag)
{// Change current animation if proper key is pressed or released
    void self = getlocalvar("self");
    int Dir = getentityproperty(self, "direction");
    void Health = getentityproperty(self,"health");    
    int iPIndex = getentityproperty(self,"playerindex"); //Get player index
    void iRKey;

      if (Key=="U"){ //Up Required?
        iRKey = playerkeys(iPIndex, 0, "moveup"); // "Up"
      } else if (Key=="D"){ //Down Required?
        iRKey = playerkeys(iPIndex, 0, "movedown"); // "Down"
      } else if (Key=="L"){ //Left Required?
        iRKey = playerkeys(iPIndex, 0, "moveleft"); // "Left"
      } else if (Key=="R"){ //Right Required?
        iRKey = playerkeys(iPIndex, 0, "moveright"); // "Right"
      } else if (Key=="F"){ //Forward Required?
        if (Dir == 0){ // Facing Left?
          iRKey = playerkeys(iPIndex, 0, "moveleft"); // "Left"
        } else { // Facing Right
          iRKey = playerkeys(iPIndex, 0, "moveright"); // "Right"
        }
      } else if (Key=="B"){ //Backward Required?
        if (Dir == 1){ // Facing Right?
          iRKey = playerkeys(iPIndex, 0, "moveleft"); // "Left"
        } else { // Facing Left
          iRKey = playerkeys(iPIndex, 0, "moveright"); // "Right"
        }
      } else if (Key=="J"){ //Jump Required?
        iRKey = playerkeys(iPIndex, 0, "jump"); // "Jump"
      } else if (Key=="A"){ //Attack Required?
        iRKey = playerkeys(iPIndex, 0, "attack"); // "Attack"
      } else if (Key=="A2"){ //Attack2 Required?
        iRKey = playerkeys(iPIndex, 0, "attack2"); // "Attack2"
      } else if (Key=="S"){ //Special Required?
        iRKey = playerkeys(iPIndex, 0, "special"); // "Special"
      } else if (Key=="A4"){ //Attack4 Required?
        iRKey = playerkeys(iPIndex, 0, "attack4"); // "Attack4"
      }

      if (Hflag==1){ //Not holding the button case?
        iRKey = !iRKey; //Take the opposite condition
      }

      if (iRKey){
        changeentityproperty(self, "animation", openborconstant(Ani), 2);
        changeentityproperty(self, "animpos", Frame);
      }
}

I don't know if sarawinter.c has this script somewhere in one of included scripts but if it doesn't, you'll have to copy it there.

Attack animation would be like this:
Code:
anim	attack
	delay	9
	bbox	11 8 43 72
	offset	30 77
	frame	data/chars/sarawinter/m4_atk1.gif
	sound	data/sounds/fuzilshoot.wav
	offset	28 76
	@cmd	shoot "bullet" 48 50 1
	frame	data/chars/sarawinter/m4_atk2.gif
	sound	data/sounds/fuzilshoot.wav
	offset	28 69
	@cmd	shoot "bullet" 48 50 1
	frame	data/chars/sarawinter/m4_atk3.gif
	sound	data/sounds/fuzilshoot.wav
	offset	28 76
	@cmd	shoot "bullet" 48 50 1
	frame	data/chars/sarawinter/m4_atk4.gif
	sound	data/sounds/fuzilshoot.wav
	offset	28 69
	@cmd	shoot "bullet" 48 50 1
	frame	data/chars/sarawinter/m4_atk5.gif #
	offset	30 77
	@cmd	keyint "ANI_ATTACK1" 1 "A" 0
	frame	data/chars/sarawinter/m4_atk1.gif

With that script, her ATTACK animation will be looped as long as attack1 key is held.

After you got this right, we can move to shooting limiting part :)
 
Bloodbane said:
Looks like we'll have to do this one step at a time. First looping part.
For automatic shooting, you need script to loop animation if certain key is held, attack1 key in this case. I usually use this function:
Code:
void keyint(void Ani, int Frame, void Key, int Hflag)
{// Change current animation if proper key is pressed or released
    void self = getlocalvar("self");
    int Dir = getentityproperty(self, "direction");
    void Health = getentityproperty(self,"health");    
    int iPIndex = getentityproperty(self,"playerindex"); //Get player index
    void iRKey;

      if (Key=="U"){ //Up Required?
        iRKey = playerkeys(iPIndex, 0, "moveup"); // "Up"
      } else if (Key=="D"){ //Down Required?
        iRKey = playerkeys(iPIndex, 0, "movedown"); // "Down"
      } else if (Key=="L"){ //Left Required?
        iRKey = playerkeys(iPIndex, 0, "moveleft"); // "Left"
      } else if (Key=="R"){ //Right Required?
        iRKey = playerkeys(iPIndex, 0, "moveright"); // "Right"
      } else if (Key=="F"){ //Forward Required?
        if (Dir == 0){ // Facing Left?
          iRKey = playerkeys(iPIndex, 0, "moveleft"); // "Left"
        } else { // Facing Right
          iRKey = playerkeys(iPIndex, 0, "moveright"); // "Right"
        }
      } else if (Key=="B"){ //Backward Required?
        if (Dir == 1){ // Facing Right?
          iRKey = playerkeys(iPIndex, 0, "moveleft"); // "Left"
        } else { // Facing Left
          iRKey = playerkeys(iPIndex, 0, "moveright"); // "Right"
        }
      } else if (Key=="J"){ //Jump Required?
        iRKey = playerkeys(iPIndex, 0, "jump"); // "Jump"
      } else if (Key=="A"){ //Attack Required?
        iRKey = playerkeys(iPIndex, 0, "attack"); // "Attack"
      } else if (Key=="A2"){ //Attack2 Required?
        iRKey = playerkeys(iPIndex, 0, "attack2"); // "Attack2"
      } else if (Key=="S"){ //Special Required?
        iRKey = playerkeys(iPIndex, 0, "special"); // "Special"
      } else if (Key=="A4"){ //Attack4 Required?
        iRKey = playerkeys(iPIndex, 0, "attack4"); // "Attack4"
      }

      if (Hflag==1){ //Not holding the button case?
        iRKey = !iRKey; //Take the opposite condition
      }

      if (iRKey){
        changeentityproperty(self, "animation", openborconstant(Ani), 2);
        changeentityproperty(self, "animpos", Frame);
      }
}

I don't know if sarawinter.c has this script somewhere in one of included scripts but if it doesn't, you'll have to copy it there.

Attack animation would be like this:
Code:
anim	attack
	delay	9
	bbox	11 8 43 72
	offset	30 77
	frame	data/chars/sarawinter/m4_atk1.gif
	sound	data/sounds/fuzilshoot.wav
	offset	28 76
	@cmd	shoot "bullet" 48 50 1
	frame	data/chars/sarawinter/m4_atk2.gif
	sound	data/sounds/fuzilshoot.wav
	offset	28 69
	@cmd	shoot "bullet" 48 50 1
	frame	data/chars/sarawinter/m4_atk3.gif
	sound	data/sounds/fuzilshoot.wav
	offset	28 76
	@cmd	shoot "bullet" 48 50 1
	frame	data/chars/sarawinter/m4_atk4.gif
	sound	data/sounds/fuzilshoot.wav
	offset	28 69
	@cmd	shoot "bullet" 48 50 1
	frame	data/chars/sarawinter/m4_atk5.gif #
	offset	30 77
	@cmd	keyint "ANI_ATTACK1" 1 "A" 0
	frame	data/chars/sarawinter/m4_atk1.gif

With that script, her ATTACK animation will be looped as long as attack1 key is held.

After you got this right, we can move to shooting limiting part :)

IT WORKS PERFECTLY! God Bless you!

Can we go on to make sure the bullets are spent when shooting?
 
Glad you got that working  ;D

Assuming you use MP as bullet, you need to spend MP when shooting. Then add another script to end shooting when MP is not enough.
You need these functions:
Code:
void mpcost(int Cost)
{// Spend some MP
    void self = getlocalvar("self");
    int MP = getentityproperty(self,"mp");

    changeentityproperty(self, "mp", MP-Cost); //Spend!
}

void aniLimit(void Ani, int Frame, int Limit)
{// Change current animation if MP falls below limit
    void self = getlocalvar("self");
    void MP = getentityproperty(self,"mp");    

    if (MP < Limit){
      changeentityproperty(self, "animation", openborconstant(Ani), 2);
      changeentityproperty(self, "animpos", Frame);
    }
}

Her ATTACK1 animation becomes this:
Code:
anim	attack
	delay	9
	bbox	11 8 43 72
	offset	30 77
	frame	data/chars/sarawinter/m4_atk1.gif
	offset	28 76
	@cmd	aniLimit "ANI_ATTACK1" 6 5
	@cmd	mpcost 5
	@cmd	shoot "bullet" 48 50 1
	sound	data/sounds/fuzilshoot.wav
	frame	data/chars/sarawinter/m4_atk2.gif
	offset	28 69
	@cmd	aniLimit "ANI_ATTACK1" 6 5
	@cmd	mpcost 5
	@cmd	shoot "bullet" 48 50 1
	sound	data/sounds/fuzilshoot.wav
	frame	data/chars/sarawinter/m4_atk3.gif
	offset	28 76
	@cmd	aniLimit "ANI_ATTACK1" 6 5
	@cmd	mpcost 5
	@cmd	shoot "bullet" 48 50 1
	sound	data/sounds/fuzilshoot.wav
	frame	data/chars/sarawinter/m4_atk4.gif
	offset	28 69
	@cmd	aniLimit "ANI_ATTACK1" 6 5
	@cmd	mpcost 5
	@cmd	shoot "bullet" 48 50 1
	sound	data/sounds/fuzilshoot.wav
	frame	data/chars/sarawinter/m4_atk5.gif #
	delay	5
	offset	30 77
	@cmd	aniLimit "ANI_ATTACK1" 6 5
	@cmd	keyint "ANI_ATTACK1" 1 "A" 0
	frame	data/chars/sarawinter/m4_atk1.gif
	frame	data/chars/sarawinter/m4_atk1.gif

She spends 5 MP per shoot. Just before each shot, there's an MP check. If MP is below 5 when checked, she immediately jumps to end of animation IOW ends shooting.
 
Then, the MP is consumed when shooting, but after the MP reaches zero, the character continues with the weapon and continues shooting.

Is it possible to let only ammunition be consumed instead of the MP?
 
Back
Top Bottom