Hi! Welcome to the forum for Platinum Arts Sandbox Free 3D Game Maker. I currently have the forums locked as I am attempting to properly update them.

In the meantime please join the new Discord Server!

If you have any questions please e-mail me through the Platinum Arts website.

Making NPC's Fight

Having issues not related to a specific Sandbox game mode? Get help here!
Please also read the rules for support when posting support requests.
Failure to comply with the forum rules may result in your topic being locked without resolution.
Locked
donnelly517
Member
Member
Posts: 44
Joined: April 11th, 2012, 10:14 pm
Name: Evan Donnelly

Making NPC's Fight

Post 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.
Helping to map Broken Shield and Revelade Revolution.
User avatar
kddekadenz
Member
Member
Posts: 423
Joined: July 17th, 2011, 11:02 am
Name: kdd
Contact:

Re: Making NPC's Fight

Post 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 :)
Kelgar is an advanced RPG beeing developed in Sandbox
donnelly517
Member
Member
Posts: 44
Joined: April 11th, 2012, 10:14 pm
Name: Evan Donnelly

Re: Making NPC's Fight

Post by donnelly517 »

Thanks. I thought it'd be more complicated than that. I'm liking this forum.
Helping to map Broken Shield and Revelade Revolution.
donnelly517
Member
Member
Posts: 44
Joined: April 11th, 2012, 10:14 pm
Name: Evan Donnelly

Re: Making NPC's Fight

Post 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?
Helping to map Broken Shield and Revelade Revolution.
Hirato
Developer
Developer
Posts: 689
Joined: May 30th, 2009, 1:23 pm
IRC Username: hirato

Re: Making NPC's Fight

Post 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)
This is not a url, clicking it is pointless
User avatar
kddekadenz
Member
Member
Posts: 423
Joined: July 17th, 2011, 11:02 am
Name: kdd
Contact:

Re: Making NPC's Fight

Post 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
]
Kelgar is an advanced RPG beeing developed in Sandbox
Locked