[code] Poison Needles


(bacon) #1

In g_local.h
Find:

qboolean		maxlivescalced;

Add below it:


	// bacon
	int				poisonClient;
	// -bacon

In bg_public.h
Find:

// Rafael - mg42		// (SA) I don't understand these here.  can someone explain?
	PERS_HWEAPON_USE,

Add below:

	
	// bacon
	PERS_POISONED,
	// - bacon

We use PERS_POISONED so that you can do some kind of effect client-side without needing to do much coding :slight_smile:

Then in g_active.c after the health regeneration code of ClientTimerActions() add this:

// bacon - here we will take away HP from the client every second
		if ( ent->client->ps.persistant[PERS_POISONED] ) {
			int	health;
			gentity_t *attacker = &g_entities[ent->client->poisonClient];	// our poisoner ;o

			// everytime we run this we will take away 3 more HP
			health = ( ent->client->ps.persistant[PERS_POISONED] * 3 );
			if ( health > 10 )
				health = 10;

			// take away the health and increase our counter
			G_Damage(ent, attacker, attacker, NULL, NULL, health, 0, MOD_POISON);
			ent->client->ps.persistant[PERS_POISONED]++;
		}

Now in g_weapon.c
After:

// Arnout: calculate ranks to update numFinalDead arrays. Have to do it manually as addscore has an early out
				if( g_gametype.integer == GT_WOLF_LMS ) {
					CalculateRanks();
				}
			}

Add:

// bacon - poison an enemy
			else if ( (traceEnt->client->ps.pm_type != PM_DEAD) && (traceEnt->client->sess.sessionTeam != ent->client->sess.sessionTeam) ) {
				traceEnt->client->ps.persistant[PERS_POISONED] = 1;	// this is our first second
				traceEnt->client->poisonClient = ent->client->ps.clientNum;
			}

In g_items.c (the pickup_health() function)
After:

int			max;
	int			quantity = 0;

Add:

	// bacon - cure me!
	if ( other->client->ps.persistant[PERS_POISONED] )
		other->client->ps.persistant[PERS_POISONED] = 0;

In g_client.c
Find:

for( i = 0 ; i < MAX_PERSISTANT ; i++ ) {
		client->ps.persistant[i] = persistant[i];
	}

Below it add:

// bacon - cure me!
	if ( ent->client->ps.persistant[PERS_POISONED] )
		ent->client->ps.persistant[PERS_POISONED] = 0;

All done :slight_smile:


(Demolama) #2

man isnt bacon a nice guy !! everyone thank him who will be mooching this code … I perhaps will mooch it at a later date when I make a fun mod :stuck_out_tongue:


(No1_sonuk) #3

DON’T IMPLEMENT THIS!
A poison-free ET is a happy ET.
In RtCW, I /kill when poisoned (the ONLY time I ever do) and that’s only because I like playing on one server that has it enabled. In other instances, I avoid poison-servers.


(bani) #4

unless you need to transmit information from qagame to cgame, don’t use ps.persistant[] to track status. ps.persistant[] fields are transmitted to clients. just add a new field to the client struct, eg (int)client->poison and save some bandwidth.


(-xXx-Suicide) #5

I’m not sure if I’m doing this right; is this correct?


/*
==================
ClientTimerActions

Actions that happen once a second
==================
*/
void ClientTimerActions( gentity_t *ent, int msec ) {
	gclient_t *client;

	client = ent->client;
	client->timeResidual += msec;

	while( client->timeResidual >= 1000 ) {
		client->timeResidual -= 1000;

		// regenerate
		if( client->sess.playerType == PC_MEDIC ) {
			if( ent->health < client->ps.stats[STAT_MAX_HEALTH]) {
				ent->health += 3;
				if ( ent->health > client->ps.stats[STAT_MAX_HEALTH] * 1.1){
					ent->health = client->ps.stats[STAT_MAX_HEALTH] * 1.1;
				}
			} else if( ent->health < client->ps.stats[STAT_MAX_HEALTH] * 1.12) {
				ent->health += 2;
				if( ent->health > client->ps.stats[STAT_MAX_HEALTH] * 1.12 ) {
					ent->health = client->ps.stats[STAT_MAX_HEALTH] * 1.12;
				}
			}
		
		} else {
			// count down health when over max
			if ( ent->health > client->ps.stats[STAT_MAX_HEALTH] ) {
				ent->health--;
			}
		}
		//adding here on wing and prayer XXX
			// bacon - here we will take away HP from the client every second 
		if ( ent->client->ps.persistant[PERS_POISONED] ) { 
			int   health; 
			gentity_t *attacker = &g_entities[ent->client->poisonClient];   // our poisoner ;o 

			// everytime we run this we will take away 3 more HP 
			health = ( ent->client->ps.persistant[PERS_POISONED] * 3 ); 
			if ( health > 10 ) 
				health = 10; 

			// take away the health and increase our counter 
			G_Damage(ent, attacker, attacker, NULL, NULL, health, 0, MOD_POISON); 
			ent->client->ps.persistant[PERS_POISONED]++; 
      }
	}
}


(-xXx-Suicide) #6

it would seem I would want to put it before the else, but yet it doesn’t look right there…

This is in g_active.c


(-xXx-Suicide) #7

well, ,lmao, I did something differnet this build… it wokred! Rock on!
One small bug to squish… I put something in the wrong place because you spawn poisoned if you weren’t cured prior to death :lol:


(bani) #8

didnt i tell you not to use ps.persistant[]


(-xXx-Suicide) #9

Indeed. I’m working on learning how to modify the client struct and work with it. It’s a learning experience. This is also why my forums have a “coding bloopers” section =D
I’m just trying to figure out what does what and how, still… this is a part of the game.

Any, erm, hints, however, would be appreciated!

Secondarily, how did you come to learn so much, such that you could make the statement about bandwidth usage, etc? Was it just studying the code, a programming background, just looking at it and going “oh, it does x,y,z!” This goes to anyyone who would like to answer (in a different topic if I am getting too off-course.)


(Rain) #10

Yes.

Primarily, we attacked just about anything network-related so that we could cut back on bandwidth usage in etpro; so, we’ve acquired a rather intimate hatred of that code, in particular. :banana: