Persistent Stores
#1
Posté 15 décembre 2010 - 08:15
I need to make the stores im using for silicon scouts loot system persistent, so dm can add to the stores in game and contents are restored after reset.
#2
Posté 16 décembre 2010 - 09:20
#4
Posté 16 décembre 2010 - 09:35
#5
Posté 16 décembre 2010 - 09:46
FP!
Modifié par Fester Pot, 16 décembre 2010 - 09:46 .
#6
Posté 16 décembre 2010 - 10:07
#7
Posté 16 décembre 2010 - 11:28
#8
Posté 18 décembre 2010 - 12:09
void StoreNPC(string sVar, object oNPC);
void StoreTreasure(object oBox, string sVar);
void main()
{
//Where the treasure is located..
object oWay = GetWaypointByTag("ref_point");
string sCamp = "AXIS_TREASURE";
object oTres = GetNearestObjectByTag("ss_t_chest_1", oWay); //Merchant Tag
object oDM = GetPCSpeaker();
object oBox = GetNearestObjectByTag("dm_item_maker", oDM);
object oItem;
//If it's NOT a DM STOP HERE!
if(!GetIsDM(oDM))
{
AssignCommand(oDM, ClearAllActions());
FloatingTextStringOnCreature("Only DMs can use this dresser!", oDM, FALSE);
return;
}
else
{
//Cycle through the items in the box and put them in the module treasure chest
oItem = GetFirstItemInInventory(oBox);
while(GetIsObjectValid(oItem))
{
AssignCommand(oTres, ActionTakeItem(oItem, oBox));
oItem = GetNextItemInInventory(oBox);
}
//Set that we have stored items!
SetCampaignInt(sCamp, "LOW_STORED", TRUE);
location lLocal = GetLocation(oTres);
object oStore = CreateObject(OBJECT_TYPE_CREATURE, "axis_per_tres", lLocal, FALSE);
SendMessageToAllDMs(GetName(oDM) + ": Has stored items into the module treasure system." );
WriteTimestampedLogEntry(GetName(oDM) + ": Has Stored items in the Module Treasure
System****************");
//Make sure ALL of the items get placed in the NPC's inventory!
DelayCommand(7.0, StoreTreasure(oStore, sCamp));
}
//Script End
}
//PROTOTYPEs DEFINED
void StoreNPC(string sVar, object oNPC)
{
StoreCampaignObject(sVar, "MOD_LOW", oNPC);
}
void StoreTreasure(object oBox, string sVar)
{
// Spawn in the NPC storer
location lLoc = GetLocation(oBox); //The Treasure's Location..
object oStorer = GetNearestObjectByTag("axis_per_tres", oBox);
object oItem = GetFirstItemInInventory(oBox);
while(GetIsObjectValid(oItem))
{
CopyItem(oItem, oStorer, TRUE);
oItem = GetNextItemInInventory(oBox);
}
DelayCommand(20.0, StoreNPC(sVar, oStorer));
DelayCommand(35.0, DestroyObject(oStorer, 0.0f));
}
This is in the onmodload event that restores items on restart
void KillInventory(object oObject);
void StoreTreasure(object oBox, location lLoc);
//Main Script
void main()
{
//Stop the treasure generation on creatures, so they won't drop loot..
SetLocalInt(GetModule(), "X2_L_NOTREASURE", TRUE);
//Where the treasure is located..
object oWay = GetWaypointByTag("ref_point");
string sCamp = "AXIS_TREASURE";
//See if the database has stored a treasure or not...
int nLow = GetCampaignInt(sCamp, "LOW_STORED");
//The Module Treasure Chest
object oLow = GetNearestObjectByTag("ss_t_chest_1", oWay);
location lLow = GetLocation(oLow);
int nMed = GetCampaignInt(sCamp, "MED_STORED");
object oMed = GetNearestObjectByTag("X0_MOD_TREASURE_MED", oWay);
location lMed = GetLocation(oMed);
int nHigh = GetCampaignInt(sCamp, "HIGH_STORED");
object oHigh = GetNearestObjectByTag("X0_MOD_TREASURE_HIGH", oWay);
location lHigh = GetLocation(oHigh);
int nUniq = GetCampaignInt(sCamp, "UNIQ_STORED");
object oUniq = GetNearestObjectByTag("X0_MOD_TREASURE_UNIQ", oWay);
location lUniq = GetLocation(oUniq);
//Retrieve all module treasure..
if(nLow)
{
KillInventory(oLow);
RetrieveCampaignObject(sCamp, "MOD_LOW", lLow);
SetLocalString(oLow, "STORE_TAG", "axis_per_tres");
DelayCommand(8.0, StoreTreasure(oLow, lLow));//Give the box time to empty..
}
if(nMed)
{
KillInventory(oMed);
RetrieveCampaignObject(sCamp, "MOD_MED", lMed);
SetLocalString(oMed, "STORE_TAG", "axis_per_tres2");
DelayCommand(9.0, StoreTreasure(oMed, lMed));
}
if(nHigh)
{
KillInventory(oHigh);
RetrieveCampaignObject(sCamp, "MOD_HIGH", lHigh);
SetLocalString(oHigh, "STORE_TAG", "axis_per_tres3");
DelayCommand(10.0, StoreTreasure(oHigh, lHigh));
}
if(nUniq)
{
KillInventory(oUniq);
RetrieveCampaignObject(sCamp, "MOD_UNIQ", lUniq);
SetLocalString(oUniq, "STORE_TAG", "axis_per_tres4");
DelayCommand(11.0, StoreTreasure(oUniq, lUniq));
}
//////////////////////////////////////////////////////////////////////////
}
//PROTOTYPEs DEFINED
void KillInventory(object oObject)
{
object oItem;
oItem = GetFirstItemInInventory(oObject);
while(GetIsObjectValid(oItem))
{
DestroyObject(oItem);
oItem = GetNextItemInInventory(oObject);
}
}
void StoreTreasure(object oBox, location lLoc)
{
object oNPC, oItem;
string sTag;
sTag = GetLocalString(oBox, "STORE_TAG");
oNPC= GetNearestObjectByTag(sTag, oBox);
oItem = GetFirstItemInInventory(oNPC);
while(GetIsObjectValid(oItem))
{
AssignCommand(oBox, ActionTakeItem(oItem, oNPC));
oItem = GetNextItemInInventory(oNPC);
}
//For Debugging..
//WriteTimestampedLogEntry(sTag + " Module Treasure Has Been Retrieved");
DestroyObject(oNPC, 30.0f);
}
Modifié par Madasahatter, 18 décembre 2010 - 12:19 .
#9
Posté 24 décembre 2010 - 08:02
#10
Posté 24 décembre 2010 - 08:32
I'm going to reinvent the wheel on ya though.
First thing to do would be to put an invisible creature right at your store. Give it a unique tag so that it relates to that specific store.
Then you will need some type of interval system set up to save the items from the store to the invisible creature. Whatever method you use will be up to you but I wouldn't do it too often. Might be a bit of a resource hog or cause a bit of lag. But you might want to use a script like so to save the items to the invisible creature and then save it to the database:
Note: The script above also destroys all the items on the creature first and then saves all the new ones.void main()
{
//get the store
object oStore = GetObjectByTag("Tag of store");
//get the invisible creature that we will store stuff on
object oStorer = GetNearestObjectByTag("Tag of invisible creature", oStore, 1);
//just declaring oItem
object oItem;
//now we destroy inventory of creature to make sure we don't keep adding the
//same stuff over and over
oItem = GetFirstItemInInventory(oStorer);
while (GetIsObjectValid(oItem))
{
DestroyObject(oItem);
oItem = GetNextItemInInventory(oStorer);
}
//now we copy all the items from the store onto the invisible creature
oItem = GetFirstItemInInventory(oStore);
while (GetIsObjectValid(oItem))
{
CopyItem(oItem, oStorer, TRUE);
oItem = GetNextItemInInventory(oStore);
}
//now we save the creature to the database:
StoreCampaignObject("STORED_STORES", "Tag of store", oStorer);
}
The last thing you will need to do is figure out where/how exactly you want to bring the invisible creature back it when the server restarts or what not. This should be a one time thing. Maybe you could use an execute script line in your OnModuleLoad event and run this scrpt from there. And probably have a specific waypoint for the invisible creature to be spawned back in/restored. A script like so should do the trick to bring it back to the waypoint:
void main()
{
location lWP = GetLocation(GetWaypointByTag("Tag of waypoint"));
object oStore = GetObjectByTag("Tag of store");
object oStorer = RetrieveCampaignObject("STORED_STORES", "Tag of store", lWP);
object oItem = GetFirstItemInInventory(oStorer);
while (GetIsObjectValid(oItem))
{
CopyItem(oItem, oStore, TRUE);
oItem = GetNextItemInInventory(oStorer);
}
}
Note: These are both pretty generic scripts that can be streamlined for efficientcy depending on how you work it but hopefully it gets this working for you for now.
Good luck.
Modifié par GhostOfGod, 24 décembre 2010 - 08:36 .
#11
Posté 24 décembre 2010 - 08:42
1. Create a new merchant, place the pshop_onstoreclose in the advanced tab OnStoreClosed and note the resref.
2. Create an NPC that will be your shopkeeper, and put a String named sStoreTag with a value equal the resref of the merchant`s.
3. Create a conversation for your shop and replace the script, usually something like openstore001, to open the shop with the one in pshop_OnOpenDialogue.
4. Compile and Load
5. If it is working properly, a database should be created with the resref specified.
My guess is that you didn't do all of the above.
#12
Posté 24 décembre 2010 - 10:32
I followed the instructions, it creates a db but removes items from the merchant and does not restore them on server restart..
Ghost I will check out your work after xmas..
Thanx all and have a gud one... all the best
#13
Posté 24 décembre 2010 - 10:35
#14
Posté 25 décembre 2010 - 12:17
//Idea , TritonX
// pshop_OnOpenDialogue
// Script created by Old Man`s Beard, June 06
// Thanks to Lex and UOAbigail for their support
// Put this script in a conversation to open the store.
// Also very important, you have to name a string sStoreTag on the NPC
// valued the same as the resref of your // merchant`s blueprint.
// Use to load a stores data base with nwn db
void OHS_LoadStore(object oStore, string sDBName);
void OHS_LoadStore(object oStore, string sDBName)
{
location lStore = GetLocation(oStore);
int bLoaded = GetLocalInt(oStore,"OHS_STORE_LOADED");
if (GetIsObjectValid(oStore) && !bLoaded)
{
int nItems = GetCampaignInt(sDBName,"N_ITEMS");
PrintString(IntToString(nItems)+" in "+sDBName);
object oItem;
int ILRStackSize, nChargesStarting;
int nNth;
for (nNth=1; nNth
{
oItem = RetrieveCampaignObject(sDBName,"ITEM_"+IntToString(nNth),GetLocation(oStore),oStore);
if (GetPlotFlag(oItem) )// || GetStolenFlag(oItem)) remove // to Destroy Plot and Stolen Items
{
DestroyObject(oItem);
}
else
{
ILRStackSize = StringToInt(Get2DAString("baseitems","ILRStackSize",GetBaseItemType(oItem)));
SetItemStackSize(oItem,ILRStackSize);
nChargesStarting = StringToInt(Get2DAString("baseitems","ChargesStarting",GetBaseItemType(oItem)));
if (nChargesStarting>0) SetItemCharges(oItem,nChargesStarting);
// SetInfiniteFlag(oItem,TRUE); //Uncomment if you want stackable to be infinite
}
}
SetLocalInt(oStore,"OHS_STORE_LOADED",TRUE);
}
}//needed for function
///////////////////////////////////////////////////////////////////////////////
void main()
{
////replace "sStoreTag" with name of variable on NPC
string sStoreTag=GetLocalString(OBJECT_SELF,"sStoreTag");
object oStore = GetObjectByTag("OHS_STORE");
if (!GetIsObjectValid(oStore))
{ //replace "resrefofyourstore" by one in your palette
oStore = CreateObject(OBJECT_TYPE_STORE,"resrefofyourstore",GetLocation(OBJECT_SELF));
}
if (GetObjectType(oStore) == OBJECT_TYPE_STORE)
{ //was "OHS_PERSISTENT_STORE" replaced with sStoreTag
OHS_LoadStore(oStore,sStoreTag);
OpenStore(oStore, GetPCSpeaker());
}
else
{
ActionSpeakStringByStrRef(53090, TALKVOLUME_TALK);
}
}// end of script
I tried to labe the things you need to do the script never called for the string you set on the npc now it does. Fester pots script or suggested script works quite simply and well. The person just needs to update the script on the vault with the script I posted for NWN1. I haven't cleaned it up all the way. But I tested and it worked. I also altered the on close script to include stole items. if you have any more question please ask, I can
send you a erf of the fixed script.
Greyfort
Modifié par Greyfort, 25 décembre 2010 - 12:24 .





Retour en haut






