Quake3World.com Forums
     Programming Discussion
        Nothing happens when touching an item


Post new topicReply to topic
Login | Profile | | FAQ | Search | IRC




Print view Previous topic | Next topic 
Topic Starter Topic: Nothing happens when touching an item

Commander
Commander

Joined: 23 Oct 2007
Posts: 107
PostPosted: 08-12-2009 10:50 AM           Profile Send private message  E-mail  Edit post Reply with quote


I've spawned a new entity like this:

Code:
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!



_________________
/callvote kick all_enemies


Top
                 

Mentor
Mentor

Joined: 12 Mar 2005
Posts: 3957
PostPosted: 08-16-2009 10:58 AM           Profile Send private message  E-mail  Edit post Reply with quote


Rawing, you need to set gf->r.contents to something like CONTENTS_TRIGGER.




Top
                 

Commander
Commander

Joined: 23 Oct 2007
Posts: 107
PostPosted: 08-16-2009 07:42 PM           Profile Send private message  E-mail  Edit post Reply with quote


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.)



_________________
/callvote kick all_enemies


Top
                 

Commander
Commander

Joined: 23 Oct 2007
Posts: 107
PostPosted: 08-16-2009 07:52 PM           Profile Send private message  E-mail  Edit post Reply with quote


uh, I was wrong o.O it still doesn't call Touch_Item.



_________________
/callvote kick all_enemies


Top
                 

Mentor
Mentor

Joined: 12 Mar 2005
Posts: 3957
PostPosted: 08-17-2009 02:12 AM           Profile Send private message  E-mail  Edit post Reply with quote


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()?




Top
                 

Commander
Commander

Joined: 23 Oct 2007
Posts: 107
PostPosted: 08-17-2009 06:11 AM           Profile Send private message  E-mail  Edit post Reply with quote


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?



_________________
/callvote kick all_enemies


Top
                 

Commander
Commander

Joined: 23 Oct 2007
Posts: 107
PostPosted: 08-17-2009 06:19 AM           Profile Send private message  E-mail  Edit post Reply with quote


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 =/



_________________
/callvote kick all_enemies


Top
                 

Commander
Commander

Joined: 23 Oct 2007
Posts: 107
PostPosted: 08-18-2009 12:20 AM           Profile Send private message  E-mail  Edit post Reply with quote


Okay, touching the ghost flag works. Other problem now: On death, you don't drop the red-/blueflag but a ghost flag?! TossClientItems:
Code:
if(self->client->ps.powerups[PW_REDFLAG]){
   item = BG_FindItemForPowerup(PW_REDFLAG);
   Drop_Item( self, item, 0);
}

BG_FindItemForPowerup:
Code:
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.



_________________
/callvote kick all_enemies


Last edited by Rawing on 08-19-2009 03:29 AM, edited 2 times in total.

Top
                 

Mentor
Mentor

Joined: 12 Mar 2005
Posts: 3957
PostPosted: 08-18-2009 10:30 AM           Profile Send private message  E-mail  Edit post Reply with quote


I'm not quite sure what you mean. Do you have a screenshot of this 'ghost' flag?




Top
                 

Mentor
Mentor

Joined: 12 Mar 2005
Posts: 3957
PostPosted: 08-18-2009 10:31 AM           Profile Send private message  E-mail  Edit post Reply with quote


Ah wait, do you mean TA's neutral flag?




Top
                 

Commander
Commander

Joined: 23 Oct 2007
Posts: 107
PostPosted: 08-19-2009 03:26 AM           Profile Send private message  E-mail  Edit post Reply with quote


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.



_________________
/callvote kick all_enemies


Top
                 

Mentor
Mentor

Joined: 12 Mar 2005
Posts: 3957
PostPosted: 08-20-2009 12:09 AM           Profile Send private message  E-mail  Edit post Reply with quote


Right, after some parsing I get what you mean. Could you post the complete function where the "drop red/blue flag" code lives?




Top
                 

Commander
Commander

Joined: 23 Oct 2007
Posts: 107
PostPosted: 08-20-2009 12:17 AM           Profile Send private message  E-mail  Edit post Reply with quote


Here it is...
Code:
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);
   }
}



_________________
/callvote kick all_enemies


Top
                 
Quake3World.com | Forum Index | Programming Discussion


Post new topic Reply to topic


cron
Quake3World.com
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group