PDA

Просмотр полной версии : [Вопрос] [Вопрос] Вывод GangZones с MySQL



Johhny
15.08.2015, 15:03
Здравствуйте знатоки PAWN, я делаю мод с нуля на MySQL R39-2
Координаты GangZon-ы у меня есть а вот как их вызвать я не знаю.
Начнём с начало.

Я сделал enum


enum E_GHETTO_DATA
{
X,
Y,
XX,
YY,
ORM: Member,
ORM: ID
}

Добавил ко всем new

new Ghetto[120][E_GHETTO_DATA];// Это сделал чтобы читал все 120 территорий, не знаю если я правильно сделал

В OnGameModeInit

mysql_tquery(1, "SELECT * FROM `ghetto`", "OnMySQL_Gangs");

А вот что добавить в OnMySQL_Gangs я не знаю.

forward OnMySQL_Gangs();
public OnMySQL_Gangs()
{
printf("Ганг зоны работают"); // Это сообщения появляется при вкл. мода.
}

Вопросы: Будет ли работать система? И как сделать чтоб выявились территорий на карту.
За ранее спасибо.

P.S: Если будет нужно координаты Gang Zon-ов я могу их добавить.

wAx
15.08.2015, 15:24
GangZoneCreate, GangZoneShowForAll вроде-бы, по циклу перебирай в OnMySQL_Gangs и создавай.

Johhny
15.08.2015, 15:43
GangZoneCreate, GangZoneShowForAll вроде-бы, по циклу перебирай в OnMySQL_Gangs и создавай.
У меня в MySQL Уже есть координаты для GangZoneCreate, ну я хз как сделать чтоб заработало эти координаты.

wAx
15.08.2015, 15:52
У меня в MySQL Уже есть координаты для GangZoneCreate, ну я хз как сделать чтоб заработало эти координаты.


new r,f;
cache_get_data(r,f,1);
for(new i; i < r; i++)
{
Ghetto[i][X] = cache_get_field_content_float(i, "название_столбца", 1);
Ghetto[i][Y] = cache_get_field_content_float(i, "название_столбца", 1);
...

}

gangzone.ini
15.08.2015, 16:12
enum E_GHETTO_DATA
{
Float: X,
Float: Y,
Float: XX,
Float: YY,
ORM: Member,
ORM: ID
}

Так надо, или нет?

Johhny
15.08.2015, 16:46
enum E_GHETTO_DATA
{
Float: X,
Float: Y,
Float: XX,
Float: YY,
ORM: Member,
ORM: ID
}

Так надо, или нет?

В каком смысле?

- - - Добавлено - - -



new r,f;
cache_get_data(r,f,1);
for(new i; i < r; i++)
{
Ghetto[i][X] = cache_get_field_content_float(i, "название_столбца", 1);
Ghetto[i][Y] = cache_get_field_content_float(i, "название_столбца", 1);
...

}

НЕ совсем понял.

Desulaid
15.08.2015, 17:20
В каком смысле?

- - - Добавлено - - -



НЕ совсем понял.

Просто выгрузи из БД все 120 территори =) Каждая итерация цикла заполняет массив со своим интерационным значением (0-119). Цикл всю возню возьмет на себя.

$continue$
15.08.2015, 18:40
Накидал тут, может где то ошибки и есть:
В начало мода куда нибудь


enum e_GHETTO_DATA
{
Float: x_coordinate_west_side_gz,
Float: y_coordinate_south_side_gz,
Float: x_coordinate_east_side_gz,
Float: y_coordinate_north_side_gz,
fraction_id
}



new counter_gang_zones = 0;
new DataGhetto[120][e_GHETTO_DATA];
#define TABLE_GANG_ZONE_BAND "ghetto"



public OnGameModeInit()
{
// connect_id - id подключение, записывают в перееменную: connect_id = mysql_connect(ip_addreas, users, date_base, data_pase_password);
mysql_function_query(connect_id, "SELECT * FROM `"TABLE_GANG_ZONE_BAND"`", true, "CallBackLoadGangZoneBand", "");
}



forward CallBackLoadGangZoneBand();
public CallBackLoadGangZoneBand()
{
new rows, fields;
cache_get_data(rows, fields);
if(rows == 0)
return print("[Предупреждение][Загрузка GangZone]: В базе данных нет GangZones!");
if(rows != sizeof(DataGhetto))
return printf("[Предупреждение][Загрузка GangZone]: В базе данных больше зон[%d], чем в массиве DataGhetto[%d][e_GHETTO_DATA]!", rows, sizeof(DataGhetto));

// Судя прописывать название столцов с координатами
static const column_one_coordinates[] = !"x_coordinate_west_side_gz";
static const column_two_coordinates[] = !"y_coordinate_south_side_gz";
static const column_three_coordinates[] = !"x_coordinate_east_side_gz";
static const column_four_coordinates[] = !"y_coordinate_north_side_gz";
static const column_id_fraction[] = !"fraction_id";

for(new i = 0; i < sizeof(DataGhetto); i++)
{
DataGhetto[i][x_coordinate_west_side_gz] = cache_get_field_content_float(i, column_one_coordinates);
DataGhetto[i][y_coordinate_south_side_gz] = cache_get_field_content_float(i, column_two_coordinates);
DataGhetto[i][x_coordinate_east_side_gz] = cache_get_field_content_float(i, column_three_coordinates);
DataGhetto[i][y_coordinate_north_side_gz] = cache_get_field_content_float(i, column_four_coordinates);
DataGhetto[i][fraction_id] = cache_get_field_content_int(i, "column_id_fraction");

}
counter_gang_zones = rows;
printf("[Загрузка GangZone]: Загрузка GangZones прошла успешна! Загружено %d GangZone", counter_gang_zones);
return (rows == 0) ? 0 : 1;
}

gangzone.ini
16.08.2015, 01:34
В каком смысле?

Ну ты же берешь координаты, а не что-то другое, значит надо Float..

Johhny
16.08.2015, 11:56
Ну ты же берешь координаты, а не что-то другое, значит надо Float..

Я это уже вчера сделал, я тоже заметил что не поставил Float:

Johhny
16.08.2015, 17:03
Спасибо всем. Проблему решил.

Johhny
16.08.2015, 18:16
Накидал тут, может где то ошибки и есть:
В начало мода куда нибудь


enum e_GHETTO_DATA
{
Float: x_coordinate_west_side_gz,
Float: y_coordinate_south_side_gz,
Float: x_coordinate_east_side_gz,
Float: y_coordinate_north_side_gz,
fraction_id
}



new counter_gang_zones = 0;
new DataGhetto[120][e_GHETTO_DATA];
#define TABLE_GANG_ZONE_BAND "ghetto"



public OnGameModeInit()
{
// connect_id - id подключение, записывают в перееменную: connect_id = mysql_connect(ip_addreas, users, date_base, data_pase_password);
mysql_function_query(connect_id, "SELECT * FROM `"TABLE_GANG_ZONE_BAND"`", true, "CallBackLoadGangZoneBand", "");
}



forward CallBackLoadGangZoneBand();
public CallBackLoadGangZoneBand()
{
new rows, fields;
cache_get_data(rows, fields);
if(rows == 0)
return print("[Предупреждение][Загрузка GangZone]: В базе данных нет GangZones!");
if(rows != sizeof(DataGhetto))
return printf("[Предупреждение][Загрузка GangZone]: В базе данных больше зон[%d], чем в массиве DataGhetto[%d][e_GHETTO_DATA]!", rows, sizeof(DataGhetto));

// Судя прописывать название столцов с координатами
static const column_one_coordinates[] = !"x_coordinate_west_side_gz";
static const column_two_coordinates[] = !"y_coordinate_south_side_gz";
static const column_three_coordinates[] = !"x_coordinate_east_side_gz";
static const column_four_coordinates[] = !"y_coordinate_north_side_gz";
static const column_id_fraction[] = !"fraction_id";

for(new i = 0; i < sizeof(DataGhetto); i++)
{
DataGhetto[i][x_coordinate_west_side_gz] = cache_get_field_content_float(i, column_one_coordinates);
DataGhetto[i][y_coordinate_south_side_gz] = cache_get_field_content_float(i, column_two_coordinates);
DataGhetto[i][x_coordinate_east_side_gz] = cache_get_field_content_float(i, column_three_coordinates);
DataGhetto[i][y_coordinate_north_side_gz] = cache_get_field_content_float(i, column_four_coordinates);
DataGhetto[i][fraction_id] = cache_get_field_content_int(i, "column_id_fraction");

}
counter_gang_zones = rows;
printf("[Загрузка GangZone]: Загрузка GangZones прошла успешна! Загружено %d GangZone", counter_gang_zones);
return (rows == 0) ? 0 : 1;
}


Более оптимизированный и быстрый:


forward OnMySQL_Gangs();
public OnMySQL_Gangs()
{
new connects;
new rows = cache_get_row_count(connects);
new time = GetTickCount();
if(!rows) return printf("Гангзоны не загружены");
for(new i = 0; i < rows; i++)
{
GZInfo[i][X] = cache_get_field_content_float(i, "X", connects);
GZInfo[i][Y] = cache_get_field_content_float(i, "Y", connects);
GZInfo[i][XX] = cache_get_field_content_float(i, "XX", connects);
GZInfo[i][XY] = cache_get_field_content_float(i , "XY", connects);
GZInfo[i][Member] = cache_get_field_content_int(i, "Member", connects);
GZInfo[i][ID] = GangZoneCreate(GZInfo[i][X],GZInfo[i][Y],GZInfo[i][XX],GZInfo[i][XY]);
}
printf("LoadGangZone: Загружено %d | Время: %d (ms)", rows, GetTickCount()-time);
return true;
}

$continue$
16.08.2015, 18:32
Более оптимизированный и быстрый:


forward OnMySQL_Gangs();
public OnMySQL_Gangs()
{
new connects;
new rows = cache_get_row_count(connects);
new time = GetTickCount();
if(!rows) return printf("Гангзоны не загружены");
for(new i = 0; i < rows; i++)
{
GZInfo[i][X] = cache_get_field_content_float(i, "X", connects);
GZInfo[i][Y] = cache_get_field_content_float(i, "Y", connects);
GZInfo[i][XX] = cache_get_field_content_float(i, "XX", connects);
GZInfo[i][XY] = cache_get_field_content_float(i , "XY", connects);
GZInfo[i][Member] = cache_get_field_content_int(i, "Member", connects);
GZInfo[i][ID] = GangZoneCreate(GZInfo[i][X],GZInfo[i][Y],GZInfo[i][XX],GZInfo[i][XY]);
}
printf("LoadGangZone: Загружено %d | Время: %d (ms)", rows, GetTickCount()-time);
return true;
}

Можно поинтересоваться чем?

Johhny
16.08.2015, 19:49
Можно поинтересоваться чем?

Сровни твой код и это код который я прислал.

$continue$
16.08.2015, 19:51
Сровни твой код и это код который я прислал.

Различие по сути - нуль.