shape1
shape2
shape3
shape4
shape7
shape8

Система авто из Gamer


Basis

chto tut doljno bit`!?
Пользователь
24.06.2014
824
271
0
22
Для начала ко всем enum и new добавим
enum

enum cInfo
{
cID,
cOwner[MAX_PLAYER_NAME],
cModel,
cPrice,
Float:cX,
Float:cY,
Float:cZ,
Float:cA,
cColor1,
cColor2,
cInt,
cWorld,
cLock,
cNumber[64],
Float:cBenzin,
cEngine,
Float:cMilliage,
cLights,
}
new CarInfo[MAX_VEHICLES][cInfo];
new Text3D:CarLabel[MAX_VEHICLES];
new AllCars;
в OnGameModeInit

LoadCars();
в конец мода добавим пару стоков

стоки для загрузки,сохранения и для номеровstock LoadCars()
{
    new ids[32],str[64];
    new iniOpens = ini_openFile("cars.cfg");
    ini_getInteger(iniOpens, "AllCars", AllCars);
    ini_closeFile(iniOpens);
    if(AllCars != 0)
    {
        for(new car = 1; car <= AllCars; car++)
{
   format(ids,sizeof(ids),"cars/%d.ini",car);
   new inicOpen = ini_openFile(ids);
   ini_getInteger(inicOpen, "cModel", CarInfo[car][cModel]);
   ini_getFloat(inicOpen, "cX", CarInfo[car][cX]);
   ini_getFloat(inicOpen, "cY", CarInfo[car][cY]);
   ini_getFloat(inicOpen, "cZ", CarInfo[car][cZ]);
   ini_getFloat(inicOpen, "cA", CarInfo[car][cA]);
   ini_getInteger(inicOpen, "cColor1", CarInfo[car][cColor1]);
   ini_getInteger(inicOpen, "cColor2", CarInfo[car][cColor2]);
   ini_getString(inicOpen, "cOwner", str);
   format(CarInfo[car][cOwner],24,"%s",str);
   ini_getInteger(inicOpen, "cPrice", CarInfo[car][cPrice]);
   ini_getInteger(inicOpen, "cLock", CarInfo[car][cLock]);
   ini_getString(inicOpen, "cNumber", str);
        format(CarInfo[car][cNumber],64,"%s",str);
        ini_getFloat(inicOpen, "cBenzin", CarInfo[car][cBenzin]);
        ini_getFloat(inicOpen, "cMilliage", CarInfo[car][cMilliage]);
        ini_getInteger(inicOpen, "cInt", CarInfo[car][cInt]);
        ini_getInteger(inicOpen, "cWorld", CarInfo[car][cWorld]);
   ini_closeFile(inicOpen);
//==============================================================================
   if(!strcmp(CarInfo[car][cOwner],"Nones",false))
   {
CarInfo[car][cID] = CreateVehicle(CarInfo[car][cModel],CarInfo[car][cX],CarInfo[car][cY],CarInfo[car][cZ],CarInfo[car][cA],CarInfo[car][cColor1],CarInfo[car][cColor2],60000*4);
   }
            else
   {
CarInfo[car][cID] = CreateVehicle(CarInfo[car][cModel],CarInfo[car][cX],CarInfo[car][cY],CarInfo[car][cZ],CarInfo[car][cA],CarInfo[car][cColor1],CarInfo[car][cColor2],60000*4);
   }
   if(CarInfo[car][cLock] == 1)
             {
        for(new i = 0; i < MAX_PLAYERS; i++)
             {
        SetVehicleParamsForPlayer(car,i,0,1);
        }
        printf("Ìàøèí çàãðóæåíî: %d",AllCars);
}
}
}
    return 1;
}
stock SaveCars(car)
{
new ids[32];
format(ids,sizeof(ids),"cars/%d.ini",car);
new iniccOpen = ini_openFile(ids);
ini_setInteger(iniccOpen, "cModel", CarInfo[car][cModel]);
ini_setFloat(iniccOpen, "cX", CarInfo[car][cX]);
ini_setFloat(iniccOpen, "cY", CarInfo[car][cY]);
ini_setFloat(iniccOpen, "cZ", CarInfo[car][cZ]);
ini_setFloat(iniccOpen, "cA", CarInfo[car][cA]);
ini_setInteger(iniccOpen, "cColor1", CarInfo[car][cColor1]);
ini_setInteger(iniccOpen, "cColor2", CarInfo[car][cColor2]);
ini_setString(iniccOpen, "cOwner", CarInfo[car][cOwner]);
ini_setInteger(iniccOpen, "cPrice", CarInfo[car][cPrice]);
ini_setInteger(iniccOpen, "cLock", CarInfo[car][cLock]);
ini_setString(iniccOpen, "cNumber", CarInfo[car][cNumber]);
ini_setFloat(iniccOpen, "cBenzin", CarInfo[car][cBenzin]);
ini_setFloat(iniccOpen, "cMilliage", CarInfo[car][cMilliage]);
ini_setInteger(iniccOpen, "cInt", CarInfo[car][cInt]);
ini_setInteger(iniccOpen, "cWorld", CarInfo[car][cWorld]);
ini_closeFile(iniccOpen);
return true;
}
stock CreateCars(car)
{
new ids[32];
format(ids,sizeof(ids),"cars/%d.ini",car);
new iniccOpen = ini_createFile(ids);
if(iniccOpen < 0 ) iniccOpen = ini_openFile(ids);
ini_setInteger(iniccOpen, "cModel", CarInfo[car][cModel]);
ini_setFloat(iniccOpen, "cX", CarInfo[car][cX]);
ini_setFloat(iniccOpen, "cY", CarInfo[car][cY]);
ini_setFloat(iniccOpen, "cZ", CarInfo[car][cZ]);
ini_setFloat(iniccOpen, "cA", CarInfo[car][cA]);
ini_setInteger(iniccOpen, "cColor1", CarInfo[car][cColor1]);
ini_setInteger(iniccOpen, "cColor2", CarInfo[car][cColor2]);
ini_setString(iniccOpen, "cOwner", CarInfo[car][cOwner]);
ini_setInteger(iniccOpen, "cPrice", CarInfo[car][cPrice]);
ini_setInteger(iniccOpen, "cLock", CarInfo[car][cLock]);
ini_setString(iniccOpen, "cNumber", CarInfo[car][cNumber]);
ini_setFloat(iniccOpen, "cBenzin", CarInfo[car][cBenzin]);
ini_setFloat(iniccOpen, "cMilliage", CarInfo[car][cMilliage]);
ini_setInteger(iniccOpen, "cInt", CarInfo[car][cInt]);
ini_setInteger(iniccOpen, "cWorld", CarInfo[car][cWorld]);
ini_closeFile(iniccOpen);
return true;
}
stock GetRealID(carid)
{
for(new i; i < MAX_VEHICLES;i++)
{
if(CarInfo[cID] == carid)
{
return i;
}
}
return -1;
}
stock GetPlayerCar(playerid)
{
new playercars = 0;
new pName[MAX_PLAYER_NAME];
for(new i = 1; i <= AllCars; i++)
{
if(!strcmp(CarInfo[cOwner],pName,true)) playercars++, SetPVarInt(playerid, "PlayerCar", i);
}
return playercars;
}
stock LockCar(carid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SetVehicleParamsForPlayer(carid,i,0,1);
}
}
}
//==============================================================================
stock UnLockCar(carid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(!IsAPlane(carid))
{
SetVehicleParamsForPlayer(carid,i,0,0);
}
}
}
}
stock randomchar()
{
new rand; rand = random(12);
new chr[200];
switch(rand)
{
case 0: format(chr,200,"%s","À");
case 1: format(chr,200,"%s","Á");
case 2: format(chr,200,"%s","Â");
case 3: format(chr,200,"%s","Ã");
case 4: format(chr,200,"%s","Ä");
case 5: format(chr,200,"%s","Ê");
case 6: format(chr,200,"%s","Ë");
case 7: format(chr,200,"%s","Ì");
case 8: format(chr,200,"%s","Í");
case 9: format(chr,200,"%s","Î");
case 10: format(chr,200,"%s","Ï");
case 11: format(chr,200,"%s","Ð");
}
return chr;
}[/spoiler]ко всем диалогам
if(dialogid == 24)
{
if(response)
{
new cars = GetPVarInt(playerid,"cars_sell");
   new price = (CarInfo[GetRealID(cars)][cPrice]/2);
RemovePlayerFromVehicle(playerid);
GivePlayerMoney(playerid,price);
Player[playerid][pMoney] += price;
strmid(CarInfo[GetRealID(cars)][cOwner],"Nones",0,strlen("Nones"),24);
SendClientMessage(playerid, COLOR_YELLOW, "Âû óñïåøíî ïðîäàëè ñâîþ ìàøèíó");
CarInfo[GetRealID(cars)][cLock] = 0;
SaveCars(GetRealID(cars));
DeletePVar(playerid,"cars_sell");
format(string, sizeof(string), "Ò/Ñ íà ïðîäàæå");
Update3DTextLabelText(CarLabel[CarInfo[GetRealID(cars)][cID]], 0xFFFF00FF, string);
return true;
}
else
{
DeletePVar(playerid,"cars_sell");
SendClientMessage(playerid, COLOR_GRAD2, "Âû îòêàçàëèñü îò ïðîäàæè!");
return true;
}
}

в OnPlayerStateChange

if(newstate == PLAYER_STATE_DRIVER)
{
if(GetRealID(cars) != -1)
{
new str[128];
if(!strcmp(CarInfo[GetRealID(cars)][cOwner],"Nones",false))
{
                TogglePlayerControllable(playerid,0);
format(str,sizeof(str),"Ýòîò àâòîìîáèëü ïðîäà¸òüñÿ çà: %d ðóá",CarInfo[GetRealID(cars)][cPrice]);
SendClientMessage(playerid,-1,str);
SendClientMessage(playerid,-1,"×òîáû êóïèòü ââåäèòå /buycar èëè /exit äëÿ âûõîäà èç àâòîìîáèëÿ");
return true;
}
}
}
ко всем командам

if(strcmp(cmd, "/park", true) == 0)
{
   if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_GRAD2, "Âû äîëæíû áûòü â àâòîìîáèëå");
new cars = GetPlayerVehicleID(playerid);
if(GetRealID(cars) == -1) return SendClientMessage(playerid, COLOR_GRAD2, "Âû äîëæíû áûòü â ñâî¸ì àâòîìîáèëå");
   if(!strcmp(CarInfo[GetRealID(cars)][cOwner],GN(playerid),true))
   {
GetVehiclePos(cars, CarInfo[GetRealID(cars)][cX],CarInfo[GetRealID(cars)][cY],CarInfo[GetRealID(cars)][cZ]);
GetVehicleZAngle(cars, CarInfo[GetRealID(cars)][cA]);
new world = GetPlayerVirtualWorld(playerid);
            new int = GetPlayerInterior(playerid);
            CarInfo[GetRealID(cars)][cWorld] = world;
            CarInfo[GetRealID(cars)][cInt] = int;
SaveCars(GetRealID(cars));
SendClientMessage(playerid, COLOR_YELLOW, "Òåïåðü âàø àâòîìîáèëü áóäåò ïðèïàðêîâàí â ýòîì ìåñòå");
return 1;
   }
   else return SendClientMessage(playerid, COLOR_GRAD2, "Ýòîò òðàíñïîðò íå Âàø");
}
   if(strcmp(cmd, "/lock", true) == 0)
{
   if(IsPlayerConnected(playerid))
   {
new newcar = -1;
new cars;
for(cars = 1; cars <= MAX_VEHICLES; cars ++)
{
   if(GetRealID(cars) != -1)
   {
   if(!strcmp(CarInfo[GetRealID(cars)][cOwner],GN(playerid),false))
   {
       new Float:lcx,Float:lcy,Float:lcz;
       GetVehiclePos(cars, lcx,lcy,lcz);
       if(IsPlayerInRangeOfPoint(playerid,4,lcx,lcy,lcz))
       {
           newcar = GetRealID(cars);
           break;
   }
}
}
}
if(newcar == -1) return SendClientMessage(playerid,COLOR_GREY,"Òû äîëæåí áûòü âîçëå ñâîåãî àâòîìîáèëÿ!");
if(CarInfo[newcar][cLock] == 1)
{
  format(string, sizeof(string), "* %s îòêðûâàåò çàìîê.", GN(playerid));
   ProxDetector(15.0, playerid, string, COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE);
format(string, sizeof(string), "~w~ABO–O€…‡’ ~g~OKP‘");
GameTextForPlayer(playerid, string, 5000, 5);
UnLockCar(cars);
CarInfo[newcar][cLock] = 0;
SaveCars(newcar);
return true;
}
else if(CarInfo[newcar][cLock] == 0)
{
   format(string, sizeof(string), "* %s çàêðûâàåò çàìîê.", GN(playerid));
ProxDetector(15.0, playerid, string, COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE);
format(string, sizeof(string), "~w~ABO–O€…‡’ ~r~ˆAKP‘");
GameTextForPlayer(playerid, string, 5000, 5);
LockCar(cars);
CarInfo[newcar][cLock] = 1;
SaveCars(newcar);
return 1;
}
}
}
   if(strcmp(cmd, "/buycar", true) == 0)
{
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_GRAD2, "Âû äîëæíû áûòü â àâòîìîáèëå");
new cars = GetPlayerVehicleID(playerid);
if(GetRealID(cars) == -1)return SendClientMessage(playerid, COLOR_GRAD2, "");
if(!strcmp(CarInfo[GetRealID(cars)][cOwner],"Nones",true))
{
if(Player[playerid][pMoney] < CarInfo[GetRealID(cars)][cPrice])
{
TogglePlayerControllable(playerid,1);
RemovePlayerFromVehicle(playerid);
return SendClientMessage(playerid, COLOR_GRAD2, "Ó âàñ íåò äåíåã íà ïîêóïêó");
}
new carpla = 0;
for(new i = 1; i <= AllCars; i++)
{
if(!strcmp(CarInfo[cOwner],GN(playerid),false,24)) carpla++;
}
if(Player[playerid][pVip] == 3)
{
if(carpla >= 2) return SendClientMessage(playerid, COLOR_GRAD2, "Ó âàñ ñëèøêîì ìíîãî ìàøèí");
}
else if(carpla >= 1) return SendClientMessage(playerid, COLOR_GRAD2, "Ó âàñ ñëèøêîì ìíîãî ìàøèí");


GivePlayerMoney(playerid,-CarInfo[GetRealID(cars)][cPrice]);
Player[playerid][pMoney] -=CarInfo[GetRealID(cars)][cPrice];
format(CarInfo[GetRealID(cars)][cOwner],24,"%s",GN(playerid));
SaveCars(GetRealID(cars));
TogglePlayerControllable(playerid,1);
SendClientMessage(playerid, COLOR_GRAD2, "Âû óñïåøíî êóïèëè ñåáå ìàøèíó");
return true;
}
else return SendClientMessage(playerid, COLOR_GRAD2, "Ýòîò òðàíñïîðò èìååò âëàäåëüöà");
}
   if(strcmp(cmd, "/selladdcar", true) == 0)
{
if(!GetPVarInt(playerid,"Create_Car")) return SendClientMessage(playerid, -1, "Âû íå ñîçäàâàëè àâòî /selladdcar!");
if(!IsPlayerInVehicle(playerid, GetPVarInt(playerid,"Create_Car"))) return SendClientMessage(playerid, -1, "Âû äîëæíû áûòü â ñïåöèàîíî ñîçäàííîì àâòî!");
if(Player[playerid][pAdmin] <= 7) return SendClientMessage(playerid, -1, "Ó âàñ íåò ïðàâ íà èñïîëüçîâàíèå ýòîé êîìàíäû!");
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /selladdcar [Ñóììà]");
new money = strval(tmp);
AllCars++;
GetVehiclePos(GetPVarInt(playerid,"Create_Car"), CarInfo[AllCars][cX],CarInfo[AllCars][cY],CarInfo[AllCars][cZ]);
GetVehicleZAngle(GetPVarInt(playerid,"Create_Car"), CarInfo[AllCars][cA]);
CarInfo[AllCars][cID] = GetPVarInt(playerid,"Create_Car");
CarInfo[AllCars][cModel] = GetVehicleModel(GetPVarInt(playerid,"Create_Car"));
CarInfo[AllCars][cColor1] = -1;
CarInfo[AllCars][cColor2] = -1;
format(CarInfo[AllCars][cOwner],24,"Nones");
CarInfo[AllCars][cPrice] = money;
new iniccOpen = ini_openFile("cars.cfg");
ini_setInteger(iniccOpen, "AllCars", AllCars);
ini_closeFile(iniccOpen);
DeletePVar(playerid,"Create_Car");
CreateCars(AllCars);
SendClientMessage(playerid, COLOR_GRAD2, "Àâòî óñïåøíî ñîçäàíî");
return true;
}
   if(strcmp(cmd, "/dellcar", true) == 0)
{
if(Player[playerid][pAdmin] <= 7) return SendClientMessage(playerid, -1, "Ó âàñ íåò ïðàâ íà èñïîëüçîâàíèå ýòîé êîìàíäû!");
DestroyVehicle(GetPVarInt(playerid,"Create_Car"));
DeletePVar(playerid,"Create_Car");
GetVehiclePos(GetPVarInt(playerid,"Create_Car"), CarInfo[AllCars][cX],CarInfo[AllCars][cY],CarInfo[AllCars][cZ]);
GetVehicleZAngle(GetPVarInt(playerid,"Create_Car"), CarInfo[AllCars][cA]);
return SendClientMessage(playerid, -1, "Âû óäàëèëè àâòî!");
}
   if(strcmp(cmd, "/addcar", true) == 0)
{
if(GetPVarInt(playerid,"Create_Car") > 0) return SendClientMessage(playerid, -1, "Âû óæå ñîçäàëè àâòîìîáèëü /dellcar!");
if(Player[playerid][pAdmin] <= 7 ) return SendClientMessage(playerid, -1, "Ó âàñ íåò ïðàâ íà èñïîëüçîâàíèå ýòîé êîìàíäû!");
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /addcar [carid]");
new car = strval(tmp);
new Float:X,Float:Y,Float:Z;
GetPlayerPos(playerid, X,Y,Z);
new idcar = CreateVehicle(car, X,Y,Z, 0.0, -1, -1, 60000*4);
SetPVarInt(playerid,"Create_Car",idcar);
if(Player[playerid][pAdmin] >=10)
{
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "Àäìèíèñòðàòîð: %s [ID %d] ñîçäàë àâòî íà ïðîäàæó [%d]  .",sendername,playerid,idcar);
ABroadCast(COLOR_LIGHTRED,string,1);
}
SendClientMessage(playerid, COLOR_GRAD2, "Èñïîëüçóéòå /selladdcar èëè /dellcar èëè /incars");
return true;
}
в OnGameModInit
добавим загрузку машин и загрузку номеров

for(new car = 1; car <= AllCars; car++)
{
if(!strcmp(CarInfo[GetRealID(car)][cOwner],"Nones",false))
{
SetVehiclePos(car,CarInfo[GetRealID(car)][cX],CarInfo[GetRealID(car)][cY],CarInfo[GetRealID(car)][cZ]);
SetVehicleZAngle(car,CarInfo[GetRealID(car)][cA]);
SetVehicleVirtualWorld(car, CarInfo[GetRealID(car)][cWorld]);
LinkVehicleToInterior(car, CarInfo[GetRealID(car)][cInt]);
}
else
{
SetVehiclePos(car,CarInfo[GetRealID(car)][cX],CarInfo[GetRealID(car)][cY],CarInfo[GetRealID(car)][cZ]);
SetVehicleZAngle(car,CarInfo[GetRealID(car)][cA]);
SetVehicleVirtualWorld(car, CarInfo[GetRealID(car)][cWorld]);
LinkVehicleToInterior(car, CarInfo[GetRealID(car)][cInt]);
}
ChangeVehicleColor(car,CarInfo[GetRealID(car)][cColor1],CarInfo[GetRealID(car)][cColor2]);
}
for(new car = 1; car <= AllCars; car++)
{
if(strcmp(CarInfo[car][cOwner],"Nones",true) != 0)
{
if(strcmp(CarInfo[car][cNumber],"None",true,64) != 0)
{
CarLabel[CarInfo[car][cID]] = Create3DTextLabel(CarInfo[car][cNumber],0xFFFF00FF, 0.0, 0.0, 0.0,20.0,0,0);
Attach3DTextLabelToVehicle(CarLabel[CarInfo[car][cID]] , CarInfo[car][cID], 0.0, 0.0, 1.1);
}
else
{
CarLabel[CarInfo[car][cID]] = Create3DTextLabel("ТРАНЗИТ",0xFF0000FF, 0.0, 0.0, 0.0,20.0,0,0);
Attach3DTextLabelToVehicle(CarLabel[CarInfo[car][cID]] , CarInfo[car][cID], 0.0, 0.0, 1.1);
}
}
else
{
CarLabel[CarInfo[car][cID]] = Create3DTextLabel("Т/С на продаже",0xFFFF00FF, 0.0, 0.0, 0.0,20.0,0,0);
Attach3DTextLabelToVehicle(CarLabel[CarInfo[car][cID]] , CarInfo[car][cID], 0.0, 0.0, 1.1);
}
}

и в папку scriptfiles добавим папку
папку cars и файлик cars.cfg
Вот и всё.Вырезал из мода и переделал я (Basis) 
Тут есть продажа,покупка,паркинг,команды для номеров нету,но если надо то скину
подойдёт для new.pwn

 
Последнее редактирование модератором:

Basis

chto tut doljno bit`!?
Пользователь
24.06.2014
824
271
0
22
Sten сказал(а):
Вы когда копируете хоть раскладку клавиатуры переключайте на русскую, а то иероглифы глаза мозолят. 
Не знал,учту,а так иероглифы пропадут при вставке в мод

 

weberta

Новичок
Пользователь
13.03.2017
0
1
0
Сколько игрок может иметь авто ?