Forum

Weapon slots

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Weapon slots

Postby sniperz227 » Mon Sep 12, 2011 2:46 am

hi i've been trying to code in weapon slots for my FPS mod. I tried to make a float for secondary weapon and primary but it wouldnt compile when i ran it you can look at it in my code below. In those primary weapon and secondary weapon i wrote the primary weapons and secondary weapons as you can see in the code below. What i want to do now is make it so that when a player spawns he can only carry 2 primary weapons that are defined in the primary weapon float and 1 secondary weapon. i attempted to write that but i dont think its right. my code is below please read it and tell me what to do. Also when im done would i have to call the function in PutInClient in client.qc?

code :
Code: Select all
/*
===============
Player weapons
===============
*/
Void () Weapon_Type =
{
float Wep_Primary;
float Wep_Secondary;

if (self.classname = "player")
{
self.Wep_Primary == IT_M40A3 | IT_ACR ;
bprint (" Primary Weapon"); // print when you have one of the primary weapons.
bprint ("/n");
self.Wep_Secondary == IT_HKM23;
bprint ("Secondary Weapon"); // print when you have a secondary weapon.
bprint ("/n");
}
}

/*
============
Weapon Slots
============
*/
void () Wep_Slots =
{
self.weapon = self.Wep_Primary + 2 && self.Wep_Secondary + 1; // can only carry 2 primary and 1 secondary weapons
};


Thanks, sniperz227
sniperz227
 
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

Re: Weapon slots

Postby gnounc » Mon Sep 12, 2011 3:52 am

Your floats need to be .floats
and their scope needs to be global, so not inside a function.
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Re: Weapon slots

Postby Nahuel » Mon Sep 12, 2011 8:09 pm

.float Wep_Primary;
.float Wep_Secondary;
/*
===============
Player weapons
===============
*/
Void () Weapon_Type =
{


if (self.classname = "player")
{
self.Wep_Primary == IT_M40A3 | IT_ACR ;
bprint (" Primary Weapon"); // print when you have one of the primary weapons.
bprint ("/n");
self.Wep_Secondary == IT_HKM23;
bprint ("Secondary Weapon"); // print when you have a secondary weapon.
bprint ("/n");
}
}

/*
============
Weapon Slots
============
*/
void () Wep_Slots =
{
self.weapon = self.Wep_Primary + 2 && self.Wep_Secondary + 1; // can only carry 2 primary and 1 secondary weapons
};
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: Weapon slots

Postby Electro » Mon Sep 12, 2011 11:00 pm

You're trying to assign values with ==

== is for conditional checks. To assign something, using a single =

Code: Select all
self.Wep_Secondary = IT_HKM23;


Also use tabs for indentation. Your formatting is pretty slack, check the original qc code for examples on how things should be indented.
Might be worth saying if something still doesn't work too, rather than just posting a chunk of code yeah?

\n can be done on the same line as the first bprint

bprint prints to everyone on the server. sprint goes to specific clients.
Benjamin Darling
http://www.bendarling.net/

Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
Electro
 
Posts: 312
Joined: Wed Dec 29, 2004 11:25 pm
Location: Brisbane, Australia

Re: Weapon slots

Postby sniperz227 » Tue Sep 13, 2011 1:17 am

Electro wrote:You're trying to assign values with ==

== is for conditional checks. To assign something, using a single =

Code: Select all
self.Wep_Secondary = IT_HKM23;


Also use tabs for indentation. Your formatting is pretty slack, check the original qc code for examples on how things should be indented.
Might be worth saying if something still doesn't work too, rather than just posting a chunk of code yeah?

\n can be done on the same line as the first bprint

bprint prints to everyone on the server. sprint goes to specific clients.


umm i didi this for my new code and it still doesn't work ? I called both functions in PutClientInServer so that they would get called when a new map loads but it didnt work. here's my new code any idea's? also when i try and make sprint instead of bprint i get a parm error or something like that

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 ();
   Aggression();
   
   W_SetCurrentAmmo ();
   Weapon_Type();
   Wep_Slots();

   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);



self.ammo_m40a3 = 20;
// ammo for m40a3

self.exam_m40a3 = 5;
//clip size for m40a3

self.ammo_hkm23 = 48;
// ammo for hkm23

self.exam_hkm23 = 12;
// clip size for hkm23

self.ammo_acr = 30;
// acr ammo

self.exam_acr = 120;
// acr clip
};


Code: Select all
.float Wep_Primary;
.float Wep_Secondary;

/*
===============
Player weapons
===============
*/
Void () Weapon_Type =
{
if (self.classname = "player")
{
self.Wep_Primary = IT_M40A3 | IT_ACR ;
bprint (" Primary Weapon");
bprint ("/n");
self.Wep_Secondary = IT_HKM23;
bprint ("Secondary Weapon");
bprint ("/n");
}
}

/*
============
Weapon Slots
============
*/
void () Wep_Slots =
{
self.weapon = self.Wep_Primary + 2 && self.Wep_Secondary + 1;
};


/*
============
ImpulseCommands

============
*/
void() ImpulseCommands =
{
   if (self.impulse >= 1 && self.impulse <= 8)
      W_ChangeWeapon ();

   if (self.impulse == 9)
      CheatCommand ();
   if (self.impulse == 10)
      CycleWeaponCommand ();
   if (self.impulse == 11)
      ServerflagsCommand ();
   if (self.impulse == 12)
      CycleWeaponReverseCommand ();
   if (self.impulse == 15)
      reload ();
   if (self.impulse == 256)
      Weapon_Type ();
   if (self.impulse == 258)
      Wep_Slots();

   if (self.impulse == 255)
      QuadCheat ();
      
   self.impulse = 0;
};


sniperz227
 
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

Re: Weapon slots

Postby Electro » Tue Sep 13, 2011 1:37 am

Yeah, need to read the parm error. It would say it's expecting an entity as the first.
Look in defs.qc and search for sprint. You will find that your code will need to be changed to:

Code: Select all
sprint(self, "bla bla bla\n");


I have no idea what you're trying to do with Wep_Slots.

.weapon is your current weapon

I THINK you're trying to set .items to give them the weapons?
In which case it'd be more like.

self.items = self.items | self.Wep_Primary;
self.items = self.items | self.Wep_Secondary;
Benjamin Darling
http://www.bendarling.net/

Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
Electro
 
Posts: 312
Joined: Wed Dec 29, 2004 11:25 pm
Location: Brisbane, Australia

Re: Weapon slots

Postby sniperz227 » Wed Sep 14, 2011 9:40 pm

umm yee sorta like that except i want it so that the player can only hold 2 primary weapons(i know i've only put 2 in but im putting more after) and only 1 secondary
sniperz227
 
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

Re: Weapon slots

Postby Electro » Wed Sep 14, 2011 10:19 pm

I recommend for the sake of the HUD (and heaps of other stuff in qc) that you use the existing items field.

Then how you select them as primary/secondary is entirely up to you. It's not like having them also stored in items is going to stop you having them as primary/secondary weapons, those are merely how you think of them.
Benjamin Darling
http://www.bendarling.net/

Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
Electro
 
Posts: 312
Joined: Wed Dec 29, 2004 11:25 pm
Location: Brisbane, Australia

Re: Weapon slots

Postby sniperz227 » Thu Sep 15, 2011 7:44 pm

um yee but i want it so that say i had 4 primary weapons i can only use two of those
sniperz227
 
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

Re: Weapon slots

Postby ceriux » Thu Sep 15, 2011 7:58 pm

he wants a halo styled weapon system with an extra slot.
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: Weapon slots

Postby sniperz227 » Thu Sep 15, 2011 8:05 pm

no like call of duty where you have 2 primary and 1 secondary and the only way to get another one is drop a primary n then you can pick another primary up
sniperz227
 
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

Re: Weapon slots

Postby ceriux » Fri Sep 16, 2011 3:25 am

sniperz227 wrote:no like call of duty where you have 2 primary and 1 secondary and the only way to get another one is drop a primary n then you can pick another primary up



like what i said... a halo styled weapon system with an extra slot.. another words you want to limit how many weapons the player can carry. im sure if you look around the forums you can find some code that would be useful , might just require a little bit of thinking and editing.
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: Weapon slots

Postby Spike » Fri Sep 16, 2011 4:05 am

the easy way to do 1 secondary weapon is to say 'mneh, they're just all mutually exclusive' and clear out all secondary weapon bits upon secondary weapon pickup, just before setting the flag.

the lame way to do 2 primary weapons is to say 'mneh, they're nearly all mutually exclusive' and clear out all primary weapon bits except for the next numerically higher (rotated) weapon bit which you already have, but otherwise same idea as for secondary weapons. This will mean that if you have the sg+rl, and you grab the ng, it drops the sg. if you grabbed the lg, it drops the rl. well, it works without lots of extra fields at least. you could retain the next numerically lower instead if you wanted slightly more obvious grabbing. it'll be 0 or 1 bits cleared depending on how many you currently have, of course, hence why its easier to retain the first found and clear any others.

then you've still got the .weapon/.items fields for a working hud and stuff.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: Weapon slots

Postby ceriux » Fri Sep 16, 2011 4:38 am

id just make 4 .floats (primary & secondary - primary_wep & secondary_wep) then in the pick up code if primary < 2 allow a pickup if not drop current weapon then pick up. pretty much the same for secondary except if its < 1. id assign primary_wep & secondary_wep to the weapons world entities, so the counter i made knew weather the weapon was a primary or secondary so it could add to the counter when the pickup was made. sorry if this makes no sense...
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: Weapon slots

Postby sniperz227 » Sat Sep 17, 2011 5:04 pm

ye i get it i just don`t know how i would write don`t drop weapon in qc :P
sniperz227
 
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

Next

Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest