mysql_format(MySQLCon, QuerY, sizeof(QuerY), "SELECT * FROM `vehicles` WHERE `Owner` = %d", pInfo[playerid][pID]); mysql_pquery(MySQLCon, QuerY, "OnVehiclesLoad", "");
forward OnVehiclesLoad(playerid); public OnVehiclesLoad(playerid) { for(new r = 0; r < cache_num_rows(); ++r, UlIDV++) { printf("RR: %d", UlIDV); new ORM:ormid = Veh[UlIDV][ORM_ID] = orm_create("vehicles"); orm_addvar_int(ormid, Veh[UlIDV][ID], "ID"); //this is the key orm_setkey(ormid, "ID"); //here we declare it as the key orm_addvar_int(ormid, Veh[UlIDV][Owner], "Owner"); orm_addvar_int(ormid, Veh[UlIDV][Model], "Model"); orm_addvar_float(ormid, Veh[UlIDV][PosX], "PosX"); orm_addvar_float(ormid, Veh[UlIDV][PosY], "PosY"); orm_addvar_float(ormid, Veh[UlIDV][PosZ], "PosZ"); orm_addvar_float(ormid, Veh[UlIDV][VAngle], "VAngle"); orm_addvar_int(ormid, Veh[UlIDV][Color1], "Color1"); orm_addvar_int(ormid, Veh[UlIDV][Color2], "Color2"); orm_addvar_int(ormid, Veh[UlIDV][Paintjob], "Paintjob"); orm_addvar_int(ormid, Veh[UlIDV][Value], "Value"); orm_addvar_int(ormid, Veh[UlIDV][Lock], "Lock"); orm_addvar_string(ormid, Veh[UlIDV][Plate], 16, "Plate"); orm_addvar_float(ormid, Veh[UlIDV][KM], "KM"); orm_addvar_int(ormid, Veh[UlIDV][Mod0], "Mod0"); orm_addvar_int(ormid, Veh[UlIDV][Mod1], "Mod1"); orm_addvar_int(ormid, Veh[UlIDV][Mod2], "Mod2"); orm_addvar_int(ormid, Veh[UlIDV][Mod3], "Mod3"); orm_addvar_int(ormid, Veh[UlIDV][Mod4], "Mod4"); orm_addvar_int(ormid, Veh[UlIDV][Mod5], "Mod5"); orm_addvar_int(ormid, Veh[UlIDV][Mod6], "Mod6"); orm_addvar_int(ormid, Veh[UlIDV][Mod7], "Mod7"); orm_addvar_int(ormid, Veh[UlIDV][Mod8], "Mod8"); orm_addvar_int(ormid, Veh[UlIDV][Mod9], "Mod9"); orm_addvar_int(ormid, Veh[UlIDV][Mod10], "Mod10"); orm_addvar_int(ormid, Veh[UlIDV][Mod11], "Mod11"); orm_addvar_int(ormid, Veh[UlIDV][Mod12], "Mod12"); orm_addvar_int(ormid, Veh[UlIDV][Mod13], "Mod13"); orm_addvar_int(ormid, Veh[UlIDV][Mod14], "Mod14"); orm_addvar_int(ormid, Veh[UlIDV][Mod15], "Mod15"); orm_addvar_int(ormid, Veh[UlIDV][Mod16], "Mod16"); orm_addvar_string(ormid, Veh[UlIDV][Class], 13, "Class"); orm_apply_cache(ormid, UlIDV); Veh[UlIDV][ServerID] = CreateVehicle(Veh[UlIDV][Model], Veh[UlIDV][PosX], Veh[UlIDV][PosY], Veh[UlIDV][PosZ], Veh[UlIDV][VAngle], Veh[UlIDV][Color1], Veh[UlIDV][Color2], -1); } return 1; }
[13:10:36] [debug] Run time error 4: "Array index out of bounds" [13:10:36] [debug] Accessing element at index 65535 past array upper bound 1999 [13:10:36] [debug] AMX backtrace: [13:10:36] [debug] #0 0004f104 in public OnVehiclesLoad (1) from GM.amx
Veh[UlIDV][ServerID] = CreateVehicle(Veh[UlIDV][Model], Veh[UlIDV][PosX], Veh[UlIDV][PosY], Veh[UlIDV][PosZ], Veh[UlIDV][VAngle], Veh[UlIDV][Color1], Veh[UlIDV][Color2], -1);
enum e_Veh { //..... ServerID, //..... }; new Veh[MAX_VEHICLES][e_Veh];
// code...... printf("RRd: %d", Veh[UlIDV][Model]); Veh[UlIDV][ServerID] = CreateVehicle(Veh[UlIDV][Model], Veh[UlIDV][PosX], Veh[UlIDV][PosY], Veh[UlIDV][PosZ], Veh[UlIDV][VAngle], Veh[UlIDV][Color1], Veh[UlIDV][Color2], -1); // code......
Veh[INVALID_VEHICLE_ID][...];
printf("Veh index: %i", UlIDV); Veh[UlIDV][ServerID] = CreateVehicle(Veh[UlIDV][Model], Veh[UlIDV][PosX], Veh[UlIDV][PosY], Veh[UlIDV][PosZ], Veh[UlIDV][VAngle], Veh[UlIDV][Color1], Veh[UlIDV][Color2], -1);
Then I would print out the index whenever you want to access the "Veh" veriable to make sure it won't exceed the 1999 value.
Like this: Код:
printf("Veh index: %i", UlIDV); Veh[UlIDV][ServerID] = CreateVehicle(Veh[UlIDV][Model], Veh[UlIDV][PosX], Veh[UlIDV][PosY], Veh[UlIDV][PosZ], Veh[UlIDV][VAngle], Veh[UlIDV][Color1], Veh[UlIDV][Color2], -1); |
[17:37:57] Model: 468 [17:37:57] Veh index: 0 [17:37:57] Model: 602 [17:37:57] Veh index: 1 [17:37:57] Model: 411 [17:37:57] Veh index: 2 [17:37:57] Model: 496 [17:37:57] Veh index: 3 [17:37:57] Model: 462 [17:37:57] Veh index: 4 [17:37:57] Model: 463 [17:37:57] Veh index: 5
[17:38:38] Model: 0 [17:38:38] Veh index: 6 [17:38:38] [debug] Run time error 4: "Array index out of bounds" [17:38:38] [debug] Accessing element at index 65535 past array upper bound 1999 [17:38:38] [debug] AMX backtrace: [17:38:38] [debug] #0 0004ed6c in public OnVehiclesLoad (1) from GM.amx
// ** INCLUDES
#include <a_samp>
#include <a_mysql>
// ** DEFINES
// *** DATABASE
// **** GENERAL
#define MYSQL_HOST "localhost"
#define MYSQL_USER "root"
#define MYSQL_PASSWORD ""
#define MYSQL_DATABASE "mysql_vehicles"
// **** TABLES
// ***** VEHICLES
// ****** GENERAL
#define TABLE_VEHICLES "vehicles"
// ****** FIELDS
#define VEHICLES_MODEL "model"
#define VEHICLES_POSITION_X "position_x"
#define VEHICLES_POSITION_Y "position_y"
#define VEHICLES_POSITION_Z "position_z"
#define VEHICLES_ANGLE "angle"
#define VEHICLES_COLOR_1 "color_1"
#define VEHICLES_COLOR_2 "color_2"
#define VEHICLES_RESPAWN_DELAY "respawn_delay"
#define VEHICLES_SIREN "siren"
// ** ARRAYS AND ENUMERATORS
enum eCreatedVehiclesInfo
{
created_vehicle_info_model,
Float:created_vehicle_info_x,
Float:created_vehicle_info_y,
Float:created_vehicle_info_z,
Float:created_vehicle_info_angle,
created_vehicle_info_color_1,
created_vehicle_info_color_2,
created_vehicle_info_respawn,
created_vehicle_info_siren
};
new aCreatedVehiclesInfo[MAX_VEHICLES][eCreatedVehiclesInfo];
// ** VARIABLES
// *** GLOBAL VARIABLES
// **** DATABASE
static vehicles_database;
// ** MAIN
main()
{
print("Loaded \"mysql_vehicles.amx\".");
}
// ** CALLBACKS
public OnGameModeInit()
{
LoadDatabase();
LoadVehicles();
return 1;
}
public OnGameModeExit()
{
return 1;
}
// ** FUNCTIONS
stock LoadDatabase()
{
mysql_log(LOG_ERROR | LOG_WARNING | LOG_DEBUG);
vehicles_database = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
if(mysql_errno(vehicles_database))
{
print("[MySQL] Couldn't connect to "#MYSQL_DATABASE".");
}
else
{
new query[800];
print("[MySQL] Connected to "#MYSQL_DATABASE".");
strcat(query, "CREATE TABLE IF NOT EXISTS "#TABLE_VEHICLES"(");
strcat(query, ""#VEHICLES_MODEL" INT(20),");
strcat(query, ""#VEHICLES_POSITION_X" FLOAT(20),");
strcat(query, ""#VEHICLES_POSITION_Y" FLOAT(20),");
strcat(query, ""#VEHICLES_POSITION_Z" FLOAT(20),");
strcat(query, ""#VEHICLES_ANGLE" FLOAT(20),");
strcat(query, ""#VEHICLES_COLOR_1" INT(20),");
strcat(query, ""#VEHICLES_COLOR_2" INT(20),");
strcat(query, ""#VEHICLES_RESPAWN_DELAY" INT(20),");
strcat(query, ""#VEHICLES_SIREN" INT(20))");
mysql_query(vehicles_database, query);
}
return 1;
}
stock LoadVehicles()
{
new query[500];
strcat(query, "SELECT `"#VEHICLES_MODEL"`, `"#VEHICLES_POSITION_X"`, `"#VEHICLES_POSITION_Y"`, `"#VEHICLES_POSITION_Z"`, `"#VEHICLES_ANGLE"`, `"#VEHICLES_COLOR_1"`, `"#VEHICLES_COLOR_2"`, `"#VEHICLES_RESPAWN_DELAY"`, `"#VEHICLES_SIREN"` FROM `"#TABLE_VEHICLES"`");
mysql_function_query(vehicles_database, query, true, "OnVehiclesLoaded", "");
return 1;
}
forward OnVehiclesLoaded();
public OnVehiclesLoaded()
{
new vehicleid, model, Float:x, Float:y, Float:z, Float:angle, color_1, color_2, respawn_delay, siren;
for(new i = 0, j = cache_get_row_count(vehicles_database); i < j; i ++)
{
model = cache_get_row_int(i, 0, vehicles_database);
x = cache_get_row_float(i, 1, vehicles_database);
y = cache_get_row_float(i, 2, vehicles_database);
z = cache_get_row_float(i, 3, vehicles_database);
angle = cache_get_row_float(i, 4, vehicles_database);
color_1 = cache_get_row_int(i, 5, vehicles_database);
color_2 = cache_get_row_int(i, 6, vehicles_database);
respawn_delay = cache_get_row_int(i, 7, vehicles_database);
siren = cache_get_row_int(i, 8, vehicles_database);
vehicleid = CreateVehicle(model, x, y, z, angle, color_1, color_2, respawn_delay, siren);
aCreatedVehiclesInfo[vehicleid][created_vehicle_info_model] = model;
aCreatedVehiclesInfo[vehicleid][created_vehicle_info_x] = x;
aCreatedVehiclesInfo[vehicleid][created_vehicle_info_y] = y;
aCreatedVehiclesInfo[vehicleid][created_vehicle_info_z] = z;
aCreatedVehiclesInfo[vehicleid][created_vehicle_info_angle] = angle;
aCreatedVehiclesInfo[vehicleid][created_vehicle_info_color_1] = color_1;
aCreatedVehiclesInfo[vehicleid][created_vehicle_info_color_2] = color_2;
aCreatedVehiclesInfo[vehicleid][created_vehicle_info_respawn] = respawn_delay;
aCreatedVehiclesInfo[vehicleid][created_vehicle_info_siren] = siren;
}
return 1;
}
pawn Код:
|
But you can not create more than 5 vehicles! |