Hi All,
Here is my script, which I have taken liberty to add some flexibility to allow my own use moving forward …
To use, you must place this script of a trigger on enter, and add three variables to it:-
- The tag of the placeable being used for items found goes in “PLACETAG”.
- The number of items to be found goes in “QUANTITY”
- The ResRef of the item to be created goes in “RR1”.
NB: You can stipulate other items in RR2, RR3, etc, up to a maximum of ten items, as long as you have placed ten placeables. (You can leave these higher RRx references off in your example.)
Then ensure you have the ten chests with the SAME tag, and is placed in the “PLACETAG” on trigger.
Ensure your QUANTITY is set to 4 on the trigger for your example. (Vary figure if required.)
Ensure that “RR1” on trigger has the resref of the item to be created in chests.
There are benefits to this script, as you can place the same tagged placeable (up to ten) and vary the item being randomly dropped. Either all the same or different resrefs.
I have to go offline now, but will check the other posts later.
Thanks, Lance.
////////////////////////////////////////////////////////////////////////////////////
// CREATE X OBJECTS ON Y PLACEABLES AT RANDOM (Y CALCULATED FROM ENVIRONMENT COUNT - MAX TEN)
// I.E. JUST PLACE THE PLACEABLES WITH THE SAME TAG TO RANDOMIZE BETWEEN. (MAXIMUM TEN SETUP)
// SETUP: USE THIS SCRIPT ON A TRIGGER WITH VARIABLE STRUCTURE AS FOLLOWS:-
// 1) A STRING VARIABLE CALLED "PLACETAG" WITH THE TAG OF THE PLACEABLE BEING USED FOR RANDOM FIND.
// 2) AN INTEGER VARIABLE CALLED "QUANTITY" WITH THE TOTAL NUMBER OF ITEMS TO FIND IN THE SET = X.
// 3) STRING VARIABLES IN FORMAT "RR1" "RR2" "RR3", ETC CONTAINING RESREF OF OBJECT(S) TO CREATE.
// NB: IF RR2 and above are not stipulated, then RR1 will be used for all object creations
// up to the number of objects listed in "QUANTITY". ITEM TO CREATE IS A SINGLE ITEM OF ITS TYPE
// ANY CREATURE PASSING THROUGH THIS TRIGGER WILL SETUP THE RANDOM PLACED OBJECTS
////////////////////////////////////////////////////////////////////////////////////
// GET A NUMBER FROM A LETTER
int GetAProximityInteger(string sLetter);
int GetAProximityInteger(string sLetter)
{
sLetter = GetStringUpperCase(sLetter);
int iNumber = 0;
if(sLetter == "A"){iNumber = 1;}
else if(sLetter == "B"){iNumber = 2;}
else if(sLetter == "C"){iNumber = 3;}
else if(sLetter == "D"){iNumber = 4;}
else if(sLetter == "E"){iNumber = 5;}
else if(sLetter == "F"){iNumber = 6;}
else if(sLetter == "G"){iNumber = 7;}
else if(sLetter == "H"){iNumber = 8;}
else if(sLetter == "I"){iNumber = 9;}
else if(sLetter == "J"){iNumber = 10;}
return iNumber;
}
// RETURN A RANDOM LETTER FOR THOSE THAT REMAIN IN DESIGNATED SERIES
string GetNewRandomLetter(object oTrigger);
string GetNewRandomLetter(object oTrigger)
{
string sRETURN;
string sPickFrom = GetLocalString(oTrigger, "LettersRemain"); // E.g. Could start with "abcd"
int iLettersRemain = GetStringLength(sPickFrom); // E.g. 4 in this case
int ThisLetter = Random(iLettersRemain); // E.g. 0-3 possible here.
sRETURN = GetSubString(sPickFrom, ThisLetter, 1); // E.g. 0 would return "a"
// CREATE & STORE REMAINING ALPHABET STRING
int nRightCount = iLettersRemain - ThisLetter - 1; // E.g. 4 - 0 - 1 = 3 (-1 is GetSubString 0 correction)
int nLeftCount = iLettersRemain - nRightCount - 1; // E.g. 4 - 3 - 1 = 0 (-1 is for this allocation)
string sRHRemain = GetStringRight(sPickFrom, nRightCount); // E.g. "bcd" in this case
string sLHRemain = GetStringLeft(sPickFrom, nLeftCount); // E.g. Nothing to return in this case.
string sRemainingLetters = sLHRemain + sRHRemain;
SetLocalString(oTrigger, "LettersRemain", sRemainingLetters); // Now stores "bcd" as possible remianing letters to choose from.
return sRETURN; // E.g. Returns "a"
}
////////////////////////////////////////////////////////////////////////////////////
// CREATE ITEMS REQUIRED ON RANDOM PLACEABLES
////////////////////////////////////////////////////////////////////////////////////
void CreateItemsOnPlaceables(object oTrigger, int iQTY, int iY, string sPlaceTag);
void CreateItemsOnPlaceables(object oTrigger, int iQTY, int iY, string sPlaceTag)
{
string sRR1 = GetLocalString(oTrigger, "RR1"); string sRR2 = GetLocalString(oTrigger, "RR2");
string sRR3 = GetLocalString(oTrigger, "RR3"); string sRR4 = GetLocalString(oTrigger, "RR4");
string sRR5 = GetLocalString(oTrigger, "RR5"); string sRR6 = GetLocalString(oTrigger, "RR6");
string sRR7 = GetLocalString(oTrigger, "RR7"); string sRR8 = GetLocalString(oTrigger, "RR8");
string sRR9 = GetLocalString(oTrigger, "RR9"); string sRR10 = GetLocalString(oTrigger, "RR10");
int iCount = 1;
while(iCount <= iQTY)
{
// GET THE ITEM RESREF FOR THIS PLACEABLE
string sRR = "RR" + IntToString(iCount);
sRR = GetLocalString(oTrigger, sRR);
if(sRR == ""){sRR = GetLocalString(oTrigger, "RR1");}
// NOW GET A RANDOM PLACEABLE FROM THOSE AVAILABLE (BASE ON RANDOM LETTER) TO CREATE ITEM
string sLetter = GetNewRandomLetter(oTrigger);
int iProximity = GetAProximityInteger(sLetter);
object oPlaceableToUse = GetNearestObjectByTag(sPlaceTag, oTrigger, iProximity);
// DEBUG FEEDBACK
// SendMessageToPC(GetFirstPC(), ">>> CREATING: " + sRR + " ON " + sPlaceTag + " AT PROXIMITY " + IntToString(iProximity) + "");
// CREATE APPROPRIATE RANDOM ITEM ON PLACEABLE
CreateItemOnObject(sRR, oPlaceableToUse, 1, "", 0);
iCount = iCount + 1;
}
DelayCommand(2.0, DestroyObject(oTrigger, 0.0, 0));
}
void main()
{
// WAIT UNTIL WE HAVE A VALID PC IN THE GAME FOR FEEDBACK (IN CASE CREATURE TRIGGERS)
object oPC = GetFirstPC(); if(oPC == OBJECT_INVALID){return;}
// THE TRIGGER OBJECT ITSELF
object oTrigger = OBJECT_SELF;
// INITIALIZE (GET NUMBER PLACEABLES INVOLVED)
if(GetLocalInt(oTrigger, "LBDONE")){return;}
// GATHER INFO FROM THE TRIGGER VARS
string sPlaceTag = GetLocalString(oTrigger, "PLACETAG");
int iQTY = GetLocalInt(oTrigger, "QUANTITY");
string sRR1 = GetLocalString(oTrigger, "RR1");
// CALCULATE PLACEABLE OBJECTS BEING USED (Y)
int iY = 0; int iNth = 0;
object oPlaceable = GetObjectByTag(sPlaceTag, iNth);
while(oPlaceable != OBJECT_INVALID)
{
iY = iY + 1;
iNth = iNth + 1;
oPlaceable = GetObjectByTag(sPlaceTag, iNth);
}
// DEBUG FEEDBACK
int iSTOP = 0;
if(sPlaceTag == ""){SendMessageToPC(oPC, "<<< PLACEABLE TAG NOT SETUP ON TRIGGER >>>"); iSTOP = 1;}
if(iQTY == 0){SendMessageToPC(oPC, "<<< ITEM QUANTITY NOT SETUP ON TRIGGER >>>"); iSTOP = 1;}
if(sRR1 == ""){SendMessageToPC(oPC, "<<< AT LEAST ONE RESREF REQUIRED FOR TRIGGER >>>"); iSTOP = 1;}
if(iY == 0){SendMessageToPC(oPC, "<<< NO PLACEABLE OBJECTS WITH TAG " + sPlaceTag + " SET FOR TRIGGER >>>"); iSTOP = 1;}
else if(iY < 2){SendMessageToPC(oPC, "<<< A MINIMUM OF 2 OBJECTS MUST BE USED WITH RANDOM TRIGGER >>>"); iSTOP = 1;}
// INCORRECT LOGIC POSSIBILITY
if(iQTY > iY){SendMessageToPC(oPC, "<<< CANNOT HAVE MORE ITEM OBJECTS THAN PLACEABLES >>>"); iSTOP = 1;}
if(iSTOP == 1){return;}
/////////////////////////////////////////////////////////////////////////////////////////////
// NOW MARK AS DONE, INITIALIZE AND SETUP THE ITEMS ON THE PLACEABLE OBJECTS
/////////////////////////////////////////////////////////////////////////////////////////////
SetLocalInt(oTrigger, "LBDONE", 1);
// SETUP A TEMP STRING VAR FOR CALCULATIONS BASED ON Y (MAX 10)
string sLetterString = "AB";
if(iY == 3){sLetterString = "ABC";}
else if(iY == 4){sLetterString = "ABCD";}
else if(iY == 5){sLetterString = "ABCDE";}
else if(iY == 6){sLetterString = "ABCDEF";}
else if(iY == 7){sLetterString = "ABCDEFG";}
else if(iY == 8){sLetterString = "ABCDEFGH";}
else if(iY == 9){sLetterString = "ABCDEFGHI";}
else if(iY == 10){sLetterString= "ABCDEFGHIJ";}
SetLocalString(oTrigger, "LettersRemain", sLetterString);
DelayCommand(0.1, CreateItemsOnPlaceables(oTrigger, iQTY, iY, sPlaceTag));
}