Activating and Fixing AI In Coop Games: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (typo)
m (and another one)
Line 63: Line 63:




Now open the '''h2mp_gamerules.cpp''' file. Then, at the very bottom of the file, add this piece of code:
Now open the '''hl2mp_gamerules.cpp''' file. Then, at the very bottom of the file, add this piece of code:
<pre>
<pre>
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

Revision as of 16:34, 16 February 2006

Introduction

Howdy!

Many people asked me why their NPCs were not moving or attacking the player in their HL2DM Coop mod. Well, NPCs do not attack you or whatever because Half-Life 2: Deathmatch does not initially include the NPCs' relation ship table. Thus I am going to teach you how to lead them to do something more decent than patrolling around their spawn-point.


The Relationship Table

Creating the Table

First of all, we should define the NPCs relationship table. Open the BaseEntity.h file, then in the enum Class_T definition, after the #elif defined( CSTRIKE_DLL ) block, add this:

//***THOMAS*** INITS NPCs' RELATION SHIP TABLE FOR HL2DM
#elif defined ( HL2MP_DLL || HL2MP )
// For CLASSIFY
enum Class_T
{
	CLASS_NONE=0,				
	CLASS_PLAYER,			
	CLASS_PLAYER_ALLY,
	CLASS_PLAYER_ALLY_VITAL,
	CLASS_ANTLION,
	CLASS_BARNACLE,
	CLASS_BULLSEYE,
	CLASS_CITIZEN_PASSIVE,	
	CLASS_CITIZEN_REBEL,
	CLASS_COMBINE,
	CLASS_COMBINE_GUNSHIP,
	CLASS_CONSCRIPT,
	CLASS_HEADCRAB,
	CLASS_MANHACK,
	CLASS_METROPOLICE,		
	CLASS_MILITARY,		
	CLASS_SCANNER,		
	CLASS_STALKER,		
	CLASS_VORTIGAUNT,
	CLASS_ZOMBIE,
	CLASS_PROTOSNIPER,
	CLASS_MISSILE,
	CLASS_FLARE,
	CLASS_EARTH_FAUNA,

	NUM_AI_CLASSES
};
//***

Loading the Table

All right! Now we have to tell the Game Rules to use this relationship table when we start a HL2DM game. Open the hl2mp_gamerules.h file. Under the public: tab, add this:

//***THOMAS*** INITS NPCs' RELATION SHIP TABLE FOR HL2DM
#ifndef CLIENT_DLL 
void InitDefaultAIRelationships( void );
#endif
//***


Now open the hl2mp_gamerules.cpp file. Then, at the very bottom of the file, add this piece of code:

//------------------------------------------------------------------------------
// Purpose : Initialize all default class relationships
// Input   :
// Output  :
//------------------------------------------------------------------------------
//***THOMAS*** INITS NPCs' RELATION SHIP TABLE FOR HL2DM
#ifndef CLIENT_DLL 
void CHL2MPRules::InitDefaultAIRelationships( void )
{
	//Copy contents of the hl2_gamerules InitDefaultAIRelationships to here
}
#endif
//***


Let's finish by adding this in the CHL2MPRules::CHL2MPRules() function:

//***THOMAS*** INITS NPCs' RELATION SHIP TABLE FOR HL2DM
InitDefaultAIRelationships();
//***

Import skills data

Few people noticed that NPCs were not causing any damage to the player and that they could die instantly. This issue is simply caused by the fact the file skill.cfg is missing from the "\cfg" directory in the mod-dir. To fix it, create a new text file with Notepad, put the code bellow in it, then rename the file to skill.cfg.

// ===========
//  NPCs
// ============
// Barnacle
sk_barnacle_health		"35"

// Barney
sk_barney_health		"35"

// Bullseye
sk_bullseye_health		"35"

//Bullsquid
sk_bullsquid_health		"40"
sk_bullsquid_dmg_bite   	"15"
sk_bullsquid_dmg_whip   	"25"
sk_bullsquid_dmg_spit		"10"

// Citizen
sk_citizen_health		"40"

// Combine Soldier
sk_combine_s_health		"50"
sk_combine_s_kick		"10"

// Combine Guard
sk_combine_guard_health	"70"
sk_combine_guard_kick	"15"

// strider
sk_strider_health		"350"
sk_strider_num_missiles1	"5"
sk_strider_num_missiles2	"7"
sk_strider_num_missiles3	"7"

// Headcrab
sk_headcrab_health		"10"
sk_headcrab_melee_dmg	"5"

// Fast Headcrab
sk_headcrab_fast_health	"10"

// Poison Headcrab
sk_headcrab_poison_health	"35"

// Houndeye
sk_houndeye_health		"80"
sk_houndeye_dmg_blast	"15"

// Manhack
sk_manhack_health		"25"
sk_manhack_melee_dmg	"20"

// Metropolice
sk_metropolice_health	"40"
sk_metropolice_stitch_reaction "1.0"
sk_metropolice_stitch_tight_hitcount "2"
sk_metropolice_stitch_at_hitcount "1"
sk_metropolice_stitch_behind_hitcount "3"
sk_metropolice_stitch_along_hitcount "2"

// Rollermine
sk_rollermine_shock		"10"
sk_rollermine_stun_delay "3"
sk_rollermine_vehicle_intercept "1"

// Scanner (City)
sk_scanner_health		"30"
sk_scanner_dmg_dive		"25"

// Stalker
sk_stalker_health		"50"
sk_stalker_melee_dmg	"5"

// Vortigaunt
sk_vortigaunt_health	"100"
sk_vortigaunt_dmg_claw	"10"
sk_vortigaunt_dmg_rake	"25"
sk_vortigaunt_dmg_zap	"20"
sk_vortigaunt_armor_charge "30"

// Zombie
sk_zombie_health	"50"
sk_zombie_dmg_one_slash	"10"
sk_zombie_dmg_both_slash	"25"

// Poison Zombie
sk_zombie_poison_health		"175"
sk_zombie_poison_dmg_spit	"20"

//Antlion
sk_antlion_health			"30"
sk_antlion_swipe_damage		"5"
sk_antlion_jump_damage		"5"

//Antlion Guard
sk_antlionguard_health		"500"
sk_antlionguard_dmg_charge	"20"
sk_antlionguard_dmg_shove	"10"

//Antlion Grub
//sk_antliongrub_health		"5"

//Ichthyosaur
sk_ichthyosaur_health		"200"
sk_ichthyosaur_melee_dmg	"8"

// Combine Gunship
sk_gunship_burst_size		"15"
sk_gunship_health_increments	"5"
sk_npc_dmg_gunship		"40"
sk_npc_dmg_gunship_to_plr	"3"

// Combine Helicopter
sk_npc_dmg_helicopter			"6"
sk_npc_dmg_helicopter_to_plr	"3"
sk_helicopter_grenadedamage		"30"
sk_helicopter_grenaderadius		"275"
sk_helicopter_grenadeforce		"55000"

// Combine Dropship
sk_npc_dmg_dropship		"2"

// Combine APC
sk_apc_health				"750"


// =================
//  WEAPONS
// =================

sk_plr_dmg_ar2			"8"
sk_npc_dmg_ar2			"3"
sk_max_ar2				"60"
sk_max_ar2_altfire		"3"

sk_plr_dmg_alyxgun		"5"
sk_npc_dmg_alyxgun		"3"
sk_max_alyxgun			"150"

sk_plr_dmg_pistol		"5"
sk_npc_dmg_pistol		"3"
sk_max_pistol			"150"

sk_plr_dmg_smg1			"4"
sk_npc_dmg_smg1			"3"
sk_max_smg1				"225"

sk_plr_dmg_buckshot			"8"	
sk_npc_dmg_buckshot			"3"
sk_max_buckshot				"30"

sk_max_pulsemg			"200"

sk_plr_dmg_rpg_round		"100"
sk_npc_dmg_rpg_round		"50"
sk_max_rpg_round			"3"

sk_plr_dmg_smg1_grenade		"100"
sk_npc_dmg_smg1_grenade		"50"
sk_max_smg1_grenade		"3"
sk_smg1_grenade_radius		"250"

//sk_plr_dmg_gauss			"25"
//sk_plr_max_dmg_gauss		"30"

sk_plr_dmg_sniper_round		"13"
sk_npc_dmg_sniper_round		"100"
sk_max_sniper_round			"60"

sk_plr_dmg_357				"40"
sk_npc_dmg_357				"30"
sk_max_357					"12"

sk_plr_dmg_crossbow			"100"
sk_npc_dmg_crossbow			"10"
sk_max_crossbow				"10"

sk_plr_dmg_airboat			"3"
sk_npc_dmg_airboat			"3"

//sk_dmg_sniper_penetrate_plr	"10"
//sk_dmg_sniper_penetrate_npc	"100"

sk_plr_dmg_grenade			"150"	
sk_npc_dmg_grenade			"75"
sk_max_grenade				"5"

sk_plr_dmg_crowbar			"13"
sk_npc_dmg_crowbar			"5"

sk_plr_dmg_stunstick		"10"
sk_npc_dmg_stunstick		"40"	// Kill a citizen in one hit

//sk_plr_dmg_satchel			"150"
//sk_npc_dmg_satchel			"75"
//sk_satchel_radius			"150"

// Mortar Synth projectile
//sk_dmg_energy_grenade		"2"
//sk_energy_grenade_radius	"100"

sk_dmg_homer_grenade		"20"
sk_homer_grenade_radius		"100"

// Bullsquid spit
sk_dmg_spit_grenade			"30"	
sk_spit_grenade_radius		"120"

//sk_plr_dmg_tripmine			"150"
//sk_npc_dmg_tripmine			"125"
//sk_tripmine_radius			"200"

sk_plr_dmg_fraggrenade 		"125"
sk_npc_dmg_fraggrenade		"75"
sk_fraggrenade_radius 		"250"

// HEALTH/SUIT CHARGE DISTRIBUTION
sk_suitcharger		"75"
sk_suitcharger_citadel		"500"
sk_suitcharger_citadel_maxarmor	"200"
sk_battery			"15"
sk_healthcharger		"50"
sk_healthkit		"25"
sk_healthvial		"10"

// Combine balls
sk_combineball_seek_angle	"15"
sk_combineball_guidefactor	"1.0"

// NPC damage adjusters
sk_npc_head		"3"
sk_npc_chest	"1"
sk_npc_stomach	"1"
sk_npc_arm		"1"
sk_npc_leg		"1"

// player damage adjusters
sk_player_head		"3"
sk_player_chest		"1"
sk_player_stomach	"1"
sk_player_arm		"1"
sk_player_leg		"1"

// Allies
sk_ally_regen_time	"0.2"

// Jeep
sk_max_gauss_round	"30"

Conclusion

This tutorial should help you to get NPCs working in HL2DM. You could do it manually for each NPC, but I think this should help you not to waste time!

Happy programming! Template:Otherlang:en Template:Otherlang:en:fr