Aller au contenu

Photo

Having Creatures Attack a Placeable


  • Veuillez vous connecter pour répondre
7 réponses à ce sujet

#1
Darin

Darin
  • Members
  • 282 messages
 My kobolds are bad at tactics.  With three barrels of Alchemist fire around my player, they just attack the player instead.

Barrels spawn from triggers outside this trigger (near entrences to area).

When player crosses a trigger near the barrels, this runs:


// script_name: maus_kobold_ambush
/*
Description:

*/
// Name_Date




void main()
{
object oPC = GetEnteringObject();




if(!(GetLocalInt(OBJECT_SELF, "nSpawn")==1) && (TRUE) )
{
int nN = 1;
int nRand;
object oKobold, oTarget;
location lKobold;
string sTag = "wp_kob_spawn_1";
for (nN; nN<=4; nN++)
{
if(nN==4)
{
oTarget=oPC;
}
else
{
oTarget = GetObjectByTag( "drl_afbarrel");
}
lKobold = GetLocation(GetWaypointByTag(sTag));
oKobold = CreateObject(OBJECT_TYPE_CREATURE, "tod_kobold", lKobold, FALSE);
nRand = d4(1)+1;
CreateItemOnObject("nw_wammbu005", oKobold, nRand);
AssignCommand(oKobold, ActionEquipMostDamagingRanged());
ClearAllActions(oKobold);
AssignCommand(oKobold, ActionAttack(oTarget, FALSE));
}
SetLocalInt(OBJECT_SELF, "nSpawn",1);
}
}


...but they don't attack the barrel!  Any ideas on what I could do?

Modifié par EpicFetus, 25 mai 2012 - 04:50 .


#2
Darin

Darin
  • Members
  • 282 messages
(wow, format on this post = fail)

Modifié par EpicFetus, 25 mai 2012 - 04:50 .


#3
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 603 messages
Put in some debug statements so that you can tell if they are attempting to attack the barrel or if they are not even trying. That will determine whether it is the script or the characteristics of the barrel that are the problem.

Regards

#4
Dann-J

Dann-J
  • Members
  • 3 161 messages
I wonder if it matters what faction the barrel is in? You'd need the barrel to be hostile to the player if you're running a script off it to damage the players, but it might also have to be hostile to the kobolds for them to attack it. You might need the barrel to have a custom faction that is hostile to everyone.

I'd also restructure the way you're adding actions to their action queue. I'd be clearing all actions first (adding the TRUE flag to force them out of any combat actions), then delaying the other two AssignCommands slightly to get well clear of the ClearAllActions. A delay of 0.1 before equipping ranged weapons, and 0.2 before attacking the barrels may be prudent. The player won't notice such small delays, but the script will.

#5
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
Well for starters the script shouldn't even compile.

This line requires an int for it's parameter not an object(defaults to FALSE/0 I believe):

    ClearAllActions(oKobold);

Should be somthing more like:

    AssignCommand(oKobald, ClearAllActions());

Or if you also want to make sure you clear the combat state:

    AssignCommand(oKobald, ClearAllActions(TRUE));


And I know I'm not the best scripter in the world but wouldn't this:

    if(!(GetLocalInt(OBJECT_SELF, "nSpawn")==1) && (TRUE) )

be the same as this?:

    if (!GetLocalInt(OBJECT_SELF, "nSpawn"))

It just looks really confusing.

Modifié par GhostOfGod, 25 mai 2012 - 10:06 .


#6
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
Also, use GetNearestObjectByTag to get the barrels, otherwise they'll try to attack the first barrel created in the whole module, which might not even be in the same area.

Even better, when you first spawn the barrels, use that script to assign a barrel to each kobold as a local object (object oBarrel = CreateObject(....); object oKobold = GetObjectByTag(Kobold1); SetLocalObject(oKobold, "oBarrel", oBarrel); ). Then the kobold can just use GetLocalObject to get the right barrel.

You can spawn the Kobolds at the same time and set them to script hidden, and just have your trigger unhide the kobolds.

Actually, your problem is that you need to insert the command to attack the barrels in a heartbeat script. The kobolds get their action queue cleared with every heartbeat, so they don't have a chance to attack before the queue gets cleared.

#7
Darin

Darin
  • Members
  • 282 messages
if(!(GetLocalInt(OBJECT_SELF, "nSpawn")==1) && (TRUE) )

the true is a placeholder for some other statement that will make sure it only happens when relevant to the plot.

Was hoping to avoid a heartbeat, to be honest.

Ghost - you were right, must have been running the version pre-adding that command, though to be honest I didn't think clearing their queue would matter.

Modifié par EpicFetus, 25 mai 2012 - 02:01 .


#8
MasterChanger

MasterChanger
  • Members
  • 686 messages

EpicFetus wrote...

if(!(GetLocalInt(OBJECT_SELF, "nSpawn")==1) && (TRUE) )

the true is a placeholder for some other statement that will make sure it only happens when relevant to the plot.


Keep in mind that if a local int is undefined, it equals 0. So (!GetLocalInt(OBJECT_SELF, "nSpawn")) would run if the variable is not defined.

If you want it to run only when it is not 1 (i.e. 0 or 2 or 3 or...) !=1 works just as well as !(GetLocal....==1).

Was hoping to avoid a heartbeat, to be honest.


A heartbeat is not that terrible if it only runs when it's needed as opposed to constantly. One easy way to do this is to use the local string variable called "X2_SPECIAL_COMBAT_AI_SCRIPT" * = <name of your custom AI>. This only runs when DetermineCombatRound runs, which only runs when the creature is in combat.

Anyway, as LotRS said, the creature's actions are re-determined every round (which is necesary to running any kind of AI if you think about it). So you won't be able to get away from using some sort of heartbeat behavior any way.


* This is defined in nw_i0_generic. Check that script for more info.