script running from switch for now
#include "x3_inc_string"
#include "iof_include"
#include "stocks_inc_const"
void main()
{
int nActive = GetLocalInt (OBJECT_SELF,"X2_L_PLC_ACTIVATED_STATE");
// * Play Appropriate Animation
if (!nActive)
{
ActionPlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);
}
else
{
ActionPlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE);
}
// * Store New State
SetLocalInt(OBJECT_SELF,"X2_L_PLC_ACTIVATED_STATE",!nActive);
//Create new table for items from "chest_999" with auto index
// :: CREATE TABLE "temp_vault" (
// :: `columnid` INT(6) NOT NULL AUTO_INCREMENT,
// :: `player` VARCHAR(21) NOT NULL DEFAULT '',
// :: `tag` VARCHAR(21) NOT NULL DEFAULT '',
// :: `container` VARCHAR(9) NOT NULL DEFAULT 'chest_998',
// :: `item` VARCHAR(21) NOT NULL DEFAULT '',
// :: `count` INT(10) UNSIGNED NULL DEFAULT NULL,
// :: `identified` TINYINT(4) NULL DEFAULT NULL,
// :: PRIMARY KEY (`columnid`,`player`, `tag`, `container`, `item`)
// :: )
// :: COLLATE='utf8_general_ci'
// :: ENGINE=MyISAM;
string sSQL = "CREATE TABLE IF NOT EXISTS `temp_vault` (`columnid` INT(9) NOT NULL AUTO_INCREMENT, `player` VARCHAR(22) NOT NULL DEFAULT '',`tag` VARCHAR(22) NOT NULL DEFAULT '',`container` VARCHAR(22) NOT NULL DEFAULT '',`item` VARCHAR(22) NOT NULL DEFAULT '',`count` INT(10) UNSIGNED NULL DEFAULT NULL,`identified` TINYINT(4) NULL DEFAULT NULL,PRIMARY KEY (`columnid`, `player`, `tag`, `container`, `item`))COLLATE='utf8_general_ci'ENGINE=MyISAM;";
SQLExecDirect(sSQL);
//insert items into the temp database from vault_items database
//insert into temp_vault (player, tag, container, item, count, identified)
//SELECT * FROM vault_items Where container = 'chest_999'"
string sSQLa = "insert into temp_vault (player, tag, container, item, count, identified) SELECT * FROM vault_items Where container = 'chest_999'";
SQLExecDirect(sSQLa);
//Delete items inserted into "temp_table" from "vault_items"
string sSQLb = "DELETE FROM vault_items Where container = 'chest_999'";
SQLExecDirect(sSQLb);
//Get the number of rows in "temp_table"
string sSQLd ="SELECT MAX(columnid) FROM temp_vault";
SQLExecDirect(sSQLd);
//convert to integer
int iNumRows = SQLFetch();
//loop through each row
int iRowCount;
while (iRowCount < iNumRows)
{
string sRowCount = IntToString(iRowCount);
//retreive "item" from the column
string sSQLc = "SELECT `item`, `count` FROM temp_vault Where columnid = '" + sRowCount + "'";
SQLExecDirect(sSQLc);
string sItemTagValue = SQLGetData(1);
int iNumItems = StringToInt(SQLGetData(2));
//retreive "count" from the column
//string sSQLc = "SELECT `count` FROM temp_vault Where columnid = '" + sRowCount + "'";
//SQLExecDirect(sSQLc);
//int iNumItems = StringToInt(SQLGetData(1));
//loop through each item
int iItemCount;
string sNoZeroes;
while (iItemCount < iNumItems)
{
//Get the last 3 of the tag string
string sItemTagNumber = GetStringRight(sItemTagValue, 3);
//Remove the zeroes
// Get the local string variable's contents.
string sItemTagNumberNoZero = GetLocalString(OBJECT_SELF, "sItemTagNumber");
// Change all the zeroes in it to nul.
sItemTagNumberNoZero = StringReplace(sItemTagNumberNoZero, "0", "");
// Save the result back in the local string variable.
SetLocalString(OBJECT_SELF, "sItemTagNumber", sItemTagNumberNoZero);
//Convert to integer so we can use it
int iItemInteger = StringToInt(sItemTagNumberNoZero);
//Roll Dice
int iRoll = d20(1);
int iDTwoNegTagSum = iItemInteger - d2(1);
int iDTwoPosTagSum = iItemInteger + d2(1);
int iDFourNegTagSum = iItemInteger - d4(1);
int iDFourPosTagSum = iItemInteger + d4(1);
int iDSixNegTagSum = iItemInteger - d6(1);
int iDSixPosTagSum = iItemInteger + d6(1);
int iDDFourNegTagSum = iItemInteger - d4(2);
int iDDFourPosTagSum = iItemInteger + d4(2);
//Convert to string
string sDTwoNegTagSum = IntToString(iDTwoNegTagSum);
string sDTwoPosTagSum = IntToString(iDTwoPosTagSum);
string sDFourNegTagSum = IntToString(iDFourNegTagSum);
string sDFourPosTagSum = IntToString(iDFourPosTagSum);
string sDSixNegTagSum = IntToString(iDSixNegTagSum);
string sDSixPosTagSum = IntToString(iDSixPosTagSum);
string sDDFourNegTagSum = IntToString(iDDFourNegTagSum);
string sDDFourPosTagSum = IntToString(iDDFourPosTagSum);
//Check tag string center value for "Stock" or "Bond"
//If not it gets thrown out with the trash when temp_vault is deleted
string sStockCheckString = GetSubString(sItemTagValue, 4, 9);
string sBondCheckString = GetSubString(sItemTagValue, 4,
;
//Calculate to new item
if (iRoll == 1)
{
//If item is a bond
if (sBondCheckString == "bond")
{
//check for date here
if (iDFourNegTagSum <= 0)
{
return;
}
else
{
//Generate new item tag from list at stocks_inc_const
string sItem = "sStock" + "sDFourNegTagSum";
//get "player" and "tag" from "temp_vault"
string sSQLx = "SELECT `player`, `tag` , FROM temp_vault Where columnid = '" + sRowCount + "'";
SQLExecDirect(sSQLx);
string sPlayerLoginID = SQLGetData(1);
string sPlayerCharacterName = (SQLGetData(2));
//Put the new item in "vault_items"
string sSQLw = "insert into vault_items (player, tag, container, item, count, identified)VALUES("+ sPlayerLoginID +","+ sPlayerCharacterName +"," + sVaultTag +"," + sItem +", 1, 1)";
SQLExecDirect(sSQLw);
}
}
//If item is a stock
else if (sStockCheckString == "stock")
{
if (iDDFourNegTagSum <= 0)
{
return;
}
else
{
//Generate new item tag from list at stocks_inc_const
string sItem = "sStock" + "sDDFourNegTagSum";
//get "player" and "tag" from "temp_vault"
string sSQLx = "SELECT `player`, `tag` , FROM temp_vault Where columnid = '" + sRowCount + "'";
SQLExecDirect(sSQLx);
string sPlayerLoginID = SQLGetData(1);
string sPlayerCharacterName = (SQLGetData(2));
//Put the new item in "vault_items"
string sSQLw = "insert into vault_items (player, tag, container, item, count, identified)VALUES("+ sPlayerLoginID +","+ sPlayerCharacterName +"," + sVaultTag +"," + sItem +", 1, 1)";
SQLExecDirect(sSQLw);
}
}
}
else if (iRoll == 2)
{
//If item is a bond
if (sBondCheckString == "bond")
{
//check for date here
if (iDFourNegTagSum <= 0)
{
return;
}
else
{
//Generate new item tag from list at stocks_inc_const
string sItem = "sStock" + "sDFourNegTagSum";
//get "player" and "tag" from "temp_vault"
string sSQLx = "SELECT `player`, `tag` , FROM temp_vault Where columnid = '" + sRowCount + "'";
SQLExecDirect(sSQLx);
string sPlayerLoginID = SQLGetData(1);
string sPlayerCharacterName = (SQLGetData(2));
//Put the new item in "vault_items"
string sSQLw = "insert into vault_items (player, tag, container, item, count, identified)VALUES("+ sPlayerLoginID +","+ sPlayerCharacterName +"," + sVaultTag +"," + sItem +", 1, 1)";
SQLExecDirect(sSQLw);
}
}
//If item is a stock
else if (sStockCheckString == "stock")
{
if (iDSixNegTagSum <= 0)
{
return;
}
else
{
//Generate new item tag from list at stocks_inc_const
string sItem = "sStock" + "sDSixNegTagSum";
//get "player" and "tag" from "temp_vault"
string sSQLx = "SELECT `player`, `tag` , FROM temp_vault Where columnid = '" + sRowCount + "'";
SQLExecDirect(sSQLx);
string sPlayerLoginID = SQLGetData(1);
string sPlayerCharacterName = (SQLGetData(2));
//Put the new item in "vault_items"
string sSQLw = "insert into vault_items (player, tag, container, item, count, identified)VALUES("+ sPlayerLoginID +","+ sPlayerCharacterName +"," + sVaultTag +"," + sItem +", 1, 1)";
SQLExecDirect(sSQLw);
}
}
}
else if (iRoll == 3)
{
//If item is a bond
if (sBondCheckString == "bond")
{
//check for date here
//Generate new item tag from list at stocks_inc_const
string sItem = sItemTagValue;
//get "player" and "tag" from "temp_vault"
string sSQLx = "SELECT `player`, `tag` , FROM temp_vault Where columnid = '" + sRowCount + "'";
SQLExecDirect(sSQLx);
string sPlayerLoginID = SQLGetData(1);
string sPlayerCharacterName = (SQLGetData(2));
//Put the new item in "vault_items"
string sSQLw = "insert into vault_items (player, tag, container, item, count, identified)VALUES("+ sPlayerLoginID +","+ sPlayerCharacterName +"," + sVaultTag +"," + sItem +", 1, 1)";
SQLExecDirect(sSQLw);
}
//If item is a stock
else if (sStockCheckString == "stock")
{
if (iDSixNegTagSum <= 0)
{
return;
}
else
{
//Generate new item tag from list at stocks_inc_const
string sItem = "sStock" + "sDSixNegTagSum";
//get "player" and "tag" from "temp_vault"
string sSQLx = "SELECT `player`, `tag` , FROM temp_vault Where columnid = '" + sRowCount + "'";
SQLExecDirect(sSQLx);
string sPlayerLoginID = SQLGetData(1);
string sPlayerCharacterName = (SQLGetData(2));
//Put the new item in "vault_items"
string sSQLw = "insert into vault_items (player, tag, container, item, count, identified)VALUES("+ sPlayerLoginID +","+ sPlayerCharacterName +"," + sVaultTag +"," + sItem +", 1, 1)";
SQLExecDirect(sSQLw);
}
}
}
else if (iRoll == 4)
{
//If item is a bond
if (sBondCheckString == "bond")
{
//check for date here
//Generate new item tag from list at stocks_inc_const
string sItem = sItemTagValue;
//get "player" and "tag" from "temp_vault"
string sSQLx = "SELECT `player`, `tag` , FROM temp_vault Where columnid = '" + sRowCount + "'";
SQLExecDirect(sSQLx);
string sPlayerLoginID = SQLGetData(1);
string sPlayerCharacterName = (SQLGetData(2));
//Put the new item in "vault_items"
string sSQLw = "insert into vault_items (player, tag, container, item, count, identified)VALUES("+ sPlayerLoginID +","+ sPlayerCharacterName +"," + sVaultTag +"," + sItem +", 1, 1)";
SQLExecDirect(sSQLw);
}
//If item is a stock
else if (sStockCheckString == "stock")
{
if (iDFourNegTagSum <= 0)
{
return;
}
else
{
//Generate new item tag from list at stocks_inc_const
string sItem = "sStock" + "sDFourNegTagSum";
//get "player" and "tag" from "temp_vault"
string sSQLx = "SELECT `player`, `tag` , FROM temp_vault Where columnid = '" + sRowCount + "'";
SQLExecDirect(sSQLx);
string sPlayerLoginID = SQLGetData(1);
string sPlayerCharacterName = (SQLGetData(2));
//Put the new item in "vault_items"
string sSQLw = "insert into vault_items (player, tag, container, item, count, identified)VALUES("+ sPlayerLoginID +","+ sPlayerCharacterName +"," + sVaultTag +"," + sItem +", 1, 1)";
SQLExecDirect(sSQLw);
}
}
}
else if (iRoll == 5)
{
//If item is a bond
if (sBondCheckString == "bond")
{
//check for date here
//Generate new item tag from list at stocks_inc_const
string sItem = sItemTagValue;
//get "player" and "tag" from "temp_vault"
string sSQLx = "SELECT `player`, `tag` , FROM temp_vault Where columnid = '" + sRowCount + "'";
SQLExecDirect(sSQLx);
string sPlayerLoginID = SQLGetData(1);
string sPlayerCharacterName = (SQLGetData(2));
//Put the new item in "vault_items"
string sSQLw = "insert into vault_items (player, tag, container, item, count, identified)VALUES("+ sPlayerLoginID +","+ sPlayerCharacterName +"," + sVaultTag +"," + sItem +", 1, 1)";
SQLExecDirect(sSQLw);
}
//If item is a stock
else if (sStockCheckString == "stock")
{
if (iDFourNegTagSum <= 0)
{
return;
}
else
{
//Generate new item tag from list at stocks_inc_const
string sItem = "sStock" + "sDFourNegTagSum";
//get "player" and "tag" from "temp_vault"
string sSQLx = "SELECT `player`, `tag` , FROM temp_vault Where columnid = '" + sRowCount + "'";
SQLExecDirect(sSQLx);
string sPlayerLoginID = SQLGetData(1);
string sPlayerCharacterName = (SQLGetData(2));
//Put the new item in "vault_items"
string sSQLw = "insert into vault_items (player, tag, container, item, count, identified)VALUES("+ sPlayerLoginID +","+ sPlayerCharacterName +"," + sVaultTag +"," + sItem +", 1, 1)";
SQLExecDirect(sSQLw);
}
}
}
else if (iRoll == 6)
{
//If item is a bond
if (sBondCheckString == "bond")
{
//check for date here
//Generate new item tag from list at stocks_inc_const
string sItem = sItemTagValue;
//get "player" and "tag" from "temp_vault"
string sSQLx = "SELECT `player`, `tag` , FROM temp_vault Where columnid = '" + sRowCount + "'";
SQLExecDirect(sSQLx);
string sPlayerLoginID = SQLGetData(1);
string sPlayerCharacterName = (SQLGetData(2));
//Put the new item in "vault_items"
string sSQLw = "insert into vault_items (player, tag, container, item, count, identified)VALUES("+ sPlayerLoginID +","+ sPlayerCharacterName +"," + sVaultTag +"," + sItem +", 1, 1)";
SQLExecDirect(sSQLw);
}
//If item is a stock
else if (sStockCheckString == "stock")
{
if (iDTwoNegTagSum <= 0)
{
return;
}
else
{
//Generate new item tag from list at stoc