(Fsc) Система личных автомобилей

Готовые решения скриптов, filterScript

Moderator: SJplayer

Avatar
Topic author
SJplayer M
Модератор
Модератор
Posts: 191
With us: 7 years 4 months

(Fsc) Система личных автомобилей

Post #1by SJplayer » 3 Jul 2013, 16:49

(Fsc) Система личных автомобилей
Автор: Seregamil

phpBB [media]


Все хранится в одной базе данных сохранение на a_sampdb
В системе : покупка/продажа/создание/парковка/смена цвета/починка

Команды:

Code: Select all

/car [id] - создать машину обычную  
/create [money] - из этой машины создать личную, money = стоимости  
/asellcar [id] - продать машину по ее ID(указан в 3D тексте)


Код

Code: Select all

/*
Car system - a_sampdb

By Seregamil
*/

#include <a_samp>

main(){}

#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 base "cars.db"
#define m_car 500

new loaded;
new DB: cars;

new CarNames[][] =
{
    "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "Sentinel",
    "Dumper", "Firetruck", "Trashmaster", "Stretch", "Manana", "Infernus",
    "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam",
    "Esperanto", "Taxi", "Washington", "Bobcat", "Whoopee", "BF Injection",
    "Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus",
    "Rhino", "Barracks", "Hotknife", "Trailer", "Previon", "Coach", "Cabbie",
    "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral",
    "Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder",
    "Reefer", "Tropic", "Flatbed", "Yankee", "Caddy", "Solair", "Berkley's RC Van",
    "Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale",
    "Oceanic","Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy",
    "Hermes", "Sabre", "Rustler", "ZR-350", "Walton", "Regina", "Comet", "BMX",
    "Burrito", "Camper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper",
    "Rancher", "FBI Rancher", "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking",
    "Blista Compact", "Police Maverick", "Boxvillde", "Benson", "Mesa", "RC Goblin",
    "Hotring Racer A", "Hotring Racer B", "Bloodring Banger", "Rancher", "Super GT",
    "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropduster", "Stunt",
     "Tanker", "Roadtrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra",
     "FCR-900", "NRG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune",
     "Cadrona", "FBI Truck", "Willard", "Forklift", "Tractor", "Combine", "Feltzer",
     "Remington", "Slamvan", "Blade", "Freight", "Streak", "Vortex", "Vincent",
    "Bullet", "Clover", "Sadler", "Firetruck", "Hustler", "Intruder", "Primo",
    "Cargobob", "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite",
    "Windsor", "Monster", "Monster", "Uranus", "Jester", "Sultan", "Stratium",
    "Elegy", "Raindance", "RC Tiger", "Flash", "Tahoma", "Savanna", "Bandito",
    "Freight Flat", "Streak Carriage", "Kart", "Mower", "Dune", "Sweeper",
    "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley", "Stafford", "BF-400",
    "News Van", "Tug", "Trailer", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club",
    "Freight Box", "Trailer", "Andromada", "Dodo", "RC Cam", "Launch", "Police Car",
     "Police Car", "Police Car", "Police Ranger", "Picador", "S.W.A.T", "Alpha",
     "Phoenix", "Glendale", "Sadler", "Luggage", "Luggage", "Stairs", "Boxville",
     "Tiller", "Utility Trailer"
};

enum ca{car,ID,Float:x,Float:y,Float:z,Float:a,clr1,clr2,own[24],Text3D:TXT,price,sell,perdi};

new cinfo[m_car][ca];

public OnGameModeInit()
{
    loaded = 0;
    if(fexist(base)) cars = db_open(base);
    else{
        cars = db_open(base);
        db_query(cars, "CREATE TABLE cars (PERSONAL int, ID int, X float, Y float, Z float, A float, COLOR1 int, COLOR2 int, PRICE int, SELL int, OWNER varchar)");
    }
    new DBResult:qresult;
    qresult = db_query(cars,"SELECT * FROM `cars`");
    new buffer[150];
    new i;
    while(i!=db_num_rows(qresult)){
        db_get_field_assoc(qresult, "PERSONAL", buffer, sizeof(buffer));
        cinfo[i][perdi] = strval(buffer);

        db_get_field_assoc(qresult, "ID", buffer, sizeof(buffer));
        cinfo[i][ID] = strval(buffer);
        
        db_get_field_assoc
(qresult, "X", buffer, sizeof(buffer));
        cinfo[i][x] = floatstr(buffer);
        
        db_get_field_assoc
(qresult, "Y", buffer, sizeof(buffer));
        cinfo[i][y] = floatstr(buffer);
        
        db_get_field_assoc
(qresult, "Z", buffer, sizeof(buffer));
        cinfo[i][z] = floatstr(buffer);
        
        db_get_field_assoc
(qresult, "A", buffer, sizeof(buffer));
        cinfo[i][a] = floatstr(buffer);
        
        db_get_field_assoc
(qresult, "COLOR1", buffer, sizeof(buffer));
        cinfo[i][clr1] = strval(buffer);
        
        db_get_field_assoc
(qresult, "COLOR2", buffer, sizeof(buffer));
        cinfo[i][clr2] = strval(buffer);
        
        db_get_field_assoc
(qresult, "PRICE", buffer, sizeof(buffer));
        cinfo[i][price] = strval(buffer);
        
        db_get_field_assoc
(qresult, "SELL", buffer, sizeof(buffer));
        cinfo[i][sell] = strval(buffer);
        
        db_get_field_assoc
(qresult, "OWNER", buffer, sizeof(buffer));
        format(cinfo[i][own],24,"%s",buffer);
        
        cinfo
[i][car] = CreateVehicle(cinfo[i][ID],cinfo[i][x],cinfo[i][y],cinfo[i][z],cinfo[i][a],cinfo[i][clr1],cinfo[i][clr2],9999999);

        new string[256];
        format(string, 256, "{00ff00}ID: {ffffff}%d\n{00ff00}Владелец: {ffffff}%s\n{00ff00}Стоймость: {ffffff}%d\n{00ff00}Цена продажи: {ffffff}%d", cinfo[i][perdi],cinfo[i][own],cinfo[i][price],cinfo[i][sell]);
        cinfo[i][TXT] = Create3DTextLabel(string, -1, cinfo[i][x], cinfo[i][y], cinfo[i][z], 20.0, 0, 1);
        
        Attach3DTextLabelToVehicle
(cinfo[i][TXT], cinfo[i][car], 0, 0, 0);
        //printf("%d,%f,%f,%f,%f,%d,%d,%d,%d,%s",cinfo[i][ID],cinfo[i][x],cinfo[i][y],cinfo[i][z],cinfo[i][a],cinfo[i][clr1],cinfo[i][clr2],cinfo[i][price],cinfo[i][sell],cinfo[i][own]);
        db_next_row(qresult);
        loaded++;
        i++;
    }
    db_free_result(qresult);
    return 1;
}

public OnGameModeExit()
{
    db_close(cars);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    SetPlayerPos(playerid,-285.4013,1562.1003,75.7344);
    GivePlayerMoney(playerid,9999999);
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(car,3,cmdtext);
    dcmd(create,6,cmdtext);
    dcmd(asellcar,8,cmdtext);
    return 0;
}

dcmd_asellcar(playerid,params[]){
    if(!IsPlayerAdmin(playerid)) return false;
    if(!strlen(params)) return SendClientMessage(playerid,-1,"/asellcar [id]");
    if(strval(params) > loaded) return SendClientMessage(playerid,-1,"Отсутствует такая тачка");
    new DBResult: okay;
    new query[512];
    format(query,sizeof(query),"UPDATE `cars` SET `OWNER` = 'Nobody' WHERE `PERSONAL` = '%d'", strval(params));
    okay = db_query(cars,query);
    db_free_result(okay);

    format(cinfo[strval(params)][own],24,"Nobody");

    new string[256];
    format(string, 256, "{00ff00}ID: {ffffff}%d\n{00ff00}Владелец: {ffffff}%s\n{00ff00}Стоймость: {ffffff}%d\n{00ff00}Цена продажи: {ffffff}%d", cinfo[strval(params)][perdi],cinfo[strval(params)][own],cinfo[strval(params)][price],cinfo[strval(params)][sell]);
    Update3DTextLabelText(cinfo[strval(params)][TXT],-1,string);
    return true;
}

dcmd_create(playerid,params[]){
    if(!IsPlayerAdmin(playerid)) return false;
    if(!IsPlayerInAnyVehicle(playerid)) return false;
    for(new i;i!=m_car;i++){
        if(GetPlayerVehicleID(playerid) != cinfo[i][car]){
            if(!strlen(params)) return SendClientMessage(playerid,-1,"Укажите цену для покупки");
            if(strval(params)< 10000) return SendClientMessage(playerid,-1,"Не меньше 10000$");
            new selle = strval(params) / 2;
            new Query[256];
            new Float:pos[4];
            new local = GetVehicleModel(GetPlayerVehicleID(playerid));
            GetVehiclePos(GetPlayerVehicleID(playerid),pos[0],pos[1],pos[2]);
            GetVehicleZAngle(GetPlayerVehicleID(playerid), pos[3]);
            format(Query, sizeof(Query), "INSERT INTO `cars` (`PERSONAL`, `ID`, `X`, `Y`, `Z`, `A`, `COLOR1`, `COLOR2`, `PRICE`, `SELL`, `OWNER`)VALUES('%d','%d','%f','%f','%f','%f','%d','%d','%d','%d','%s')",loaded, local, pos[0],pos[1],pos[2],pos[3],random(100),random(100),strval(params),selle,"Nobody");
            db_query(cars, Query);
            DestroyVehicle(GetPlayerVehicleID(playerid));

            cinfo[loaded][perdi] = loaded;
            cinfo[loaded][ID] = local;
            cinfo[loaded][x] = pos[0];
            cinfo[loaded][y] = pos[1];
            cinfo[loaded][z] = pos[2];
            cinfo[loaded][a] = pos[3];
            cinfo[loaded][clr1] = random(100);
            cinfo[loaded][clr2] = random(100);
            cinfo[loaded][price] = strval(params);
            cinfo[loaded][sell] = selle;
            format(cinfo[loaded][own],24,"Nobody");
            cinfo[loaded][car] = CreateVehicle(cinfo[loaded][ID],cinfo[loaded][x],cinfo[loaded][y],cinfo[loaded][z],cinfo[loaded][a],cinfo[loaded][clr1],cinfo[loaded][clr2],9999999);
            new string[256];
            format(string, 256, "{00ff00}ID: {ffffff}%d\n{00ff00}Владелец: {ffffff}%s\n{00ff00}Стоймость: {ffffff}%d\n{00ff00}Цена продажи: {ffffff}%d", loaded,cinfo[loaded][own],cinfo[loaded][price],cinfo[loaded][sell]);
            cinfo[loaded][TXT] = Create3DTextLabel(string, -1, cinfo[loaded][x], cinfo[loaded][y], cinfo[loaded][z], 20.0, 0, 1);
            Attach3DTextLabelToVehicle(cinfo[loaded][TXT], cinfo[loaded][car], 0, 0, 0);
            //printf("%d,%f,%f,%f,%f,%d,%d,%d,%d,%s",cinfo[loaded][ID],cinfo[loaded][x],cinfo[loaded][y],cinfo[loaded][z],cinfo[loaded][a],cinfo[loaded][clr1],cinfo[loaded][clr2],cinfo[loaded][price],cinfo[loaded][sell],cinfo[loaded][own]);
            loaded++;
            break;
        }
    }
    return true;
}

dcmd_car(playerid,params[]){
    if(!strlen(params)) return false;
    if(!IsPlayerAdmin(playerid)) return false;
    if(strval(params) < 400 || strval(params) > 611) return SendClientMessage(playerid,-1,"400 - 611");
    new Float:pos[4];
    GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
    GetPlayerFacingAngle(playerid,pos[3]);
    PutPlayerInVehicle(playerid,CreateVehicle(strval(params),pos[0],pos[1],pos[2],pos[3],1,1,99999),0);
    return true;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys){
    if(newkeys & KEY_NO){
        if(IsPlayerInAnyVehicle(playerid)){
            for(new i;i!=m_car;i++){
                if(GetPlayerVehicleID(playerid) == cinfo[i][car]){
                    new str[100];
                    format(str,100,"%s",CarNames[GetVehicleModel(GetPlayerVehicleID(playerid))-400]);
                    ShowPlayerDialog(playerid,612,DIALOG_STYLE_LIST,str,">>> Починка\n>>> Сменить цвет\n>>> Припарковать\n>>> Продать","Выбор","Отмена");
                    break;
                }
            }
        }
    }
    return true;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER){
        for(new i;i!=m_car;i++){
            if(GetPlayerVehicleID(playerid) == cinfo[i][car]){
                new name[24];
                GetPlayerName(playerid,name,24);
                if(strcmp(cinfo[i][own], "Nobody", true)==0){
                    new str[128];
                    format(str,128,"{ffffff}Вы желаете приобрести {00ff00}%s {ffffff}за {00ff00}%d$?",CarNames[GetVehicleModel(GetPlayerVehicleID(playerid))-400],cinfo[i][price]);
                    ShowPlayerDialog(playerid,611,DIALOG_STYLE_MSGBOX,"  ",str,"Покупка", "Отмена");
                    break;
                }
                else if(strcmp(cinfo[i][own], name, true)==0) break;
                else {
                    RemovePlayerFromVehicle(playerid);
                    break;
                }
            }
            else continue;
        }
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 611){
        if(!response) return RemovePlayerFromVehicle(playerid);
        else{
            for(new i;i!=m_car;i++){
                if(GetPlayerVehicleID(playerid) == cinfo[i][car]){
                    if(GetPlayerMoney(playerid)<cinfo[i][price]) {
                        SendClientMessage(playerid,-1,"Недостаточно средств");
                        RemovePlayerFromVehicle(playerid);
                        break;
                    }

                    GivePlayerMoney(playerid,-cinfo[i][price]);

                    new name[24];
                    GetPlayerName(playerid,name,24);

                    cinfo[i][own] = name;
                    new string[256];
                    format(string, 256, "{00ff00}ID: {ffffff}%d\n{00ff00}Владелец: {ffffff}%s\n{00ff00}Стоймость: {ffffff}%d\n{00ff00}Цена продажи: {ffffff}%d", cinfo[i][perdi],cinfo[i][own],cinfo[i][price],cinfo[i][sell]);
                    Update3DTextLabelText(cinfo[i][TXT],-1,string);

                    new DBResult: okay;
                    new query[512];
                    format(query,sizeof(query),"UPDATE `cars` SET `OWNER` = '%s' WHERE `PERSONAL` = '%d'", cinfo[i][own], cinfo[i][perdi]);
                    okay = db_query(cars,query);
                    db_free_result(okay);
                    new str[256];
                    format(str,256,"{ffffff}Вы приобрели {00ff00}%s {ffffff}за {00ff00}%d$",CarNames[GetVehicleModel(GetPlayerVehicleID(playerid))-400],cinfo[i][price]);
                    SendClientMessage(playerid,-1,str);
                    break;
                }
            }
        }
    }
    if(dialogid == 612){
        if(response){
            switch(listitem){
                case 0:{//repair
                    SetVehicleHealth(GetPlayerVehicleID(playerid),1000);
                    RepairVehicle(GetPlayerVehicleID(playerid));
                    SendClientMessage(playerid,-1,"Починено!");
                }
                case 1:{//change color
                    ShowPlayerDialog(playerid,613,DIALOG_STYLE_INPUT,"Введите 1 цвет","  ","Дальше","Отмена");
                }
                case 2:{//park
                    for(new i;i!=m_car;i++){
                        if(GetPlayerVehicleID(playerid) == cinfo[i][car]){
                            new Float:pos[4];
                            GetVehiclePos(cinfo[i][car],pos[0],pos[1],pos[2]);
                            GetVehicleZAngle(cinfo[i][car], pos[3]);
                            new DBResult: okay;
                            new query[512];
                            format(query,sizeof(query),"UPDATE `cars` SET `X` = '%f', `Y` = '%f', `Z` = '%f', `A` = '%f' WHERE `PERSONAL` = '%d'", pos[0],pos[1],pos[2],pos[3], i);
                            okay = db_query(cars,query);
                            db_free_result(okay);
                            cinfo[i][x] = pos[0];
                            cinfo[i][y] = pos[1];
                            cinfo[i][z] = pos[2];
                            cinfo[i][a] = pos[3];
                            SendClientMessage(playerid,-1,"Припаркованно!");
                            break;
                        }
                    }
                }
                case 3:{//sell
                    for(new i;i!=m_car;i++){
                        if(GetPlayerVehicleID(playerid) == cinfo[i][car]){
                            new name[24];
                            GetPlayerName(playerid,name,24);
                            if(strcmp(cinfo[i][own], name, true)==0){

                                new DBResult: okay;
                                new query[512];
                                format(query,sizeof(query),"UPDATE `cars` SET `OWNER` = 'Nobody' WHERE `PERSONAL` = '%d'", i);
                                okay = db_query(cars,query);
                                db_free_result(okay);

                                GivePlayerMoney(playerid,cinfo[i][sell]);
                                format(cinfo[i][own],24,"Nobody");

                                new string[256];
                                format(string, 256, "{00ff00}ID: {ffffff}%d\n{00ff00}Владелец: {ffffff}%s\n{00ff00}Стоймость: {ffffff}%d\n{00ff00}Цена продажи: {ffffff}%d", cinfo[i][perdi],cinfo[i][own],cinfo[i][price],cinfo[i][sell]);
                                Update3DTextLabelText(cinfo[i][TXT],-1,string);
                            
                                SendClientMessage
(playerid,-1,"Продано!");
                                RemovePlayerFromVehicle(playerid);
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    if(dialogid == 613){
        if(response){
            if(!strlen(inputtext)) return ShowPlayerDialog(playerid,613,DIALOG_STYLE_INPUT,"Введите 1 цвет","  ","Дальше","Отмена");
            if(strval(inputtext) < 0 || strval(inputtext) > 255) return ShowPlayerDialog(playerid,613,DIALOG_STYLE_INPUT,"Введите 1 цвет","  ","Дальше","Отмена");
            SetPVarInt(playerid,"ColorPaint",strval(inputtext));
            ShowPlayerDialog(playerid,614,DIALOG_STYLE_INPUT,"Введите второй текст","  ","Установить", "Назад");
        }
    }
    if(dialogid == 614){
        if(!response) return ShowPlayerDialog(playerid,613,DIALOG_STYLE_INPUT,"Введите 1 цвет","  ","Дальше","Отмена");
        if(!strlen(inputtext)) return ShowPlayerDialog(playerid,614,DIALOG_STYLE_INPUT,"Введите второй текст","  ","Установить", "Назад");
         if(strval(inputtext) < 0 || strval(inputtext) > 255) return ShowPlayerDialog(playerid,614,DIALOG_STYLE_INPUT,"Введите второй текст","  ","Установить", "Назад");
        ChangeVehicleColor(GetPlayerVehicleID(playerid),GetPVarInt(playerid,"ColorPaint"),strval(inputtext));
        for(new i;i!=m_car;i++){
            if(GetPlayerVehicleID(playerid) == cinfo[i][car]){
                new DBResult: okay;
                new query[512];
                format(query,sizeof(query),"UPDATE `cars` SET `COLOR1` = '%d', `COLOR2` = '%d' WHERE `PERSONAL` = '%d'", GetPVarInt(playerid,"ColorPaint"),strval(inputtext),cinfo[i][perdi]);
                okay = db_query(cars,query);
                db_free_result(okay);
                DeletePVar(playerid,"ColorPaint");
            }
        }
    }
    return 1;
}

! ! !


  • Similar Topics
    Replies
    Views
    Last post

Return to “Скрипты / FS”

Who is online

Users browsing this forum: 1 guest