AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   Monster AI - Headcrab (https://forums.alliedmods.net/showthread.php?t=55357)

GHW_Chronic 05-20-2007 06:12

Monster AI - Headcrab
 
26 Attachment(s)
http://i4.tinypic.com/2jc8nc8.jpg
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.
_

Emp` 05-22-2007 09:43

Re: Monster AI - Headcrab
 
Nicely done. Any plans for other monsters?

XxAvalanchexX 05-22-2007 13:43

Re: Monster AI - Headcrab
 
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.

Zenith77 05-22-2007 16:34

Re: Monster AI - Headcrab
 
I see a lot of new plugins being made with your new Monster API Chronic =p.

GHW_Chronic 05-22-2007 17:45

Re: Monster AI - Headcrab
 
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 05-22-2007 21:13

Re: Monster AI - Headcrab
 
*update* made the maxspeed cvar able to be messed with without causing the headcrab to completely overshoot its target and yadayada

GHW_Chronic 05-23-2007 21:26

Re: Monster AI - Headcrab
 
*update* fixed a problem where headcrabs would jump in the exact opposite direction of you if you were directly behind them.

GHW_Chronic 05-28-2007 06:25

Re: Monster AI - Headcrab
 
*update* minor bug fixes.

P4rD0nM3 07-11-2007 08:03

Re: Monster AI - Headcrab
 
Thanks for the update. More more AIs please!

GHW_Chronic 07-11-2007 17:39

Re: Monster AI - Headcrab
 
Quote:

Originally Posted by P4rD0nM3 (Post 502013)
Thanks for the update. More more AIs please!

I've actually made the beta AI for the zombie but I am having model issues.


All times are GMT -4. The time now is 15:46.

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