Raised This Month: $12 Target: $400
 3% 

Monster AI - Headcrab


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GHW_Chronic
SourceMod Donor
Join Date: Sep 2004
Location: Texas
Old 05-20-2007 , 06:12   Monster AI - Headcrab
Reply With Quote #1


YouTube Video

  • This is the first of hopefully several scripts that create and manage Half-Life monsters so they can be spawned and messed with in several mods.
  • This script cannot be used as a plugin by itself. You can spawn headcrabs with the simple test plugin that is also attached.
  • This script has built in natives, check out the test plugin to see how simple it is to make a plugin with this script. (Test plugin command: spawn_headcrab)



Code:
/**************
*             *
*  Variables  *
*             *
**************/

/*
*
*  Custom flags for the headcrab ents.
*
*/
#define FL_PSYCHIC	(1<<32)		//Finds an enemy even if it isn't in the headcrab's viewcone.
#define FL_FRIENDLY	(1<<33)		//Headcrab doesn't attempt to attack players.
#define FL_IN_JUMP	(1<<34)		//Is set when the headcrab is in the middle of attacking a player.
#define FL_IN_RIGHT	(1<<35)		//Is set when the headcrab is piviting right. When set, headcrab pivits right.
#define FL_IN_LEFT	(1<<36)		//Is set when the headcrab is piviting left. When set, headcrab pivits left.
#define FL_IN_FORWARD	(1<<37)		//Is set when the headcrab is moving forward. When set, headcrab moves forward.
#define FL_IN_BACK	(1<<38)		//When set, headcrab moves backwards.
#define FL_STOPPED	(1<<39)		//Headcrab AI plugin does not deal with the headcrab. Think for that headcrab is skipped.
#define FL_WANDER	(1<<40)		//If set, headcrab will wander around when it doesnt have an enemy.
#define FL_EXPLODE	(1<<42)		//If set, headcrab will explode after dieing.
#define FL_KAMIKAZE	(1<<43)		//If set, headcrab will explode and die after attacking (like HL Squeek).
#define FL_FROZEN2	(1<<44)		//If set, headcrab is frozen completely. No plugin can affect it except by removing it.
#define FL_FRIENDLY_1	(1<<45)		//If set, friendly to players on team 1
#define FL_FRIENDLY_2	(1<<46)		//If set, friendly to players on team 2
#define FL_FRIENDLY_3	(1<<47)		//If set, friendly to players on team 3
#define FL_FRIENDLY_4	(1<<48)		//If set, friendly to players on team 4

/*
*
*  The sequences for the headcrabs.
*
*/
#define SQ_IDLE		0
#define SQ_TURNLEFT	9
#define SQ_TURNRIGHT	8
#define SQ_RUN		3
#define SQ_DIE		7
#define SQ_IN_AIR	13
#define SQ_IN_JUMP	5

/*
*
*  The framerates for all of the headcrab
*  sequences.
*
*/
#define FR_IDLE		1.0
#define FR_TURNLEFT	0.5
#define FR_TURNRIGHT	0.5
#define FR_RUN		1.5
#define FR_DIE		1.0
#define FR_IN_AIR	1.0
#define FR_IN_JUMP	1.0

/*
*
*  The color of the headcrab's blood.
*
*/
#define BLOOD_COLOR	204

/*
*
*  Technical information for use with
*  dealing with headcrab damage and death.
*  This doesn't need to be changed for
*  any reason.
*
*/
#define HEALTH_OFFSET	100000.0

/*
*
*  This number plus the amount of time it
*  takes to do the think equals the delay
*  from the beginning of one think to another.
*
*/
#define THINK_DELAY	0.000000




/**************
*             *
*  Functions  *
*             *
**************/

/*
*
*  This function returns the created entity's
*  number. The spawned entity has a few keys
*  filled in including:
*    health 	- 100.0
*    takedamage - 1.0
*    maxspeed	- 20.0
*    dmg	- 1.0
*    flags	- FL_WANDER
*
*  Do not fear to mess with any variable set
*  by this function. These keys have all been
*  programmed to be read as variable in the
*  headcrab's think.
*
*/
native create_headcrab()

/*
*
*  Sets a headcrab's health. Use this instead
*  of setting the health / max_health keys.
*
*/
native set_headcrab_health(ent,Float:health)

/*
*
*  Kills a headcrab. Reads the headcrab's flags
*  for more information.
*
*/
native kill_headcrab(ent)




/*************
*            *
*  Forwards  *
*            *
*************/

/*
*
*  This forward is called right before
*  a headcrab is killed.
*
*  Returning PLUGIN_HANDLED will stop
*  the headcrab ent from being deleted.
*
*/
forward headcrab_killed(ent)


Requires CHR_Engine Stocks.
_
Attached Files
File Type: sma Get Plugin or Get Source (GHW_Headcrab.sma - 4905 views - 16.1 KB)
File Type: amxx GHW_Headcrab.amxx (20.9 KB, 2137 views)
File Type: sma Get Plugin or Get Source (GHW_Headcrab_test.sma - 2968 views - 477 Bytes)
File Type: amxx GHW_Headcrab_test.amxx (2.4 KB, 1125 views)
File Type: inc headcrab.inc (3.7 KB, 2390 views)

Last edited by GHW_Chronic; 05-28-2007 at 06:25.
GHW_Chronic is offline
Send a message via AIM to GHW_Chronic
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 05-22-2007 , 09:43   Re: Monster AI - Headcrab
Reply With Quote #2

Nicely done. Any plans for other monsters?
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 05-22-2007 , 13:43   Re: Monster AI - Headcrab
Reply With Quote #3

Wow, excellent work. I once tried to do something like this but failed miserably.

I thought you might want to know, however, that (1<<32) equals (1<<0), (1<<33) equals (1<<1), and so forth. In other words, once it gets past (1<<31), it begins looping (at least on 32-bit machines). So you might be touching into other flags.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 05-22-2007 , 16:34   Re: Monster AI - Headcrab
Reply With Quote #4

I see a lot of new plugins being made with your new Monster API Chronic =p.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
GHW_Chronic
SourceMod Donor
Join Date: Sep 2004
Location: Texas
Old 05-22-2007 , 17:45   Re: Monster AI - Headcrab
Reply With Quote #5

wow avalanche, very informative. I had run into a problem where flag 1<<41 was messing up which makes sense because it is FL_ONGROUND which is set by the game (which is why my flags skip from 40 to 42). But I haven't found any problems so far.
GHW_Chronic is offline
Send a message via AIM to GHW_Chronic
GHW_Chronic
SourceMod Donor
Join Date: Sep 2004
Location: Texas
Old 05-22-2007 , 21:13   Re: Monster AI - Headcrab
Reply With Quote #6

*update* made the maxspeed cvar able to be messed with without causing the headcrab to completely overshoot its target and yadayada
GHW_Chronic is offline
Send a message via AIM to GHW_Chronic
GHW_Chronic
SourceMod Donor
Join Date: Sep 2004
Location: Texas
Old 05-23-2007 , 21:26   Re: Monster AI - Headcrab
Reply With Quote #7

*update* fixed a problem where headcrabs would jump in the exact opposite direction of you if you were directly behind them.
GHW_Chronic is offline
Send a message via AIM to GHW_Chronic
GHW_Chronic
SourceMod Donor
Join Date: Sep 2004
Location: Texas
Old 05-28-2007 , 06:25   Re: Monster AI - Headcrab
Reply With Quote #8

*update* minor bug fixes.
GHW_Chronic is offline
Send a message via AIM to GHW_Chronic
P4rD0nM3
Veteran Member
Join Date: Feb 2006
Old 07-11-2007 , 08:03   Re: Monster AI - Headcrab
Reply With Quote #9

Thanks for the update. More more AIs please!
P4rD0nM3 is offline
GHW_Chronic
SourceMod Donor
Join Date: Sep 2004
Location: Texas
Old 07-11-2007 , 17:39   Re: Monster AI - Headcrab
Reply With Quote #10

Quote:
Originally Posted by P4rD0nM3 View Post
Thanks for the update. More more AIs please!
I've actually made the beta AI for the zombie but I am having model issues.
GHW_Chronic is offline
Send a message via AIM to GHW_Chronic
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:43.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode