Hey guys,
I have a list of many custom items (say 100+) that I want players to be able to find randomly, either as monster drops or treasures (or by picking certain placeables). What’s the best way to go about it?
This is one our Mod uses. This would require that all your item resrefs be similar/same and sequential.
Just put it in the “OnDeath” for the mob.
void main()
{
int nItemNum = d100(2);
if (nItemNum <= 9)
{
string sItem = "ULITEM_00" + IntToString(nItemNum);
CreateItemOnObject(sItem, OBJECT_SELF, 1);
}
else if (nItemNum <= 99)
{
string sItem = "ULITEM_0" + IntToString(nItemNum);
CreateItemOnObject(sItem, OBJECT_SELF, 1);
}
else
{
string sItem = ("ULITEM_" + IntToString(nItemNum));
CreateItemOnObject(sItem, OBJECT_SELF, 1);
}
}
This one is a little more sinister and complicated. It leaves the prospect you get nothing…
void main()
{
ExecuteScript("uberloot", OBJECT_SELF);
int nDiceRoll = d100(1);
if(nDiceRoll <= 10)
{
int nItemNum = d100(1);
if (nItemNum <= 9)
{
string sItem = "KelObjectHigh00" + IntToString(nItemNum);
CreateItemOnObject(sItem, OBJECT_SELF, 1);
}
else if (nItemNum <= 99)
{
string sItem = "KelObjectHigh0" + IntToString(nItemNum);
CreateItemOnObject(sItem, OBJECT_SELF, 1);
}
else
{
string sItem = ("KelObjectHigh" + IntToString(nItemNum));
CreateItemOnObject(sItem, OBJECT_SELF, 1);
}
}
else if(nDiceRoll <= 20)
{
int nItemNum = d100(1)+100;
string sItem = ("KelObjectHigh" + IntToString(nItemNum));
CreateItemOnObject(sItem, OBJECT_SELF, 1);
}
else if(nDiceRoll <= 30)
{
int nItemNum = d100(1)+200;
string sItem = ("KelObjectHigh" + IntToString(nItemNum));
CreateItemOnObject(sItem, OBJECT_SELF, 1);
}
}
Thanks,
I assume I can use the same script on the “OnSpawn” of placeables/treasures as well so it won’t just be monsters loot?
I actually don’t know… I’ve never dealt with a placeable/chest. I would think it would work with the OnOpen of a chest… As far as picking up a placeable, I would think that would deal with the OnAcquire events, and I can’t think of a clean way to do that off the top of my head.
Okay,
If I’m tagging the resref with incremental numbers without using zeroes at the beginning, for instance ULITEM_1 till ULITEM_555 , I would be able to use fewer lines of codes, right?
i.e.
void main()
{
int nitemnumber = d555;
int rolldice = d100;
if (rolldice > 98)
{
string sItem = "ULITEM_" + IntToString(nItemNum);
CreateItemOnObject(sItem, OBJECT_SELF, 1);
}
}
Does it matter that items can be duplicated? If not, that code is good, giving a 1% chance of finding a special item.
Does “picking” a placeable simply mean opening it? In that case, the script is similar, except that you only want it to happen once, so add these lines before the “if” statement:
if (GetLocalInt(OBJECT_SELF, "AlreadyOpened")) return;
SetLocalInt(OBJECT_SELF, "AlreadyOpened", TRUE);
That’s not a problem with creature drops, because a creature can only die once.
True, but this is for a PW. How can I do it so that chest can be re-accessed after a certain amount of time?
Ah, yes, you’d need to set the local variable to a timestamp, comparing it with the current time.
Yea, I just realized I got the answer for the timedelay on another thread so I could use that - Respawn item in inventory of placeable after X time
I think that solved this issue; I’ll check it out soon and post back if there are any hitches.
Thanks!
I say that likely works. That assumes you want the same chance for all items.
And that NWN assumes that saying “d555” means “give me a random number between 555”.
For the script I submitted (particularly the Kelt items), This was organized so that items of particular value were arranged in order. I would recommend a predetermined length to your item name… maybe not length, but number of trailing digits. A call for “ULITEM1” might be called with the same diceroll as “ULITEM107”, as both contain “ULITEM1”.
Consider that you have a 2% of getting SOMETHING. But your chance of getting a particular item is 2/555 (or 0.0036036036%) chance.
Also,
You can have that one run on a boss too, inside your bosses loot script. In this loot script, our mod uses Tag based scripting (as I understand it) to link the bosses resref to the items resref. And he can still drops some other stuff.
void main()
{
ExecuteScript ("uberloot", OBJECT_SELF);
ExecuteScript ("lootgems", OBJECT_SELF);
string sName = GetResRef(OBJECT_SELF);
{
int nDiceRoll = d100(1);
if(nDiceRoll <= 10)
{
CreateItemOnObject((sName+"1"), OBJECT_SELF, 1);
}
else if(nDiceRoll <= 20)
{
CreateItemOnObject((sName+"2"), OBJECT_SELF, 1);
}
else if(nDiceRoll <= 30)
{
CreateItemOnObject((sName+"3"), OBJECT_SELF, 1);
}
}
}
Understand please, that I wrote exactly 0 percent of this. I’ve reverse engineered this all and can take no credit for any of it. This came from Craig Suters “World of Amon” mod.