- 05, Nov 2014
- #1
Система домов c 0 для new.pwn, *Это не для MYSQL* а для обычных модов MxINI
К остальным Define'ам
#define MAX_HOUSES 500
В - enum pInfo
pHouse
В - OnPlayerConnect
PlayerInfo[playerid][pHouse] = 255;
Загрузка/сохранение переменной pHouse // надеюсь разберетесь куда ставить
ini_setInteger(File,"House",PlayerInfo[playerid][pHouse]); // OnPlayerRegister
ini_getInteger(File,"House",PlayerInfo[playerid][pHouse]); // OnPlayerLogin
ini_setInteger(File,"House",PlayerInfo[playerid][pHouse]); // SaveAccount
В - public OnPlayerLogin // в конец
if(PlayerInfo[playerid][pHouse] != 255 && strcmp(HousesInfo[PlayerInfo[playerid][pHouse]][hOwner], PlayerInfo[playerid][pName], true)) PlayerInfo[playerid][pHouse] = 255;
К остальным переменным new
//================== Дом =======================================================
enum hInfo
{
hOwned, hOwner[24],
Float: hX, Float: hY, Float: hZ, hInterior, hVirtWorld,
hPrice,
hLock,
hPickup,
hIcon,
hLevel
};
new HousesInfo[MAX_HOUSES][hInfo];
new Text3D: houses_text[MAX_HOUSES];
new AllHouse;//Всего домов
enum hiInfo
{
Float: hiX, Float: hiY, Float: hiZ, hiInt
};
new HInts[][hiInfo] = //Интерьеры
{
{235.508994, 1189.169897, 1080.339966, 3}, // 0
{225.756989, 1240.000000, 1082.149902, 2}, // 1
{223.043991, 1289.259888, 1082.199951, 1}, // 2
{225.630997, 1022.479980, 1084.069946, 7}, // 3
{295.138977, 1474.469971, 1080.519897, 15}, // 4
{328.493988, 1480.589966, 1084.449951, 15}, // 5
{385.803986, 1471.769897, 1080.209961, 15}, // 6
{2220.26, -1148.01, 1025.80, 15}, // 7
{2451.77, -1699.80, 1013.51, 2}, // 8
{2251.85, -1138.16, 1050.63, 9}, // 9
{2260.76, -1210.45, 1049.02, 10}, // 10
{2496.65, -1696.55, 1014.74, 3}, // 11
{1299.14, -794.77, 1084.00, 5}, // 12
{2262.83, -1137.71, 1050.63, 10}, // 13
{2365.42, -1131.85, 1050.88, 8}, // 14
{2324.33, -1144.79, 1050.71, 12}, // 15
{2233.6919, -1112.8107, 1050.8828, 5}, // 16
{2319.1272, -1023.9562, 1050.2109, 9}, // 17
{239.2819, 1114.1991, 1080.9922, 5}, // 18
{446.3247, 509.9662, 1001.4195, 12}, // 19
{446.626, 1397.738, 1084.3047, 2}, // 20
{261.1165, 1287.2197, 1080.2578, 4}, // 21
{306.1966, 307.819, 1003.3047, 4}, // 22
{24.3769, 1341.1829, 1084.375, 10}, // 23
{221.6766, 1142.4962, 1082.6094, 4}, // 24
{-262.1759, 1456.6158, 1084.3672, 4}, // 25
{234.2826, 1065.229, 1084.2101, 6}, // 26
{-68.5145, 1353.8485, 1080.2109, 6}, // 27
{-285.2511, 1471.197, 1084.375, 15}, // 28
{-42.5267, 1408.23, 1084.4297, 8}, // 29
{84.9244, 1324.2983, 1083.8594, 9}, // 30
{22.7322, 1404.7037, 1084.4297, 5}, // 31
{244.6048, 304.8997, 999.1484, 1}, // 32
{2216.1282, -1076.3052, 1050.4844, 1} // 33
};
В - OnGameModeInit
LoadHouses();//Загружаем дома.
Немного ниже
//==================== Дом =================================================
for(new h = 0; h < AllHouse; h++)
{
if(HousesInfo[h][hOwned] == 0)
{
format(string,sizeof(string), "{FF9900}*** Продается ***\n\n{ffffff}Номер: {AFAFAF}%d\n{FFFFFF}Стоимость: {AFAFAF}%d {FFFFFF}[$]\nУровень: {AFAFAF}%d{ffffff}\n\nЧтобы купить, введите {AFAFAF}/buyhouse",h,HousesInfo[h][hPrice],HousesInfo[h][hLevel]);
houses_text[h] = Create3DTextLabel(string, 0xFFFFFFFF, HousesInfo[h][hX], HousesInfo[h][hY], HousesInfo[h][hZ]+0.5, 10.0, 0, 1);
HousesInfo[h][hIcon] = CreateDynamicMapIcon(HousesInfo[h][hX], HousesInfo[h][hY], HousesInfo[h][hZ], 31, COLOR_WHITE, 0, -1, -1, 400.0);
HousesInfo[h][hPickup] = CreatePickup(1273, 23, HousesInfo[h][hX], HousesInfo[h][hY], HousesInfo[h][hZ]);
}
else if(HousesInfo[h][hOwned] == 1)
{
format(string,sizeof(string), "Дом № %d\n\nУровень: %d\nВладелец: %s",h,HousesInfo[h][hLevel],HousesInfo[h][hOwner]);
houses_text[h] = Create3DTextLabel(string, 0xFFFFFFFF, HousesInfo[h][hX], HousesInfo[h][hY], HousesInfo[h][hZ]+0.5, 10.0, 0, 1);
HousesInfo[h][hIcon] = CreateDynamicMapIcon(HousesInfo[h][hX], HousesInfo[h][hY], HousesInfo[h][hZ], 32, COLOR_WHITE, 0, -1, -1, 400.0);
HousesInfo[h][hPickup] = CreatePickup(1272, 23, HousesInfo[h][hX], HousesInfo[h][hY], HousesInfo[h][hZ]);
}
}
В - public OnGameModeExit()
SaveHouses(); // Сохраняем дома.
В - public OnPlayerCommandText
if(strcmp(cmd, "/createhouse", true) == 0)
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) return SCM(playerid, COLOR_WHITE,"{FF9900}>{FFFFFF} /createhouse [0-33] [цена]");
new intid = strval(tmp);
tmp = strtok(cmdtext, idx);
if(intid > 33 || intid < 0) return SCM(playerid, COLOR_WHITE, "{ff3300}x{FFFFFF} От 0 до 33!");
if(!strlen(tmp)) return SCM(playerid, COLOR_WHITE,"{FF9900}>{FFFFFF} /createhouse [0-33] [цена]");
new hprice = strval(tmp);
if(hprice > 50000000 || hprice < 100) return SCM(playerid, COLOR_WHITE, "{ff3300}x{FFFFFF} От 100$ до 50.000.000$!");
new Float:XX, Float: YY, Float:ZZ;
GetPlayerPos(playerid,XX,YY,ZZ);
HousesInfo[AllHouse][hOwned] = 0;
strmid(HousesInfo[AllHouse][hOwner], "None", 0, strlen("None"), 255);
HousesInfo[AllHouse][hX] = XX;
HousesInfo[AllHouse][hY] = YY;
HousesInfo[AllHouse][hZ] = ZZ;
HousesInfo[AllHouse][hInterior] = intid;
HousesInfo[AllHouse][hVirtWorld] = AllHouse;
HousesInfo[AllHouse][hPrice] = hprice;
HousesInfo[AllHouse][hLock] = 1;
HousesInfo[AllHouse][hLevel] = 1;
format(string,sizeof(string), "{FF9900}*** Продается ***\n\n{ffffff}Номер: {AFAFAF}%d\n{FFFFFF}Стоимость: {AFAFAF}%d {FFFFFF}[$]\nУровень: {AFAFAF}%d{ffffff}\n\nЧтобы купить, введите {AFAFAF}/buyhouse",AllHouse,HousesInfo[AllHouse][hPrice],HousesInfo[AllHouse][hLevel]);
houses_text[AllHouse] = Create3DTextLabel(string, 0xFFFFFFFF, HousesInfo[AllHouse][hX], HousesInfo[AllHouse][hY], HousesInfo[AllHouse][hZ]+0.5, 10.0, 0, 1);
HousesInfo[AllHouse][hIcon] = CreateDynamicMapIcon(HousesInfo[AllHouse][hX], HousesInfo[AllHouse][hY],HousesInfo[AllHouse][hZ], 31, COLOR_WHITE, 0, -1, -1, 400.0);
HousesInfo[AllHouse][hPickup] = CreatePickup(1273, 23, HousesInfo[AllHouse][hX], HousesInfo[AllHouse][hY],HousesInfo[AllHouse][hZ]);
AllHouse++;
SaveHouses();
return true;
}
if(strcmp(cmd, "/delhouse", true) == 0)
{
if(AllHouse == 0) return SCM(playerid, COLOR_WHITE, "{ff3300}x{FFFFFF} Домов больше нету!");
for(new h = 0; h <= AllHouse; h++)
{
if(strcmp(HousesInfo[h][hOwner],"None",true)!= 0) return SCM(playerid, COLOR_WHITE,"{ff3300}x{ffffff} Данный дом удалить нельзя. Сперва его нужно освободить (/asellhouse)!");
if(IsPlayerInRangeOfPoint(playerid, 1.0, HousesInfo[h][hX], HousesInfo[h][hY], HousesInfo[h][hZ]))
{
HousesInfo[h][hX] = 0;
HousesInfo[h][hY] = 0;
HousesInfo[h][hZ] = 0;
HousesInfo[h][hInterior] = 0;
HousesInfo[h][hVirtWorld] = 0;
HousesInfo[h][hPrice] = 0;
HousesInfo[h][hLock] = 0;
HousesInfo[h][hLevel] = 0;
HousesInfo[h][hOwned] = 0;
HousesInfo[h][hOwner] = 0;
Delete3DTextLabel(Text3D:houses_text[h]);
DestroyDynamicMapIcon(HousesInfo[h][hIcon]);
DestroyPickup(HousesInfo[h][hPickup]);
AllHouse--;
SaveHouses();
format(string, sizeof(string), "Вы удалил дом № %d",h);
SCM(playerid, COLOR_WHITE, string);
}
}
return true;
}
else if(strcmp(cmd, "/asellhouse", true) == 0)
{
for(new h = 0; h <= AllHouse; h++)
{
if(IsPlayerInRangeOfPoint(playerid, 1.0, HousesInfo[h][hX], HousesInfo[h][hY], HousesInfo[h][hZ]))
{
strmid(HousesInfo[h][hOwner],"None", 0, 5, 5);
HousesInfo[h][hOwned] = 0;
HousesInfo[h][hLock] = 1;
SaveHouses();
UpdateHouse(h);
format(string, sizeof(string), "Вы освободили дом № %d",h);
SCM(playerid, COLOR_WHITE, string);
}
}
return true;
}
if(strcmp(cmd, "/sethprice", true) == 0)
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) return SCM(playerid, COLOR_WHITE, "{FF9900}>{FFFFFF} /sethprice [цена]");
new proplev = strval(tmp);
if(proplev > 50000000 || proplev < 1) return SCM(playerid, COLOR_WHITE, "{ff3300}x{FFFFFF} От 1$ до 50.000.000$!");
for(new h = 0; h <= AllHouse; h++)
{
if(IsPlayerInRangeOfPoint(playerid, 1.0, HousesInfo[h][hX], HousesInfo[h][hY], HousesInfo[h][hZ]))
{
HousesInfo[h][hPrice] = proplev;
format(string, sizeof(string), "Цена дома № %d теперь %d",h,HousesInfo[h][hPrice]);
SCM(playerid, COLOR_WHITE, string);
UpdateHouse(h);
}
}
SaveHouses();
return true;
}
if(strcmp(cmd, "/sethlvl", true) == 0)
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) return SCM(playerid, COLOR_WHITE, "{FF9900}>{FFFFFF} /sethlvl [уровень]");
new proplev = strval(tmp);
if(proplev > 500 || proplev < 1) return SCM(playerid, COLOR_WHITE, "{ff3300}x{FFFFFF} От 1 до 500!");
for(new h = 0; h <= AllHouse; h++)
{
if(IsPlayerInRangeOfPoint(playerid, 1.0, HousesInfo[h][hX], HousesInfo[h][hY], HousesInfo[h][hZ]))
{
HousesInfo[h][hLevel] = proplev;
format(string, sizeof(string), "Уровень дома № %d теперь %d",h,HousesInfo[h][hLevel]);
SCM(playerid, COLOR_WHITE, string);
UpdateHouse(h);
}
}
SaveHouses();
return true;
}
if(strcmp(cmd, "/sethint", true) == 0)
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) return SCM(playerid, COLOR_WHITE, "{FF9900}>{FFFFFF} /sethint [0-33]");
new proplev = strval(tmp);
if(proplev > 33 || proplev < 0) return SCM(playerid, COLOR_WHITE, "{ff3300}x{FFFFFF} От 0 до 33!");
for(new h = 0; h <= AllHouse; h++)
{
if(IsPlayerInRangeOfPoint(playerid, 1.0, HousesInfo[h][hX], HousesInfo[h][hY], HousesInfo[h][hZ]))
{
HousesInfo[h][hInterior] = proplev;
format(string, sizeof(string), "Интерьер дома № %d теперь %d",h,HousesInfo[h][hInterior]);
SCM(playerid, COLOR_WHITE, string);
}
}
SaveHouses();
return true;
}
if(strcmp(cmd, "/sellhouse", true) == 0)
{
new hid = PlayerInfo[playerid][pHouse];
if(hid == 255) return SCM(playerid, COLOR_WHITE, "{ff3300}x{ffffff} Вы не владеете домом!");
if(hid != 255 && strcmp(PlayerInfo[playerid][pName], HousesInfo[hid][hOwner], true) == 0)
{
strmid(HousesInfo[hid][hOwner],"None", 0, 5, 5);
HousesInfo[hid][hOwned] = 0;
PlayerInfo[playerid][pHouse]= 255;
HousesInfo[hid][hLock] = 1;
SaveHouses();
PlayerInfo[playerid][pCash] += HousesInfo[hid][hPrice]/2;
UpdateHouse(hid);
SCM(playerid, COLOR_WHITE,"- Вы продали свой дом.");
}
else
{
SCM(playerid, COLOR_WHITE, "{ff3300}x{ffffff} Вы не владелец дома!");
}
return true;
}
if(strcmp(cmd, "/buyhouse", true) == 0)
{
if(PlayerInfo[playerid][pHouse] != 255) return SCM(playerid, COLOR_WHITE,"{ff3300}x{ffffff} У вас уже есть дом!");
for(new h = 0; h <= AllHouse; h++)
{
if(!IsPlayerInRangeOfPoint(playerid, 1.0, HousesInfo[h][hX], HousesInfo[h][hY], HousesInfo[h][hZ])) continue;
if(PlayerInfo[playerid][pCash] < HousesInfo[h][hPrice])return SCM(playerid, COLOR_WHITE,"{ff3300}x{ffffff} У вас недостаточно денег на покупку дома!");
if(strcmp(HousesInfo[h][hOwner],"None",true)!= 0) return SCM(playerid, COLOR_WHITE,"{ff3300}x{ffffff} Дом уже куплен!");
HousesInfo[h][hOwned] = 1;
strmid(HousesInfo[h][hOwner], PlayerInfo[playerid][pName], 0, 24, 24);
PlayerInfo[playerid][pHouse] = h;
PlayerInfo[playerid][pCash] -= HousesInfo[h][hPrice];
UpdateHouse(h);
SaveHouses();
SCM(playerid, COLOR_WHITE,"- Поздравляем вас с покупкой дома. (/househelp - помощь по дому)");
SetPlayerInterior(playerid, HInts[HousesInfo[h][hInterior]][hiInt]);
SetPlayerVirtualWorld(playerid, HousesInfo[h][hVirtWorld]);
SetPlayerPos(playerid, HInts[HousesInfo[h][hInterior]][hiX], HInts[HousesInfo[h][hInterior]][hiY], HInts[HousesInfo[h][hInterior]][hiZ]);
}
return true;
}
if(strcmp(cmd, "/open", true) == 0)
{
if(HousesInfo[PlayerInfo[playerid][pHouse]][hLock])
{
HousesInfo[PlayerInfo[playerid][pHouse]][hLock] = 0;
SCM(playerid, COLOR_WHITE, "Вы открыли дом.");
}
else
{
HousesInfo[PlayerInfo[playerid][pHouse]][hLock] = 1;
SCM(playerid, COLOR_WHITE, "Вы закрыли дом.");
}
SaveHouses();
return true;
}
if(strcmp(cmd, "/househelp", true) == 0)
{
if(PlayerInfo[playerid][pHouse] == 255) return SCM(playerid, COLOR_WHITE, "{ff3300}x{ffffff} Вы не владеете домом!");
SCM(playerid, COLOR_WHITE, "==============[Помощь по домам]==============");
SCM(playerid, COLOR_WHITE, "{ff3300}>{ffffff} /open - Открыть/Закрыть дом");
SCM(playerid, COLOR_WHITE, "{ff3300}>{ffffff} /sellhouse - Продать дом");
SCM(playerid, COLOR_WHITE, "=============================================");
return true;
}
В - public OnPlayerSpawn
new hh = PlayerInfo[playerid][pHouse];
if(hh != 255)//Дом есть.Будет спавнится в своём доме.
{
SetPlayerInterior(playerid, HInts[HousesInfo[hh][hInterior]][hiInt]);
SetPlayerPos(playerid, HInts[HousesInfo[hh][hInterior]][hiX], HInts[HousesInfo[hh][hInterior]][hiY], HInts[HousesInfo[hh][hInterior]][hiZ]);
SetPlayerVirtualWorld(playerid, HousesInfo[hh][hVirtWorld]);
return true;
}
if(hh == 255)//Дома нету.Будет спавнится с ЖД вокзале ЛС.
{
SetPlayerPos(playerid,1757.6338,-1895.7892,13.5561);
SetPlayerFacingAngle(playerid, 270.8289);
SetPlayerInterior(playerid, 0);
SetPlayerVirtualWorld(playerid,0);
}
В - public OnPlayerKeyStateChange
if(newkeys == 1024)
{
for(new i = 0; i < AllHouse; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 2.0, HousesInfo[i][hX], HousesInfo[i][hY], HousesInfo[i][hZ]))
{
if(!HousesInfo[i][hLock] || PlayerInfo[playerid][pHouse] == i)
{
SetPlayerInterior(playerid,HInts[HousesInfo[i][hInterior]][hiInt]);
SetPlayerPos(playerid,HInts[HousesInfo[i][hInterior]][hiX],HInts[HousesInfo[i][hInterior]][hiY],HInts[HousesInfo[i][hInterior]][hiZ]);
SetPlayerVirtualWorld(playerid,HousesInfo[i][hVirtWorld]);
}
}
if(IsPlayerInRangeOfPoint(playerid, 2.0, HInts[HousesInfo[i][hInterior]][hiX], HInts[HousesInfo[i][hInterior]][hiY], HInts[HousesInfo[i][hInterior]][hiZ]) && GetPlayerVirtualWorld(playerid) == HousesInfo[i][hVirtWorld])
{
SetPlayerInterior(playerid, 0);
SetPlayerPos(playerid, HousesInfo[i][hX], HousesInfo[i][hY] ,HousesInfo[i][hZ]);
SetPlayerVirtualWorld(playerid, 0);
}
}
}
В конец мода
//==================== Дом =====================================================
stock LoadHouses()
{
new File = ini_openFile("House/config.ini");
ini_getInteger(File,"Houses",AllHouse);
ini_closeFile(File);
new arrCoords[10][64];
new strFromFile2[256];
new File: file = fopen("House/houses.cfg", io_read);
if(file)
{
new idx;
while (idx < AllHouse)
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, ',');
HousesInfo[idx][hOwned] = strval(arrCoords[0]);
strmid(HousesInfo[idx][hOwner], arrCoords[1], 0, strlen(arrCoords[1]), 255);
HousesInfo[idx][hX] = floatstr(arrCoords[2]);
HousesInfo[idx][hY] = floatstr(arrCoords[3]);
HousesInfo[idx][hZ] = floatstr(arrCoords[4]);
HousesInfo[idx][hInterior] = strval(arrCoords[5]);
HousesInfo[idx][hVirtWorld] = strval(arrCoords[6]);
HousesInfo[idx][hPrice] = strval(arrCoords[7]);
HousesInfo[idx][hLock] = strval(arrCoords[8]);
HousesInfo[idx][hLevel] = strval(arrCoords[9]);
idx++;
}
printf("[ Загрузка ... ] Дома загружены - %d",idx);
fclose(file);
}
return true;
}
stock SaveHouses()//Сохранение домов
{
new File = ini_openFile("House/config.ini");
ini_setInteger(File,"Houses",AllHouse);
ini_closeFile(File);
new idx;
new File: file2;
while(idx < AllHouse)
{
new coordsstring[300];
format(coordsstring, sizeof(coordsstring), "%d,%s,%f,%f,%f,%d,%d,%d,%d,%d\n",
HousesInfo[idx][hOwned],
HousesInfo[idx][hOwner],
HousesInfo[idx][hX],
HousesInfo[idx][hY],
HousesInfo[idx][hZ],
HousesInfo[idx][hInterior],
HousesInfo[idx][hVirtWorld],
HousesInfo[idx][hPrice],
HousesInfo[idx][hLock],
HousesInfo[idx][hLevel]);
if(!idx) file2 = fopen("House/houses.cfg", io_write);
else file2 = fopen("House/houses.cfg", io_append);
fwrite(file2, coordsstring);
idx++;
fclose(file2);
}
return true;
}
stock UpdateHouse(h)
{
new string[228];
DestroyDynamicMapIcon(HousesInfo[h][hIcon]);
DestroyPickup(HousesInfo[h][hPickup]);
if(HousesInfo[h][hOwned] == 0)
{
format(string,sizeof(string), "{FF9900}*** Продается ***\n\n{ffffff}Номер: {AFAFAF}%d\n{FFFFFF}Стоимость: {AFAFAF}%d {FFFFFF}[$]\nУровень: {AFAFAF}%d{ffffff}\n\nЧтобы купить, введите {AFAFAF}/buyhouse",h,HousesInfo[h][hPrice],HousesInfo[h][hLevel]);
Update3DTextLabelText(houses_text[h], 0xFFFFFFFF, string);
HousesInfo[h][hIcon] = CreateDynamicMapIcon(HousesInfo[h][hX], HousesInfo[h][hY],HousesInfo[h][hZ], 31, COLOR_WHITE, 0, -1, -1, 400.0);
HousesInfo[h][hPickup] = CreatePickup(1273, 23, HousesInfo[h][hX], HousesInfo[h][hY],HousesInfo[h][hZ]);
}
else if(HousesInfo[h][hOwned] == 1)
{
format(string,sizeof(string), "Дом № %d\n\nУровень: %d\nВладелец: %s",h,HousesInfo[h][hLevel],HousesInfo[h][hOwner]);
Update3DTextLabelText(houses_text[h], 0xFFFFFFFF, string);
HousesInfo[h][hIcon] = CreateDynamicMapIcon(HousesInfo[h][hX], HousesInfo[h][hY],HousesInfo[h][hZ], 32, COLOR_WHITE, 0, -1, -1, 400.0);
HousesInfo[h][hPickup] = CreatePickup(1272, 23, HousesInfo[h][hX], HousesInfo[h][hY],HousesInfo[h][hZ]);
}
}
//==============================================================================