Page 1 of 1

Making NPC's Fight

Posted: April 14th, 2012, 8:15 pm
by donnelly517
How can I put two types of NPC's into opposing factions so that they attack each other on sight? I want to have guards that are friendly or neutral to you and soldiers that attack them, and also you. But any answer would be helpful if that can't be done.

Re: Making NPC's Fight

Posted: April 15th, 2012, 10:35 am
by kddekadenz
1) create at least 2 factions in data/rpg/games/yourgame/factions
-> they can be empty, be sure to follow the naming conventions (0.cfg,1.cfg,2.cfg...)

2) Add to critters/.cfg -> r_char_faction number (example: player's cfg: r_char_faction 0; enemie's cfg: r_char_faction 1)

3) add to the script you assigned to the enemie's critter (via r_char_script number) the following code:

Code: Select all

r_script_signal spawn [
	r_additem self replacewithnumberofweapon 1
	r_equip self replacewithnumberofweapon 0
]
and

Code: Select all

r_script_signal update [
  if (!= (r_get_faction self) (r_get_faction actor)) [
    r_action_clear self
    r_action_attack self actor
  ]
]
I hope this helps you :)

Re: Making NPC's Fight

Posted: April 15th, 2012, 11:21 am
by donnelly517
Thanks. I thought it'd be more complicated than that. I'm liking this forum.

Re: Making NPC's Fight

Posted: April 15th, 2012, 12:47 pm
by donnelly517
Only problem I'm having is that the console says "actor" is an invalid reference of "incomptible type." It makes no sense because "actor" is used lots my scripts for enemies, although never under "update", only under attacks caused by colliding with the enemy and such. Do you know what I'm doing wrong?

Re: Making NPC's Fight

Posted: April 15th, 2012, 7:04 pm
by Hirato
The "actor" is not set when update is called (if it is, it's set to NULL).
The bestway to do what you want it to loop through all the entities and act on any you see (r_cansee for that)

Re: Making NPC's Fight

Posted: April 16th, 2012, 9:38 am
by kddekadenz
Hirato wrote:The "actor" is not set when update is called (if it is, it's set to NULL).
The bestway to do what you want it to loop through all the entities and act on any you see (r_cansee for that)
You mean like this?

Code: Select all

if (r_cansee self actor) [
r_action_clear self
r_action_attack self actor
]