Nothing happens when touching an item

Locked
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Nothing happens when touching an item

Post 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!
[color=#FF0000]/callvote kick all_enemies[/color]
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Nothing happens when touching an item

Post by ^misantropia^ »

Rawing, you need to set gf->r.contents to something like CONTENTS_TRIGGER.
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: Nothing happens when touching an item

Post 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.)
[color=#FF0000]/callvote kick all_enemies[/color]
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: Nothing happens when touching an item

Post by Rawing »

uh, I was wrong o.O it still doesn't call Touch_Item.
[color=#FF0000]/callvote kick all_enemies[/color]
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Nothing happens when touching an item

Post 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()?
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: Nothing happens when touching an item

Post 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?
[color=#FF0000]/callvote kick all_enemies[/color]
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: Nothing happens when touching an item

Post 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 =/
[color=#FF0000]/callvote kick all_enemies[/color]
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: Nothing happens when touching an item

Post 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.
Last edited by Rawing on Wed Aug 19, 2009 11:29 am, edited 2 times in total.
[color=#FF0000]/callvote kick all_enemies[/color]
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Nothing happens when touching an item

Post by ^misantropia^ »

I'm not quite sure what you mean. Do you have a screenshot of this 'ghost' flag?
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Nothing happens when touching an item

Post by ^misantropia^ »

Ah wait, do you mean TA's neutral flag?
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: Nothing happens when touching an item

Post 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.
[color=#FF0000]/callvote kick all_enemies[/color]
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Nothing happens when touching an item

Post 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?
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: Nothing happens when touching an item

Post 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);
	}
}
[color=#FF0000]/callvote kick all_enemies[/color]
Locked