Page 1 of 1

Event setting var in cgame module

Posted: Fri Aug 21, 2009 3:38 am
by Rawing
I'm really, really, really confused. I'm trying to set a var in the cgame module everytime you die...
player_die:

Code: Select all

PM_AddEvent(EV_RESET_ZOOM);
CG_EntityEvent:

Code: Select all

case EV_RESET_ZOOM:
		DEBUGNAME("EV_RESET_ZOOM");
		if ( es->number == cg.snap->ps.clientNum ) {
			cg.zoomed= qfalse;
		}
		break;
Result: Everytime you kill someone or die yourself, zoom will be reset. What's bugging me is, it's the same as EV_NOAMMO:

Code: Select all

PM_AddEvent( EV_NOAMMO );

Code: Select all

	case EV_NOAMMO:
		DEBUGNAME("EV_NOAMMO");
//		trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.noAmmoSound );
		if ( es->number == cg.snap->ps.clientNum ) {
			CG_OutOfAmmoChange();
		}
		break;
And the outofammochange obviously works :confused:

Re: Event setting var in cgame module

Posted: Fri Aug 21, 2009 8:38 am
by ^misantropia^
Simple test to check if the event is received: set cg.zoomed = qfalse unconditionally.

Re: Event setting var in cgame module

Posted: Fri Aug 21, 2009 8:43 am
by Rawing
Uh, the problem is, it IS set to qfalse... it should be set to false everytime you die but not if you kill someone.

Re: Event setting var in cgame module

Posted: Fri Aug 21, 2009 10:42 am
by ^misantropia^
Then I'm not quite getting the problem, I fear. How and what are you trying to accomplish and what is bugging it?

Re: Event setting var in cgame module

Posted: Fri Aug 21, 2009 11:13 am
by Rawing
Okay, okay:
When you die, cg.zoomed should be set to qfalse. So I've placed the PM_AddEvent line into player_die, and cgame should set cg.zoomed to qfalse.
The problem:
If you kill someone, player_die is run... and your zoom is reset though YOU didn't die. That's why there's the

Code: Select all

if ( es->number == cg.snap->ps.clientNum )
line, but it doesn't seem to do anything, which is strange coz it's the same as with CG_NoAmmoChange... (CG_NoAmmoChange obviously changes YOUR weapon and not someone else's...)

Re: Event setting var in cgame module

Posted: Sat Aug 29, 2009 3:51 pm
by Rawing

Code: Select all

G_AddEvent(self, EV_RESET_ZOOM, 0);

Code: Select all

case EV_RESET_ZOOM:
		DEBUGNAME("EV_RESET_ZOOM");
		//if ( cent->currentState.number == cg.snap->ps.clientNum )
			cg.zoomed= qfalse;
		break;
doesn't work, too :offended:

Re: Event setting var in cgame module

Posted: Tue Sep 01, 2009 10:13 pm
by ZTurtleMan
By adding the below code, cgame will zoom out when the active player dies. EV_OBITUARY is sent everytime a player dies so clients can show death messages.

Code: Select all

	case EV_OBITUARY:
		DEBUGNAME("EV_OBITUARY");
+		// check for death of the current clientNum
+		if ( es->otherEntityNum == cg.snap->ps.clientNum ) {
+			// if zoomed in, zoom out
+			CG_ZoomUp_f();
+		}
		CG_Obituary( es );
		break;
The above code was written by myself and may be used in the GPL or Q3 SDK source code.

Re: Event setting var in cgame module

Posted: Wed Sep 02, 2009 8:42 am
by Rawing
That did it thanks!