Forum

Help creating Lastweap code?

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Help creating Lastweap code?

Postby gnounc » Mon Oct 05, 2009 3:25 am

Electro was helping me to create a "Lastweap" function so that I can make an alias like

alias quickaxe "impulse 0; +attack; wait; -attack; impulse 13;"

and bind a single button to attack with an axe, then switch back
to the weapon I was using (similar to quick kick in Duke3d)

It's finished..only it doesnt work.
I get a "no weapon" error every time.


So far I've added

Code: Select all
.float lastweap;



inserted

Code: Select all
self.lastweap = self.impulse;


into the W_ChangeWeapon function





added

Code: Select all
if (self.impulse == 13)
      W_LastWeap ();


to the impulse list

and copied the W_ChangeWeapon function
renaming it W_LastWeap




my weapons.qc can be seen in its entirety here:

http://pastebin.org/35525

Any help appreciated
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Postby Electro » Mon Oct 05, 2009 9:26 pm

Hmm but this isn't how I showed you to do it.
Anyway...

In W_LastWeap should actually be setting the weapon, right?

self.weapon = fl;

before
W_SetCurrentAmmo ();

I assume that when you're testing this, you haven't actually changed weapon to anything yet, so lastweap hasn't been set.

Looks like you will need to change to another weapon, then try use lastweap. Otherwise lastweap isn't set, and has no fallback, instead it's looking for fl to be 0. You have no weapon 0.
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

I have the code you gave me as well : )

Postby gnounc » Tue Oct 06, 2009 4:09 am

Sorry, that was pretty rude of me in retrospect.
I wanted to write what I understood (alongside the code you gave me)

I've been looking at both. At the moment they both do mostly the same thing.

The code you gave me (ill post it below so you can call me out if I left anything out) prints to screen "No Weapon" and switches to axe, but wont switch back, which i dont understand since lastweap is set at the beginning of the change weapon command.

The code i have does exactly the same thing, except it doesnt print out "No Weapon".


In testing ive been using impulse 9 cheat so i have all weapons before trying the custom impulse 13.
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

weapons.qc

Postby gnounc » Tue Oct 06, 2009 4:10 am

Code: Select all
/*
============
W_ChangeWeapon

============
*/
.float lastweap;

void() W_ChangeWeapon =
{
   local   float   it, am, fl;
   
   it = self.items;
   am = 0;
   
   if (self.impulse == 1)
   {
      fl = IT_AXE;
   }
   else if (self.impulse == 2)
   {
      fl = IT_SHOTGUN;
      if (self.ammo_shells < 1)
         am = 1;
   }
   else if (self.impulse == 3)
   {
      fl = IT_SUPER_SHOTGUN;
      if (self.ammo_shells < 2)
         am = 1;
   }      
   else if (self.impulse == 4)
   {
      fl = IT_NAILGUN;
      if (self.ammo_nails < 1)
         am = 1;
   }
   else if (self.impulse == 5)
   {
      fl = IT_SUPER_NAILGUN;
      if (self.ammo_nails < 2)
         am = 1;
   }
   else if (self.impulse == 6)
   {
      fl = IT_GRENADE_LAUNCHER;
      if (self.ammo_rockets < 1)
         am = 1;
   }
   else if (self.impulse == 7)
   {
      fl = IT_ROCKET_LAUNCHER;
      if (self.ammo_rockets < 1)
         am = 1;
   }
   else if (self.impulse == 8)
   {
      fl = IT_LIGHTNING;
      if (self.ammo_cells < 1)
         am = 1;
   }

   self.impulse = 0;
   
   if (!(self.items & fl))
   {   // don't have the weapon or the ammo
      sprint (self, "no weapon.\n");
      return;
   }
   
   if (am)
   {   // don't have the ammo
      sprint (self, "not enough ammo.\n");
      return;
   }

//
// set weapon, set ammo
//
   self.weapon = fl;      
   self.lastweap = self.weapon;
   W_SetCurrentAmmo ();
};

*
============
Lastweap Impulse List

Dictionary so to speak
============
*/

float() W_ImpulseForLastWeapon =
{
   if (self.lastweap == IT_AXE)         return 1;
   else if (self.lastweap == IT_SHOTGUN)      return 2;
   else if (self.lastweap == IT_SUPER_SHOTGUN)   return 3;
   else if (self.lastweap == IT_NAILGUN)      return 4;
   else if (self.lastweap == IT_SUPER_NAILGUN)   return 5;
   else if (self.lastweap == IT_GRENADE_LAUNCHER)   return 6;
   else if (self.lastweap == IT_ROCKET_LAUNCHER)   return 7;
   else if (self.lastweap == IT_LIGHTNING)      return 8;

   return 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 == 13)
      self.impulse = W_ImpulseForLastWeapon();
      W_ChangeWeapon ();
   
   
   if (self.impulse == 255)
      QuadCheat ();
      
   self.impulse = 0;
};
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Postby Electro » Tue Oct 06, 2009 5:13 am

Code: Select all
if (self.impulse == 13)
      self.impulse = W_ImpulseForLastWeapon();
      W_ChangeWeapon ();


This is bad.

that means that W_ChangeWeapon is actually ALWAYS called, not when you just do impulse 13. It needs braces.

Code: Select all
if (self.impulse == 13)
{
      self.impulse = W_ImpulseForLastWeapon();
      W_ChangeWeapon ();
}


Try that and see how it goes.
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

No weapon error gone : )

Postby gnounc » Wed Oct 07, 2009 8:02 am

"No Weapon" error message is gone

Impulse 13 still switches directly to the axe
and does nothing the second time, even after weapon switch.

I take it that has to do with what you were saying about it checking
for fl and fl being set to 0?

But if thats the case, shouldnt it work after a weapon switch?
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Postby r00k » Wed Oct 07, 2009 11:40 am

maybe move

Code: Select all
self.lastweap = self.weapon;


before

Code: Select all
self.weapon = fl;


and at the top of cycleweapon and cycleweaponreverse
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

HUZZAH!

Postby gnounc » Thu Oct 08, 2009 4:06 am

Thanks Electro
Thanks rOOk

works like a charm now : )

and I understand the code, so I'm quite happy, thanks.


Except, why did I need to move

self.lastweap = self.weapon;

above self.weapon = fl; ?
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Postby r00k » Thu Oct 08, 2009 4:12 am

u need to know what u changed from to next before u can go back to next.
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Ah gotcha

Postby gnounc » Thu Oct 08, 2009 4:18 am

Thanks
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Postby r00k » Thu Oct 08, 2009 4:55 am

Image removed, keep it SFW.
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Tits or GTF.......oh

Postby gnounc » Thu Oct 08, 2009 8:10 am

Image
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Postby r00k » Fri Oct 09, 2009 6:58 am

lol!

Code: Select all

 if ((player.classname != "nun") || (!player.items & IT_BACON))
     GTFO();




Hmm, Virgin tits or bacon :/ tough call...
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

mmmm bacon

Postby gnounc » Sun Oct 11, 2009 4:32 am

Images removed, keep it SFW.

It is foolish to resist
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Postby Spirit » Sun Oct 11, 2009 7:14 am

Please do not make the standard of this board plummet into Retardland.
Improve Quaddicted, send me a pull request: https://github.com/SpiritQuaddicted/Quaddicted-reviews
Spirit
 
Posts: 1031
Joined: Sat Nov 20, 2004 9:00 pm

Next

Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest