These are the new triggers and aliases I have in use and its coming along pretty smoothly.
Deleter
<triggers>
<trigger
enabled="y"
expand_variables="y"
match="You drop *."
send_to="12"
sequence="100"
>
<send>require "tprint"
DatabaseOpen ("db", GetInfo (66) .. "InventoryDB.sqlite", 6)
rc = DatabaseExec ("db", [[
CREATE TABLE IF NOT EXISTS items(
item_id INTEGER NOT NULL PRIMARY KEY autoincrement,
character_name TEXT NOT NULL,
description TEXT NOT NULL,
quantity INT DEFAULT 1
);
]])
-- drop some data into the database
rc = DatabaseExec ("db",
[[
DELETE FROM items
WHERE character_name = '@Current_Character'
AND description = '%1';
]])
-- finished with the statement
DatabaseFinalize ("db")
DatabaseClose ("db") -- close it</send>
</trigger>
</triggers>
Inserter
<triggers>
<trigger
enabled="y"
expand_variables="y"
match="You get *."
send_to="12"
sequence="100"
>
<send>require "tprint"
DatabaseOpen ("db", GetInfo (66) .. "InventoryDB.sqlite", 6)
rc = DatabaseExec ("db", [[
CREATE TABLE IF NOT EXISTS items(
item_id INTEGER NOT NULL PRIMARY KEY autoincrement,
character_name TEXT NOT NULL,
description TEXT NOT NULL,
quantity INT DEFAULT 1
);
]])
-- put some data into the database
rc = DatabaseExec ("db",
[[
INSERT INTO items (character_name, description) VALUES ('@Current_Character', '%1');
]])
-- finished with the statement
DatabaseFinalize ("db")
DatabaseClose ("db") -- close it</send>
</trigger>
</triggers>
Database Viewer
<aliases>
<alias
match="database"
enabled="y"
send_to="12"
sequence="100"
>
<send>require "tprint"
DatabaseOpen ("db", GetInfo (66) .. "InventoryDB.sqlite", 6)
rc = DatabaseExec ("db", [[
CREATE TABLE IF NOT EXISTS items(
item_id INTEGER NOT NULL PRIMARY KEY autoincrement,
character_name TEXT NOT NULL,
description TEXT NOT NULL,
quantity INT DEFAULT 1
);
]])
-- prepare a query
DatabasePrepare ("db", "SELECT character_name, description FROM items ORDER BY character_name")
-- find the column names
names = DatabaseColumnNames ("db")
-- ***DROPPED OUT*** tprint (names)
-- prints the header
print (" Character Item ")
print ("+--------------------------------------+")
-- execute to get the first row
rc = DatabaseStep ("db") -- read first row
-- now loop, displaying each row, and getting the next one
while rc == 100 do
print ("")
names = DatabaseColumnText ("db", 1)
items = DatabaseColumnText ("db", 2)
print (" ", names, " ", items)
rc = DatabaseStep ("db") -- read next row
end -- while loop
-- finished with the statement
DatabaseFinalize ("db")
DatabaseClose ("db") -- close it</send>
</alias>
</aliases>
Database Output
Character Item
+--------------------------------------+
Aerin a copper medallion
Aerin black muslin wrappings
Artemis a scorched length of bamboo
Artemis a small brass lantern
Ibauthwyn a lump of indigo
Renald a bo staff
Renald a wooden mallet
As far as the output goes there are only a few personal changes I'd like to make so I'm going to put those on the back burner and focus on the functionality.
First off, I have a trigger running already on world connect to open up my second account and can add the CREATE TABLE to that trigger, do I need to run the database open/finalize/close on that trigger?
The second issue is deleting only one instance of an item of certain characters. I thought about adding in triggers for when "You get two small brass lanterns." it would do a loop 2x and insert "a small brass lantern" each time but that would require a lot of work to differentiate between items that will be listed with a/an.
Let's say my inventory is "You are carrying a thorned staff, a small brass lantern, a thorned staff, a scorched length of bamboo, a small brass lantern, a steel-shod
quarterstaff, a thorned staff, two steel-shod quarterstaves, and a small brass lantern." and I drop a thorned staff (just one of them), is there a way to delete only one of the 3 instead of all 3? |