View Single Post
Re: How to detect entity [properties] ?
Old
  (#6)
botman
Super Moderator
 
Status: Offline
Posts: 280
Join Date: Jan 2004
Location: Plano, TX
Default Re: How to detect entity [properties] ? - 27-05-2004

Intercepting the key/value pairs of an entity is a little more complex than that. First you have to store the entvars pointer when the entity is created, then in DispatchKeyValue, when keys are stored for that specific entity, you can examine what the values of those keys are.

For the HPB bot, I keep a global variable to store the pent (entvars pointer)...

Code:
edict_t *pent_info_tfdetect = NULL;
This variable gets NULLed out everytime a new map begins loading (when the code sees the "worldspawn" entity being created).

In DispatchKeyValue(), I check to see if an entity is being created by looking for the "classname" key (since Worldcraft/Hammer always makes the "classname" for entities the first key to be passed into the MOD code)...
Code:
	 else if (pent_info_tfdetect == NULL)
	 {
		 if ((strcmp(pkvd->szKeyName, "classname") == 0) &&
			 (strcmp(pkvd->szValue, "info_tfdetect") == 0))
		 {
			pent_info_tfdetect = pentKeyvalue;
		 }
	 }
....and then, also in DispatchKeyValue(), when other keys are being passed to the MOD code, I compare the pentKeyvalue being passed in to the pointer of the specific entity I am looking for and check which key is being passed in...
Code:
 if (mod_id == TFC_DLL)
{
	 if (pentKeyvalue == pent_info_tfdetect)
	 {
		 if (strcmp(pkvd->szKeyName, "ammo_medikit") == 0) // max BLUE players
			max_team_players[0] = atoi(pkvd->szValue);
		 else if (strcmp(pkvd->szKeyName, "ammo_detpack") == 0) // max RED players
			max_team_players[1] = atoi(pkvd->szValue);
		 else if (strcmp(pkvd->szKeyName, "maxammo_medikit") == 0) // max YELLOW players
			max_team_players[2] = atoi(pkvd->szValue);
		 else if (strcmp(pkvd->szKeyName, "maxammo_detpack") == 0) // max GREEN players
			max_team_players[3] = atoi(pkvd->szValue);
		 else if (strcmp(pkvd->szKeyName, "maxammo_shells") == 0) // BLUE class limits
			team_class_limits[0] = atoi(pkvd->szValue);
		 else if (strcmp(pkvd->szKeyName, "maxammo_nails") == 0) // RED class limits
			team_class_limits[1] = atoi(pkvd->szValue);
		 else if (strcmp(pkvd->szKeyName, "maxammo_rockets") == 0) // YELLOW class limits
			team_class_limits[2] = atoi(pkvd->szValue);
		 else if (strcmp(pkvd->szKeyName, "maxammo_cells") == 0) // GREEN class limits
			team_class_limits[3] = atoi(pkvd->szValue);
		 else if (strcmp(pkvd->szKeyName, "team1_allies") == 0) // BLUE allies
			team_allies[0] = atoi(pkvd->szValue);
		 else if (strcmp(pkvd->szKeyName, "team2_allies") == 0) // RED allies
			team_allies[1] = atoi(pkvd->szValue);
		 else if (strcmp(pkvd->szKeyName, "team3_allies") == 0) // YELLOW allies
			team_allies[2] = atoi(pkvd->szValue);
		 else if (strcmp(pkvd->szKeyName, "team4_allies") == 0) // GREEN allies
			team_allies[3] = atoi(pkvd->szValue);
	 }
So in your case, you would need a global variable for the control_flag entity (assuming that was what DoD called that entity)...
Code:
edict_t *control_point = NULL;
int dod_flag; // entity 'control_flag' key "point_allies_target" calue gets stored here
...you would need to NULL it out when the world is spawned (in DispatchSpawn)...
Code:
	 if (strcmp(pClassname, "worldspawn") == 0)
	 {
		 // do level initialization stuff here...
 
		 control_point = NULL;
...and you need to add the checks in DispatchKeyValue()...
Code:
 if (mod_id == DOD_DLL)
{
	 if (pentKeyvalue == control_point)
	 {
		 if (strcmp(pkvd->szKeyName, "point_allies_target") == 0)
			dod_flag = atoi(pkvd->szValue);
	 }
	 else if (control_point == NULL)
	 {
		 if ((strcmp(pkvd->szKeyName, "classname") == 0) &&
			 (strcmp(pkvd->szValue, "control_point") == 0))
		 {
			control_point = pentKeyvalue;
		 }
	 }
...and then once the map is completely loaded, you can just examine the 'dod_flag' variable to see what the 'control_point' entity had in the "point_allies_target" key when that entity was spawned.

If there was more than one 'control_point' entity, then you would have to create and array of global edict_t pointers, and store each one separately. All of the entities that I intercept in the HPB bot code are assumed to have only 1 of those entities in each map (the HPB bot code doesn't contain any examples of reading the key/value properties from a bunch of entities having the exact same classname).

botman

Last edited by botman; 27-05-2004 at 15:29..
  
Reply With Quote