Index | FAQ | Search | Memberlist | Usergroups | Profile | Log in to check your private messages | Log in | Register

Help creating Lastweap code? Goto page 1, 2 Next

| Inside3d Forums Forum Index -> QuakeC Programming

View previous topic :: View next topic
Author | Message
--- | ---
gnounc Joined: 06 Apr 2009 Posts: 120 |

Posted: Mon Oct 05, 2009 3:25 am Post subject: Help creating Lastweap code? |

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:
.float lastweap;

inserted

Code:
self.lastweap = self.impulse;

into the W_ChangeWeapon function
added

Code:
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

Back to top |

Electro Joined: 29 Dec 2004 Posts: 241 Location: Brisbane, Australia |

Posted: Mon Oct 05, 2009 9:26 pm Post subject: |

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.
_________________
Unit reporting!
http://www.bendarling.net/

Back to top |

gnounc Joined: 06 Apr 2009 Posts: 120 |

Posted: Tue Oct 06, 2009 4:09 am Post subject: I have the code you gave me as well : ) |

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.

Back to top |

gnounc Joined: 06 Apr 2009 Posts: 120 |

Posted: Tue Oct 06, 2009 4:10 am Post subject: weapons.qc |

Code:
/* ============ 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;
};

Back to top |

Electro Joined: 29 Dec 2004 Posts: 241 Location: Brisbane, Australia |

Posted: Tue Oct 06, 2009 5:13 am Post subject: |

Code:
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:
if (self.impulse == 13) { self.impulse = W_ImpulseForLastWeapon(); W_ChangeWeapon (); }

Try that and see how it goes.
_________________
Unit reporting!
http://www.bendarling.net/

Back to top |

gnounc Joined: 06 Apr 2009 Posts: 120 |

Posted: Wed Oct 07, 2009 8:02 am Post subject: No weapon error gone : ) |

"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?

Back to top |

r00k Joined: 13 Nov 2004 Posts: 483 |

Posted: Wed Oct 07, 2009 11:40 am Post subject: |

maybe move

Code:
self.lastweap = self.weapon;

before

Code:
self.weapon = fl;

and at the top of cycleweapon and cycleweaponreverse

Back to top |

gnounc Joined: 06 Apr 2009 Posts: 120 |

Posted: Thu Oct 08, 2009 4:06 am Post subject: HUZZAH! |

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

Back to top |

r00k Joined: 13 Nov 2004 Posts: 483 |

Posted: Thu Oct 08, 2009 4:12 am Post subject: |

u need to know what u changed from to next before u can go back to next.

Back to top |

gnounc Joined: 06 Apr 2009 Posts: 120 |

Posted: Thu Oct 08, 2009 4:18 am Post subject: Ah gotcha |

Thanks

Back to top |

r00k Joined: 13 Nov 2004 Posts: 483 |

Posted: Thu Oct 08, 2009 4:55 am Post subject: |

Image removed, keep it SFW.

Back to top |

gnounc Joined: 06 Apr 2009 Posts: 120 |

Posted: Thu Oct 08, 2009 8:10 am Post subject: Tits or GTF.......oh |

Back to top |

r00k Joined: 13 Nov 2004 Posts: 483 |

Posted: Fri Oct 09, 2009 6:58 am Post subject: |

lol!

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

Hmm, Virgin tits or bacon :/ tough call...

Back to top |

gnounc Joined: 06 Apr 2009 Posts: 120 |

Posted: Sun Oct 11, 2009 4:32 am Post subject: mmmm bacon |

Images removed, keep it SFW. It is foolish to resist

Back to top |

Spirit Joined: 20 Nov 2004 Posts: 476 |

Posted: Sun Oct 11, 2009 7:14 am Post subject: |

Please do not make the standard of this board plummet into Retardland. _________________ Quake Maps

Back to top |

Display posts from previous:

| Inside3d Forums Forum Index -> QuakeC Programming | All times are GMT Goto page 1, 2 Next
Page 1 of 2

Jump to:

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2004 phpBB Group