Grenade entity coding help
Moderator: InsideQC Admins
8 posts
• Page 1 of 1
Grenade entity coding help
I have a function that I want to happen X amount of times. I was successful with that. I used a float nade_lives and made the function have a certain amount of lives.
So that is all done. But I want to come up with an item to replenish those lives. And I've got it in the map, and I can grab it, But it doesn't replenish the lives. Any help? code:
void() nade_touch =
{
if (other.classname != "player")
return;
if (self.nade_lives >= 4) {
sprint (self, "Cannot Hold anymore Grenades\n");
}
else {
self.nade_lives += 1;
sprint (self, "picked up a Frag grenade\n");
sound (self, CHAN_WEAPON, "weapons/grenpick.wav", 1, ATTN_NORM);
stuffcmd (other, "bf\n");
self.mdl = self.model;
self.model = string_null;
self.solid = SOLID_NOT;
if (deathmatch) {
self.nextthink = time + 20;
self.think = SUB_regen;
}
activator = other;
SUB_UseTargets();
}
};
void() item_nade =
{
self.touch = nade_touch;
setmodel(self, "progs/fraggren.mdl");
precache_sound ("weapons/grenpick.wav");
setsize (self, '0 0 0', ' 2 2 2');
StartItem();
};
I had the code a bit different a while back, but I changed it in trying to fix. So basically I want the touch function to centerprint "picked up a grenade, and I want it to
give
self.nade_lives += 1;
That is all.
My grenade count is 4. Thus I use the if statement
if (self.nade_lives >= 4)
4 Is my max, so if The player has 4 grenades, then He can't pick up anymore.
Thanks in advance. I thought this was going to be pretty simple, but It's turning into a pain.
So that is all done. But I want to come up with an item to replenish those lives. And I've got it in the map, and I can grab it, But it doesn't replenish the lives. Any help? code:
void() nade_touch =
{
if (other.classname != "player")
return;
if (self.nade_lives >= 4) {
sprint (self, "Cannot Hold anymore Grenades\n");
}
else {
self.nade_lives += 1;
sprint (self, "picked up a Frag grenade\n");
sound (self, CHAN_WEAPON, "weapons/grenpick.wav", 1, ATTN_NORM);
stuffcmd (other, "bf\n");
self.mdl = self.model;
self.model = string_null;
self.solid = SOLID_NOT;
if (deathmatch) {
self.nextthink = time + 20;
self.think = SUB_regen;
}
activator = other;
SUB_UseTargets();
}
};
void() item_nade =
{
self.touch = nade_touch;
setmodel(self, "progs/fraggren.mdl");
precache_sound ("weapons/grenpick.wav");
setsize (self, '0 0 0', ' 2 2 2');
StartItem();
};
I had the code a bit different a while back, but I changed it in trying to fix. So basically I want the touch function to centerprint "picked up a grenade, and I want it to
give
self.nade_lives += 1;
That is all.
My grenade count is 4. Thus I use the if statement
if (self.nade_lives >= 4)
4 Is my max, so if The player has 4 grenades, then He can't pick up anymore.
Thanks in advance. I thought this was going to be pretty simple, but It's turning into a pain.
-

Mexicouger - Posts: 514
- Joined: Sat May 01, 2010 10:12 pm
Re: Grenade entity coding help
remember self is the NADE and other is the player.
- r00k
- Posts: 1110
- Joined: Sat Nov 13, 2004 10:39 pm
r00k is right, you're confunding the entities references: nade_touch() is called when the grenade is touched by a player, not the inverse.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
You've definitely got a problem with trying to send a print to a grenade and so on, because you confuse the difference between self and other, but I don't understand what nade_lives is for. You said it was being used as a counter to execute a function a certain number of times, but yet you seem to also be using it to determine the max number of nades a player can carry. I guess you are just using nade_lives for entirely different purposes for both the player and grenade entities, which is fine, but you mention it being used for one thing but show us code of it being used for something else. Threw me off.
-

Pulseczar - Posts: 37
- Joined: Sat Aug 12, 2006 6:45 pm
Pulseczar wrote:Probably depends on compiler.
Well, i was looking at the health code When I was creating this. And at the beginning of
void() item_health
It said
self.touch = health_touch;
So i followed that. I knew that self.touch was for the item and not the player, but my mind couldn't connect the dots. So I will try other.touch.
Also, I use FTEqccgui.
This is my impulse function just to clarify that section
And nade_lives if a float.
case 28:
{
Set_FOV ( FOV_DEFAULT ); // So that your FOV returns to it's normal state
self.pfov = FOV_DEFAULT;
if (self.nade_lives > 0) { // Used also for nade count. If you have more than 0, than you can throw a nade
pre_player_throw_grenade ();
self.nade_lives -= 1;
sprint (self, ftos(self.nade_lives));
sprint (self, " grenades\n");
return; }
else //Otherwise, It says you don't have any nades
centerprint (self, "No Grenades\n");
break;
}
case 49: // A little test feature I setup for replenishing your grenades until I got the Item setup.
{
if (self.nade_lives >= 4) // So if you have 4 grenades, You can't pick up anymore. That's how I set my limit
_sprint (self, "Cannot Hold anymore Grenades\n");
else { // Otherwise, Add a grenade to your inventory
self.nade_lives += 1;
sprint (self, ftos(self.nade_lives)); // Used to show how many grenades you have
sprint (self, " grenades\n");
}
}
-

Mexicouger - Posts: 514
- Joined: Sat May 01, 2010 10:12 pm
as r00k said, in touch functions, self is the thing that was touched (your item) and other is the thing that touched it (the player).
in think/spawn functions, self is the item that is thinking/spawning, and other is not valid.
that much has no dependence upon your choice of qcc.
hence the other.classname check instead of self.classname.
ent.field += foo; is known to be buggy in some builds of fteqcc. more recent ones are okay as far as I'm aware. But this is not the main issue.
in think/spawn functions, self is the item that is thinking/spawning, and other is not valid.
that much has no dependence upon your choice of qcc.
hence the other.classname check instead of self.classname.
ent.field += foo; is known to be buggy in some builds of fteqcc. more recent ones are okay as far as I'm aware. But this is not the main issue.
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
8 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
