weapon slots

Discuss programming in the QuakeC language.
Post Reply
sniperz227
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

weapon slots

Post by sniperz227 »

hey sniperz227, im having problem with some of my code. what i codded was weapon slots (primary and secondary weapons). i made a seperate weapon slot called weapon_slots.qc that looks like this :

Code: Select all

/*
====================
Primary Weapon Cycle
====================
*/

void () NewWeaponCycle =
{
	local float it, am;

	it = self.items;
	self.impulse = 11;
	
	while(1)
	{
		am = 0;
	if (self.weapon == IT_AXE)
	{
		self.weapon = IT_M9;
	}
	if ( (it & self.weapon) && am == 0)
	{
		W_SetCurrentAmmo ();
		return;
	}
   }
	
};

/*
=============================
Primary Weapon Reverse Cycle
=============================
*/
void() NewReverseCycle =
{
	local	float	it, am;
	
	it = self.items;
	self.impulse = 0;

	while (1)
	{
		am = 0;

		if (self.weapon == IT_AXE)
		{
			self.weapon = IT_L96A1;
			if (self.ammo_l96a1 < 1)
				am = 1;
		}
		else if (self.weapon == IT_L96A1)
		{
			self.weapon = IT_M40A3;
			if (self.ammo_m40a3 < 1)
				am = 1;
		}
		if ( (it & self.weapon) && am == 0)
		{
			W_SetCurrentAmmo ();
			return;
		}
	}

};
/*
---------------
Primary Weapons
---------------
*/

void() Pri_Weapon =
{
	self.items = self.items|
	IT_L96A1|
	IT_M40A3;
	NewReverseCycle();
	NewWeaponCycle();
	W_Attack();
	W_SetCurrentAmmo();

};
basically in the pri_Wepaons fucntion i reset the inventory to all my primary weapon(there will be more than 2 later) and then called the W_Attack and W_SetCurrentAmmo() so that it knows all the attack info for the weapon etc... then i made a new weapon cycle and reverse cycle also so that it only cycles through the primary weapons... and then i called Pri_Weapon() in Put_InClientServer in client.qc so it puts that in instead of the kurok stuff.

Code: Select all

/*
===========
PutClientInServer

called each time a player is spawned
============
*/
void() DecodeLevelParms;
void() PlayerDie;


void() PutClientInServer =
{
	local	entity spot;

	spot = SelectSpawnPoint ();

	self.classname = "player";
	self.health = 100;
	self.takedamage = DAMAGE_AIM;
	self.solid = SOLID_SLIDEBOX;
	self.movetype = MOVETYPE_WALK;
	self.show_hostile = 0;
	self.max_health = 100;
	self.flags = FL_CLIENT;
	self.air_finished = time + 12;
	self.dmg = 2;   		// initial water damage
	self.super_damage_finished = 0;
	self.radsuit_finished = 0;
	self.invisible_finished = 0;
	self.invincible_finished = 0;
	self.effects = 0;
	self.invincible_time = 0;

	DecodeLevelParms ();
	
	Pri_Weapon();
	W_SetCurrentAmmo ();

	self.attack_finished = time;
	self.th_pain = player_pain;
	self.th_die = PlayerDie;
	
	self.deadflag = DEAD_NO;
// paustime is set by teleporters to keep the player from moving a while
	self.pausetime = 0;
	
//	spot = SelectSpawnPoint ();

	self.origin = spot.origin + '0 0 1';
	self.angles = spot.angles;
	self.fixangle = TRUE;		// turn this way immediately

// oh, this is a hack!
	setmodel (self, "progs/eyes.mdl");
	modelindex_eyes = self.modelindex;

	setmodel (self, "progs/player.mdl");
	modelindex_player = self.modelindex;

	setsize (self, VEC_HULL_MIN, VEC_HULL_MAX);
	
	self.view_ofs = '0 0 22';

	player_stand1 ();
	
	if (deathmatch || coop)
	{
		makevectors(self.angles);
		spawn_tfog (self.origin + v_forward*20);
	}

	spawn_tdeath (self.origin, self);

	


/*
==========
ammo codes
==========
*/

self.exam_m40a3 = 5;// m40a3 clip size
self.ammo_m40a3 = 20;// m40a3 ammo

self.ammo_m9 = 60; // m9 Ammo
self.exam_m9 = 15; // m9 clip size

self.ammo_l96a1 = 20; // l96a1 ammo
self.exam_l96a1 = 5; // l96a1 clip
};

anyways compiles fine but when i run it in dark places i get this error:Image
Qrv
Posts: 45
Joined: Thu Oct 20, 2011 7:43 am
Location: Stuck in a Slipgate.

Re: weapon slots

Post by Qrv »

Im tired, so I prob got some bits wrong here, but at a glance, it seems that theres a runaway loop, and looking at the New weapon cycle functions you've wrote,
your using while(1) loops, meaning there must be either a return, or a break to the loop.

Inside your loops, you set am = 0; constantly, i'm probably missing something here, but I dont think it needs to be in the loop ( in the function NewWeaponCycle ),
you can just declare it before the loop.
In the same function, the if's seem to only "really" get run once, as nothing changes:

Code: Select all

void () NewWeaponCycle =
{
   local float it, am;

   it = self.items;
   self.impulse = 11;
   
   while(1)
   {
      am = 0; // QRV : <- Not sure this needs to be here, but ok...

   // This checks if self.weapon == IT_AXE, 
  // okay...
   if (self.weapon == IT_AXE)
   {
      self.weapon = IT_M9;
   }

   // This checks i belive if the players items includes what self.weapon is, at a guess, i assume its set to IT_M9, but that assumes
   // that you only allow the player to start a level with IT_AXE elsewhere in code. Off top of my head, i dont recall the function thats in, probably decodelevelparams or something
  // your also checking if am == 0, which is always true as i see it, as you set am = 0 earlier ...
   if ( (it & self.weapon) && am == 0)
   {
      W_SetCurrentAmmo ();
      return;
   }

  // and this is where the loop re-runs itself, but as nothing changes self.weapon or am in the loop, this is probably a runaway never ending loop....
   }
   
};
Hopefully my comments in the code above are right, i think im right, but i am tired and not even checking the code in detail.
But it does seem this loop will never exit, to me, but i might be wrong.

Your other function appears to fall pray to the same problems as the one above, so I wont go thru it.

Try getting just one function to work properly, then adapt it to cycle in reverse, might be easier for now, iunno.

Hope'd to have helped anyway, lol.



EDIT:

Also, in "Pri_Weapon", you force self.items to be self.items = self.items| IT_L96A1| IT_M40A3;
(Or maybe its some strange toggle, iunno, im tired and getting confused. I hate working with bitflags or whatever they're called)
Which means in your if()'s, self.items == IT_AXE, will surely never be called.

I also dont see why you cycle forwards and backwards in the pri_weapon function, again i might well be missing something if your using some system for extra weapons, instead of just replacing the standard ones.
I'm looking for a Mapper, Modeller/Animator and a Sound effect/Music person, to work on an exciting project. PM Me here, or catch me on IRC for further info.
sniperz227
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

Re: weapon slots

Post by sniperz227 »

umn the am = 0; is suppose to be there . what i did was copy the original weapon cycle and paste it but dleete all the other weapons and add in mine. and i added axe and stuff and still got the same error. also i cant replace the old cyclewepaon with mine is cuz i have to make 2 of them one for secondary weapons and one for primary weapons so my code ould work:P
Post Reply