Author Topic: Item Database  (Read 1022 times)

What is the best way to make an item database that can handle me searching for certain items often without lagging the server? I need this database to store both physical items and non physical.

With "Items" do you mean itmes like guns or simple "objects"?

With "Items" do you mean itmes like guns or simple "objects"?
Objects that store some information of items. Just like their UI names and damage and stuff.

A script group, the children being script objects which contain whatever info you need.

^^

I was going to say that..


Just an example, for some ideas.
Code: [Select]
if(!isObject(%client.ItemList))
{
%client.ItemList = new ScriptObject() //You can also use SimSet's to automatically delete the field when the variable is deleted.
{
Slot1 = "4 1"; //EX: Slot1 = "ItemID Quantity";
};
}

function getinvslot1(%client)
{
%inv1 = getWord(%client.ItemList.Slot1,0);
%inv1amount = getword(%client.ItemList.Slot1, 1);
return %inv1 SPC %inv1amount;
}

^^

I was going to say that..


Just an example, for some ideas.
Code: [Select]
if(!isObject(%client.ItemList))
{
%client.ItemList = new ScriptObject() //You can also use SimSet's to automatically delete the field when the variable is deleted.
{
Slot1 = "4 1"; //EX: Slot1 = "ItemID Quantity";
};
}

function getinvslot1(%client)
{
%inv1 = getWord(%client.ItemList.Slot1,0);
%inv1amount = getword(%client.ItemList.Slot1, 1);
return %inv1 SPC %inv1amount;
}

Not what i said lol. Use a script group and tag it to the client, then add script objects which contain relevant info to the group.

Well I wasn't making an inventory system but I was planning on making one in the future.

Well I wasn't making an inventory system but I was planning on making one in the future.

Even so, use ONE main container object.

What do you think?
Code: [Select]
if(isObject(Database))
{
Database.delete();
}

new scriptGroup(Database);

function Database::populate(%this)
{
for(%i = 1; isObject(%this.item[%i]); %i++)
{
%this.item[%i].delete();
%this.item[%i] = "";
}

//IMPORTANT!!! Do not change the order that things are registered
//in unless you want to mess everyone's inventories up.

%this.registerItem("Bronze Sword", "Level\t1", "Damage\t15", "physicalItem\tBronzeSwordItem");
}

function Database::registerItem(%this, %name, %a, %b, %c, %d, %e, %f, %g, %h, %i, %j, %k, %l, %m, %n, %o, %p, %q)
{
if(%name $= "")
{
return;
}

%itemID = %this.getItemCount() + 1;
%this.item[%itemID] = new scriptObject();
%this.item[%itemID].name = %name;

if(%a !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%a), " ", "") SPC "= \"" @ restFields(%a) @ "\";");

if(%b !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%b), " ", "") SPC "= \"" @ restFields(%b) @ "\";");

if(%c !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%c), " ", "") SPC "= \"" @ restFields(%c) @ "\";");

if(%d !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%d), " ", "") SPC "= \"" @ restFields(%d) @ "\";");

if(%e !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%e), " ", "") SPC "= \"" @ restFields(%e) @ "\";");

if(%f !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%f), " ", "") SPC "= \"" @ restFields(%f) @ "\";");

if(%g !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%g), " ", "") SPC "= \"" @ restFields(%g) @ "\";");

if(%h !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%h), " ", "") SPC "= \"" @ restFields(%h) @ "\";");

if(%i !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%i), " ", "") SPC "= \"" @ restFields(%i) @ "\";");

if(%j !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%j), " ", "") SPC "= \"" @ restFields(%j) @ "\";");

if(%k !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%k), " ", "") SPC "= \"" @ restFields(%k) @ "\";");

if(%l !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%l), " ", "") SPC "= \"" @ restFields(%l) @ "\";");

if(%m !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%m), " ", "") SPC "= \"" @ restFields(%m) @ "\";");

if(%n !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%n), " ", "") SPC "= \"" @ restFields(%n) @ "\";");

if(%o !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%o), " ", "") SPC "= \"" @ restFields(%o) @ "\";");

if(%p !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%p), " ", "") SPC "= \"" @ restFields(%p) @ "\";");

if(%q !$= "")
eval("%this.item[%itemID]." @ strReplace(firstField(%q), " ", "") SPC "= \"" @ restFields(%q) @ "\";");
}

function Database::getItemCount(%this)
{
for(%i = 0; isObject(%this.item[%i + 1]); %i++) { }

return %i;
}

function Database::isItem(%this, %string)
{
if(trim(%sting) $= "")
{
return false;
}

for(%i = 1; isObject(%this.item[%i]); %i++)
{
if(%this.item[%i].name $= %string)
{
return true;
}
}

return false;
}

Database.populate();
« Last Edit: January 14, 2013, 02:02:16 PM by jes00 »

All of those if statements hurt my soul.
« Last Edit: January 14, 2013, 03:11:50 PM by elm »


All of those switches will still hurt my soul, just as bad.

Jes, when i get home later, be on so i can help you.
« Last Edit: January 14, 2013, 03:25:17 PM by elm »


Instead of using variables like %a, just do something like %var[0], %var[1], %var[2], and then loop through all of them.

Instead of using variables like %a, just do something like %var[0], %var[1], %var[2], and then loop through all of them.

Exactly.