Using variables drasticlaly lowered the amount of unique scripts I had about the place.
Here's a basic and flexible example.
Put a Hay Roll or Bail of Hay in your area.
Make it PLOT (so others won't destroy it) Usable, and Has Inventory.
Tab over to Scripts and under the OnOpen type 'objectloot' and hit edit. (this should create a script for you real quick.)
copy and paste this into it
void main()
{
SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);
string SDROP1 = GetLocalString(OBJECT_SELF, "SDROP1");
string SDROP2 = GetLocalString(OBJECT_SELF, "SDROP2");
string SDROP3 = GetLocalString(OBJECT_SELF, "SDROP3");
string SDROP4 = GetLocalString(OBJECT_SELF, "SDROP4");
string SDROP5 = GetLocalString(OBJECT_SELF, "SDROP5");
string SDROP6 = GetLocalString(OBJECT_SELF, "SDROP6");
int sometimesloot = d6();
if (sometimesloot == 1){CreateItemOnObject(SDROP1);}
if (sometimesloot == 2){CreateItemOnObject(SDROP2);}
if (sometimesloot == 3){CreateItemOnObject(SDROP3);}
if (sometimesloot == 4){CreateItemOnObject(SDROP4);}
if (sometimesloot == 5){CreateItemOnObject(SDROP5);}
if (sometimesloot == 6){CreateItemOnObject(SDROP6);}
}
Save and close the scripting page and back to your Hay Bale profile page. Hit the Advanced tab and click on the Variable... button.
Under name, add SDROP1, type will be string, value will be needle
Click Add
Repeat this so you have SDROP1 - SDROP3 with needle and SDROP4 - 6 without any value
Click OK and OK again to exit your Object properties screen.
Now create a needle. I used Miscellaneous Small 2* from the CEP to find a needle. I try and keep the TAG and the ResRef of all my custom items the exactly the same. So in this case, it's named needle
Build and test your module.
You'll see that when you click on the Hay bale, you should see a needle about half the time. Hopefully you can see how this can be very dynamic in the long run.
Here's my full script for object spawning items.
void main()
{
if(GetIsObjectValid(GetFirstItemInInventory(OBJECT_SELF)) || GetLocalInt(OBJECT_SELF,"DO_ONCE")) return;
SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);
string SDROP1 = GetLocalString(OBJECT_SELF, "SDROP1");
string SDROP2 = GetLocalString(OBJECT_SELF, "SDROP2");
string SDROP3 = GetLocalString(OBJECT_SELF, "SDROP3");
string SDROP4 = GetLocalString(OBJECT_SELF, "SDROP4");
string SDROP5 = GetLocalString(OBJECT_SELF, "SDROP5");
string SDROP6 = GetLocalString(OBJECT_SELF, "SDROP6");
string SDROP7 = GetLocalString(OBJECT_SELF, "SDROP7");
string SDROP8 = GetLocalString(OBJECT_SELF, "SDROP8");
string SDROP9 = GetLocalString(OBJECT_SELF, "SDROP9");
string SDROP10 = GetLocalString(OBJECT_SELF, "SDROP10");
string SDROP11 = GetLocalString(OBJECT_SELF, "SDROP11");
string SDROP12 = GetLocalString(OBJECT_SELF, "SDROP12");
int sometimesloot = d12();
if (sometimesloot == 1){CreateItemOnObject(SDROP1);}
if (sometimesloot == 2){CreateItemOnObject(SDROP2);}
if (sometimesloot == 3){CreateItemOnObject(SDROP3);}
if (sometimesloot == 4){CreateItemOnObject(SDROP4);}
if (sometimesloot == 5){CreateItemOnObject(SDROP5);}
if (sometimesloot == 6){CreateItemOnObject(SDROP6);}
if (sometimesloot == 7){CreateItemOnObject(SDROP7);}
if (sometimesloot == {CreateItemOnObject(SDROP8);}
if (sometimesloot == 9){CreateItemOnObject(SDROP9);}
if (sometimesloot == 10){CreateItemOnObject(SDROP10);}
if (sometimesloot == 11){CreateItemOnObject(SDROP11);}
if (sometimesloot == 12){CreateItemOnObject(SDROP12);}
SetLocalInt(OBJECT_SELF,"DO_ONCE",TRUE);
DelayCommand(600.0,DeleteLocalInt(OBJECT_SELF,"DO_ONCE")); //10min delay 300.0 is 5min delay
}