player's landmines


(Distopia) #1

Does anyone know how to determine the number of landmines (armed) an individual player has delpoyed? Is this value stored anywhere?
I need to find this number so I can limit the mines individually instead of by team.


(bacon) #2

In g_missile.c
Under g_CountTeamLandmines() add this

int G_CountPlayerLandmines ( gentity_t *ent ) {
	int i;
	int cnt = 0;

	for( i = MAX_CLIENTS ; i<level.num_entities ; i++ ) {
		if ( !ent->inuse ) {
			continue;
		}

		if ( ent->s.eType != ET_MISSILE) {
			continue;
		}

		if ( ent->methodOfDeath != MOD_LANDMINE) {
			continue;
		}

		if ( ent->s.clientNum == ent->parent->s.clientNum ) {
			cnt++;
		}
	}

	return cnt;
}

Then in g_weapon.c
Change

} else if(G_CountTeamLandmines(ent->client->sess.sessionTeam) >= MAX_TEAM_LANDMINES ) {

To

} else if(G_CountPlayerLandmines(ent) >= MAX_TEAM_LANDMINES ) {

Finally in [b]g_local.h]
Under

int G_CountTeamLandmines ( team_t team );

add

int G_CountPlayerLandmines( gentity_t *ent );

(Distopia) #3

bacon, thats almost too easy. I’ve been trying to make it complicated, and didnt even think of it that way. Beautiful.
Just have to modify it a bit and then see if all works well… thanks a bunch


(Distopia) #4

Bacon, i think there’s something wrong with the code.

Right here, you set up a nice loop to check objects once for each non-player entity.

But


   for( i = MAX_CLIENTS ; i<level.num_entities ; i++ ) { 

But you’re only examining ent itself that many times.
I noticed after my landmine counts never updated as I planted away.


      if ( !ent->inuse ) { 
         continue; 
      } 

      if ( ent->s.eType != ET_MISSILE) { 
         continue; 
      } 

      if ( ent->methodOfDeath != MOD_LANDMINE) { 
         continue; 
      } 

      if ( ent->s.clientNum == ent->parent->s.clientNum ) { 
         cnt++; 
      } 
   } 

   return cnt; 
}

change the code to


int G_CountPlayerLandmines ( gentity_t *ent ) 
{   
	int	i; 
	int cnt = 0; 

	for( i = MAX_CLIENTS ; i<level.num_entities ; i++ ) { 
		if ( !level.gentities[i].inuse ) { 
			continue; 
		} 

		if ( level.gentities[i].s.eType != ET_MISSILE) { 
			continue; 
		} 

		if ( level.gentities[i].methodOfDeath != MOD_LANDMINE) { 
			continue; 
		} 

		if ( ent->client->ps.clientNum == level.gentities[i].parent->s.clientNum ) { 
			cnt++;		 
		} 
	} 

                      return cnt; 
}

Thanks for getting me on the right track, though… thought I’d post this in case anyone else is using this code too


([RW]FRED) #5

Hmmm

ent = g_entities + i; was missing… LOL


(Distopia) #6

make sure you dont change ent unless you store it’s client number first.

either way, i’m happy now it’s working, at first i just ran around with infinite mines…