11.09.2016, 16:07
Hello,
I am making my own inventory system but there is a problem when I try to load more than 4 objects.
So I have 2 tables in mysql.
one is called objects and contains all the information about the object (name,displayid,maxuses...)
and the other one is called inventories with all the objects owned by players and its properties (fingerprints, uses)
This is my code:
I load everything into an array with this code:
It worked until I added a fifth object 'Empty Bottle'
I get this error when starting the server:
I am making my own inventory system but there is a problem when I try to load more than 4 objects.
So I have 2 tables in mysql.
one is called objects and contains all the information about the object (name,displayid,maxuses...)
and the other one is called inventories with all the objects owned by players and its properties (fingerprints, uses)
This is my code:
PHP код:
public OnGameModeInit()
{
new queryy[512];
mysql_format(mysql, queryy, sizeof(queryy), "SELECT ObjectID FROM `objects` ORDER BY ObjectID DESC LIMIT 1");
mysql_tquery(mysql, queryy, "countobjects");
return 1;
}
forward countobjects();
public countobjects()
{
objamount = cache_get_field_content_int(0, "ObjectID") + 1;
for(new i; i < objamount; i++)
{
GetObjectInfo(i);
}
}
PHP код:
stock GetObjectInfo(id)
{
new queryy[100];
mysql_format(mysql, queryy, sizeof(queryy), "SELECT * FROM `objects` WHERE `ObjectID` = '%i'", id);
new Cache:result = mysql_query(mysql, queryy);
new name[126];
cache_get_field_content(0, "Name", name);
InventoryInfo[Obj: id][Name] = name;
InventoryInfo[Obj: id][MaxUses] = cache_get_field_content_int(0, "MaxUses", mysql);
InventoryInfo[Obj: id][DisplayID] = cache_get_field_content_int(0, "DisplayID", mysql);
InventoryInfo[Obj: id][Action] = cache_get_field_content_int(0, "ActionID", mysql);
InventoryInfo[Obj: id][Type] = cache_get_field_content_int(0, "Type", mysql);
InventoryInfo[Obj: id][BodyX] = cache_get_field_content_float(0, "BodyX");
InventoryInfo[Obj: id][BodyY] = cache_get_field_content_float(0, "BodyY");
InventoryInfo[Obj: id][BodyZ] = cache_get_field_content_float(0, "BodyZ");
printf("Object loaded: %s | ObjectID: %i | MaxUses: %i | Action: %i | Type: %i", InventoryInfo[Obj: id][Name], id, InventoryInfo[Obj: id][MaxUses], InventoryInfo[Obj: id][Action], InventoryInfo[Obj: id][Type]);
cache_delete(result);
return name;
}
I get this error when starting the server:
PHP код:
Object loaded: Water | ObjectID: 0 | MaxUses: 4 | Action: 21 | Type: 14
Object loaded: Sprunk | ObjectID: 1 | MaxUses: 4 | Action: 21 | Type: 14
Object loaded: M&Ms | ObjectID: 2 | MaxUses: 4 | Action: 7 | Type: 5
Object loaded: Chips | ObjectID: 3 | MaxUses: 4 | Action: 7 | Type: 5
//there should be a 5th object here called 'Empty bottle'
[debug] Run time error 4: "Array index out of bounds"
[debug] Accessing element at index 4 past array upper bound 3
[debug] AMX backtrace:
[debug] #0 00013548 in GetObjectInfo (id=4) at C:\...\prp-gamemode.pwn:1011
[debug] #1 0000d970 in public countobjects () at C:\...\prp-gamemode.pwn:158