View previous topic :: View next topic |
Author |
Message |
Mexicouger

Joined: 01 May 2010 Posts: 129
|
Posted: Fri May 14, 2010 4:07 am Post subject: 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. |
|
Back to top |
|
 |
r00k
Joined: 13 Nov 2004 Posts: 483
|
Posted: Fri May 14, 2010 4:24 am Post subject: Re: Grenade entity coding help |
|
|
remember self is the NADE and other is the player. |
|
Back to top |
|
 |
frag.machine

Joined: 25 Nov 2006 Posts: 728
|
Posted: Fri May 14, 2010 1:23 pm Post subject: |
|
|
r00k is right, you're confunding the entities references: nade_touch() is called when the grenade is touched by a player, not the inverse. _________________ frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/ |
|
Back to top |
|
 |
Pulseczar

Joined: 12 Aug 2006 Posts: 37
|
Posted: Fri May 14, 2010 2:08 pm Post subject: |
|
|
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. _________________ http://www.customtf.net/ |
|
Back to top |
|
 |
ceriux

Joined: 06 Sep 2008 Posts: 968 Location: Florida, USA
|
Posted: Fri May 14, 2010 4:26 pm Post subject: |
|
|
shouldnt this "self.nade_lives += 1; " be "self.nade_lives = self.nade_lives +1;" _________________ QuakeDB - Quake ModDB Group |
|
Back to top |
|
 |
Pulseczar

Joined: 12 Aug 2006 Posts: 37
|
|
Back to top |
|
 |
Mexicouger

Joined: 01 May 2010 Posts: 129
|
Posted: Fri May 14, 2010 9:47 pm Post subject: |
|
|
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");
}
} |
|
Back to top |
|
 |
Spike
Joined: 05 Nov 2004 Posts: 944 Location: UK
|
Posted: Sat May 15, 2010 12:57 am Post subject: |
|
|
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. _________________ What's a signature? |
|
Back to top |
|
 |
|