307 lines
8.0 KiB
Plaintext
307 lines
8.0 KiB
Plaintext
|
//Script Name: ac_ibag
|
|||
|
//////////////////////////////////////////
|
|||
|
//Created by: Genisys / Guile
|
|||
|
//ON: 6/17/08
|
|||
|
/////////////////////////////////////////
|
|||
|
/* **Notes**
|
|||
|
This is the OnActivate Item Script for
|
|||
|
the item tagnamed ibag, which will allow
|
|||
|
the PC to move undroppable items around
|
|||
|
in thier inventory, and it can also
|
|||
|
bag all such items as well.
|
|||
|
*/
|
|||
|
////////////////////////////////////////
|
|||
|
//Required Include
|
|||
|
#include "x2_inc_switches"
|
|||
|
///////////////////////////////////////
|
|||
|
//PROTOTYPES DECLARED
|
|||
|
int GetNum(object oTarget);
|
|||
|
void GiveBack(object oTarget);
|
|||
|
void StoreItem(object oStored);
|
|||
|
void SortContainer(object oTarget);
|
|||
|
void SortBox(object oTarget);
|
|||
|
///////////////////////////////////////
|
|||
|
|
|||
|
//Main Script
|
|||
|
void main()
|
|||
|
{
|
|||
|
// Check if we have the correct event firing the script
|
|||
|
if (GetUserDefinedItemEventNumber() != X2_ITEM_EVENT_ACTIVATE) return;
|
|||
|
|
|||
|
//Major Variables Defined...
|
|||
|
object oPC = GetItemActivator();
|
|||
|
object oTarget = GetItemActivatedTarget();
|
|||
|
object oBox = GetObjectByTag("ibagbox");
|
|||
|
object oBox2 = GetObjectByTag("ibag2box");
|
|||
|
|
|||
|
|
|||
|
//If the PC Is targeting themself Do this..
|
|||
|
if(oTarget==oPC)
|
|||
|
{
|
|||
|
|
|||
|
if(GetLocalInt(GetModule(), "INVUSE")==1)
|
|||
|
{
|
|||
|
FloatingTextStringOnCreature("This system is busy, try again later", oPC, FALSE);
|
|||
|
//Stop the script here!
|
|||
|
return;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//This is a fix to Module Event Scripts (Prevents them from firing on PC)
|
|||
|
SetLocalInt(GetModule(), "INVUSE", 1);
|
|||
|
//Allow the system to be useable again after some time..
|
|||
|
DelayCommand(24.1, SetLocalInt(GetModule(), "INVUSE", 0));
|
|||
|
}
|
|||
|
|
|||
|
object oMine = GetFirstItemInInventory(oPC);
|
|||
|
while(GetIsObjectValid(oMine))
|
|||
|
{
|
|||
|
//If the item is Undroppable!
|
|||
|
if(GetItemCursedFlag(oMine))
|
|||
|
{
|
|||
|
//Don't take bags!
|
|||
|
if(!GetHasInventory(oMine))
|
|||
|
{
|
|||
|
DelayCommand(1.0, AssignCommand(oBox, ActionTakeItem(oMine, oPC)));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
oMine = GetNextItemInInventory(oPC);
|
|||
|
}
|
|||
|
|
|||
|
//Give the loop time to get all the items!
|
|||
|
DelayCommand(6.0, SortBox(oBox));
|
|||
|
|
|||
|
//Run this again to make sure we get all of the items!
|
|||
|
DelayCommand(12.0, SortBox(oBox));
|
|||
|
|
|||
|
//Run this again to make sure we get all of the items!
|
|||
|
DelayCommand(18.0, SortBox(oBox));
|
|||
|
|
|||
|
//Finally return all items in the box to the PC. (If any remain.)
|
|||
|
DelayCommand(24.0, GiveBack(oBox));
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/////////////////////////////////////////////////////
|
|||
|
//CONDITIONALS
|
|||
|
|
|||
|
//Otherwise if they are not targeting themself, do this..
|
|||
|
else
|
|||
|
{
|
|||
|
//Tell the PC they can only target items..
|
|||
|
if(GetObjectType(oTarget)!= OBJECT_TYPE_ITEM)
|
|||
|
{
|
|||
|
FloatingTextStringOnCreature("You must target an item!", oPC, FALSE);
|
|||
|
return;
|
|||
|
}
|
|||
|
//Tell the PC they must target items in their inventory only!
|
|||
|
if(GetItemPossessor(oTarget)!=oPC)
|
|||
|
{
|
|||
|
FloatingTextStringOnCreature("You must target an item in your inventory!", oPC, FALSE);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
///////////////////////////////////////////////////////////////////////
|
|||
|
//If they have passed the conditionals, let's continue..
|
|||
|
|
|||
|
//If the pc targets the Special Bag (there are 2 different ones!)
|
|||
|
//Then remove it's content and place it in the PC's inventory!
|
|||
|
if(GetTag(oTarget)=="ibagboxbag" || GetTag(oTarget)=="plotbag")
|
|||
|
{
|
|||
|
object oContent = GetFirstItemInInventory(oTarget);
|
|||
|
while(GetIsObjectValid(oContent)==TRUE)
|
|||
|
{
|
|||
|
//Put the items in the bag in the ibagbox
|
|||
|
AssignCommand(oBox, ActionTakeItem(oContent, oTarget));
|
|||
|
|
|||
|
//Move on to the next item after taking this one.
|
|||
|
oContent = GetNextItemInInventory(oTarget);
|
|||
|
//While loop end
|
|||
|
}
|
|||
|
|
|||
|
//Return the items!
|
|||
|
DelayCommand(1.7, GiveBack(oBox));
|
|||
|
//Destroy the bag now..
|
|||
|
DelayCommand(2.0, DestroyObject(oTarget,0.0f));
|
|||
|
//Stop here
|
|||
|
return;
|
|||
|
|
|||
|
//If statement end
|
|||
|
}
|
|||
|
|
|||
|
//Another Conditional (If they are not targeting a special bag)
|
|||
|
//Tell the PC they can't target non-plot containers
|
|||
|
if(GetHasInventory(oTarget))
|
|||
|
{
|
|||
|
FloatingTextStringOnCreature("You must target the Special Items Bag!", oPC, FALSE);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
//////////////////////////////////////////////////////////////////////////
|
|||
|
//If the player is targeting just 1 Undroppable Item
|
|||
|
|
|||
|
//Let's make sure it's UnDroppable!
|
|||
|
if(GetItemCursedFlag(oTarget)==FALSE)
|
|||
|
{
|
|||
|
//Tell the PC the item must be undroppable & plot!
|
|||
|
FloatingTextStringOnCreature("You must target an undroppable item only!", oPC, FALSE);
|
|||
|
//Stop the script here!
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
//If they don't have a special bag give them one
|
|||
|
if(GetItemPossessedBy(oPC, "itoolbag")==OBJECT_INVALID)
|
|||
|
{
|
|||
|
CreateItemOnObject("NW_IT_CONTAIN006", oPC, 1, "itoolbag");
|
|||
|
}
|
|||
|
|
|||
|
object oBag = GetItemPossessedBy(oPC, "itoolbag");
|
|||
|
|
|||
|
//We can't take this plot item, it would present big problems!
|
|||
|
if(GetTag(oTarget)=="pcidname")
|
|||
|
{
|
|||
|
FloatingTextStringOnCreature("This item may not be moved, sorry.", oPC);
|
|||
|
return;
|
|||
|
}
|
|||
|
//Otherise have the storage box take the item.
|
|||
|
else
|
|||
|
{
|
|||
|
//Make the box take the item!
|
|||
|
AssignCommand(oBox, ActionTakeItem(oTarget, oPC));
|
|||
|
}
|
|||
|
|
|||
|
//Make the bag unsellable and undroppable!
|
|||
|
DelayCommand(0.2, SetItemCursedFlag(oBag, TRUE));
|
|||
|
DelayCommand(0.3, SetPlotFlag(oBag, TRUE));
|
|||
|
//Give the bag a nice Bright Yellow new name identifying it clearly :)
|
|||
|
//Even if it was already set before, because we don't know..
|
|||
|
DelayCommand(0.4, SetName(oBag, "<c<><63> >Special Items"));
|
|||
|
|
|||
|
//Make the ibagbox put the item in the bag!
|
|||
|
DelayCommand(0.5, StoreItem(oBox));
|
|||
|
|
|||
|
|
|||
|
//Else statement end
|
|||
|
}
|
|||
|
|
|||
|
//Main Script end
|
|||
|
}
|
|||
|
|
|||
|
/////////////////////////////////////////////////////////////////////
|
|||
|
//PROTOTYPE DEFINED
|
|||
|
void GiveBack(object oTarget)
|
|||
|
{
|
|||
|
object oBox = oTarget;
|
|||
|
object oPC = GetItemActivator();
|
|||
|
object oGiven = GetFirstItemInInventory(oBox);
|
|||
|
while(GetIsObjectValid(oGiven)==TRUE)
|
|||
|
{
|
|||
|
AssignCommand(oBox, ActionGiveItem(oGiven, oPC));
|
|||
|
|
|||
|
oGiven = GetNextItemInInventory(oBox);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
////////////////////////////////////////////////////////
|
|||
|
//PROTOTYPE DEFINED
|
|||
|
// Return the number of items oTarget possesses in thier inventory
|
|||
|
int GetNum(object oTarget)
|
|||
|
{
|
|||
|
int nNum = 0;
|
|||
|
object oItem = GetFirstItemInInventory(oTarget);
|
|||
|
|
|||
|
while (GetIsObjectValid(oItem) == TRUE)
|
|||
|
{
|
|||
|
nNum = nNum +1;
|
|||
|
oItem = GetNextItemInInventory(oTarget);
|
|||
|
}
|
|||
|
return nNum;
|
|||
|
|
|||
|
//END PROTOTYPE
|
|||
|
}
|
|||
|
|
|||
|
///////////////////////////////////////////////////////
|
|||
|
//PROTOTYPE DEFINED
|
|||
|
void StoreItem(object oStored)
|
|||
|
{
|
|||
|
object oBox = oStored;
|
|||
|
object oPC = GetItemActivator();
|
|||
|
object oGiven = GetFirstItemInInventory(oBox);
|
|||
|
while(GetIsObjectValid(oGiven)==TRUE)
|
|||
|
{
|
|||
|
//Put the item in the bag on the PC!
|
|||
|
DelayCommand(0.2, AssignCommand(oBox, ActionGiveItem(oGiven,
|
|||
|
GetItemPossessedBy(oPC, "itoolbag"))));
|
|||
|
|
|||
|
oGiven = GetNextItemInInventory(oBox);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/////////////////////////////////////////////////
|
|||
|
//PROTOTYPE DEFINED
|
|||
|
void SortContainer(object oTarget)
|
|||
|
{
|
|||
|
|
|||
|
//Declare Major Variables
|
|||
|
object oPC = GetItemActivator();
|
|||
|
object oNPC = GetObjectByTag("ibag2box");
|
|||
|
object oBox = GetObjectByTag(GetTag(oTarget));
|
|||
|
object oMine;
|
|||
|
object oBag = GetItemPossessedBy(oNPC, GetTag(oTarget)+ "bag");
|
|||
|
|
|||
|
//First Put all the items that will fit into the bag
|
|||
|
//on the NPC into the bag..
|
|||
|
oMine = GetFirstItemInInventory(oTarget);
|
|||
|
while(GetIsObjectValid(oMine)==TRUE)
|
|||
|
{
|
|||
|
AssignCommand(oTarget, ActionGiveItem(oMine, oBag));
|
|||
|
|
|||
|
oMine = GetNextItemInInventory(oTarget);
|
|||
|
}
|
|||
|
|
|||
|
//Give the bag a colorful name.. :)
|
|||
|
DelayCommand(0.2, SetName(oBag, "<c<><63> >Special Items"));
|
|||
|
|
|||
|
//Make the bags unsellable and undroppable!!
|
|||
|
DelayCommand(0.3, SetItemCursedFlag(oBag, TRUE));
|
|||
|
DelayCommand(0.3, SetPlotFlag(oBag, TRUE));
|
|||
|
|
|||
|
//Give the PC the bag now that it has items in it!
|
|||
|
DelayCommand(0.4, AssignCommand(oNPC, ActionGiveItem(oBag, oPC)));
|
|||
|
|
|||
|
//PROTOTYPE END
|
|||
|
}
|
|||
|
|
|||
|
//////////////////////////////////////////////////
|
|||
|
//PROTOTYPE DEFINED
|
|||
|
void SortBox(object oTarget)
|
|||
|
{
|
|||
|
|
|||
|
//Declare Major Variables
|
|||
|
object oPC = GetLastUsedBy();
|
|||
|
object oBox = GetObjectByTag(GetTag(oTarget));
|
|||
|
object oItem;
|
|||
|
object oNPC = GetObjectByTag("ibag2box");
|
|||
|
|
|||
|
//We only continue if the box has items!
|
|||
|
if(GetNum(oBox)>0)
|
|||
|
{
|
|||
|
//Give the NPC a Bag to store items in!
|
|||
|
//Give the bag the tagname of the box!
|
|||
|
CreateItemOnObject("NW_IT_CONTAIN006", oNPC, 1, GetTag(oBox) + "bag");
|
|||
|
|
|||
|
//Start putting items in the bag on the NPC
|
|||
|
DelayCommand(0.3, SortContainer(oTarget));
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
//NOTE: If the box has 0 items, no need to continue!
|
|||
|
|
|||
|
//PROTOTYPES END
|
|||
|
}
|
|||
|
|
|||
|
/////////////////SCRIPT END////////////////////////////////
|