Crate Error :!
#1

Help me, please

Code:
[20:43:50] [debug] Run time error 4: "Array index out of bounds"
[20:43:50] [debug]  Accessing element at index 22 past array upper bound 19
[20:43:50] [debug] AMX backtrace:
[20:43:50] [debug] #0 0002e388 in public OnQueryFinish () from NG-RP.amx
and code error:
Code:
case LOADCRATE_THREAD:
		{
		    for(new i; i < rows; i++)
		    {
				new crateid, szResult[32], string[128];
				cache_get_field_content(i, "id", szResult, MainPipeline); crateid = strval(szResult);
				cache_get_field_content(i, "Active", szResult, MainPipeline); CrateInfo[crateid][crActive] = strval(szResult);
				cache_get_field_content(i, "CrateX", szResult, MainPipeline); CrateInfo[crateid][crX] = strval(szResult);
				cache_get_field_content(i, "CrateY", szResult, MainPipeline); CrateInfo[crateid][crY] = strval(szResult);
				cache_get_field_content(i, "CrateZ", szResult, MainPipeline); CrateInfo[crateid][crZ] = strval(szResult);
				cache_get_field_content(i, "GunQuantity", szResult, MainPipeline); CrateInfo[crateid][GunQuantity] = strval(szResult);
				cache_get_field_content(i, "InVehicle", szResult, MainPipeline); CrateInfo[crateid][InVehicle] = strval(szResult);
    			if(CrateInfo[crateid][InVehicle] != INVALID_VEHICLE_ID)
	   			{
			    	CrateInfo[crateid][crActive] = 0;
	       			CrateInfo[crateid][InVehicle] = INVALID_VEHICLE_ID;
			    }
	   			if(CrateInfo[crateid][crActive])
	   			{
       				CrateInfo[crateid][InVehicle] = INVALID_VEHICLE_ID;
		        	CrateInfo[crateid][crObject] = CreateDynamicObject(964,CrateInfo[crateid][crX],CrateInfo[crateid][crY],CrateInfo[crateid][crZ],0.00000000,0.00000000,0.00000000);
		        	format(string, sizeof(string), "Serial Number: #%d\n High Grade Materials: %d/50", i, CrateInfo[i][GunQuantity]);
			        CrateInfo[crateid][crLabel] = CreateDynamic3DTextLabel(string, COLOR_ORANGE, CrateInfo[crateid][crX],CrateInfo[crateid][crY],CrateInfo[crateid][crZ]+1, 20.0, _, _, 1, 0, 0, _, 20.0);

				}
			}
Code:
#define         MAX_CRATES                  20
enum crateInfo
{
	crActive,
	crObject,
	Float: crX,
	Float: crY,
	Float: crZ,
	GunQuantity,
	InVehicle,
	Text3D: crLabel,
}

new CrateInfo[20][crateInfo];
Reply
#2

Try this:
pawn Code:
#define         MAX_CRATES                  50
enum crateInfo
{
    crActive,
    crObject,
    Float: crX,
    Float: crY,
    Float: crZ,
    GunQuantity,
    InVehicle,
    Text3D: crLabel,
}

new CrateInfo[MAX_CRATES][crateInfo];
Reply
#3

Quote:
Originally Posted by EiresJason
View Post
Try this:
pawn Code:
#define         MAX_CRATES                  50
enum crateInfo
{
    crActive,
    crObject,
    Float: crX,
    Float: crY,
    Float: crZ,
    GunQuantity,
    InVehicle,
    Text3D: crLabel,
}

new CrateInfo[MAX_CRATES][crateInfo];
Error in gameserver:
Code:
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 0
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 1
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 2
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 3
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 4
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 5
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 6
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 7
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 8
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 9
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 10
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 11
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 12
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 13
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 14
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 15
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 16
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 17
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 18
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '65535' WHERE id = 19
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 20
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 21
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 22
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 23
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 24
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 25
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 26
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 27
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 28
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 29
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 30
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 31
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 32
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 33
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 34
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 35
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 36
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 37
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 38
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 39
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 40
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 41
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 42
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 43
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 44
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 45
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 46
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 47
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 48
[20:52:31] UPDATE `crates` SET  `Active` = '0', `CrateX` = '0.00', `CrateY` = '0.00', `CrateZ` = '0.00', `GunQuantity` = '0', `InVehicle` = '0' WHERE id = 49
Code Crate in Database
Code:
-- ----------------------------
-- Table structure for crates
-- ----------------------------
DROP TABLE IF EXISTS `crates`;
CREATE TABLE `crates` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `Active` int(11) NOT NULL DEFAULT '0',
  `CrateX` float NOT NULL DEFAULT '0',
  `CrateY` float NOT NULL DEFAULT '0',
  `CrateZ` float NOT NULL DEFAULT '0',
  `GunQuantity` int(11) NOT NULL DEFAULT '50',
  `InVehicle` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=50 DEFAULT CHARSET=latin1;
Reply
#4

Ooops, my bad.

Try this.

pawn Code:
for(new i; i < rows; i++)
            {
                new crateid, szResult[32], string[128];
                cache_get_field_content(i, "id", szResult, MainPipeline); crateid = strval(szResult);
                if(crateid != 0 && crateid < MAX_CRATES)
                {
                    cache_get_field_content(i, "Active", szResult, MainPipeline); CrateInfo[crateid][crActive] = strval(szResult);
                    cache_get_field_content(i, "CrateX", szResult, MainPipeline); CrateInfo[crateid][crX] = strval(szResult);
                    cache_get_field_content(i, "CrateY", szResult, MainPipeline); CrateInfo[crateid][crY] = strval(szResult);
                    cache_get_field_content(i, "CrateZ", szResult, MainPipeline); CrateInfo[crateid][crZ] = strval(szResult);
                    cache_get_field_content(i, "GunQuantity", szResult, MainPipeline); CrateInfo[crateid][GunQuantity] = strval(szResult);
                    cache_get_field_content(i, "InVehicle", szResult, MainPipeline); CrateInfo[crateid][InVehicle] = strval(szResult);
                    if(CrateInfo[crateid][InVehicle] != INVALID_VEHICLE_ID)
                    {
                        CrateInfo[crateid][crActive] = 0;
                        CrateInfo[crateid][InVehicle] = INVALID_VEHICLE_ID;
                    }
                    if(CrateInfo[crateid][crActive])
                    {
                        CrateInfo[crateid][InVehicle] = INVALID_VEHICLE_ID;
                        CrateInfo[crateid][crObject] = CreateDynamicObject(964,CrateInfo[crateid][crX],CrateInfo[crateid][crY],CrateInfo[crateid][crZ],0.00000000,0.00000000,0.00000000);
                        format(string, sizeof(string), "Serial Number: #%d\n High Grade Materials: %d/50", i, CrateInfo[i][GunQuantity]);
                        CrateInfo[crateid][crLabel] = CreateDynamic3DTextLabel(string, COLOR_ORANGE, CrateInfo[crateid][crX],CrateInfo[crateid][crY],CrateInfo[crateid][crZ]+1, 20.0, _, _, 1, 0, 0, _, 20.0);

                    }
                }  
            }
If this doesn't work, maybe wait until someone with MySQL experience sees this thread and fixes it.
Reply
#5

It dosen't work !!
Reply
#6

Set '50' to the number of rows you have.
pawn Code:
#define         MAX_CRATES                  50

Also, switch back to this.

case LOADCRATE_THREAD:
        {
            for(new i; i < rows; i++)
            {
                new crateid, szResult[32], string[128];
                cache_get_field_content(i, "id", szResult, MainPipeline); crateid = strval(szResult);
                cache_get_field_content(i, "Active", szResult, MainPipeline); CrateInfo[crateid][crActive] = strval(szResult);
                cache_get_field_content(i, "CrateX", szResult, MainPipeline); CrateInfo[crateid][crX] = strval(szResult);
                cache_get_field_content(i, "CrateY", szResult, MainPipeline); CrateInfo[crateid][crY] = strval(szResult);
                cache_get_field_content(i, "CrateZ", szResult, MainPipeline); CrateInfo[crateid][crZ] = strval(szResult);
                cache_get_field_content(i, "GunQuantity", szResult, MainPipeline); CrateInfo[crateid][GunQuantity] = strval(szResult);
                cache_get_field_content(i, "InVehicle", szResult, MainPipeline); CrateInfo[crateid][InVehicle] = strval(szResult);
                if(CrateInfo[crateid][InVehicle] != INVALID_VEHICLE_ID)
                {
                    CrateInfo[crateid][crActive] = 0;
                    CrateInfo[crateid][InVehicle] = INVALID_VEHICLE_ID;
                }
                if(CrateInfo[crateid][crActive])
                {
                    CrateInfo[crateid][InVehicle] = INVALID_VEHICLE_ID;
                    CrateInfo[crateid][crObject] = CreateDynamicObject(964,CrateInfo[crateid][crX],CrateInfo[crateid][crY],CrateInfo[crateid][crZ],0.00000000,0.00000000,0.00000000);
                    format(string, sizeof(string), "Serial Number: #%d\n High Grade Materials: %d/50", i, CrateInfo[i][GunQuantity]);
                    CrateInfo[crateid][crLabel] = CreateDynamic3DTextLabel(string, COLOR_ORANGE, CrateInfo[crateid][crX],CrateInfo[crateid][crY],CrateInfo[crateid][crZ]+1, 20.0, _, _, 1, 0, 0, _, 20.0);

                }
            }
Reply
#7

Thank very much :X
Reply
#8

np

EDIT: Remember, if you add crates, you have to re-set 'MAX_CRATES' to the total crates again.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)