Jump to content

Trouble with a custom tactic


Metsumi

Recommended Posts

Hi,

 

To begin, i'm french so i am sorry for my bad spelling, i hope you can understand me ^^.

 

I try to do a customized tactic for a group of warrior. They have to circle a target, and attack it. But the target object is loose between the "signalevent" function and the "geteventobject" in the case " EVENT_TYPE_CUSTOM_EVENT_01" of the switch.

Moreover, i not sure with my way to define the "fRadius" of the "GetObjectsInShape" function, is it right?

 

I tried a lot of things, but i haven't found any solution... Please, help my poor brain! ^^

 

#include "rules_h"
#include "log_h"
#include "utility_h"
#include "global_objects_h"
#include "ai_main_h_2"
#include "ai_ballista_h"
#include "design_tracking_h"
#include "sys_rewards_h"
#include "sys_autoscale_h"
#include "sys_rubberband_h"
#include "sys_soundset_h"
#include "sys_ambient_h"
#include "sys_treasure_h"
#include "sys_areabalance"
#include "aoe_effects_h"

int IsInTactic = GetLocalInt(OBJECT_SELF,"ENCERCLEMENT_DEFENSEUR");

void Encerclement(object cible)
{

float fRadius = 0.5f;
object[] oTargets = GetObjectsInShape(OBJECT_TYPE_CREATURE, SHAPE_SPHERE, GetLocation(OBJECT_SELF), fRadius,0.0f,0.0f,TRUE);
int i = 0;
int nSize = GetArraySize(oTargets);
while( i < nSize )
{

	float dist = GetDistanceBetween(OBJECT_SELF, oTargets[i]);

	if(GetTeamId(oTargets[i])==3 && dist < 1.0f && oTargets[i] != OBJECT_SELF)
	{
		AddCommand(OBJECT_SELF, CommandMoveAwayFromObject(oTargets[i], 1.0f), TRUE, TRUE);
	}
	
	i++;
}

if(!IsDead(cible))
{
	event EVENT_TYPE_ENCERCLEMENT = Event(EVENT_TYPE_CUSTOM_EVENT_01);
	SetEventObject(EVENT_TYPE_ENCERCLEMENT,0,cible);
	SignalEvent(OBJECT_SELF,EVENT_TYPE_ENCERCLEMENT,1);
	
	
	AddCommand(OBJECT_SELF, CommandAttack(cible), TRUE, TRUE);
}
else
{
	SetLocalInt(OBJECT_SELF,"ENCERCLEMENT_DEFENSEUR",0);
}
}

void main()
{
event ev = GetCurrentEvent();
int nEventType = GetEventType(ev);

// If TRUE, we won't redirect to rules core
int bEventHandled = FALSE;

#ifdef DEBUG
Log_Events("", ev);
#endif

if (IsPartyMember(OBJECT_SELF))
{
	Warning("Party member " + ToString(OBJECT_SELF) + " firing events into creature_core. This is a critical bug. Please inform Yaron");
	HandleEvent(ev, R"rules_core.ncs"); // fix it
	return;
}

//if we can see ennemies, we start tactics
if(IsPerceivingHostiles(OBJECT_SELF))
{
	if(IsInTactic == 0)
	{

		float fRadius = 20.0;
		object[] oTargets = GetObjectsInShape(OBJECT_TYPE_CREATURE, SHAPE_SPHERE, GetLocation(OBJECT_SELF), fRadius,0.0f,0.0f,TRUE);
		int i = 0;
		int nTargetSize = GetArraySize(oTargets);


		while(GetTeamId(oTargets[i])!=1 && GetTeamId(oTargets[i])!=2 && i < nTargetSize)
		{
			i++;
		}
		
	   
		if(i != nTargetSize)
		{
			event EVENT_TYPE_ENCERCLEMENT = Event(EVENT_TYPE_CUSTOM_EVENT_01);
			SetEventObject(EVENT_TYPE_ENCERCLEMENT,0,oTargets[i]);

			DisplayFloatyMessage(OBJECT_SELF, "I see a bad guy called :  "+ GetTag(oTargets[i]));


			object[] oTeam = GetTeam(GetTeamId(OBJECT_SELF), OBJECT_TYPE_CREATURE);
			int nTeamSize = GetArraySize(oTeam);

			int index;

			SetLocalInt(OBJECT_SELF,"ENCERCLEMENT_DEFENSEUR",1);

			for (index = 0; index < nTeamSize; index++)
			{
				float dist = GetDistanceBetween(OBJECT_SELF, oTeam[index]);

				int IsFriendInTactics = GetLocalInt(oTeam[index],"ENCERCLEMENT_DEFENSEUR");

				if(dist<15.0f && IsFriendInTactics==0)
				{
					SignalEvent(oTeam[index],EVENT_TYPE_ENCERCLEMENT,1);
				}
				SignalEvent(OBJECT_SELF,EVENT_TYPE_ENCERCLEMENT,1);
			}
		}

	}
}

switch (nEventType)
{
	// -----------------------------------------------------------------
	// Damage over time tick event.
	// This is activated from EffectDOT and keeps rescheduling itself
	// while DOTs are in effect on the creature
	// -----------------------------------------------------------------
 case EVENT_TYPE_CUSTOM_EVENT_01:
	{
		object cible = GetEventObject(ev, 0);
		DisplayFloatyMessage(OBJECT_SELF, "My target is :  "+GetTag(cible),FLOATY_MESSAGE,16777215,5.0);
		Encerclement(cible);
	}
  ///////////////////////
  //I hide the other default cases
  ///////////////////////
}
// -------------------------------------------------------------------------
// Any event not handled falls through to rules_core:
// -------------------------------------------------------------------------
if (!bEventHandled)
{
	HandleEvent(ev, RESOURCE_SCRIPT_RULES_CORE);
}

}

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...