Initial commit
Initial commit.
This commit is contained in:
111
_module/nss/ss_treasure.nss
Normal file
111
_module/nss/ss_treasure.nss
Normal file
@@ -0,0 +1,111 @@
|
||||
void main()
|
||||
{
|
||||
string sType;
|
||||
int i;
|
||||
int iChance;
|
||||
int iNumber;
|
||||
int iInventory;
|
||||
int iRoll;
|
||||
int iCount;
|
||||
object oTChest;
|
||||
object oItem;
|
||||
object oItem2;
|
||||
|
||||
int MAX_num_TABLES;
|
||||
|
||||
MAX_num_TABLES = 10;
|
||||
|
||||
|
||||
|
||||
for (i = 0; i <= MAX_num_TABLES; i++)
|
||||
{
|
||||
sType = GetLocalString(OBJECT_SELF,"ss_t_chest_"+IntToString(i));
|
||||
if (sType != "") // kick out if the string is empty
|
||||
{
|
||||
iChance= StringToInt(GetStringLeft(sType,3));
|
||||
iNumber= StringToInt(GetStringRight(sType,3));
|
||||
|
||||
while (iNumber > 0)
|
||||
{
|
||||
// pulls the chance denominator desired, if no local int is
|
||||
//specified it assumes that the denominator is 100.
|
||||
iRoll = GetLocalInt(OBJECT_SELF,"ss_t_chest_"+IntToString(i));
|
||||
|
||||
// This defaults to 100
|
||||
if (iRoll == 0) iRoll=100;
|
||||
|
||||
iRoll = (Random(iRoll)+1); //roll chance
|
||||
//SendMessageToPC(GetFirstPC(),"you rolled: "+ IntToString(iRoll));
|
||||
//SendMessageToPC(GetFirstPC(),"chance was: "+ IntToString(iChance));
|
||||
|
||||
if (iRoll > iChance)
|
||||
{
|
||||
iNumber--;
|
||||
}else
|
||||
{
|
||||
|
||||
//count up the inventory in the treasure chest
|
||||
oTChest =GetObjectByTag("ss_t_chest_"+IntToString(i));
|
||||
iInventory=0;
|
||||
object oInv = GetFirstItemInInventory(oTChest);
|
||||
while (oInv != OBJECT_INVALID)
|
||||
{
|
||||
iInventory=iInventory+1;
|
||||
oInv=GetNextItemInInventory(oTChest);
|
||||
}
|
||||
//SendMessageToPC(GetFirstPC(),"Num of Inventory: "+IntToString(iInventory));
|
||||
iRoll = (Random(iInventory)+1); //roll random item position
|
||||
//SendMessageToPC(GetFirstPC(),"Num in Inventory: "+IntToString(iRoll));
|
||||
oItem = GetFirstItemInInventory(oTChest);
|
||||
if (iRoll ==1) // get first item here
|
||||
{
|
||||
}else //otherwise roll over until I get the correct item.
|
||||
{
|
||||
for (iCount = 2; iCount <= iRoll; iCount++)
|
||||
{
|
||||
oItem = GetNextItemInInventory(oTChest);
|
||||
}
|
||||
}
|
||||
if (GetLocalInt(oTChest,"finite") > 0 )
|
||||
{
|
||||
//This is a uniqe spawn kill the original
|
||||
// unique spawns limied to a single draw.
|
||||
CopyItem(oItem,OBJECT_SELF,TRUE);//create item on NPC
|
||||
DestroyObject(oItem,0.01);
|
||||
iNumber=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
CopyItem(oItem,OBJECT_SELF,TRUE);//create item on NPC
|
||||
iNumber--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//Generate Gold Coins
|
||||
string sGolds = GetLocalString(OBJECT_SELF,"ss_t_golds");
|
||||
|
||||
int iNumDice = StringToInt(GetStringLeft(sGolds,3));
|
||||
int iPenalty = StringToInt(GetStringRight(sGolds,3));
|
||||
sGolds = GetStringLeft(sGolds,7);
|
||||
int iDice= StringToInt(GetStringRight(sGolds,3));
|
||||
|
||||
int iGolds =0;
|
||||
|
||||
for (i=iNumDice; i>0;i--)
|
||||
{
|
||||
iGolds = iGolds + (Random(iDice)+1);
|
||||
}
|
||||
|
||||
iGolds = iGolds + iPenalty;
|
||||
|
||||
if (GetObjectType(OBJECT_SELF) == OBJECT_TYPE_CREATURE)
|
||||
{
|
||||
GiveGoldToCreature(OBJECT_SELF,iGolds);
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateItemOnObject("nw_it_gold001",OBJECT_SELF,iGolds);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user