Aller au contenu

Photo

All monsters attack object


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

#1
Buddywarrior

Buddywarrior
  • Members
  • 256 messages
On an object's heart beat script I'm trying to get all creatures in the area to attack it. I'm getting two errors in game. One is 'You cannot perform that action on a friendly target due to pvp settings', and a too many instructions error. I think my code is checking all areas. How can I solve this?


void main()
{
// stop all actions creatues are doing and attack the Radioactive Core
    int i = 1;
    object oCreature = GetNearestObject(OBJECT_TYPE_CREATURE, OBJECT_SELF, i);
    while (GetIsObjectValid(oCreature))    {         AssignCommand(oCreature, ClearAllActions(TRUE));         AssignCommand(oCreature, ActionAttack(OBJECT_SELF));         i++;
    }}

Modifié par Buddywarrior, 11 janvier 2014 - 12:03 .


#2
MagicalMaster

MagicalMaster
  • Members
  • 2 003 messages

Buddywarrior wrote...

One is 'You cannot perform that action on a friendly target due to pvp settings'

When you have the following code:

AssignCommand(oCreature, ActionAttack(OBJECT_SELF));

Since you're assigning the command to oCreature, the ActionAttack is telling oCreature to attack itself!  If you created a variable called oSelf that that set to be the calling object then you could use ActionAttack(oSelf) instead.

Buddywarrior wrote...

and a too many instructions error. I think my code is checking all areas. How can I solve this?

Let me ask you this: when does oCreature get updated to something BESIDES the first creature in the following code?

    object oCreature = GetNearestObject(OBJECT_TYPE_CREATURE, OBJECT_SELF, i);
    while (GetIsObjectValid(oCreature))    {         AssignCommand(oCreature, ClearAllActions(TRUE));         AssignCommand(oCreature, ActionAttack(OBJECT_SELF));         i++;
    }

#3
Buddywarrior

Buddywarrior
  • Members
  • 256 messages
sorry for the code looking sloppy. the forums used to support code. 


I'll add the oSelf to OBJECT_SELF, and I wasn't sure so I'll add a line to make sure it's only to creatures in the same area as the object itself. Will make changes after it's done building. Thanks!

Modifié par Buddywarrior, 11 janvier 2014 - 12:08 .


#4
MagicalMaster

MagicalMaster
  • Members
  • 2 003 messages
Quote this post if you want to see how I formatted this:

void main()
{
    // stop all actions creatues are doing and attack the Radioactive Core
    int i = 1;
    object oSelf = OBJECT_SELF;

    object oCreature = GetNearestObject(OBJECT_TYPE_CREATURE, OBJECT_SELF, i);
    while (GetIsObjectValid(oCreature)) 
    {
        AssignCommand(oCreature, ClearAllActions(TRUE));
        AssignCommand(oCreature, ActionAttack(oSelf));
        i++;
    }
}

That code should fix the friendly target message.  But you'll still get a too many instructions message -- see the second half of my earliest post for a hint why that would be.

Modifié par MagicalMaster, 11 janvier 2014 - 12:26 .


#5
Buddywarrior

Buddywarrior
  • Members
  • 256 messages
oCreature = GetNextObjectInArea(OBJECT_SELF);

Don't know why I ever takes breaks away from this game. Always the best community. Thanks MagicalMaster.

#6
MagicalMaster

MagicalMaster
  • Members
  • 2 003 messages
That, strictly speaking, wasn't the problem -- but you can get it to work using that as well. Let me know if you have other issues.