[FS] Advanced GPS System

Stich

Администратор
Команда форума
Администратор
Сообщения
8
Баллы
168
Краткое описание:
Весьма интересный скрипт, который идеально впишется на сервер с любым жанром.
GPS со стрелкой поворачивающейся к месту назначения и указывающий расстояние до цели.
Скрипт работает на SQL и настраивается прямо из игры.

Команды:
/gps - включить gps
/turnoff - отключить gps
/fsave [имя] - создать новую локацию в gps
/fedit [старое имя] , [новое имя] - переименовать существующую локацию

Код скрипта:
Код:
#include <a_samp>
#include <a_sampdb>

#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

#define GPSFile ("Positions.db") //Файл в который происходит сохранение
#define MAX_LOCATIONS 50 //Максимальное кол-во локаций
#define UseTd // Поставь в начало этой строки   //  если не хочешь использовать TextDraw
#define GPSDialogID 1111
enum FGPS
{
    ID,
    Float: LocationX,
    Float: LocationY,
    Float: LocationZ,
    PlaceName[128]
};

new GPSInfo[MAX_LOCATIONS][FGPS];
new DB:GPSDB;
new gValue[128];
new GPSObject[MAX_PLAYERS];
#if defined UseTd
    new Text:GPSTD;
#endif

stock Float:PointAngle(playerid, Float:xa, Float:ya, Float:xb, Float:yb)
{
    new Float:carangle;
    new Float:xc, Float:yc;
    new Float:angle;
    xc = floatabs(floatsub(xa,xb));
    yc = floatabs(floatsub(ya,yb));
    if (yc == 0.0 || xc == 0.0)
    {
        if(yc == 0 && xc > 0) angle = 0.0;
        else if(yc == 0 && xc < 0) angle = 180.0;
        else if(yc > 0 && xc == 0) angle = 90.0;
        else if(yc < 0 && xc == 0) angle = 270.0;
        else if(yc == 0 && xc == 0) angle = 0.0;
    }
    else
    {
        angle = atan(xc/yc);
        if(xb > xa && yb <= ya) angle += 90.0;
        else if(xb <= xa && yb < ya) angle = floatsub(90.0, angle);
        else if(xb < xa && yb >= ya) angle -= 90.0;
        else if(xb >= xa && yb > ya) angle = floatsub(270.0, angle);
    }
    GetVehicleZAngle(GetPlayerVehicleID(playerid), carangle);
    return floatadd(angle, -carangle);
}

stock fcreate(filename[])
{
    if (fexist(filename)){return false;}
    new File:fhandle = fopen(filename,io_write);
    fclose(fhandle);
    return true;
}

stock Float:GetDistanceBetweenPoints(Float:X, Float:Y, Float:Z, Float:PointX, Float:PointY, Float:PointZ)
{
    new Float:Distance;Distance = floatabs(floatsub(X, PointX)) + floatabs(floatsub(Y, PointY)) + floatabs(floatsub(Z, PointZ));
    return Distance;
}

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print("Freddes GPS System старт...");
    if(!fexist(GPSFile))
    {
        fcreate(GPSFile);
        printf("Файл: %s не найден... Создание!", GPSFile);
    }
    GPSDB = db_open(GPSFile);
    LoadFGPS();
    //Lets Make A Textdraw :)
    #if defined UseTd
        GPSTD = TextDrawCreate(37.000000, 290.000000, "Distance Left:~n~~n~");
        TextDrawBackgroundColor(GPSTD, 255);
        TextDrawFont(GPSTD, 1);
        TextDrawLetterSize(GPSTD, 0.509999, 1.300000);
        TextDrawColor(GPSTD, -1);
        TextDrawSetOutline(GPSTD, 1);
        TextDrawSetProportional(GPSTD, 1);
    #endif
    return 1;
}

public OnFilterScriptExit()
{
    db_close(GPSDB);
    TextDrawHideForAll(GPSTD);
    TextDrawDestroy(GPSTD);
    print("\n--------------------------------------");
    print("Freddes GPS System загружен...");
    print("\n--------------------------------------");
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(turnoff,7,cmdtext);  // выключить gps
    dcmd(gps,3,cmdtext);      // выбрать пункт назначения
    dcmd(fsave,5,cmdtext);    // создать локацию (для rcon админа)
    dcmd(fedit,5,cmdtext);    // редактировать локацию (для rcon админа)
    return 0;
}

dcmd_gps(playerid, params[])
{
    #pragma unused params
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xE60000FF, "Вы не в машине");
    if(GetPVarInt(playerid,"YEAH") == 1) return SendClientMessage(playerid, 0xE60000FF, "Введите {00CCFA}/turnoff {E60000}чтобы отключить предыдущую позицию");
    new string[128], var[2048];
    for(new g = 0; g < sizeof(GPSInfo); g++)
     {
         format(string, 128, "%s\n", GPSInfo[g][PlaceName]);
         strcat(var,string);
     }
     if(!strlen(GPSInfo[0][PlaceName])) return SendClientMessage(playerid, 0xE60000FF, "Нет локаций в базу данных");
     ShowPlayerDialog(playerid, GPSDialogID, DIALOG_STYLE_LIST, "Система GPS - выберите локацию", var, "Ок", "Отмена");
    return 1;
}

dcmd_turnoff(playerid, params[])
{
    #pragma unused params
    if(GetPVarInt(playerid,"YEAH") == 0) return SendClientMessage(playerid, 0xE60000FF, "GPS уже {00FF15}выключен{E60000}");
       DisablePlayerCheckpoint(playerid);
       DestroyObject(GPSObject[playerid]);
       SetPVarInt(playerid,"YEAH",0);
       DeletePVar(playerid,"Spongebob");
       DeletePVar(playerid,"Mario");
       DeletePVar(playerid,"SpiderPig");
       DeletePVar(playerid,"FAIL");
       #if defined UseTd
           TextDrawHideForPlayer(playerid, GPSTD);
       #endif
       SendClientMessage(playerid, 0xFFFFFFFF, "Вы отключили GPS");
    return 1;
}

dcmd_fsave(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE60000FF, "Вы не администратор");
    new Float:PPos[3], string[128], query[256];
      GetPlayerPos(playerid, PPos[0], PPos[1], PPos[2]);
    if(!strlen(params)) return SendClientMessage(playerid, 0xE60000FF, "Использование: /FSave [имя]");
    GetLastID();
       new NewID = strval(gValue);
    format(query, sizeof(query), "INSERT INTO `FGPSSystem` (`ID`,`LocationX`,`LocationY`,`LocationZ`, `Name`) VALUES('%d','%f','%f','%f','%s');",NewID,PPos[0],PPos[1],PPos[2],params);
    db_query(GPSDB,query);
    ReloadDatabase();
    format(string,sizeof(string),"Вы добавили: {00FF33}%s {FFFFFF}в базу данных", params);
    SendClientMessage(playerid, 0xFFFFFFFF, string);
    return 1;
}

dcmd_fedit(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE60000FF, "Вы не администратор");
    new string[128], query[256], tmp[2][128];
    if(!strlen(params)) return SendClientMessage(playerid, 0xE60000FF, "Использование: /Fedit [{2D03FF}Старое имя{E60000}]{F6FF00} , {E60000}[{00FF33}Новое имя{E60000}]");
    split(params, tmp, ',');
    format(query, sizeof(query), "UPDATE `FGPSSystem` SET `Name` = '%s' WHERE `Name` = '%s'",tmp[1],tmp[0]);
    db_query(GPSDB,query);
    ReloadDatabase();
    format(string,sizeof(string),"Вы изменили имя локации: {00FF33}%s {FFFFFF}на {00FF33}%s", tmp[0],tmp[1]);
    SendClientMessage(playerid, 0xFFFFFFFF, string);
    return 1;
}

public OnPlayerUpdate(playerid)
{
    if(GetPVarInt(playerid,"YEAH") == 1)
    {
        new Float:VPos[3], Float:Rotation, TDString[128];
         GetVehiclePos(GetPlayerVehicleID(playerid),VPos[0],VPos[1],VPos[2]);
         Rotation = PointAngle(playerid, VPos[0],VPos[1], GetPVarFloat(playerid,"Spongebob"), GetPVarFloat(playerid,"Mario"));
        AttachObjectToVehicle(GPSObject[playerid], GetPlayerVehicleID(playerid), 0.0, 0.0, 1.5, 0.0, 90.0, Rotation);
        #if defined UseTd
            format(TDString, sizeof(TDString), "Distance Left:~n~~n~%.1f Meters",GetDistanceBetweenPoints(VPos[0], VPos[1], VPos[2], GetPVarFloat(playerid,"Spongebob"), GetPVarFloat(playerid,"Mario"),GetPVarFloat(playerid,"SpiderPig")));
            TextDrawSetString(GPSTD, TDString);
        #endif
    }
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    if(GetPVarInt(playerid,"YEAH") == 1)
    {
        DisablePlayerCheckpoint(playerid);
        DestroyObject(GPSObject[playerid]);
        SetPVarInt(playerid,"YEAH",0);
        DeletePVar(playerid,"Spongebob");
        DeletePVar(playerid,"Mario");
        DeletePVar(playerid,"SpiderPig");
        DeletePVar(playerid,"FAIL");
        TextDrawHideForPlayer(playerid, GPSTD);
    }
    return 1;
}

stock LoadFGPS()
{
    new query[256], DBResult:qresult, count = 0, value[128];
    if(!db_query(DB: GPSDB, "SELECT * FROM `FGPSSystem`"))
    {
        print("Таблица не найдена... Создание таблицы!");
        format(query,sizeof(query),"CREATE TABLE IF NOT EXISTS `FGPSSystem` (`ID`, `LocationX`, `LocationY`, `LocationZ`, `Name`)");
         db_query(GPSDB,query);
        print("Freddes GPS System нуждается в рестарте...");
        print("--------------------------------------\n");
        SendRconCommand("exit");
    }
    else
    {
        qresult = db_query(GPSDB,  "SELECT * FROM `FGPSSystem`");
        count = db_num_rows(qresult);
        for(new a=0;a<count;a++)
        {
            if(count >= 1 && count <= MAX_LOCATIONS)
            {
                db_get_field_assoc(qresult, "ID", value, 5);                 GPSInfo[a][ID] = strval(value);
                db_get_field_assoc(qresult, "LocationX", value, 20);         GPSInfo[a][LocationX] = floatstr(value);
                db_get_field_assoc(qresult, "LocationY", value, 20);         GPSInfo[a][LocationY] = floatstr(value);
                db_get_field_assoc(qresult, "LocationZ", value, 20);          GPSInfo[a][LocationZ] = floatstr(value);
                db_get_field(qresult,4,value,128);                          strmid(GPSInfo[a][PlaceName], value, 0, strlen(value), 128);
                printf("%d, %f, %f, %f, %s", GPSInfo[a][ID],GPSInfo[a][LocationX],GPSInfo[a][LocationY],GPSInfo[a][LocationZ],GPSInfo[a][PlaceName]);
                db_next_row(qresult);
            }
        }
        db_free_result(qresult);
        print("Freddes GPS System загружен...");
        print("--------------------------------------\n");
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == GPSDialogID && response)
    {
        GetPlayerLocationFromId(playerid, listitem);
        return 1;
    }
    return 0;
}

stock GetPlayerLocationFromId(playerid,id)
{
    new Query[128], DBResult:qresult, string[128], string2[128], NameStore[128];
    format(Query,sizeof(Query),"SELECT `LocationX`, `LocationY`, `LocationZ`, `Name` FROM `FGPSSystem` WHERE ID = '%d'", id);
    qresult = db_query(GPSDB,Query);
    db_get_field_assoc(qresult,"LocationX",string,128);        SetPVarFloat(playerid,"Spongebob",floatstr(string));
    db_get_field_assoc(qresult,"LocationY",string,128);        SetPVarFloat(playerid,"Mario",floatstr(string));
    db_get_field_assoc(qresult,"LocationZ",string,128);        SetPVarFloat(playerid,"SpiderPig",floatstr(string));
    db_get_field_assoc(qresult,"Name",string,128);            SetPVarString(playerid,"FAIL",string);
    DisablePlayerCheckpoint(playerid); //To make sure it dont bug :)
    SetPlayerCheckpoint(playerid, GetPVarFloat(playerid,"Spongebob"), GetPVarFloat(playerid,"Mario"), GetPVarFloat(playerid,"SpiderPig"), 3.0);
    GetPVarString(playerid,"FAIL", NameStore, 128);
    format(string2,sizeof(string2),"Вы отметили на карте точку {00FF33}%s{FFFFFF}.", NameStore);
    SendClientMessage(playerid, 0xFFFFFFFF, string2);
     GPSObject[playerid] = CreateObject(1318, 0, 0, 0, 0.0, 0.0, 0);
      SetPVarInt(playerid,"YEAH",1);
      #if defined UseTd
          TextDrawShowForPlayer(playerid, GPSTD);
      #endif
    db_free_result(qresult);
    return 1;
}

stock ReloadDatabase()
{
    new DBResult:qresult, count = 0, value[128];
    qresult = db_query(GPSDB, "SELECT * FROM `FGPSSystem`");
    count = db_num_rows(qresult);
    for(new a=0;a<count;a++)
    {
        if(count >= 1 && count <= MAX_LOCATIONS)
        {
             db_get_field_assoc(qresult, "ID", value, 5);                 GPSInfo[a][ID] = strval(value);
            db_get_field_assoc(qresult, "LocationX", value, 20);         GPSInfo[a][LocationX] = floatstr(value);
            db_get_field_assoc(qresult, "LocationY", value, 20);         GPSInfo[a][LocationY] = floatstr(value);
            db_get_field_assoc(qresult, "LocationZ", value, 20);          GPSInfo[a][LocationZ] = floatstr(value);
            db_get_field(qresult,4,value,128);                          strmid(GPSInfo[a][PlaceName], value, 0, strlen(value), 128);
            db_next_row(qresult);
        }
    }
    db_free_result(qresult);
    return 1;
}

stock GetLastID()
{
    new DBResult:qresult, count = 0, Value[128];
    qresult = db_query(GPSDB, "SELECT * FROM `FGPSSystem` ORDER BY `ID` DESC LIMIT 1");
    count = db_num_rows(qresult);
    for(new a=0;a<count;a++)
    {
        if(count <= MAX_LOCATIONS)
        {
             db_get_field_assoc(qresult, "ID", Value, 5);    gValue[a] = Value[a]+1;
            db_next_row(qresult);
        }
    }
    db_free_result(qresult);
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    if(GetPVarInt(playerid,"YEAH") == 1)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Вы приехали в пункт назначения");
        DisablePlayerCheckpoint(playerid);
        DestroyObject(GPSObject[playerid]);
        SetPVarInt(playerid,"YEAH",0);
        DeletePVar(playerid,"Spongebob");
        DeletePVar(playerid,"Mario");
        DeletePVar(playerid,"SpiderPig");
        DeletePVar(playerid,"FAIL");
        TextDrawHideForPlayer(playerid, GPSTD);
    }
    return 1;
}

public OnPlayerStateChange(playerid,newstate,oldstate)
{
    if(newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER)
    {
           DisablePlayerCheckpoint(playerid);
           DestroyObject(GPSObject[playerid]);
           SetPVarInt(playerid,"YEAH",0);
           DeletePVar(playerid,"Spongebob");
           DeletePVar(playerid,"Mario");
           DeletePVar(playerid,"SpiderPig");
           DeletePVar(playerid,"FAIL");
           #if defined UseTd
               TextDrawHideForPlayer(playerid, GPSTD);
           #endif
    }
    return 1;
}

stock split(const strsrc[], strdest[][], delimiter)
{
    new i, li;
    new aNum;
    new len;
    while(i <= strlen(strsrc))
    {
        if(strsrc[i] == delimiter || i == strlen(strsrc))
        {
            len = strmid(strdest[aNum], strsrc, li, i, 128);
            strdest[aNum][len] = 0;
            li = i+1;
            aNum++;
        }
        i++;
    }
    return 1;
}
Скачать:

Пожалуйста, Войдите или Зарегистрируйтесь, что бы увидеть скрытый контент.

 
Верх