136 lines
4.0 KiB
Plaintext
136 lines
4.0 KiB
Plaintext
// Name : Persistent container opened
|
|
// Purpose : Called when a player opens a persistent container
|
|
// Author : Ingmar Stieger - Altered by: Josh Dalton (Lanthar D'Alton)
|
|
// Modified : March 10, 2003
|
|
|
|
// This file is licensed under the terms of the
|
|
// GNU GENERAL PUBLIC LICENSE (GPL) Version 2
|
|
|
|
#include "aps_include"
|
|
|
|
// Stackables are handled differently to decrease number of queries.
|
|
// We can trust lowercase tag here if no resref b/c it has already been tested
|
|
// by the copycheck function.
|
|
int GetIsItemStackable(object oItem)
|
|
{
|
|
int iType = GetBaseItemType(oItem);
|
|
if (iType == BASE_ITEM_GEM || iType == BASE_ITEM_POTIONS ||
|
|
iType == BASE_ITEM_HEALERSKIT || iType == BASE_ITEM_THIEVESTOOLS ||
|
|
iType == BASE_ITEM_SCROLL || iType == BASE_ITEM_ARROW ||
|
|
iType == BASE_ITEM_BOLT || iType == BASE_ITEM_BULLET ||
|
|
iType == BASE_ITEM_DART || iType == BASE_ITEM_THROWINGAXE ||
|
|
iType == BASE_ITEM_SHURIKEN || iType == BASE_ITEM_GOLD)
|
|
return TRUE;
|
|
else
|
|
return FALSE;
|
|
}
|
|
|
|
int GetStackSize(object oItem)
|
|
{
|
|
int retval=1;
|
|
int iType = GetBaseItemType(oItem);
|
|
switch(iType)
|
|
{
|
|
case BASE_ITEM_GEM:
|
|
return 10;
|
|
case BASE_ITEM_POTIONS:
|
|
return 10;
|
|
case BASE_ITEM_HEALERSKIT:
|
|
return 10;
|
|
case BASE_ITEM_THIEVESTOOLS:
|
|
return 10;
|
|
case BASE_ITEM_SCROLL:
|
|
return 10;
|
|
case BASE_ITEM_ARROW:
|
|
return 99;
|
|
case BASE_ITEM_BOLT:
|
|
return 99;
|
|
case BASE_ITEM_BULLET:
|
|
return 99;
|
|
case BASE_ITEM_DART:
|
|
return 50;
|
|
case BASE_ITEM_THROWINGAXE:
|
|
return 50;
|
|
case BASE_ITEM_SHURIKEN:
|
|
return 50;
|
|
case BASE_ITEM_GOLD:
|
|
return 50000;
|
|
default:
|
|
return 1;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
string GetTableIndexKey()
|
|
{
|
|
object oPC=GetLocalObject(OBJECT_SELF, "LastUsedBy");
|
|
string sVaultTag;
|
|
string sPlayer;
|
|
string sTag;
|
|
|
|
sVaultTag=GetTag(OBJECT_SELF);
|
|
if (GetIsPC(oPC))
|
|
{
|
|
sPlayer = SQLEncodeSpecialChars(GetPCPlayerName(oPC));
|
|
sTag = SQLEncodeSpecialChars(GetName(oPC));
|
|
}
|
|
else
|
|
{
|
|
sPlayer = SQLEncodeSpecialChars(GetName(oPC));
|
|
sTag = GetTag(oPC);
|
|
}
|
|
|
|
string sSQL = " player='" + sPlayer + "' AND tag='" + sTag + "' AND container='" + sVaultTag + "'";
|
|
return sSQL;
|
|
}
|
|
|
|
void main()
|
|
{
|
|
object oCreature=GetLastOpenedBy();
|
|
if(GetLocalObject(OBJECT_SELF, "LastUsedBy")==OBJECT_INVALID)
|
|
SetLocalObject(OBJECT_SELF, "LastUsedBy", oCreature);
|
|
object oItem = GetFirstItemInInventory();
|
|
if(!GetIsObjectValid(oItem)) //if empty...
|
|
{
|
|
SetLocalInt(OBJECT_SELF, "began_empty", 1);
|
|
// load inventory from database and put it in container
|
|
string sSQL = "SELECT item, count, identified FROM vault_items " +
|
|
"WHERE" + GetTableIndexKey();
|
|
SQLExecDirect(sSQL);
|
|
string sItemTag;
|
|
int id;
|
|
int i, iItemCount;
|
|
int rc = SQLFirstRow();
|
|
while (rc == SQL_SUCCESS)
|
|
{
|
|
sItemTag = SQLGetData(1);
|
|
iItemCount = StringToInt(SQLGetData(2));
|
|
id = StringToInt(SQLGetData(3));
|
|
|
|
oItem = CreateItemOnObject(sItemTag, OBJECT_SELF);
|
|
iItemCount=iItemCount-1;
|
|
if (GetIsObjectValid(oItem))
|
|
{
|
|
SetIdentified(oItem, id);
|
|
int stacksize=GetStackSize(oItem);
|
|
while(iItemCount>0)
|
|
{
|
|
if(iItemCount>stacksize)
|
|
{
|
|
oItem = CreateItemOnObject(sItemTag, OBJECT_SELF, stacksize);
|
|
iItemCount-=stacksize;
|
|
}
|
|
else
|
|
{
|
|
oItem = CreateItemOnObject(sItemTag, OBJECT_SELF, iItemCount);
|
|
iItemCount=0;
|
|
}
|
|
SetIdentified(oItem, id);
|
|
}
|
|
}
|
|
|
|
rc = SQLNextRow();
|
|
}
|
|
}
|
|
}
|