Forum

Animated Ammo Box

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Animated Ammo Box

Postby Ghost_Fang » Sat Jun 25, 2011 7:56 pm

Ok so I had this idea to make a ammobox much like Half life 2's you touch/use it, it opens up and gives you ammo. For some reason I can't get it to work properly, It seemed so simple to do but I just cant get it. What did I do wrong?

Code: Select all
void() AB_touch =
{
   self.touch = SUB_Null;
   self.frame = self.frame + 1;
   self.think = AB_touch;
   self.nextthink = 1.5;
   if (self.frame == 16)
   {
   setmodel(self, "progs/ammobox-e.mdl");
   sprint(other, "You load up on ammo\n");
   other.ammo_snipershell = other.ammo_snipershell + 2;
   other.ammo_pistolblts = other.ammo_pistolblts + 9;
   other.ammo_oicwblts = other.ammo_oicwblts + 20;
   other.ammo_SMGround = other.ammo_SMGround + 15;
   other.ammo_magblts = other.ammo_magblts + 5;
   other.ammo_oicwnade = other.ammo_oicwnade + 1;
   other.ammo_shells = other.ammo_shells + 6;
      if (other.health < 86)
   other.health = other.health + 15;
   sound (other, CHAN_VOICE, "weapons/ammo1.wav", 1, ATTN_NORM);
   return;
   }
   

};
void() ammobox =
{   
      
      self.classname = "Ammo Box";
      self.touch = AB_touch;
      self.frame = 0;
      setsize (self, '-16 -16 0', '16 16 56');
      self.solid = SOLID_BBOX;
      precache_model("progs/ammobox-test.mdl");
      precache_model("progs/ammobox-e.mdl");
      precache_sound("weapons/ammo1.wav");
      setmodel(self, "progs/ammobox-test.mdl");
      StartItem();
};
Ghost_Fang
 
Posts: 336
Joined: Thu Nov 12, 2009 4:37 am

Re: Animated Ammo Box

Postby Nahuel » Sat Jun 25, 2011 11:25 pm

This code works perfectly for your ammo box, maybe is something "waste". I did not find another solution...
Code: Select all

void() amm =
{   
 setmodel(self, "progs/ammobox-e.mdl");
self.touch = SUB_Null;


};
void() AB_touch =
{


  sprint(other, "You load up on ammo\n");
   other.ammo_snipershell = other.ammo_snipershell + 2;
   other.ammo_pistolblts = other.ammo_pistolblts + 9;
   other.ammo_oicwblts = other.ammo_oicwblts + 20;
   other.ammo_SMGround = other.ammo_SMGround + 15;
   other.ammo_magblts = other.ammo_magblts + 5;
   other.ammo_oicwnade = other.ammo_oicwnade + 1;
   other.ammo_shells = other.ammo_shells + 6;
      if (other.health < 86)
   other.health = other.health + 15;
   sound (other, CHAN_VOICE, "weapons/ammo1.wav", 1, ATTN_NORM);
self.think = amm;
self.nextthink = time;
   
};
void() ammoB =
{

self.touch = AB_touch;

};
void()   ammo1   =   [0,      ammo2] {self.nextthink = (time + 0.04);  self.touch=SUB_Null; };
void()   ammo2   =   [1,      ammo3] {self.nextthink = (time + 0.04);   };
void()   ammo3   =   [2,      ammo4] {self.nextthink = (time + 0.04);   };
void()   ammo4   =   [3,      ammo5] {self.nextthink = (time + 0.04);   };
void()   ammo5   =   [4,      ammo6] {self.nextthink = (time + 0.04);   };
void()   ammo6   =   [5,      ammo7] {self.nextthink = (time + 0.04);   };
void()   ammo7   =   [6,      ammo8] {self.nextthink = (time + 0.04);   };
void()   ammo8   =   [7,      ammo9] {self.nextthink = (time + 0.04);  };
void()   ammo9   =   [8,      ammo10] {self.nextthink = (time + 0.04);   };
void()   ammo10=   [9,      ammo11] {self.nextthink = (time + 0.04);   };
void()   ammo11=   [10,      ammo12] {self.nextthink = (time + 0.04);   };
void()   ammo12=   [11,      ammo13] {self.nextthink = (time + 0.04);   };
void()   ammo13=   [12,      ammo14] {self.nextthink = (time + 0.04);   };
void()   ammo14=   [13,      ammo15] {self.nextthink = (time + 0.04);   };
void()   ammo15=   [14,      ammo16] {self.nextthink = (time + 0.04); };
void()   ammo16=   [15,      ammoB] {self.nextthink = (time + 0.01);  };

void() ammobox =
{   
      local float   oldz;
    self.classname = "Ammo Box";
      setsize (self, '-16 -16 0', '16 16 56');
self.touch = ammo1;
      self.solid = SOLID_BBOX;
      precache_model("progs/ammobox-test.mdl");
      precache_model("progs/ammobox-e.mdl");
      precache_sound("weapons/ammo1.wav");
      setmodel(self, "progs/ammobox-test.mdl");
   self.flags = FL_ITEM;      // make extra wide
   self.solid = SOLID_TRIGGER;
   self.movetype = MOVETYPE_TOSS;   
   self.velocity = '0 0 0';
   self.origin_z = self.origin_z + 6;
   oldz = self.origin_z;
   if (!droptofloor())
   {
      dprint ("Bonus item fell out of level at ");
      dprint (vtos(self.origin));
      dprint ("\n");
      remove(self);
      return;
   }
};
hi, I am nahuel, I love quake and qc.
User avatar
Nahuel
 
Posts: 492
Joined: Wed Jan 12, 2011 8:42 pm
Location: mar del plata

Re: Animated Ammo Box

Postby behind_you » Sun Jun 26, 2011 6:57 am

Your code is a bit of a mess. I cleaned it up for you. It should work now (untested!)

Code: Select all
void() Initgiveammo =
{
   setmodel(self, "progs/ammobox-e.mdl");
   sprint(other, "You load up on ammo\n");
   other.ammo_snipershell = other.ammo_snipershell + 2;
   other.ammo_pistolblts = other.ammo_pistolblts + 9;
   other.ammo_oicwblts = other.ammo_oicwblts + 20;
   other.ammo_SMGround = other.ammo_SMGround + 15;
   other.ammo_magblts = other.ammo_magblts + 5;
   other.ammo_oicwnade = other.ammo_oicwnade + 1;
   other.ammo_shells = other.ammo_shells + 6;
      if (other.health < 86)
   other.health = other.health + 15;
   sound (other, CHAN_VOICE, "weapons/ammo1.wav", 1, ATTN_NORM);

}

void()   animatebox1   =   [1,      animatebox2] {};
void()   animatebox2   =   [2,      animatebox3] {};
void()   animatebox3   =   [3,      animatebox4] {};
void()   animatebox4   =   [4,      animatebox5] {};
void()   animatebox5   =   [5,      animatebox6] {};
void()   animatebox6   =   [6,      animatebox7] {};
void()   animatebox7   =   [7,      animatebox8] {};
void()   animatebox8   =   [8,      animatebox9] {};
void()   animatebox9   =   [9,      animatebox10] {};
void()   animatebox10   =   [10,      animatebox11] {};
void()   animatebox11   =   [11,      animatebox12] {};
void()   animatebox12   =   [12,      animatebox13] {};
void()   animatebox13   =   [13,      animatebox14] {};
void()   animatebox14  =   [14,      animatebox15] {};
void()   animatebox15  =   [15,      animatebox16] {};
void()   animatebox16  =   [16,      animatebox16] {Initgiveammo()};

void() AB_touch =
{
   if (other.classname != "player")//only you can use this box
      return;
   self.touch = SUB_Null;
   Animatebox();
};

void() ammobox =
{   
      precache_model("progs/ammobox-test.mdl");
      precache_model("progs/ammobox-e.mdl");
      precache_sound("weapons/ammo1.wav");
      self.solid = SOLID_BBOX;
      self.movetype = MOVETYPE_NONE;
      setsize (self, '-16 -16 0', '16 16 56');
      setmodel(self, "progs/ammobox-test.mdl");
      setorigin(self, self.origin);
      self.classname = "Ammo Box";
      self.touch = AB_touch;
//      self.frame = 0; not needed

//      StartItem(); unnecessary for singleplayer
};
User avatar
behind_you
 
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest