Page 1 of 1

Nothing happens when touching an item

Posted: Wed Aug 12, 2009 6:50 pm
by Rawing
I've spawned a new entity like this:

Code: Select all

gentity_t *gf;
gf = G_Spawn();
gf->s.eType = ent->s.eType;
gf->s.modelindex = ent->s.modelindex;
gf->s.modelindex2 = ent->s.modelindex2;
gf->touch = ent->touch;
VectorSet (gf->r.mins, -ITEM_RADIUS, -ITEM_RADIUS, -ITEM_RADIUS);
VectorSet (gf->r.maxs, ITEM_RADIUS, ITEM_RADIUS, ITEM_RADIUS);
gf->item = ent->item;
gf->think = ent->think;
gf->inuse = ent->inuse;
G_SetOrigin( gf, ent->r.currentOrigin );
gf->classname = "team_CTF_ghostflag_red";
gf->item->pickup_name = "Red Ghost Flag";
trap_LinkEntity(gf);
"ent" is either a blue or red ctf flag. There's no problem with spawning this, but when I touch it, NOTHING happens. Touch_Item isn't even CALLED!

Re: Nothing happens when touching an item

Posted: Sun Aug 16, 2009 6:58 pm
by ^misantropia^
Rawing, you need to set gf->r.contents to something like CONTENTS_TRIGGER.

Re: Nothing happens when touching an item

Posted: Mon Aug 17, 2009 3:42 am
by Rawing
uh, oh, thanks O.o
well, Touch_Item is called now.
that single line corrupted all my work :mad: (swell, it still doesn't work. I'm used to that.)

Re: Nothing happens when touching an item

Posted: Mon Aug 17, 2009 3:52 am
by Rawing
uh, I was wrong o.O it still doesn't call Touch_Item.

Re: Nothing happens when touching an item

Posted: Mon Aug 17, 2009 10:12 am
by ^misantropia^
I suppose it also depends on the values in ent (eType, touch, etc.). But is there a reason why you can't use G_SpawnItem()?

Re: Nothing happens when touching an item

Posted: Mon Aug 17, 2009 2:11 pm
by Rawing
Hehe, yeah, well, the reason I didn't use G_SpawnItem() is that I didn't know it =)
But it seems to spawn an item with respawn and such, and I can't set it's origin can I?

Re: Nothing happens when touching an item

Posted: Mon Aug 17, 2009 2:19 pm
by Rawing
Just noticed: Touch_Item isn't called if you got already 100 armor and touch another one. Guess it's something to do with G_CanItemBeGrabbed; I'll take a look at it.

Edit: Stupid me placed the PrintMsg after the CanItemBeGrabbed line =/

Re: Nothing happens when touching an item

Posted: Tue Aug 18, 2009 8:20 am
by Rawing
Okay, touching the ghost flag works. Other problem now: On death, you don't drop the red-/blueflag but a ghost flag?! TossClientItems:

Code: Select all

if(self->client->ps.powerups[PW_REDFLAG]){
	item = BG_FindItemForPowerup(PW_REDFLAG);
	Drop_Item( self, item, 0);
}
BG_FindItemForPowerup:

Code: Select all

gitem_t	*BG_FindItemForPowerup( powerup_t pw ) {
	int		i;

	for ( i = 0 ; i < bg_numItems ; i++ ) {
		if ( (bg_itemlist[i].giType == IT_POWERUP || 
					bg_itemlist[i].giType == IT_TEAM ||
					bg_itemlist[i].giType == IT_PERSISTANT_POWERUP) && 
			bg_itemlist[i].giTag == pw ) {
			return &bg_itemlist[i];
		}
	}

	return NULL;
}
The ghost flag ain't in bg_itemlist, so why is it dropped!!??!!

Edit: lol posted the code of FindItemForHoldable... corrected that.

Re: Nothing happens when touching an item

Posted: Tue Aug 18, 2009 6:30 pm
by ^misantropia^
I'm not quite sure what you mean. Do you have a screenshot of this 'ghost' flag?

Re: Nothing happens when touching an item

Posted: Tue Aug 18, 2009 6:31 pm
by ^misantropia^
Ah wait, do you mean TA's neutral flag?

Re: Nothing happens when touching an item

Posted: Wed Aug 19, 2009 11:26 am
by Rawing
I'll try to explain, coz the ghost flags don't have a model/skin yet...
The ghost flags spawn whenever someone picks up the enemy's flag. It just marks the spot where the flag usually is. Usually, touching your team's flag -if it was dropped- will return it. I changed that, so you pick it up and have to carry it back to the base. So, if you touch the ghost flag and carry your own flag, it's returned and the ghost flag disappears.

Re: Nothing happens when touching an item

Posted: Thu Aug 20, 2009 8:09 am
by ^misantropia^
Right, after some parsing I get what you mean. Could you post the complete function where the "drop red/blue flag" code lives?

Re: Nothing happens when touching an item

Posted: Thu Aug 20, 2009 8:17 am
by Rawing
Here it is...

Code: Select all

void TossClientItems( gentity_t *self ) {
	gitem_t		*item;
	int			weapon, ammo;
	int			i, ammopack;
	
	// drop ammo packs
	for(weapon = 2; weapon < MAX_WEAPONS; weapon++){
		item = BG_FindAmmoForWeapon(weapon);
		ammopack = item->quantity;// amount of ammo you get when you pick it up
		for(ammo = self->client->ps.ammo[weapon]; ammo > ammopack; ammo -= ammopack){
			Drop_Item(self, item, 90*crandom());
		}
		Add_Ammo(self, weapon, (ammo - self->client->ps.ammo[weapon]));//set client's ammo
	}

	// drop all weapons
	for (weapon = 1; weapon < MAX_WEAPONS; weapon++ ) {
		if( !(self->client->ps.stats[STAT_WEAPONS] & (1<<weapon)) )
			continue;
		if(weapon==WP_GRENADE_LAUNCHER/*||weapon==WP_LIGHTGRENADE_LAUNCHER*/)
			continue;
	
		// find the item type for this weapon
		item = BG_FindItemForWeapon( weapon );

		// spawn the item
		Drop_Item( self, item, 70*crandom() );
		
		item->quantity = self->client->ps.ammo[weapon];
	}

	// drop all medkits
	item = BG_FindItemForHoldable(HI_MEDKIT);
	for ( i = self->client->ps.stats[STAT_MEDKITS]; i; i-- ) {
		Drop_Item( self, item, i*30*crandom());
	}
	
	// drop flag
	if(self->client->ps.powerups[PW_REDFLAG]){
		item = BG_FindItemForPowerup(PW_REDFLAG);
		Drop_Item( self, item, 0);
	}else if(self->client->ps.powerups[PW_BLUEFLAG]){
		item = BG_FindItemForPowerup(PW_BLUEFLAG);
		Drop_Item( self, item, 0);
	}
}