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

Уроки по созданию сервера и готовые решения
Ответить
Аватара пользователя
danilasar
Сообщения: 189
Зарегистрирован: 17 июл 2018, 09:55
Откуда: Саратов, Россия
Контактная информация:

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

Сообщение danilasar » 04 окт 2018, 13:33

Для начала ко всем enum:

Код: Выделить всё

enum hInfo {
hID,
Float:hiX,
Float:hiY,
Float:hiZ,
Float:hvX,
Float:hvY,
Float:hvZ,
hOwner[MAX_PLAYER_NAME],
hPrice,
hInt,
hWorld,
hLock,
hDate,
hLevel,
hvWorld,
hvInt,
hPic,
hPic2,
hMap,
hRoom,
hRent,
hNick1[MAX_PLAYER_NAME],
hNick2[MAX_PLAYER_NAME],
hNick3[MAX_PLAYER_NAME],
hNick4[MAX_PLAYER_NAME],
hNick5[MAX_PLAYER_NAME],
hBank
};
new House[1000][hInfo];
new AllHouse = 0;
new House[1000][hInfo]; 1000 это кол-во домов на сервере
в public OnGameModeInit():

Код: Выделить всё

LoadHouse();
Дальше создадим стоки loadhouse , savehouse и т.д.

Код: Выделить всё

stock LoadHouse() {
new ids[32],str[64];
new iniOpens = ini_openFile("house/house.cfg");
ini_getInteger(iniOpens, "AllHouse", AllHouse);
ini_closeFile(iniOpens);
if(AllHouse != 0) {
for(new house = 1; house <= AllHouse; house++) {
format(ids,sizeof(ids),"house/%d.ini",house);
new inihOpen = ini_openFile(ids);
ini_getFloat(inihOpen, "hiX", House[house][hiX]);
ini_getFloat(inihOpen, "hiY", House[house][hiY]);
ini_getFloat(inihOpen, "hiZ", House[house][hiZ]);
ini_getFloat(inihOpen, "hvX", House[house][hvX]);
ini_getFloat(inihOpen, "hvY", House[house][hvY]);
ini_getFloat(inihOpen, "hvZ", House[house][hvZ]);
ini_getString(inihOpen, "hOwner", str); format(House[house][hOwner],24,"%s",str);
ini_getInteger(inihOpen, "hPrice", House[house][hPrice]);
ini_getInteger(inihOpen, "hInt", House[house][hInt]);
ini_getInteger(inihOpen, "hLock", House[house][hLock]);
ini_getInteger(inihOpen, "hDate", House[house][hDate]);
ini_getInteger(inihOpen, "hLevel", House[house][hLevel]);
ini_getInteger(inihOpen, "hvWorld", House[house][hvWorld]);
ini_getInteger(inihOpen, "hvInt", House[house][hvInt]);
ini_getInteger(inihOpen, "hRoom", House[house][hRoom]);
ini_getInteger(inihOpen, "hRent", House[house][hRent]);
ini_getString(inihOpen, "hNick1", str); format(House[house][hNick1],24,"%s",str);
ini_getString(inihOpen, "hNick2", str); format(House[house][hNick2],24,"%s",str);
ini_getString(inihOpen, "hNick3", str); format(House[house][hNick3],24,"%s",str);
ini_getString(inihOpen, "hNick4", str); format(House[house][hNick4],24,"%s",str);
ini_getString(inihOpen, "hNick5", str); format(House[house][hNick5],24,"%s",str);
ini_getInteger(inihOpen, "hBank", House[house][hBank]);
ini_closeFile(inihOpen);
if(!strcmp(House[house][hOwner],"Nones",false)) {
House[house][hPic] = CreateDynamicPickup(1273, 1, House[house][hvX], House[house][hvY], House[house][hvZ],House[house][hvWorld],House[house][hvInt]);
House[house][hMap] = CreateDynamicMapIcon(House[house][hvX], House[house][hvY], House[house][hvZ], 31, -1,House[house][hvWorld],House[house][hvInt]);
House[house][hPic2] = CreateDynamicPickup(1318, 1, House[house][hiX], House[house][hiY], House[house][hiZ], house, House[house][hInt]);
} else {
House[house][hPic] = CreateDynamicPickup(1272, 1, House[house][hvX], House[house][hvY], House[house][hvZ],House[house][hvWorld],House[house][hvInt]); // vxod
House[house][hMap] = CreateDynamicMapIcon(House[house][hvX], House[house][hvY], House[house][hvZ], 32, -1,House[house][hvWorld],House[house][hvInt]);
House[house][hPic2] = CreateDynamicPickup(1318, 1, House[house][hiX], House[house][hiY], House[house][hiZ], house, House[house][hInt]); // int
}
}
printf("Домов загружено: %d",AllHouse);
}
return 1;
}
stock SaveHouse(house) {
new ids[32];
format(ids,sizeof(ids),"house/%d.ini",house);
new inihhhOpen;
inihhhOpen = ini_openFile(ids);
if(inihhhOpen == -1 || inihhhOpen == -2) inihhhOpen = ini_createFile(ids);
ini_setFloat(inihhhOpen, "hiX", House[house][hiX]);
ini_setFloat(inihhhOpen, "hiY", House[house][hiY]);
ini_setFloat(inihhhOpen, "hiZ", House[house][hiZ]);
ini_setFloat(inihhhOpen, "hvX", House[house][hvX]);
ini_setFloat(inihhhOpen, "hvY", House[house][hvY]);
ini_setFloat(inihhhOpen, "hvZ", House[house][hvZ]);
ini_setString(inihhhOpen, "hOwner", House[house][hOwner]);
ini_setInteger(inihhhOpen, "hPrice", House[house][hPrice]);
ini_setInteger(inihhhOpen, "hInt", House[house][hInt]);
ini_setInteger(inihhhOpen, "hLock", House[house][hLock]);
ini_setInteger(inihhhOpen, "hDate", House[house][hDate]);
ini_setInteger(inihhhOpen, "hLevel", House[house][hLevel]);
ini_setInteger(inihhhOpen, "hvWorld", House[house][hvWorld]);
ini_setInteger(inihhhOpen, "hvInt", House[house][hvInt]);
ini_setInteger(inihhhOpen, "hRoom", House[house][hRoom]);
ini_setInteger(inihhhOpen, "hRent", House[house][hRent]);
ini_setString(inihhhOpen, "hNick1", House[house][hNick1]);
ini_setString(inihhhOpen, "hNick2", House[house][hNick2]);
ini_setString(inihhhOpen, "hNick3", House[house][hNick3]);
ini_setString(inihhhOpen, "hNick4", House[house][hNick4]);
ini_setString(inihhhOpen, "hNick5", House[house][hNick5]);
ini_setInteger(inihhhOpen, "hBank", House[house][hBank]);
ini_closeFile(inihhhOpen);
return 1;
}
stock UpdateHouse(house) {
DestroyDynamicMapIcon(House[house][hMap]);
DestroyDynamicPickup(House[house][hPic]);
DestroyDynamicPickup(House[house][hPic2]);
if(!strcmp(House[house][hOwner],"Nones",false)) {
House[house][hPic] = CreateDynamicPickup(1273, 1, House[house][hvX], House[house][hvY], House[house][hvZ],House[house][hvWorld],House[house][hvInt]);
House[house][hMap] = CreateDynamicMapIcon(House[house][hvX], House[house][hvY], House[house][hvZ], 31, -1,House[house][hvWorld],House[house][hvInt]);
House[house][hPic2] = CreateDynamicPickup(1318, 1, House[house][hiX], House[house][hiY], House[house][hiZ], house, House[house][hInt]);
} else {
House[house][hPic] = CreateDynamicPickup(1239, 1, House[house][hvX], House[house][hvY], House[house][hvZ],House[house][hvWorld],House[house][hvInt]); // vxod
House[house][hMap] = CreateDynamicMapIcon(House[house][hvX], House[house][hvY], House[house][hvZ], 32, -1,House[house][hvWorld],House[house][hvInt]);
House[house][hPic2] = CreateDynamicPickup(1318, 1, House[house][hiX], House[house][hiY], House[house][hiZ], house, House[house][hInt]); // int
}
return 1;
}
и так у нас уже есть загрузка сохранение и обновление домов
Дальше добавим команду /addhouse

Код: Выделить всё

if(strcmp(cmd, "/addhouse", true) == 0) {
if(Player[playerid][pAdmin] <= 8) return SendClientMessage(playerid, -1, "У вас нет прав!");
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "Подсказка: /addhouse [Сумма] [Уровень]");
new money = strval(tmp);
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "Подсказка: /addhouse [Сумма] [Уровень]");
new level = strval(tmp);
AllHouse++;
GetPlayerPos(playerid, House[AllHouse][hvX],House[AllHouse][hvY],House[AllHouse][hvZ]);
format(House[AllHouse][hOwner],24,"Nones");
House[AllHouse][hDate] = gettime();
House[AllHouse][hiX] = -2284.279296;
House[AllHouse][hiY] = 90.921600;
House[AllHouse][hiZ] = -82.634101;
House[AllHouse][hPrice] = money;
House[AllHouse][hInt] = 3;
House[AllHouse][hLock] = 1;
House[AllHouse][hLevel] = level;
House[AllHouse][hvWorld] = GetPlayerVirtualWorld(playerid);
House[AllHouse][hvInt] = GetPlayerInterior(playerid);
format(House[AllHouse][hNick1],24,"Nones");
format(House[AllHouse][hNick2],24,"Nones");
format(House[AllHouse][hNick3],24,"Nones");
format(House[AllHouse][hNick4],24,"Nones");
format(House[AllHouse][hNick5],24,"Nones");
House[AllHouse][hRent] = 0;
House[AllHouse][hRoom] = 0;
House[AllHouse][hBank] = 0;
new inihhOpen = ini_openFile("house/house.cfg");
ini_setInteger(inihhOpen, "AllHouse", AllHouse);
ini_closeFile(inihhOpen);
SaveHouse(AllHouse);
House[AllHouse][hPic] = CreateDynamicPickup(1273, 1, House[AllHouse][hvX], House[AllHouse][hvY], House[AllHouse][hvZ],House[AllHouse][hvWorld],House[AllHouse][hvInt]);
House[AllHouse][hMap] = CreateDynamicMapIcon(House[AllHouse][hvX], House[AllHouse][hvY], House[AllHouse][hvZ], 31, -1,House[AllHouse][hvWorld],House[AllHouse][hvInt]);
House[AllHouse][hPic2] = CreateDynamicPickup(1318, 1, House[AllHouse][hiX], House[AllHouse][hiY], House[AllHouse][hiZ], AllHouse, House[AllHouse][hInt]);
SendClientMessage(playerid, COLOR_GRAD2, "Дом успешно создан");
if(Player[playerid][pAdmin] >=10) {
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "Администратор: %s[ID%d] создал дом",sendername,playerid);
ABroadCast(COLOR_LIGHTRED,string,1);
}
return 1;
}
в public OnPlayerPickUpPickup(playerid, pickupid)

Код: Выделить всё

for(new house = 1; house <= AllHouse; house++) {
if(IsPlayerInRangeOfPoint(playerid,2.0,House[house][hvX],House[house][hvY],House[house][hvZ])) {
GameTextForPlayer(playerid,"~w~ìA„–…E ~r~~k~~PED_SPRINT~",5000,1);
return 1;
}
else if(IsPlayerInRangeOfPoint(playerid,2.0,House[house][hiX],House[house][hiY],House[house][hiZ])) {
GameTextForPlayer(playerid,"~w~ìA„–…E ~r~~k~~PED_SPRINT~",5000,1);
return 1;
}
}
в public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)

Код: Выделить всё

if(newkeys & KEY_SPRINT)

{
for(new house = 1; house <= AllHouse; house++)
{
   if(IsPlayerInRangeOfPoint(playerid,1.0,House[house][hvX],House[house][hvY],House[house][hvZ]) && GetPlayerVirtualWorld(playerid) == House[house][hvWorld])
   {
      if(!strcmp(House[house][hOwner],"Nones",false))
        {
           format(str,sizeof(str),"\
{ffffff}Продаётся дом\n\n\
Цена: %d руб (%s)\n\
Требуемый уровень: %d (%s)\n\
\n\
Если хотите купить нажмите \"Купить\"\n\
Если не хотите нажмите \"Закрыть\""
,House[house][hPrice],(GetPlayerMoney(playerid) < House[house][hPrice]?("Недостаточно"):("Достаточно" ))
,House[house][hLevel],(Player[playerid][pLevel] < House[house][hLevel]?("Недостаточный"):("Достаточный") ));
if(Player[playerid][pLevel] < House[house][hLevel] || GetPlayerMoney(playerid) < House[house][hPrice])
{
return ShowPlayerDialog(playerid, 20,0,"Продажа Владения",str,"Закрыть","");
}
else
{
   SetPVarInt(playerid,"house_active",house);
   return ShowPlayerDialog(playerid, 21,0,"Продажа Владения",str,"Купить","Закрыть");
}
}
else
{
   new arend[32];
   if(House[house][hRent] > 0) format(arend,32,"%d руб в час",House[house][hRent]);
   else if(House[house][hRent] <= 0) format(arend,32,"Нет",House[house][hRent]);
           format(str,sizeof(str),"\
{ffffff}Дом\n\n\
Владелец: %s\n\
Статус: %s\n\
Аренда: %s\n\
\n\
Если хотите войти нажмите \"Войти\"\n\
Если не хотите нажмите \"Закрыть\""
,House[house][hOwner]
,((House[house][hLock] == 0) ? ("Открыт"):("Закрыт" )),
arend);
if(House[house][hLock] == 1)
{
return ShowPlayerDialog(playerid, 20,0,"Дом",str,"Закрыть","");
}
else
{
SetPVarInt(playerid,"house_active",house);
   return ShowPlayerDialog(playerid, 22,0,"Дом",str,"Войти","Закрыть");
}
}
   }
   else if(IsPlayerInRangeOfPoint(playerid,1.0,House[house][hiX],House[house][hiY],House[house][hiZ]) && GetPlayerVirtualWorld(playerid) == house)
   {
SetPlayerPos(playerid,House[house][hvX],House[house][hvY],House[house][hvZ]);
SetPlayerVirtualWorld(playerid,0);
SetPlayerInterior(playerid,0);
return 1;
  }
}
}[/spoiler]
в public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
[spoiler='диалоги покупки и информации дома']if(dialogid == 21) // покупка дома

{
   if(response)
   {
       new house = GetPVarInt(playerid,"house_active");
       DeletePVar(playerid,"house_active");
       new housenum = 0;
for(new house2 = 1; house2 <= AllHouse; house2++)
{
  if(!strcmp(House[house2][hOwner],GN(playerid),false)) housenum++;
}
if(Player[playerid][pAdmin] >= 9) // домов для админов 9 уровня и больше
{
   if(housenum >= 2) return SendClientMessage(playerid,-1,"Достигнуто максимальное количество домов");
}
else  // для обычных игроков
{
if(housenum >= 1) return SendClientMessage(playerid,-1,"Достигнуто максимальное количество домов");
}
       if(!IsPlayerInRangeOfPoint(playerid,3.0,House[house][hvX],House[house][hvY],House[house][hvZ] ))
       {
           return SendClientMessage(playerid,-1,"Вы отошли от дома");
       }
            if(GetPlayerMoney(playerid) < House[house][hPrice])
            {
                return SendClientMessage(playerid,-1,"У вас не хватает денег");
            }
else GivePlayerMoney(playerid, -House[house][hPrice]);
Player[playerid][pMoney] -=House[house][hPrice];
       SetPlayerPos(playerid,House[house][hiX],House[house][hiY],House[house][hiZ]);
SetPlayerVirtualWorld(playerid,house);
SetPlayerInterior(playerid,House[house][hInt]);
format(House[house][hOwner],24,GN(playerid));
House[house][hDate] = gettime();
       format(House[house][hNick1],24,"Nones");
       format(House[house][hNick2],24,"Nones");
       format(House[house][hNick3],24,"Nones");
       format(House[house][hNick4],24,"Nones");
       format(House[house][hNick5],24,"Nones");
       House[AllHouse][hRent] = 0;
       House[AllHouse][hRoom] = 0;
       House[AllHouse][hBank] = 0;
UpdateHouse(house);
SaveHouse(house);
return SendClientMessage(playerid,-1,"Вы успешно купили себе дом");
   }
   else return 1;
}
//==============================================================================
if(dialogid == 22) // вход в дом
{
   if(response)
   {
       new house = GetPVarInt(playerid,"house_active");
       DeletePVar(playerid,"house_active");
       if(!IsPlayerInRangeOfPoint(playerid,3.0,House[house][hvX],House[house][hvY],House[house][hvZ] ))
       {
           return SendClientMessage(playerid,-1,"Вы отошли от дома");
       }
SetPlayerPos(playerid,House[house][hiX],House[house][hiY],House[house][hiZ]);
SetPlayerVirtualWorld(playerid,house);
SetPlayerInterior(playerid,House[house][hInt]);
return 1;
   }
   else return 1;
   }
Файлы которые я скинул поместите в папку scriptfiles
Вот вроде и всё
Для теста я создал 1 дом


Вырезал и переделал: Basis

Был чу чуть изменён от стандартного Gamer
Player[playerid][pAdmin] замените на свою функцию администратора
Ид диалогов меняйте на свои
Иероглифы сами поменяются когда вставите в мод
Будут ошибки пишите сюда

Автор: Gamer
Вырезал и переделал: Basis
Чуть-чуть подправил: danilasar (я)

Ответить