11.02.2013, 09:44
pawn Код:
switch(var) {
case 0: {
new tmp[3][32];
}
case 1: {
new tmp[5][16];
}
}
switch(var) {
case 0: {
new tmp[3][32];
}
case 1: {
new tmp[5][16];
}
}
#define _NS_: Database__
#define DB_HOST "localhost"
#define DB_USER "root"
#define DB_PASS ""
#define DB_NAME "trucking"
#define DB_PREFIX ""
#include <YSI\y_hooks>
enum {
TB_USERS,
TB_TRUCKS,
TB_CARGOS,
TB_PLACES
}
static const dbtables[][32] = {
DB_PREFIX"users",
DB_PREFIX"trucks",
DB_PREFIX"cargos",
DB_PREFIX"places"
};
enum {
THREAD_DATALOAD,
THREAD_TRUCKLOAD,
THREAD_CARGOLOAD,
THREAD_PLACESLOAD
}
static dbhandle;
forward OnDataLoadFinish(resultid);
hook OnGameModeInit() {
dbhandle = mysql_connect(DB_HOST, DB_USER, DB_NAME, DB_PASS);
if(1 == mysql_ping()) {
mysql_debug(DEBUG);
Debug("Mysql connection succeeded");
mysql_set_charset("utf8_unicode_ci", dbhandle);
new tmp[32];
mysql_format(dbhandle, tmp, "SELECT * FROM `%s`", dbtables[TB_TRUCKS]);
mysql_function_query(dbhandle, tmp, true, "OnDataLoadFinish", "i", THREAD_TRUCKLOAD);
mysql_format(dbhandle, tmp, "SELECT * FROM `%s`", dbtables[TB_CARGOS]);
mysql_function_query(dbhandle, tmp, true, "OnDataLoadFinish", "i", THREAD_CARGOLOAD);
mysql_format(dbhandle, tmp, "SELECT * FROM `%s`", dbtables[TB_PLACES]);
mysql_function_query(dbhandle, tmp, true, "OnDataLoadFinish", "i", THREAD_PLACESLOAD);
} else {
printf("Mysql connection error!");
}
return 1;
}
hook OnGameModeExit() {
mysql_close(dbhandle);
return 1;
}
public OnDataLoadFinish(resultid) {
new rows, fields, i;
cache_get_data(rows, fields, dbhandle);
switch(resultid) {
case THREAD_TRUCKLOAD: {
new data[6][21];
for(; i != rows; i++) {
cache_get_row(i, 0, data[0], dbhandle);
cache_get_row(i, 1, data[1], dbhandle);
cache_get_row(i, 2, data[2], dbhandle);
cache_get_row(i, 3, data[3], dbhandle);
cache_get_row(i, 4, data[4], dbhandle);
cache_get_row(i, 5, data[5], dbhandle);
Modules__Vehicles__VehicleTypes[i][typeId] = strval(data[0]);
Modules__Vehicles__VehicleTypes[i][carType] = strval(data[2]);
Modules__Vehicles__VehicleTypes[i][modelId] = strval(data[3]);
Modules__Vehicles__VehicleTypes[i][maxFuel] = strval(data[4]);
Modules__Vehicles__VehicleTypes[i][maxLoad] = strval(data[5]);
Modules__Vehicles__VehicleTypes[i][price] = strval(data[5]);
}
}
case THREAD_CARGOLOAD: {
new data[5][32];
for(; i != rows; i++) {
cache_get_row(i, 0, data[0], dbhandle);
cache_get_row(i, 1, data[1], dbhandle);
cache_get_row(i, 2, data[2], dbhandle);
cache_get_row(i, 3, data[3], dbhandle);
cache_get_row(i, 4, data[4], dbhandle);
Modules__Cargo__Cargos[i][id] = strval(data[0]);
strcpy(Modules__Cargo__Cargos[i][name], data[1]);
Modules__Cargo__Cargos[i][weightRange][0] = strval(data[2]);
Modules__Cargo__Cargos[i][weightRange][1] = strval(data[3]);
//Fix teh constant
sscanf(data[4], "p<,>A<i>["MAX_VEHICLE_TYPES"]", Modules__Cargo__Cargos[i][carsPermitted]);
}
}
}
return 1;
}
#undef _NS_