Вопросы

Antoxa39
Dance 80-90, mmm Nice)

не работает такая штука,вообщем я сделал кмд которая проверяет ник игрока в бд в таблице с машинами,если найден столбец с таким ником,то спавним его тачку но:

CMD:fix(playerid,vehicleid)
{
    new query[120];
    format(query,sizeof(query),"SELECT * FROM `user_veh` WHERE `owner` = '%s'",Player[playerid][nick]);
    mysql_function_query(mysql,query,true,"check","ii",playerid,vehicleid);
    SendClientMessage(playerid, -1, "true");
}
forward check(playerid,vehicleid);
public check(playerid,vehicleid)
{
    new rows,fields;
    cache_get_data(rows,fields);
    if(rows)
    {
        SendClientMessage(playerid,-1,"ssssqwe1254");
        AddStaticVehicle(vInfo[vehicleid][vModel],vInfo[vehicleid][x],vInfo[vehicleid][y],vInfo[vehicleid][z],0.0,vInfo[vehicleid][vColor1],vInfo[vehicleid][vColor2]);
    }
    else print("тест");
}
public OnGameModeInit()
{
    loadveh();
    return 1;
}
stock loadveh()
{
    mysql_query(mysql,"SELECT * FROM `user_veh`");
    new f = cache_get_row_count(mysql);
    for(new i; i < f; i++)
    {
        vInfo[i][vID] = cache_get_field_content_int(0,"vID",mysql);
        vInfo[i][vModel] = cache_get_field_content_int(0, "vModel", mysql);
        vInfo[i][owner] = cache_get_field_content(0,"owner", Player[i][nick], mysql);
        vInfo[i][x] = cache_get_field_content_float(0,"x",mysql);
        vInfo[i][y] = cache_get_field_content_float(0,"y",mysql);
        vInfo[i][z] = cache_get_field_content_float(0,"z",mysql);
        vInfo[i][vColor2] = cache_get_field_content_int(0,"vColor1",mysql);
        vInfo[i][vColor2] = cache_get_field_content_int(0,"vColor2",mysql);
    }
}
public OnGameModeExit()
{
    mysql_close(mysql);
    clear(playerid);
    return 1;
}
stock clear()
{   
    new f = cache_get_row_count(mysql);
    for(new i; i < f; i++)
    {
        vInfo[i][vID] = 0;
        vInfo[i][vModel] = 0;
        vInfo[i][owner] = EOS;
        vInfo[i][x] = 0.0;
        vInfo[i][y] = 0.0;
        vInfo[i][z] = 0.0;
        vInfo[i][vColor2] = 0;
        vInfo[i][vColor2] = 0;
    }
}

если я пишу AddStaticVehicle(vInfo[vehicleid][vModel],vInfo[vehicleid][x],vInfo[vehicleid][y],vInfo[vehicleid][z],0.0,vInfo[vehicleid][vColor1],vInfo[vehicleid][vColor2]);

 

То машину не спавнит, а если AddStaticVehicle(любой ид модели, 0.0,0.0,2.0,0.0,3,0); то спавнит

Поделиться сообщением


Ссылка на сообщение

27 ответов на этот вопрос

  • 1
Antoxa39
Dance 80-90, mmm Nice)

@DEST вывелось

@DEST в логах есть,а в игре машины нет,

Цитата

enum veh{
vID,
owner[24],
vModel,
vColor1,
vColor2,
Float:x,
Float:y,
Float:z
};

 

 

Поделиться сообщением


Ссылка на сообщение
  • 1
Antoxa39
Dance 80-90, mmm Nice)

@glvde. [

Спойлер

18:28:46] Number of vehicle models: 0
[18:29:21] [connection] 25.49.48.2:56574 requests connection cookie.
[18:29:22] [connection] incoming connection: 25.49.48.2:56574 id: 0
[18:29:22] [join] Derk has joined the server (0:25.49.48.2)
[18:29:57] [Pawn.CMD] HandleCommand: AMX error occurred in public pc_cmd_fix: Array index out of bounds
[18:29:59] [Pawn.CMD] HandleCommand: AMX error occurred in public OnPlayerCommandText: Array index out of bounds
[18:29:59] [Pawn.CMD] HandleCommand: AMX error occurred in public OnPlayerCommandText: Array index out of bounds

 

Поделиться сообщением


Ссылка на сообщение
  • 1
Antoxa39
Dance 80-90, mmm Nice)

@glvde. 

@Sleash`en Все работает только так:

forward loadveh();
public loadveh()
{
    new s[2];
    cache_get_data(s[0],s[1]);
    for(new i; i < s[0]; i++)
    {
        vInfo[i][vID] = cache_get_field_content_int(0,"vID",mysql);
        vInfo[i][vModel] = cache_get_field_content_int(0, "vModel", mysql);
        vInfo[i][owner] = cache_get_field_content(0,"owner", Player[i][nick], mysql);
        vInfo[i][x] = cache_get_field_content_float(0,"x",mysql);
        vInfo[i][y] = cache_get_field_content_float(0,"y",mysql);
        vInfo[i][z] = cache_get_field_content_float(0,"z",mysql);
        vInfo[i][vColor2] = cache_get_field_content_int(0,"vColor1",mysql);
        vInfo[i][vColor2] = cache_get_field_content_int(0,"vColor2",mysql);
        AddStaticVehicle(vInfo[i][vModel], vInfo[i][x], vInfo[i][y], vInfo[i][z], 0.0, vInfo[i][vColor1], vInfo[i][vColor2]);
    }
}
CMD:fx(){ 
    new query[104];
    format(query,sizeof(query),"SELECT * FROM `user_veh`");
    mysql_function_query(mysql,query,true,"loadveh","");
} 
public OnGameModeInit()
{
    mysql = mysql_connect(host,user,bd,sqlpass);
    CheckConnectSQL();
    new query[104];
    format(query,sizeof(query),"SELECT * FROM `user_veh`");
    mysql_function_query(mysql,query,true,"loadveh","");
    return 1;
}

 

Поделиться сообщением


Ссылка на сообщение
  • 0
Mishunin
Освоившийся
AddStaticVehicle(vInfo[vehicleid][vModel],0.0,0.0,2.0,0.0,vInfo[vehicleid][vColor1],vInfo[vehicleid][vColor2]);

попробуй так

Поделиться сообщением


Ссылка на сообщение
  • 0
Mishunin
Освоившийся

@Antoxa39 ошибаешься, AddStaticVehicle - Создает.

вставь это:

SetVehicleToRespawn(vInfo[vehicleid][vModel]);

вместо этого:

AddStaticVehicle(vInfo[vehicleid][vModel],vInfo[vehicleid][x],vInfo[vehicleid][y],vInfo[vehicleid][z],0.0,vInfo[vehicleid][vColor1],vInfo[vehicleid][vColor2]);

 

Поделиться сообщением


Ссылка на сообщение
  • 0
1 час назад, Antoxa39 сказал:

CMD:fix(playerid,vehicleid)

здесь точно принимается корректный vehicleid? Там вроде params[] должен быть. Что-то типа этого попробуйте: 

CMD:fix(playerid, params[])
{
    new vehicleid;
    if (sscanf(params, "i", vehicleid)) return SendClientMessage(playerid, -1, "USAGE: /fix [vehicleid]");
    /*продолжение команды из старт поста*/
}

 

Поделиться сообщением


Ссылка на сообщение
  • 0

@Antoxa39 И даже "true" в чат не выводится? 

И да, зачем еще раз нужно перезаписывать playerid? Он автоматически приходит того игрока, который ввел команду, в первом аргументе. 

Если нужно указать ID другого игрока, то нужно завести под это дело отдельную переменную, чтобы не путаться. 

Поделиться сообщением


Ссылка на сообщение
  • 0

А зачем нужен параметр vehicleid в команде? Это номер личного авто игрока? Т.е. он может иметь несколько машин, и здесь выбирает порядковый номер?

Поделиться сообщением


Ссылка на сообщение
  • 0
𝙡𝙖𝙨𝙩 𝙚𝙢𝙥𝙚𝙧𝙤𝙧.
Создатель WayDev

Если найдется строка, то паблик выдаст лог в консоль. Сделал вывод координат, на которые спавнится Т/С, и не только.
Немного переписал функцию проверки.

 

Спойлер

CMD:fix(playerid, params[]) {
    new query[120];
    if(sscanf(params, "ud", params[0], params[1])) 
        return SendClientMessage(playerid, -1, "Используйте: /fix [playerid] [vehid]");

    format(query, sizeof(query), "SELECT * FROM `user_veh` WHERE `owner` = '%s'", Player[params[0]][nick]);
    mysql_function_query(mysql, query, true, "check", "ii", params[0], params[1]);
    SendClientMessage(params[0], -1, "true");
    return 1;
}

forward check(playerid, vehicleid);
public check(playerid, vehicleid) {
    new rows, fields;
    cache_get_data(rows, fields);

    if(rows) {
        for(new i; i < rows; i++) {
            vInfo[i][vModel] = cache_get_field_content_int(0, "vModel", mysql);
            if(vInfo[i][vModel] != vehicleid) {
                vInfo[i][vModel] = 0;
                continue;
            }

            vInfo[i][vID] = cache_get_field_content_int(0, "vID", mysql);
            vInfo[i][owner] = cache_get_field_content(0, "owner", Player[i][nick], mysql);
            vInfo[i][x] = cache_get_field_content_float(0, "x", mysql);
            vInfo[i][y] = cache_get_field_content_float(0, "y", mysql);
            vInfo[i][z] = cache_get_field_content_float(0, "z", mysql);
            vInfo[i][vColor2] = cache_get_field_content_int(0, "vColor1", mysql);
            vInfo[i][vColor2] = cache_get_field_content_int(0, "vColor2", mysql);

            AddStaticVehicle(vInfo[i][vModel], vInfo[i][x], vInfo[i][y], vInfo[i][z], 0.0, vInfo[i][vColor1], vInfo[i][vColor2]);
            printf("[public check]: vModel: %d; x: %2.f; y: %2.f; z: %2.f; vColor1: %d; vColor2: %d;", vInfo[i][vModel], vInfo[i][x], vInfo[i][y], vInfo[i][z], vInfo[i][vColor1], vInfo[i][vColor2]);
        }
    }
    else return print("[public check]: not found;");
    return 1;
}

 

 

Отредактировано пользователем glvde.

Поделиться сообщением


Ссылка на сообщение
  • 0
Sleash
Завсегдатый

new query[120];
mysql_function_query(mysql,query,true,"loadveh","");

Этот список действий должен помочь:

I. В OnGameModeInit вместо вызова стока, впишите запрос в БД через паблик:

new query[120];
mysql_function_query(mysql,query,true,"loadveh","");

II. Уберите stock с loadveh и объявите его как паблик (не забудьте про forward)

III. Уберите в loadveh следующую строчку:

mysql_query(mysql,"SELECT * FROM `user_veh`");

Ах да, лучше в loadveh сделать такой цикл:

 new rows,fields;
cache_get_data(rows,fields);
for(int i; i < rows; i++)
{
    //...
}
// P.S. не помню в объявлении должно быть < или <=, проверьте, будет ли спавниться последняя машина

 

Отредактировано пользователем Sleash`en

Поделиться сообщением


Ссылка на сообщение
  • 0
Antoxa39
Dance 80-90, mmm Nice)

@Sleash`en но есть баг,что если допустим в бд 2 машины, у них разные модели, допустим одна 402, другая 415 ид, и владельцы разные при включении серва спавнятся 2 машины, то только 402 ид

Поделиться сообщением


Ссылка на сообщение
  • 0
Sleash
Завсегдатый

@Antoxa39 Спавн авто у вас в паблике check, но туда код приходит от команды fx/fix, а вы там sscanf не прописали

Да-да, sscanf нужен не только для проверки того, написал ли игрок данные, но и присвоевает эти данные к переменным

Поделиться сообщением


Ссылка на сообщение
  • 0
Sleash
Завсегдатый

@Antoxa39 Спавн авто у вас в паблике check, но туда код приходит от команды fx/fix, а вы там sscanf не прописали

Да-да, sscanf нужен не только для проверки того, написал ли игрок данные, но и присвоевает эти данные к переменным

Поделиться сообщением


Ссылка на сообщение
Гость
Эта тема закрыта для публикации ответов.
  • Последние посетители   0 пользователей онлайн

    Ни одного зарегистрированного пользователя не просматривает данную страницу

  • Похожий контент

    • patrickk
      От patrickk
      Всем привет, решил написать dm сервер и довольно хорошим получился, даже на голову выше Goat dm. Оставил не решенную проблему тем что  у меня есть 4 локации с rp run и cj run ну а как добавить cj бег на те локации не знаю и как эта система работает. Надеюсь мне помогут знающие люди
    • Samolet
      От Samolet
      Здраствуйте, cоздаю копию Arizona на ОМП, опен мультиплеер, загрузил и подключил бд, но сервер не хочет вот лог :[2026-10-20T21:03:32+0300] [Info] Log file reloaded. Starting open.mp server (1.5.8.3079) from commit c6759bd8d265171ae3d86598895a23d5a8d92a3b Loading component $CAPI.so Successfully loaded component C-API (1.5.8.3079) with UID 10467dd8d4c56fc6 Loading component LegacyConfig.so Successfully loaded component LegacyConfig (1.5.8.3079) with UID 24ef6216838f9ffc Loading component NPCs.so Successfully loaded component NPCs (1.5.8.3079) with UID 3d0e59e87f4e90bc Loading component Recordings.so Successfully loaded component Recordings (1.5.8.3079) with UID 871144d399f5f613 Loading component Checkpoints.so Successfully loaded component Checkpoints (1.5.8.3079) with UID 44a937350d611dde Loading component TextDraws.so Successfully loaded component TextDraws (1.5.8.3079) with UID 9b5dc2b1d15c992a Loading component Pawn.so Successfully loaded component Pawn (1.5.8.3079) with UID 78906cd9f19c36a6 Loading component GangZones.so Successfully loaded component GangZones (1.5.8.3079) with UID b3351d11ee8d8056 Loading component Actors.so Successfully loaded component Actors (1.5.8.3079) with UID c81ca021eae2ad5c Loading component Pickups.so Successfully loaded component Pickups (1.5.8.3079) with UID cf304faa363dd971 Loading component Dialogs.so Successfully loaded component Dialogs (1.5.8.3079) with UID 44a111350d611dde Loading component Objects.so Successfully loaded component Objects (1.5.8.3079) with UID 59f8415f72da6160 Loading component Console.so Successfully loaded component Console (1.5.8.3079) with UID bfa24e49d0c95ee4 Loading component TextLabels.so Successfully loaded component TextLabels (1.5.8.3079) with UID a0c57ea80a009742 Loading component Variables.so Successfully loaded component Variables (1.5.8.3079) with UID 75e121848bc01fa2 Loading component Databases.so Successfully loaded component Databases (1.5.8.3079) with UID 80092e7eb5821a96 Loading component LegacyNetwork.so Successfully loaded component RakNetLegacyNetwork (1.5.8.3079) with UID ea9799fd79cf8442 Loading component CustomModels.so Successfully loaded component CustomModels (1.5.8.3079) with UID 15e3cb1e7c77ffff Loading component Menus.so Successfully loaded component Menus (1.5.8.3079) with UID 621e219eb97ee0b2 Loading component Vehicles.so Successfully loaded component Vehicles (1.5.8.3079) with UID 3f1f62ee9e22ab19 Loading component Classes.so Successfully loaded component Classes (1.5.8.3079) with UID 8cfb3183976da208 Loading component Timers.so Successfully loaded component Timers (1.5.8.3079) with UID 2ad8124c5ea257a3 Loaded 22 component(s) from /home/gs113492/components Executing Server Config... [2026-10-20T21:03:33+0300] [Info] Loading plugin: crashdetect.so [2026-10-20T21:03:33+0300] [Info] CrashDetect plugin 4.19 [2026-10-20T21:03:33+0300] [Info] Loading plugin: mapandreas.so [2026-10-20T21:03:33+0300] [Info] Loading plugin: streamer.so [2026-10-20T21:03:33+0300] [Info] *** Streamer Plugin v2.9.4 by Incognito loaded *** [2026-10-20T21:03:33+0300] [Info] Loading plugin: sscanf.so [2026-10-20T21:03:33+0300] [Info] [2026-10-20T21:03:33+0300] [Info] =============================== [2026-10-20T21:03:33+0300] [Info] sscanf plugin loaded. [2026-10-20T21:03:33+0300] [Info] Version: 2.8.3 [2026-10-20T21:03:33+0300] [Info] (c) 2018 Alex "Y_Less" Cole [2026-10-20T21:03:33+0300] [Info] =============================== [2026-10-20T21:03:33+0300] [Info] Loading plugin: TOTP.so [2026-10-20T21:03:33+0300] [Info] TOTP plugin v1.0.1 by Games loaded. [2026-10-20T21:03:33+0300] [Info] Loading plugin: mysql_static.so [2026-10-20T21:03:33+0300] [Info] >> plugin.mysql: R39-6 successfully loaded. [2026-10-20T21:03:33+0300] [Info] Loading plugin: libpawn_json.so [2026-10-20T21:03:34+0300] [Error] Function not registered: YSF_SetTickRate [2026-10-20T21:03:34+0300] [Error] Function not registered: PC_Init [2026-10-20T21:03:34+0300] [Info] [debug] Run time error 19: "File or function is not found" [2026-10-20T21:03:34+0300] [Info] [debug] PC_Init [2026-10-20T21:03:34+0300] [Info] [debug] YSF_SetTickRate [2026-10-20T21:03:34+0300] [Error] File or function is not found [2026-10-20T21:03:34+0300] [Error] Function not registered: PC_RegAlias [2026-10-20T21:03:34+0300] [Error] Function not registered: BS_GetWriteOffset [2026-10-20T21:03:34+0300] [Error] Function not registered: BS_Reset [2026-10-20T21:03:34+0300] [Error] Function not registered: PR_RegHandler [2026-10-20T21:03:34+0300] [Error] Function not registered: BS_Delete [2026-10-20T21:03:34+0300] [Error] Function not registered: BS_New [2026-10-20T21:03:34+0300] [Error] Function not registered: BS_ResetReadPointer [2026-10-20T21:03:34+0300] [Error] Function not registered: BS_SetWriteOffset [2026-10-20T21:03:34+0300] [Error] Function not registered: BS_IgnoreBits [2026-10-20T21:03:34+0300] [Error] Function not registered: PR_Init [2026-10-20T21:03:34+0300] [Error] Function not registered: PR_SendRPC [2026-10-20T21:03:34+0300] [Error] Function not registered: PR_SendPacket [2026-10-20T21:03:34+0300] [Error] Function not registered: BS_WriteValue [2026-10-20T21:03:34+0300] [Error] Function not registered: BS_GetNumberOfBytesUsed [2026-10-20T21:03:34+0300] [Error] Function not registered: BS_ReadValue [2026-10-20T21:03:34+0300] [Error] Function not registered: PC_Init [2026-10-20T21:03:34+0300] [Info] [debug] Run time error 19: "File or function is not found" [2026-10-20T21:03:34+0300] [Info] [debug] PC_Init [2026-10-20T21:03:34+0300] [Info] [debug] BS_ReadValue [2026-10-20T21:03:34+0300] [Info] [debug] BS_GetNumberOfBytesUsed [2026-10-20T21:03:34+0300] [Info] [debug] BS_WriteValue [2026-10-20T21:03:34+0300] [Info] [debug] PR_SendPacket [2026-10-20T21:03:34+0300] [Info] [debug] PR_SendRPC [2026-10-20T21:03:34+0300] [Info] [debug] PR_Init [2026-10-20T21:03:34+0300] [Info] [debug] BS_IgnoreBits [2026-10-20T21:03:34+0300] [Info] [debug] BS_SetWriteOffset [2026-10-20T21:03:34+0300] [Info] [debug] BS_ResetReadPointer [2026-10-20T21:03:34+0300] [Info] [debug] BS_New [2026-10-20T21:03:34+0300] [Info] [debug] BS_Delete [2026-10-20T21:03:34+0300] [Info] [debug] PR_RegHandler [2026-10-20T21:03:34+0300] [Info] [debug] BS_Reset [2026-10-20T21:03:34+0300] [Info] [debug] BS_GetWriteOffset [2026-10-20T21:03:34+0300] [Info] [debug] PC_RegAlias [2026-10-20T21:03:34+0300] [Error] File or function is not found [2026-10-20T21:03:34+0300] [Info] [debug] Run time error 19: "File or function is not found" [2026-10-20T21:03:34+0300] [Info] [debug] PC_Init [2026-10-20T21:03:34+0300] [Info] [debug] YSF_SetTickRate [2026-10-20T21:03:34+0300] [Error] File or function is not found [2026-10-20T21:03:34+0300] [Info] [debug] Run time error 19: "File or function is not found" [2026-10-20T21:03:34+0300] [Info] [debug] PC_Init [2026-10-20T21:03:34+0300] [Info] [debug] BS_ReadValue [2026-10-20T21:03:34+0300] [Info] [debug] BS_GetNumberOfBytesUsed [2026-10-20T21:03:34+0300] [Info] [debug] BS_WriteValue [2026-10-20T21:03:34+0300] [Info] [debug] PR_SendPacket [2026-10-20T21:03:34+0300] [Info] [debug] PR_SendRPC [2026-10-20T21:03:34+0300] [Info] [debug] PR_Init [2026-10-20T21:03:34+0300] [Info] [debug] BS_IgnoreBits [2026-10-20T21:03:34+0300] [Info] [debug] BS_SetWriteOffset [2026-10-20T21:03:34+0300] [Info] [debug] BS_ResetReadPointer [2026-10-20T21:03:34+0300] [Info] [debug] BS_New [2026-10-20T21:03:34+0300] [Info] [debug] BS_Delete [2026-10-20T21:03:34+0300] [Info] [debug] PR_RegHandler [2026-10-20T21:03:34+0300] [Info] [debug] BS_Reset [2026-10-20T21:03:34+0300] [Info] [debug] BS_GetWriteOffset [2026-10-20T21:03:34+0300] [Info] [debug] PC_RegAlias [2026-10-20T21:03:34+0300] [Info] Legacy Network started on ***.**.**.***:2717. Помогите пожалуйста