• Страница 1 из 1
  • 1
Форум » Программирование в Pawno » Готовые решения » Система Квартир ( для нового мода )
Система Квартир ( для нового мода )
Добавлено 31.03.2016 в 06:04 | Сообщение №1
Сообщений: 263 Репутация: 0
Администраторы
Ко всем forward
Код
forward LoadFlats();
forward split(const strsrc[], strdest[][], delimiter);
forward OnPropUpdate();

Перед enum pInfo
Код
enum fInfo
{
fOwned,
fOwner[MAX_PLAYER_NAME],
Float:fEntrancex,
Float:fEntrancey,
Float:fEntrancez,
Float:fExitx,
Float:fExity,
Float:fExitz,
fInt,
fVirtWorld,
fValue,
fLock,
fRent,
fRentabil,
fTakings,
fDate,
};
new FlatsInfo[27][fInfo];
new FlatPickup[sizeof(FlatsInfo)];
new Text3D: Flat3D[sizeof(FlatsInfo)];
new flathouse1[2];
new flathouse2[2];
new flathouse3[2];
new pickups;

Создадим stock
Код
stock UpdateFlat(idx)
{
new text[600];
if(FlatsInfo [idx][fOwned]== 0)
{
     format(text,sizeof(text),"{FF6347} * Квартира * {FFFFFF}\nНомер: {7CFC00}%d{FFFFFF}\nЦена: {7CFC00}%d{FFFFFF}\nЧтобы купить квартиру, введите {7CFC00}/buyflat{FFFFFF}",idx,FlatsInfo[idx][fValue]);
                  Update3DTextLabelText(Flat3D[idx], 0xFFFFFFFF, text);
                  DestroyPickup(FlatPickup[idx]);
FlatPickup [idx]= CreatePickup(1273, 23, FlatsInfo[idx][fEntrancex], FlatsInfo[idx][fEntrancey], FlatsInfo[idx][fEntrancez], FlatsInfo[idx][fVirtWorld]);
}
else if(FlatsInfo [idx][fOwned]== 1)
{
     format(text,sizeof(text),"{FF6347} * Квартира * {FFFFFF}\nНомер: {7CFC00}%d{FFFFFF}\nВладелец: {7CFC00}%s",idx,FlatsInfo[idx][fOwner]);
                  Update3DTextLabelText(Flat3D[idx], 0xFFFFFFFF, text);
                  DestroyPickup(FlatPickup[idx]);
     FlatPickup [idx]= CreatePickup(1272, 23, FlatsInfo[idx][fEntrancex], FlatsInfo[idx][fEntrancey], FlatsInfo[idx][fEntrancez], FlatsInfo[idx][fVirtWorld]);
}
}

В конец
Код
public LoadFlats()
{
new arrCoords[17][64];
new strFromFile2[256];
new File: file = fopen("flats.cfg", io_read);
if (file)
{
new idx;
while (idx < sizeof(FlatsInfo))
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, ',');
FlatsInfo [idx][fOwned]= strval(arrCoords[0]);
strmid(FlatsInfo[idx][fOwner], arrCoords[1], 0, strlen(arrCoords[1]), 255);
FlatsInfo [idx][fEntrancex]= floatstr(arrCoords[2]);
FlatsInfo [idx][fEntrancey]= floatstr(arrCoords[3]);
FlatsInfo [idx][fEntrancez]= floatstr(arrCoords[4]);
FlatsInfo [idx][fExitx]= floatstr(arrCoords[5]);
FlatsInfo [idx][fExity]= floatstr(arrCoords[6]);
FlatsInfo [idx][fExitz]= floatstr(arrCoords[7]);
FlatsInfo [idx][fInt]= strval(arrCoords[8]);
FlatsInfo [idx][fVirtWorld]= strval(arrCoords[9]);
FlatsInfo [idx][fValue]= strval(arrCoords[10]);
FlatsInfo [idx][fLock]= strval(arrCoords[11]);
FlatsInfo [idx][fRent]= strval(arrCoords[12]);
FlatsInfo [idx][fRentabil]= strval(arrCoords[13]);
FlatsInfo [idx][fTakings]= strval(arrCoords[14]);
FlatsInfo [idx][fDate]= strval(arrCoords[15]);
FlatsInfo [idx][fLevel]= strval(arrCoords[16]);
printf("Квартира: [%d] | Владелец: [%s]",idx,FlatsInfo[idx][fOwner]);
idx++;
}
fclose(file);
}
return 1;
}

В public OnGameModeInit после всех машин и т.д
Код
for(new f = 0; f < sizeof(FlatsInfo); f++)
{
     new text[600];
if(FlatsInfo [f][fOwned]== 0)
{
     format(text,sizeof(text),"{FF6347} * Квартира * {FFFFFF}\nНомер: {7CFC00}%d{FFFFFF}\nЦена: {7CFC00}%d{FFFFFF}\nЧтобы купить квартиру, введите {7CFC00}/buyflat{FFFFFF}",f,FlatsInfo[f][fValue]);
                          Flat3D [f]= Create3DTextLabel(text,0xFFFFFFFF,FlatsInfo[f][fEntrancex], FlatsInfo[f][fEntrancey], FlatsInfo[f][fEntrancez]+1,10,FlatsInfo[f][fVirtWorld],1);
FlatPickup [f]= CreatePickup(1273, 23, FlatsInfo[f][fEntrancex], FlatsInfo[f][fEntrancey], FlatsInfo[f][fEntrancez], FlatsInfo[f][fVirtWorld]); pickups++;
}
else if(FlatsInfo [f][fOwned]== 1)
{
     format(text,sizeof(text),"{FF6347} * Квартира * {FFFFFF}\nНомер: {7CFC00}%d{FFFFFF}\nВладелец: {7CFC00}%s",f,FlatsInfo[f][fOwner]);
                          Flat3D [f]= Create3DTextLabel(text,0xFFFFFFFF,FlatsInfo[f][fEntrancex], FlatsInfo[f][fEntrancey], FlatsInfo[f][fEntrancez]+1,10,FlatsInfo[f][fVirtWorld],1);
     FlatPickup [f]= CreatePickup(1272, 23, FlatsInfo[f][fEntrancex], FlatsInfo[f][fEntrancey], FlatsInfo[f][fEntrancez], FlatsInfo[f][fVirtWorld]); pickups++;
}
}

В public OnPropUpdate()
Код
public OnPropUpdate()
{
   new idx;
   new File: file2;
idx = 0;
while (idx < sizeof(FlatsInfo))
{
new coordsstring[256];
format(coordsstring, sizeof(coordsstring), "%d,%s,%f,%f,%f,%f,%f,%f,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
FlatsInfo[idx][fOwned],
FlatsInfo[idx][fOwner],
FlatsInfo[idx][fEntrancex],
FlatsInfo[idx][fEntrancey],
FlatsInfo[idx][fEntrancez],
FlatsInfo[idx][fExitx],
FlatsInfo[idx][fExity],
FlatsInfo[idx][fExitz],
FlatsInfo[idx][fInt],
FlatsInfo[idx][fVirtWorld],
FlatsInfo[idx][fValue],
FlatsInfo[idx][fLock],
FlatsInfo[idx][fRent],
FlatsInfo[idx][fRentabil],
FlatsInfo[idx][fTakings],
FlatsInfo[idx][fDate]);
if(idx == 0)
{
file2 = fopen("flats.cfg", io_write);
}
else
{
file2 = fopen("flats.cfg", io_append);
}
fwrite(file2, coordsstring);
idx++;
fclose(file2);
}
   return 1;
}

Добавим команды в public OnPlayerCommandText
Код
if(strcmp(cmd, "/enter", true) == 0)
   {
       if(IsPlayerConnected(playerid))
    {
     for(new i = 0; i < sizeof(FlatsInfo); i++)
     {
      if (PlayerToPoint(3, playerid,FlatsInfo[i][fEntrancex], FlatsInfo[i][fEntrancey], FlatsInfo[i][fEntrancez]) && GetPlayerVirtualWorld(playerid) == FlatsInfo[i][fVirtWorld])
      {
       //printf("Found House :%d",i);
       if(PlayerInfo [playerid][pFlatKey]== i || FlatsInfo [i][fLock]== 0)
       {
                          SetPlayerVirtualWorld(playerid,i+9999);
        SetPlayerInterior(playerid,FlatsInfo[i][fInt]);
        SetPlayerPos(playerid,FlatsInfo[i][fExitx],FlatsInfo[i][fExity],FlatsInfo[i][fExitz]);
        GameTextForPlayer(playerid, "~w~Welcome Flat", 5000, 1);
       }
       else
       {
        GameTextForPlayer(playerid, "~r~Locked", 5000, 1);
       }
      }
     }
    }
    return 1;
   }
      if(strcmp(cmdtext, "/exit", true) == 0)
      {
for(new i = 0; i <  sizeof(FlatsInfo); i++)
{
     if(GetPlayerVirtualWorld(playerid) == i+9999)
     {
     if (PlayerToPoint(3, playerid,FlatsInfo[i][fExitx], FlatsInfo[i][fExity], FlatsInfo[i][fExitz]))
     {
       
     SetPlayerInterior(playerid,3);
     SetPlayerVirtualWorld(playerid,FlatsInfo[i][fVirtWorld]);
     SetPlayerPos(playerid,FlatsInfo[i][fEntrancex],FlatsInfo[i][fEntrancey],FlatsInfo[i][fEntrancez]);
}
}
}
return 1;
}
if(strcmp(cmd, "/flat", true) == 0)
{
     GetPlayerName(playerid, giveplayer, sizeof(giveplayer));
     if(PlayerInfo [playerid][pFlatKey]!= 255 && strcmp(giveplayer, FlatsInfo[PlayerInfo[playerid][pFlatKey]][fOwner], true) == 0)
     {
ShowPlayerDialog(playerid,200,DIALOG_STYLE_LIST,"Êâàðòèðà"," - Îòêðûòü/Çàêðûòü\n - Ïðîäàòü","Äàëåå","Âûõîä");
}
else
{
SendClientMessage(playerid,COLOR_GRAD2, "Ó âàñ íåò êâàðòèðû.");
return 1;
}
}
if(strcmp(cmd, "/sellflat", true) == 0)
{
     if(IsPlayerConnected(playerid))
{
GetPlayerName(playerid, giveplayer, sizeof(giveplayer));
if(PlayerInfo [playerid][pFlatKey]== 255)
{
SendClientMessage(playerid, COLOR_GRAD2, "Ó âàñ íåò êâàðòèðû.");
return 1;
}
if(PlayerInfo [playerid][pFlatKey]!= 255 && strcmp(giveplayer, FlatsInfo[PlayerInfo[playerid][pFlatKey]][fOwner], true) == 0)
{
     new flat = PlayerInfo[playerid][pFlatKey];
FlatsInfo [flat][fLock]= 1;
FlatsInfo [flat][fOwned]= 0;
GetPlayerName(playerid, sendername, sizeof(sendername));
strmid(FlatsInfo[flat][fOwner], "-", 0, strlen("-"), 255);
GivePlayerMoney(playerid,FlatsInfo[flat][fValue]);
PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
format(string, sizeof(string), "~w~Congratulations~n~ You have sold your property for ~n~~g~$%d", FlatsInfo[flat][fValue]);
GameTextForPlayer(playerid, string, 10000, 3);
PlayerInfo [playerid][pFlatKey]= 255;
//OnPlayerSave(playerid);
UpdateFlat(flat);
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GRAD2, "Ó âàñ íåò êâàðòèðû.");
return 1;
}
}
return 1;
}

if(strcmp(cmd, "/buyflat", true) == 0)
{
     if(IsPlayerConnected(playerid))
     {
new Float:oldposx, Float:oldposy, Float:oldposz;
GetPlayerName(playerid, giveplayer, sizeof(giveplayer));
GetPlayerPos(playerid, oldposx, oldposy, oldposz);
for(new h = 0; h < sizeof(FlatsInfo); h++)
{
if(PlayerToPoint(2.0, playerid, FlatsInfo[h][fEntrancex], FlatsInfo[h][fEntrancey], FlatsInfo[h][fEntrancez]) && FlatsInfo [h][fOwned]== 0 && GetPlayerVirtualWorld(playerid) == FlatsInfo[h][fVirtWorld])
{

if((PlayerInfo [playerid][pFlatKey]!= 255 && strcmp(giveplayer, FlatsInfo[PlayerInfo[playerid][pFlatKey]][fOwner], true) == 0))
{
SendClientMessage(playerid, COLOR_GRAD2, "Ó âàñ óæå åñòü êâàðòèðà.");
return 1;
}
if(GetPlayerMoney(playerid) > FlatsInfo[h][fValue])
{
PlayerInfo [playerid][pFlatKey]= h;
FlatsInfo [h][fOwned]= 1;
GetPlayerName(playerid, sendername, sizeof(sendername));
strmid(FlatsInfo[h][fOwner], sendername, 0, strlen(sendername), 255);
GivePlayerMoney(playerid,-FlatsInfo[h][fValue]);

SetPlayerInterior(playerid,FlatsInfo[h][fInt]);
SetPlayerVirtualWorld(playerid,h+9999);
SetPlayerPos(playerid,FlatsInfo[h][fExitx],FlatsInfo[h][fExity],FlatsInfo[h][fExitz]);
GameTextForPlayer(playerid, "~w~Welcome Flat~n~You can exit at any time by moving to this door and typing /exit", 5000, 3);
SendClientMessage(playerid, COLOR_GREEN, "Âû êóïèëè êâàðòèðó!");
SendClientMessage(playerid, COLOR_GREEN, "/flat äëÿ óïðàâëåíèÿ åþ!");
//OnPlayerSave(playerid);
UpdateFlat(h);
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GRAD2, "Ó âàñ íå õâàòàåò äåíåã!");
return 1;
}
}
}
}
return 1;
}

В public OnDialogResponse добавим
Код
if(dialogid == 50)
{
     if(response)
     {
             if(listitem == 0)
{
for(new i = 0; i < sizeof(FlatsInfo); i++)
{
if ((PlayerToPoint(3, playerid,FlatsInfo[i][fEntrancex], FlatsInfo[i][fEntrancey], FlatsInfo[i][fEntrancez]) && GetPlayerVirtualWorld(playerid) == FlatsInfo[i][fVirtWorld]) || (PlayerToPoint(3, playerid,FlatsInfo[i][fExitx], FlatsInfo[i][fExity], FlatsInfo[i][fExitz]) && GetPlayerVirtualWorld(playerid) == i+9999))
{
if(PlayerInfo [playerid][pFlatKey]== i)
{
if(FlatsInfo [i][fLock]== 1)
{
FlatsInfo [i][fLock]= 0;
SendClientMessage(playerid, COLOR_WHITE, "Квартира открыта");
PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
return 1;
}
if(FlatsInfo [i][fLock]== 0)
{
FlatsInfo [i][fLock]= 1;
SendClientMessage(playerid, COLOR_WHITE, "Квартира закрыта");
PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
return 1;
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, "Это не ваша квартира.");
return 1;
}
}
}
}
else if(listitem == 1)
{
     OnPlayerCommandText(playerid, "/sellflat");
}
     }
     else { return 1; }
}

В public OnPlayerPickUpPickup(playerid, pickupid)
Код
if(pickupid == flathouse1[0]) //
{
    SetPlayerPos(playerid, 972.3107,-8.6146,1001.1484);
    SetPlayerInterior(playerid, 3);
    SetPlayerVirtualWorld(playerid,1);
    PlayerInfo [playerid][pMenudostup]= 1;
}
else if(pickupid == flathouse1[1]) //
{
    SetPlayerPos(playerid, 2066.3176,2170.3970,10.8203);
    SetPlayerInterior(playerid, 0);
    SetPlayerVirtualWorld(playerid,0);
    PlayerInfo [playerid][pMenudostup]= 2;
}
else if(pickupid == flathouse2[0]) //
{
    SetPlayerPos(playerid, 972.3107,-8.6146,1001.1484);
    SetPlayerInterior(playerid, 3);
    SetPlayerVirtualWorld(playerid,2);
    PlayerInfo [playerid][pMenudostup]= 1;
}
else if(pickupid == flathouse2[1]) //
{
    SetPlayerPos(playerid, 2031.0559,2157.7815,10.8203);
    SetPlayerInterior(playerid, 0);
    SetPlayerVirtualWorld(playerid,0);
    PlayerInfo [playerid][pMenudostup]= 2;
}
else if(pickupid == flathouse3[0]) //
{
    SetPlayerPos(playerid, 972.3107,-8.6146,1001.1484);
    SetPlayerInterior(playerid, 3);
    SetPlayerVirtualWorld(playerid,3);
    PlayerInfo [playerid][pMenudostup]= 1;
}
else if(pickupid == flathouse3[1]) //
{
    SetPlayerPos(playerid, 1839.3893,2160.1416,10.8203);
    SetPlayerInterior(playerid, 0);
    SetPlayerVirtualWorld(playerid,0);
    PlayerInfo [playerid][pMenudostup]= 2;
}

Потом добавим пикапы и в nGameModeInit
Код
flathouse1[0] = CreatePickup(1318, 2, 2064.2292,2172.2266,10.8203, 0); pickups++; // Квартирный Дом напротив Репортеров (Вход)
          flathouse1[1] = CreatePickup(1318, 2, 975.1188,-8.6426,1001.1484, 1); pickups++; // Квартирный Дом напротив Репортеров (Выход)
          flathouse2[0] = CreatePickup(1318, 2, 2032.2924,2162.4438,10.8203, 0); pickups++; // Квартирный Дом напротив Небоскрёпа ЛС (Вход)
          flathouse2[1] = CreatePickup(1318, 2, 975.1188,-8.6426,1001.1484, 2); pickups++; // Квартирный Дом напротив Небоскрёпа ЛС (Выход)
          flathouse3[0] = CreatePickup(1318, 2, 1840.3961,2155.9026,10.8203, 0); pickups++; // Квартирный Дом у Банка ЛС (Вход)
          flathouse3[1] = CreatePickup(1318, 2, 975.1188,-8.6426,1001.1484, 3); pickups++; // Квартирный Дом у Банка ЛС (Выход)

Код
LoadFlats();

В enum pInfo добавить
Код
pFlatKey,

В конец public OnPlayerConnect добавить
Код
PlayerInfo [playerid][pFlatKey]= 255;

Добавим
Код
public 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;
}

взято из Diamond City

Автор: Неизвестен


Программист любитель :)
Форум » Программирование в Pawno » Готовые решения » Система Квартир ( для нового мода )
  • Страница 1 из 1
  • 1
Поиск: