Author Topic: OnSpawn - create item  (Read 272 times)

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
OnSpawn - create item
« on: July 16, 2012, 05:11:10 am »


               On the OnSpawn script of the creature, I have a call to a function 
Loot()

I'm trying to have control over what loot drops off of some creatures. Here is what I'm trying to use to spawn loot on the creature during spawn.

string ADROP1 = GetLocalString(OBJECT_SELF, "ADROP1");            string ADROP2 = GetLocalString(OBJECT_SELF, "ADROP2");            string ADROP3 = GetLocalString(OBJECT_SELF, "ADROP3");
            CreateItemOnObject(ADROP1);            CreateItemOnObject(ADROP2);            CreateItemOnObject(ADROP3);

I have the creature death loot set to Leave Lootable Corpse. But no items drop on the creature. What am I doing wrong?
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
OnSpawn - create item
« Reply #1 on: July 16, 2012, 05:29:43 am »


               Could add some lines to your OnSpawn script kinda like so for testing. See if the problem is somewhere there first:


void main()
{

    string ADROP1 = GetLocalString(OBJECT_SELF, "ADROP1");
    string ADROP2 = GetLocalString(OBJECT_SELF, "ADROP2");
    string ADROP3 = GetLocalString(OBJECT_SELF, "ADROP3");
    object oItem1 = CreateItemOnObject(ADROP1);
    object oItem2 = CreateItemOnObject(ADROP2);
    object oItem3 = CreateItemOnObject(ADROP3);

    SendMessageToPC(GetFirstPC(), "OnSpawn test is running.");
    if (GetIsObjectValid(oItem1))
    SendMessageToPC(GetFirstPC(), "Item1  created successfully.");
    if (GetIsObjectValid(oItem2))
    SendMessageToPC(GetFirstPC(), "Item2  created successfully.");
    if (GetIsObjectValid(oItem3))
    SendMessageToPC(GetFirstPC(), "Item3  created successfully.");

}


If you don't see the first line then your OnSpawn might not be on the creature?

If you don't see the item lines then maybe its the res refs (string variables) set on the creatures?
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
OnSpawn - create item
« Reply #2 on: July 16, 2012, 05:51:27 am »


               also consider spawning loot in OnDeath event, creature's AI might use the loot for his own benefits (scrolls, potions...)
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
OnSpawn - create item
« Reply #3 on: July 16, 2012, 06:33:43 am »


               Make sure the droppable flag is set:

SetDroppableFlag(CreateItemOnObject(ADROP1),TRUE);
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
OnSpawn - create item
« Reply #4 on: July 16, 2012, 06:47:24 am »


               

Lightfoot8 wrote...

Make sure the droppable flag is set:

SetDroppableFlag(CreateItemOnObject(ADROP1),TRUE);

no need to actually, items created by script on NPC are automatically droppable
               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
OnSpawn - create item
« Reply #5 on: July 16, 2012, 07:16:58 am »


               it seams to be working just fine if the treasure model is set to body/pouch, but not as a lootable corpse. hmm..
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
OnSpawn - create item
« Reply #6 on: July 18, 2012, 05:21:06 am »


               Maybe:
SetLootable(object, int)
Sets whether a creature leaves a lootable corpse upon death

void SetLootable(
   object oCreature,
   int bLootable
);
Parameters
oCreature

NPC to set as lootable or not

bLootable

TRUE or FALSE



Description
Sets the lootable state of a *living* NPC creature.
This function will *not* work on players or dead creatures.




Remarks
This corresponds to the "leaves lootable corpse" NPC property (under advanced in the NPC's properties).

Only NPCs can be lootable, and their lootable state must be set BEFORE they die.



Known Bugs
Simply calling SetLootable doesn't appear to be sufficient to have the NPC leave a lootable corpse. The corpse left behind isn't selectable. To make a corpse lootable, add the two lines of code below to the end of the NPC's OnSpawn script:



Version
1.61

Example
SetIsDestroyable(TRUE, FALSE, TRUE);
DelayCommand(1.0, SetLootable(OBJECT_SELF, TRUE));

See Also
functions:  GetLootable
categories:  Inventory Functions
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
OnSpawn - create item
« Reply #7 on: July 18, 2012, 06:00:14 am »


               

Buddywarrior wrote...

it seams to be working just fine if the treasure model is set to body/pouch, but not as a lootable corpse. hmm..

have you triedd to move spawning items into OnDeath as I suggested? Im doing it like this and while I rarely use lootable corpses (there are few bugs with that) it worked for me.
               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
OnSpawn - create item
« Reply #8 on: July 18, 2012, 03:55:01 pm »


               I haven't. I've talked myself into thinking that leaving a little bag of treasure looks better on these rare creatures. Truth is that it's a path of least resistance and the player wont notice and/or care.