Behaviors: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
Behaviors let you assign schedules and functionality to more than one NPC class without having to re-write or derive off a certain class. | Behaviors let you assign schedules and functionality to more than one NPC class without having to re-write or derive off a certain class. | ||
For example: | For example: | ||
You have three npc classes : npc_bob , npc_fred , npc_jane | You have three npc classes : npc_bob , npc_fred , npc_jane<br> | ||
You make two behaviors : MensBathroomBehavior, WomensBathroomBehavior | You make two behaviors : MensBathroomBehavior, WomensBathroomBehavior<br> | ||
You'd assign MensBathroomBehavior to the male npcs and WomensBathroomBehavior to npc_jane. | You'd assign MensBathroomBehavior to the male npcs and WomensBathroomBehavior to npc_jane. |
Revision as of 15:55, 23 October 2006
Behaviors let you assign schedules and functionality to more than one NPC class without having to re-write or derive off a certain class.
For example:
You have three npc classes : npc_bob , npc_fred , npc_jane
You make two behaviors : MensBathroomBehavior, WomensBathroomBehavior
You'd assign MensBathroomBehavior to the male npcs and WomensBathroomBehavior to npc_jane.
Steps To Add Behavior:
- add a function to your npc class : bool npc_class::CreateBehaviors() : (comes in virtually from CAI_BehaviorHost)
- create the behaviour as a member variable in your class
- add the behavior AddBehavior( &m_WhateverBehavior ); in your CreateBehaviors() function
- let your npc class know you want to use a behavior by calling BehaviorSelectSchedule() in your SelectSchedule()
To allow the Behavior to be used you'll need a function in teh behavior:
bool CAI_WhateverBehaviour::CanSelectSchedule() { return true; }
That should do it.