Author Topic: Creature spawn with random weapons  (Read 323 times)

Legacy_EzRemake

  • Full Member
  • ***
  • Posts: 220
  • Karma: +0/-0
Creature spawn with random weapons
« on: December 03, 2013, 05:57:48 am »


               I'm trying to write a script that will give a creature a random weapon (from a list) when they spawn. This should be really easy, but for some reason it just isn't working.

I made a copy of x2_def_spawn for the monsters I want this to apply to, and simply added

ExecuteScript("bones_items", OBJECT_SELF); to it to generate the loot.

bones_items looks like this

void main()
{
    int iRand = d4(1);

    switch (iRand){
      case 1: CreateItemOnObject("waxbt003", OBJECT_SELF); break;
      case 2: CreateItemOnObject("waxbt004", OBJECT_SELF); break;
      case 3: CreateItemOnObject("waxbt005", OBJECT_SELF); break;
      case 4: CreateItemOnObject("waxbt006", OBJECT_SELF); break;
      }

    ActionEquipMostDamagingMelee();
}

The item never seems to be created, as the enemy never seems to switch to it, or drop it when they die. I've tried many different item combinations with NPCs who are able to equip anything.
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
Creature spawn with random weapons
« Reply #1 on: December 03, 2013, 06:37:24 am »


               Add this line into the script after the switch statement:

SpeakString("Created item " + IntToString(iRand));

Make sure the creature actually says that line -- if you don't see it, your script isn't firing properly.
               
               

               
            

Legacy_EzRemake

  • Full Member
  • ***
  • Posts: 220
  • Karma: +0/-0
Creature spawn with random weapons
« Reply #2 on: December 03, 2013, 07:44:31 am »


               I knew it was going to be something small and stupid, turns out in this scenario you have to refer to the tag of the item, not the resref... Seems when dealing with giving items to players it's resref, and to creatures it's tag

The more you know lol
               
               

               
            

Legacy_EzRemake

  • Full Member
  • ***
  • Posts: 220
  • Karma: +0/-0
Creature spawn with random weapons
« Reply #3 on: December 03, 2013, 09:30:38 am »


               What I've come up with looks like this

void main()
{
   int iRand = d3(1);
   object oMainhand;
   object oOffhand;

   switch (iRand){
     
case 1: oMainhand = CreateItemOnObject("CeremonialScythe", OBJECT_SELF);
                           SetDroppableFlag(oMainhand, FALSE);
                           ActionEquipItem(oMainhand, INVENTORY_SLOT_RIGHTHAND);
                           break;

     case 2: oMainhand = CreateItemOnObject("BoneSword", OBJECT_SELF);
                           oOffhand = CreateItemOnObject("BoneShield", OBJECT_SELF);
                           SetDroppableFlag(oMainhand, FALSE);
                           SetDroppableFlag(oOffhand, FALSE);
                           ActionEquipItem(oMainhand, INVENTORY_SLOT_RIGHTHAND);
                           ActionEquipItem(oOffhand, INVENTORY_SLOT_LEFTHAND);
                           break;

     case 3: oMainhand = CreateItemOnObject("BoneSword", OBJECT_SELF);
                           oOffhand = CreateItemOnObject("BoneSword", OBJECT_SELF);
                           SetDroppableFlag(oMainhand, FALSE);
                           SetDroppableFlag(oOffhand, FALSE);
                           ActionEquipItem(oMainhand, INVENTORY_SLOT_RIGHTHAND);
                           ActionEquipItem(oOffhand, INVENTORY_SLOT_LEFTHAND);
                           break;
     }

}

I plan to use this in the future, giving certain types of monsters many particular setups, more than just the three listed here. Will this cause instability or lag when multiple creatures are spawning throughout the server with scripts like this tied to them?
               
               

               


                     Modifié par EzRemake, 03 décembre 2013 - 09:34 .
                     
                  


            

Legacy_Cursed Eclipse

  • Full Member
  • ***
  • Posts: 132
  • Karma: +0/-0
Creature spawn with random weapons
« Reply #4 on: December 03, 2013, 11:46:53 am »


               or you can try this
http://nwvault.ign.c...d=51805&id=2813