123 lines
2.7 KiB
Plaintext
123 lines
2.7 KiB
Plaintext
/*--------------------------------------------------------
|
|
|
|
Script Name: gen_geg_treas
|
|
----------------------------------------------------------
|
|
Created By: Genisys(Guile)
|
|
Created On: 4/14/09
|
|
----------------------------------------------------------
|
|
This script is executed from an object's OnOpen or OnDeath
|
|
event, it used to generate an Enchanting Gem.
|
|
|
|
To Utilize this script simply place the following code
|
|
after void main() { in the event script you desire to spawn
|
|
the Gems into (by % chance)
|
|
|
|
I've added a second box, for more rare gems, this should
|
|
allow you to control how often certain ones get passed out..
|
|
|
|
|
|
ExecuteScript("gen_geg_treas", OBJECT_SELF);
|
|
|
|
----------------------------------------------------------*/
|
|
//Required Include!
|
|
#include "gen_enc_config"
|
|
|
|
//PROTOTYPE DECLARED
|
|
int nCount(object oBox);
|
|
|
|
//MAIN SCRIPT
|
|
void main()
|
|
{
|
|
/*
|
|
int nONCE = GetLocalInt(OBJECT_SELF, "ONE_TIME_SPAWN");
|
|
if(nONCE ==1)
|
|
{
|
|
//Stop here we only generate the treasure 1 time ever for this object!
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
SetLocalInt(OBJECT_SELF, "ONE_TIME_SPAWN", 1);
|
|
} */
|
|
|
|
//The % Roll
|
|
int a = d100(1);
|
|
int j = d100(1);
|
|
|
|
//The box that holds the gems!
|
|
object oWay = GetWaypointByTag("gem_ref");
|
|
object oBox = GetNearestObjectByTag("gen_chest_sys", oWay);
|
|
object oBox2 = GetNearestObjectByTag("gen_treasure", oWay);
|
|
object oSpawn;
|
|
|
|
//Get the total # of gems in the chest..
|
|
int b = nCount(oBox);
|
|
int f = nCount(oBox2);
|
|
|
|
int c = Random(b);//the selected item..
|
|
int g = Random(f);//the selected item..
|
|
|
|
int d = c +1; //add +1 to the count!
|
|
int h = g +1; //Add +1 to the count!
|
|
|
|
int e = 0; //The increment counter..
|
|
int k = 0; //the increment counter..
|
|
|
|
object oItem; //the item we are getting
|
|
|
|
//If the % Chance was rolled on the 100 sided dice then spawn a gem
|
|
if(a<=CHANCE_SPAWNED)
|
|
{
|
|
oItem = GetFirstItemInInventory(oBox);
|
|
while(GetIsObjectValid(oItem))
|
|
{
|
|
e+=1;
|
|
|
|
if(e==d)
|
|
{
|
|
//Create the item on the Object this script is used on
|
|
//Copy the variable too (CRITICAL!)
|
|
CopyItem(oItem, OBJECT_SELF, TRUE);
|
|
}
|
|
|
|
oItem = GetNextItemInInventory(oBox);
|
|
}
|
|
}
|
|
|
|
//If the % Chance was rolled on the 100 sided dice then spawn a gem
|
|
if(j>=PERC_CHANCE_SPAWNED)
|
|
{
|
|
oItem = GetFirstItemInInventory(oBox);
|
|
while(GetIsObjectValid(oItem))
|
|
{
|
|
k+=1;
|
|
|
|
if(k==h)
|
|
{
|
|
//Create the item on the Object this script is used on
|
|
//Copy the variable too (CRITICAL!)
|
|
CopyItem(oItem, OBJECT_SELF, TRUE);
|
|
}
|
|
|
|
oItem = GetNextItemInInventory(oBox);
|
|
}
|
|
}
|
|
|
|
//Main Script End..
|
|
}
|
|
|
|
//PROTOTYPE DEFINED
|
|
int nCount(object oBox)
|
|
{
|
|
int i = 0;
|
|
object oGem = GetFirstItemInInventory(oBox);
|
|
while(GetIsObjectValid(oGem))
|
|
{
|
|
i+=1;
|
|
|
|
oGem = GetNextItemInInventory(oBox);
|
|
}
|
|
|
|
return i;
|
|
}
|