So far in testing the container scripts seem to be working as far as randomness, but I can't seem to get the creature script to be very random at all. In my tests, all I could do was get the creatures to generate one type of loot, when the varibles clearly specify multiple types. Here are the scripts:
dethia_lootgen_include
/*********************************************************************Written by Dethia - 09/29/2010
This script is part of the "loot generating" system.
This include file houses the constants used by the system as well assome functions.
BELOW IS A LIST OF VARIABLES YOU CAN ADD TO A CONTAINER, UNDER TYPE, -O INDICATESTHAT THE FLAG IS OPTIONAL AND IS NOT REQUIRED!TYPE NAME EFFECTint-O LOOTGEN_NUMBER_OF_ITEMS Determines how many items will generate inside the chest, 1 by default. This variable can take on any integer value greater than 1.
int-O LOOTGEN_GOLD_AND_ITEMS This indicates that both gold and an item can spawn inside the chest. The main effect of this is that if gold is generated, an item will also be generated. If LOOTGEN_NUMBER_OF_ITEMS is greater than 1, and this value is not set to 1, gold will count as one item and will thus subtract 1 from the total number of items to spawn, if this is set to 1, gold will not subtract 1 from the total number of items to spawn. This variable can take only a value of 1.
int-O LOOTGEN_GENERATED This indicates that no loot should spawn inside the chest. It can only take a value of 1. This should primarily be used in cases where you have a static treasure inside a chest and don't want any other random things added to it.
int LOOTGEN_TYPE This variable tells the script from which master chest the particular container can be populated. It can take on any defined master loot chest value (the const ints below). You can set as many of these as you like on a single container and the system will pick random items from any one of the chests specified. This is a REQUIRED parameter!
int-O LOOTGEN_GOLD_AMOUNT This variable specifies the amount of gold a chest should have. All chests will have a chance (set by you equal to LOOTGEN_GOLD_CHANCE) to spawn 10d5 gold by default, if you add this variable on a chest, it will be populated with the gold value you specified. The variable can take on any integer value greater than 0.********************************************************************/
/*************************CONSTANTS*****************************///NOTE!!!! All of these constants should be a positive value!!!!const int LOOTGEN_TYPE_POTIONS = 1;const int LOOTGEN_TYPE_SCROLLS1 = 2;const int LOOTGEN_TYPE_SCROLLS2 = 3;const int LOOTGEN_TYPE_SCROLLS3 = 4; const int LOOTGEN_TYPE_WANDS = 5;const int LOOTGEN_TYPE_WEAPONS = 6;const int LOOTGEN_TYPE_ARMOR = 7;const int LOOTGEN_TYPE_REAGENTS = 8;const int LOOTGEN_TYPE_JUNK = 9;const int LOOTGEN_TYPE_GEMS = 10;const int LOOTGEN_TYPE_FOOD = 11;const int LOOTGEN_TYPE_RINGS = 12;const int LOOTGEN_TYPE_AMULETS = 13;const int LOOTGEN_TYPE_SLIME = 14;const int LOOTGEN_TYPE_UNDEAD = 15;const int LOOTGEN_TYPE_INSECT = 16;const int LOOTGEN_TYPE_BOOKS = 17;const int LOOTGEN_TYPE_ANY = 99;const int LOOTGEN_GOLD_CHANCE = 15; //% chance of gold appearing in chestsconst string LOOTGEN_MASTER_CHEST_TAG = "LOOT_MASTER"; //tag of master chests/**********************END OFCONSTANTS**************************/
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<////------------------------------FUNCTIONS--------------------------------////------------------------------PROTOTYPES-------------------------------////>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//
//************************************************************************************// Written by Dethia - 09/29/2010// This function will pick out a random item from a specified master chest.// Returns OBJECT_INVALID on error// oMasterChest = the chest from which we will generate the loot item//************************************************************************************object LGGetRandomLoot(object oMasterChest);
//************************************************************************************// Written by Dethia - 09/29/2010// This function will pick out a single chest type from all possible loot chests// specified and return the loot type corresponding to that chest.// Returns -1 on error// oContainer = the container which specifies the type of loot it can recieve//************************************************************************************int LGGetLootType(object oContainer);
//************************************************************************************// Written by Dethia - 09/30/2010// Populates the specified container with gold, 10d5 by default. Returns the remaining// number of items the chest should be populated with (iNumVars)// oContainer = the container that will be populated// iGold = the amount of gold this chest should have, 10d5 by default// iNumItem = the number of items this chest will contain, 1 by default//************************************************************************************int LGGoldToContainer(object oContainer, int iGold, int iNumItems = 1);
//************************************************************************************// Written by Dethia - 09/30/2010// Populates the specified container with an actual randomly generated item. The #// of items that will be generated corresponds with iNumItems// oContainer = the container that will be populated// iNumItem = the number of items this chest will contain, 1 by default//************************************************************************************void LGItemToContainer(object oContainer, int iNumItems = 1);
//************************************************************************************// Written by Dethia - 09/30/2010// This function determines how many items should be generated in a container. This// value is based on the integer variable LOOTGEN_NUMBER_OF_ITEMS.// oContainer = the container we are checking for the number of items to spawn inside it//************************************************************************************int LGGetNumberOfItemsToSpawn(object oContainer);int LGGetRandomNumberOfItemsToSpawn(object oContainer);
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<////------------------------------FUNCTIONS--------------------------------////------------------------------IMPLEMENTATION---------------------------////>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//
object LGGetRandomLoot(object oMasterChest){ //First we will determine how many items are in the chest int iNum = 0; //The yet to be determined number of items
//Let's get the first item in the chest object oRandomItem = GetFirstItemInInventory(oMasterChest);
//As long as there are items in the chest keep increasing iNum while(GetIsObjectValid(oRandomItem)) { iNum++; oRandomItem = GetNextItemInInventory(oMasterChest); }
//Now that we have the total number of items, let's randomly pick one number int iRandomItem = Random(iNum) + 1;
//Lastly we reset iNum to 0 and iterate once again through the inventory of //the container and pick out the randomly determined item iNum = 0; oRandomItem = GetFirstItemInInventory(oMasterChest); while(GetIsObjectValid(oRandomItem)) { //Increase iNum as we look through the items iNum++; //If the current item number matches the randomly generated number that's our item if(iNum == iRandomItem) { return oRandomItem; } oRandomItem = GetNextItemInInventory(oMasterChest); } //If for whatever reason no item was retrieved we return OBJECT_INVALID return OBJECT_INVALID;}
int LGGetLootType(object oContainer){ //We will iterate through all the variables, find the LOOTGEN_TYPES and randomly pick one int iNumFlags = 0; //The number of flags on the chest, each flag corresponds to //an additional chest we want to include in the process of //generating a random loot item int iNumVar = GetVariableCount(oContainer); //The number of variables on the chest
//Now we go through all the variables and find all with the name LOOTGEN_TYPE while(iNumVar >= 0) { //Get the nth variable name string sVarName = GetVariableName(oContainer, iNumVar); //If the variable name is "LOOTGEN_TYPE" increase iNumFlags by 1 if(sVarName == "LOOTGEN_TYPE") { iNumFlags++; } iNumVar--; }
//Now that we have the number of flags, randomly pick one int iFlag = Random(iNumFlags) + 1; //Let's reset the number of flags and the variable count iNumFlags = 0; iNumVar = GetVariableCount(oContainer); //Lastly we go through the variables again, and get the value of the one we randomly chose while(iNumVar >= 0) { //Get the nth variable name string sVarName = GetVariableName(oContainer, iNumVar); //If the variable name is "LOOTGEN_TYPE" increase iNumFlags by 1 if(sVarName == "LOOTGEN_TYPE") { iNumFlags++; //If iNumFlags = iFlag return the variable value as the loot type if(iNumFlags == iFlag) { return GetVariableValueInt(oContainer, iNumVar); } } iNumVar--; } //If for some reason we failed to get a proper value, we return -1 on error return -1;}
int LGGoldToContainer(object oContainer, int iGold, int iNumItems = 1){ //First let's do a roll to see if gold should be generated if(LOOTGEN_GOLD_CHANCE >= d100()) { //On a successful roll, see if the amount of gold to spawn is set on the chest if(GetLocalInt(oContainer, "LOOTGEN_GOLD_AMOUNT") > 0) { iGold = GetLocalInt(oContainer, "LOOTGEN_GOLD_AMOUNT"); } //Now that we have the amount of gold add it to the chest CreateItemOnObject("NW_IT_GOLD001", oContainer, iGold); //If the Gold and Item flag is FALSE, and only one item per chest we end here if(!GetLocalInt(oContainer, "LOOTGEN_GOLD_AND_ITEMS") && iNumItems == 1) { //Specify that the loot for this chest has already been generated SetLocalInt(oContainer, "LOOTGEN_GENERATED", TRUE); return 0; } else if(!GetLocalInt(oContainer, "LOOTGEN_GOLD_AND_ITEMS") && iNumItems > 1) { //If the # of items/chest exceeds 1, and Gold/Items flag is false iNumItems--; //We reduce the # of items to spawn by 1 } } //At the end return the value of iNumItems return iNumItems;}
void LGItemToContainer(object oContainer, int iNumItems = 1){ //First get the type of loot the container can recieve int iLootType = LGGetLootType(oContainer); //Retrieve the loot from the corresponding master chest object oLootChest = GetObjectByTag(LOOTGEN_MASTER_CHEST_TAG + IntToString(iLootType)); //Now let's get a random item from the loot chest object oLootItem = LGGetRandomLoot(oLootChest);
//Lastly we check if the item acquired is valid, if yes place it into the container if(GetIsObjectValid(oLootItem)) { CopyObject(oLootItem, GetLocation(oContainer), oContainer); //Set the LOOTGEN_GENERATED flag as true on the chest so it won't spawn additional loot SetLocalInt(oContainer, "LOOTGEN_GENERATED", TRUE); } //We decrement the number of items to generate by 1 (since we just generated 1) iNumItems--; //If the number of items to generate is still greater than 0, we generate another one if(iNumItems > 0) { LGItemToContainer(oContainer, iNumItems); }}
int LGGetNumberOfItemsToSpawn(object oContainer) { int iNumItems = 1; //The default number of items to generate //If a value greater than 1 is specified on the chest set that as the # of items to generate if(GetLocalInt(oContainer, "LOOTGEN_NUMBER_OF_ITEMS") > 1) { iNumItems = GetLocalInt(oContainer, "LOOTGEN_NUMBER_OF_ITEMS"); } //Lastly just output the value of items to generate return iNumItems; } //Kamal Added: Random die roll to determine how any items to add int LGGetRandomNumberOfItemsToSpawn(object oContainer) { int iNumItems = d4(1); //whatever dice you want. return iNumItems; }
dethia_lootgen_container_onopen
/*********************************************************************Written by Dethia - 09/29/2010
This script is part of the "loot generating" system.
This script should be placed on any container's OnOpen event for it to work.It will populate the container with an item based on the parameters set on thecontainer via variables.
The parameters should be an integer variable on the container called: "LOOTGEN_TYPE"Set as many of these as you need, each LOOTGEN_TYPE should correspond tothe numerical value designated in the dethia_lootgen_include in the constants section.
AS AN EXAMPLE:If you want a container to spawn potions and wands set it's parameters to"LOOTGEN_TYPE" = 1"LOOTGEN_TYPE" = 3
Yes you will have 2 variables with the same name, that is perfectly ok.Check the include file for information on other variables that you can seton a container.********************************************************************/#include "dethia_lootgen_include"
void main(){ //Get the chest being opened. object oChest = OBJECT_SELF; //The container the PC is looking into object oLootItem = OBJECT_INVALID; //The yet to be determined item to go into the chest
//First check if any loot has been spawned in it previously, if yes end script here if(GetLocalInt(oChest, "LOOTGEN_GENERATED")) { return; } //If we got this far, get the amount of items we need to generate int iNumItems = LGGetNumberOfItemsToSpawn(oChest);
//Before we proceed to generate a random item(s), we spawn gold first and update # of items iNumItems = LGGoldToContainer(oChest, d10(5), iNumItems);
//If we got this far and iNumItems is greater than 0, let's get a random item into the chest if(iNumItems > 0) { LGItemToContainer(oChest, iNumItems); }}
dethia_lootgen_crtr_ondeath
/*********************************************************************Written by Dethia - 09/30/2010
This script is part of the "loot generating" system.
This script should be placed on any creature you want affected by this looggeneration system. The scripts will generate the loot inside the dead creature'sinventory.
You will need to add various variables on the creature to specify from whichloot chest you wish to draw the items that the creature may possess.
AS AN EXAMPLE:If you want a creature to drop potions and wands set it's parameters to"LOOTGEN_TYPE" = 1"LOOTGEN_TYPE" = 3
Yes you will have 2 variables with the same name, that is perfectly ok.********************************************************************/#include "dethia_lootgen_include"
void main(){ object oCreature = OBJECT_SELF; //The creature that died //Determine how many items should be generated in the creature's corpse int iNumItems = LGGetNumberOfItemsToSpawn(oCreature); //Generate the loot inside the creature's corpse LGItemToContainer(oCreature, iNumItems);}
Modifié par MokahTGS, 04 mai 2013 - 04:26 .





Retour en haut







