button required for pickups/ammo/weapons in qc?

Discuss programming in the QuakeC language.
Post Reply
drm_wayne
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

button required for pickups/ammo/weapons in qc?

Post by drm_wayne »

Hi,

I am experimenting here with the stock qcv1.06, and i want to know how i can make the items (health, armor, weapons and ammo) like in
modern games.. Example: When you walk near the Items in Quake the player will just pick them up, but i want it like in Call of Duty/NZP etc:
You walk near the item (health for example), and a message says: press X to pick up health, and you need to press the X button (or any other button)
to pick it up..

2nd: i want to restrict the player to carry only one weapontype at once (he can only carry the Nailgun OR the supernailgun, same for the shotgun and the supershotgun),
so if he carrys the nailgun and picks up the supernailgun the nailgun gets removed and drops to the floor, and you have the supernailgun instead..
I think Left 4 Quake has a similar system.

thx for any help ;)
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: button required for pickups/ammo/weapons in qc?

Post by Cobalt »

What engine are you gonna use?
drm_wayne
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

Re: button required for pickups/ammo/weapons in qc?

Post by drm_wayne »

FitzQuake Plus on PC and ProQuake :)
No Darkplaces...
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: button required for pickups/ammo/weapons in qc?

Post by Cobalt »

I dont know if Fitz opened up the code so that .buttonuse is available, which would make use of the +use and -use console commands, so I will try an example in plain legacy code.

In items.qc you will find touch statements for all the items like: health_touch for the healthboxes and so on.

WARNING - very rudimentary hack follows !

Inside these touch functions at the very top for each, you might be able to add:

Code: Select all


if (!other.button2)
	{
	other.lip = time + 0.15;
	return;
	}

Then find the playerjump () function and at the very top add this:

Code: Select all

if (time <= self.lip) return;

This will generally make it so that if you are on an item you want, press spacebar (quickly) and it will not make your player jump, but take the item. After that you can jump all you want. Drawback to this is that if you are on an item you dont want to pickup and you have to jump, say to start a melee or something, you will wind up picking up that item. Of course, that could easilly be canceled out by adding code that checks if you are moving, or firing , or pressing button1 at the same time as button2. If you hold down the spacebar longer than 0.15 seconds, you will not only take the item but do a jump too.

Im sure others might have more desirable ideas that will work too.
drm_wayne
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

Re: button required for pickups/ammo/weapons in qc?

Post by drm_wayne »

thx, i will try it..
NZP and Left 4 Quake seems to have the same "feature" ;)

EDIT: BIG THX, works like a charm and exactly what i wanted :)
So this is how the other realized the Use button thing :D
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: button required for pickups/ammo/weapons in qc?

Post by Cobalt »

Glad you like it. Had no idea other engines used that kind of hack.

As for the other stuff you wanted you pretty much locate the touch code : void () weapon_touch , and check for other.weapons , ie:

Code: Select all

if (other.weapon & ((IT_ROCKET_LAUNCHER + IT_SUPER_NAILGUN) + IT_NAILGUN)))
...this would I believe ring true if the other has the RL, SNG and NG. This code is using what is called a 'bitflag' because self.weapon is a binary incremented float.


With a little work, you could most likely just 'swap' the item you are trying to pickup in the event you have the lesser powerful one being carried.
IT_NAILGUN is a lower float value than IT_SUPERNAILGUN for example. Looks like that touch code checks itself vs .classname to determine that kind of weapon it is.

If swapping the item out is not what you want there is also some legacy tossweapon code I can paste here....and you can merely call that directly if the code you make works and detects the better weapon.
drm_wayne
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

Re: button required for pickups/ammo/weapons in qc?

Post by drm_wayne »

thx ;)

Well, i have plans to make the IT_SHOTGUN "unswapable", the IT_SHOTGUN is the "secondary weapon" (a pistol), and you cant drop it.
Every other weapons (IT_SUPER_SHOTGUN, etc...) will be primary weapons, but you can only carry one of them and if you want another one
you need to "swap" them... 8)
gnounc
Posts: 428
Joined: Mon Apr 06, 2009 6:26 am

Re: button required for pickups/ammo/weapons in qc?

Post by gnounc »

if you want a dedicated button you can create an impulse to set a flag, and another to clear the flag.
from there you can simply alias one of them as +pickup and the other as -pickup, and bind a key to +pickup.

when you hold the button the flag will be set, when you release it it will be reset,
and you dont have to hijack your jump or attack function.
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: button required for pickups/ammo/weapons in qc?

Post by frag.machine »

Not exactly what you requested, but I already implemented a use button roughly like this:

Code: Select all

 // pseudocode:
 // if (self.button1) { // or any other /button/impulse/way you prefer to activate the "use"
 // make a traceline from self.origin to self.origin + small distance (hint: you can use the same distance used in W_FireAxe(), in weapons.qc);
 // if (trace found some entity other than world and this entity has the .use() function set) {
 // entity t = self; // save the current self reference
 // other = self; // other receives the current self
 // self = trace_ent; // self now is the entity we just "used"
 // self.use(); // fire the used entity .use() function
 // self = t; // restore self back to the original entity
 // }
It works surprisingly well with stock QuakeC items and buttons, for example. You can either keep the .touch() functions (so items can be both grabbed/used by touching and/or using) or simply remove them completely (I think this is more par with your idea). In both cases the jump is unaffected.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: button required for pickups/ammo/weapons in qc?

Post by Cobalt »

Thats a nice one too. Could change the traceline to a small value of findradius & check if it finds a .trigger on the ent, and if its touch = weapon_touch or if it = ammo_touch. Another possibility is add a .touch field to the player itself, and call the specific stuff right there. One thing that is more realistic but would make most hard core quake players frown, is just add a time delay so that if he is touching the item and standing still for a couple of seconds, it picks up.

In my mod I already have it coded so that if the entity touching is still attacking / firing, it cant pickup the item. That is: self.attack_finished being greater than time.


frag.machine wrote:Not exactly what you requested, but I already implemented a use button roughly like this:

Code: Select all

 // pseudocode:
 // if (self.button1) { // or any other /button/impulse/way you prefer to activate the "use"
 // make a traceline from self.origin to self.origin + small distance (hint: you can use the same distance used in W_FireAxe(), in weapons.qc);
 // if (trace found some entity other than world and this entity has the .use() function set) {
 // entity t = self; // save the current self reference
 // other = self; // other receives the current self
 // self = trace_ent; // self now is the entity we just "used"
 // self.use(); // fire the used entity .use() function
 // self = t; // restore self back to the original entity
 // }
It works surprisingly well with stock QuakeC items and buttons, for example. You can either keep the .touch() functions (so items can be both grabbed/used by touching and/or using) or simply remove them completely (I think this is more par with your idea). In both cases the jump is unaffected.
drm_wayne
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

Re: button required for pickups/ammo/weapons in qc?

Post by drm_wayne »

Looks nice, i will try them..

About the jumping: I have plans to remove jumping from my mod, because you dont need it xD
Post Reply