Author Topic: All monsters attack object  (Read 376 times)

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
All monsters attack object
« on: January 10, 2014, 11:50:22 pm »


               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 .
                     
                  


            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
All monsters attack object
« Reply #1 on: January 11, 2014, 12:04:27 am »


               

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++;
    }
               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
All monsters attack object
« Reply #2 on: January 11, 2014, 12:04:34 am »


               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 .
                     
                  


            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
All monsters attack object
« Reply #3 on: January 11, 2014, 12:25:27 am »


               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 .
                     
                  


            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
All monsters attack object
« Reply #4 on: January 11, 2014, 03:59:03 am »


               

oCreature = GetNextObjectInArea(OBJECT_SELF);

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

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
All monsters attack object
« Reply #5 on: January 11, 2014, 05:03:52 pm »


               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.