Сейчас добавим дома в свой мод.
Сначала нужно скачать файл:Ссылка
Нужно подключить его
dofile("scripts/file.nut");Далее объявим количество домов
const MAX_HOUSE = 4;
Ко всем local
local hInfo = {};Теперь в onScriptInit
for(local h = 0; h < MAX_HOUSE; h++)
{
hInfo[h] <- {};
hInfo[h].hOwned <- 0;// есть владелец или нет
hInfo[h].hOwner <- 0;// владелец
hInfo[h].hEntranceX <- " ";// коры
hInfo[h].hEntranceY <- " ";
hInfo[h].hEntranceZ <- " ";
hInfo[h].hExitX <- " ";// коры
hInfo[h].hExitY <- " ";
hInfo[h].hExitZ <- " ";
hInfo[h].hLevel <- 0;// уровень
hInfo[h].hCena <- 0;// цена
}Сейчас сделаем загрузку и сохранение
function loadHouse()
{
local myfile3 = file("house.cfg", "rb+");
local arrCoords = array(10);
local fileContent = myfile3.readFile();
local aFileContent = split(fileContent, "\n");
if(myfile3)
{
local idx = 0;
while(idx < hInfo.len())
{
arrCoords = split(aFileContent[idx],"|");
hInfo[idx].hOwned = arrCoords[0].tointeger();
hInfo[idx].hOwner = arrCoords[1].tostring();
hInfo[idx].hEntranceX = arrCoords[2].tofloat();
hInfo[idx].hEntranceY = arrCoords[3].tofloat();
hInfo[idx].hEntranceZ = arrCoords[4].tofloat();
hInfo[idx].hExitX = arrCoords[5].tofloat();
hInfo[idx].hExitY = arrCoords[6].tofloat();
hInfo[idx].hExitZ = arrCoords[7].tofloat();
hInfo[idx].hLevel = arrCoords[8].tointeger();
hInfo[idx].hCena = arrCoords[9].tointeger();
log("House "+idx+" Owner: "+ hInfo[idx].hOwner );
idx++;
}
log("|House: "+MAX_HOUSE);
}
return true;
}
addEvent("scriptInit", loadHouse);
function saveCFG()
{
local idx=0;
while (idx < hInfo.len())
{
local myfile3;
local str;
str = format(hInfo[idx].hOwned+"|"
+hInfo[idx].hOwner+"|"
+hInfo[idx].hEntranceX+"|"
+hInfo[idx].hEntranceY+"|"
+hInfo[idx].hEntranceZ+"|"
+hInfo[idx].hExitX+"|"
+hInfo[idx].hExitY+"|"
+hInfo[idx].hExitZ+"|"
+hInfo[idx].hLevel+"|"
+hInfo[idx].hCena+"\r\n");
if(idx == 0)
{
myfile3 = file("house.cfg", "wb+");
}
else
{
myfile3 = file("house.cfg", "ab+");
}
myfile3.writeline(str);
idx++;
}
idx = 0;
return true;
}Сейчас в onPlayerCommand
if(cmd[0] == "/enter") {
if(users[playerid].hkey == 255) return sendPlayerMessage(playerid, "[Ошибка] У вас уже нет Дома!",Red);
local home = users[playerid].hkey;
if(playerToPoint(playerid, 2.0, hInfo[home].hEntranceX, hInfo[home].hEntranceY, hInfo[home].hEntranceZ)) {
if(hInfo[home].hOwner == getPlayerName(playerid)) {
setPlayerCoordinates(playerid, hInfo[home].hExitX, hInfo[home].hExitY, hInfo[home].hExitZ);
setPlayerDimension(playerid, home+1);
displayPlayerText(playerid, 0.3, 0.8, "~y~Welcome Home", 5000);
}
}
}
if(cmd[0] == "/exit")
{
local home = users[playerid].hkey;
if(playerToPoint(playerid, 2.0, hInfo[home].hExitX, hInfo[home].hExitY, hInfo[home].hExitZ)) {
setPlayerCoordinates(playerid, hInfo[home].hEntranceX, hInfo[home].hEntranceY, hInfo[home].hEntranceZ);
setPlayerDimension(playerid, 0);
}
}
//=========================================/ house /=========================================//
if(cmd[0] == "/buyhouse")
{
if(users[playerid].hkey != 255) return sendPlayerMessage(playerid, "[Ошибка] У вас уже есть Дом!",Red);
for(local h = 0; h < hInfo.len(); h++) {
if(playerToPoint(playerid, 2.0, hInfo[h].hEntranceX, hInfo[h].hEntranceY, hInfo[h].hEntranceZ) && hInfo[h].hOwned == 0) {
if(users[playerid].level < hInfo[h].hLevel) return sendPlayerMessage(playerid, " Вы должны быть "+hInfo[h].hLevel+" уровня чтобы купить Дом.",Red);
if(users[playerid].money >= hInfo[h].hCena) {
users[playerid].hkey = h;
hInfo[h].hOwned = 1;
hInfo[h].hOwner = getPlayerName(playerid);
local amount = hInfo[h].hCena;
givePlayerMoney(playerid, -amount);users[playerid].money -= amount;
sendPlayerMessage(playerid, "* Поздравляем, Вы только что приобрели Дом.",lemon);
sendPlayerMessage(playerid, "* Для того чтоб продать наберите - /sellhouse.",lemon);
saveCFG();
savePlayers();
return true;
}
else {
sendPlayerMessage(playerid, "[Ошибка] Недостаточно средств!",Red);
return true;
}
}
}
return true;
}
if(cmd[0] == "/sellhouse")
{
if(users[playerid].hkey == 255) return sendPlayerMessage(playerid, "[Ошибка] У Вас нет Домa.",Red);
if(hInfo[users[playerid].hkey].hOwner == getPlayerName(playerid)) {
local bouse = users[playerid].hkey;
local amount = hInfo[bouse].hCena;
givePlayerMoney(playerid, amount);users[playerid].money += amount;
hInfo[bouse].hOwned = 0;
hInfo[bouse].hOwner = "none";
sendPlayerMessage(playerid, "Вы продали Дом за "+amount+" $", lemon);
users[playerid].hkey = 255;
savePlayers();saveCFG();
return true;
}
else {
sendPlayerMessage(playerid, "[Ошибка] У Вас нет Домa!",Red);
}
return true;
}Осталось сделать ключи
Я применяю к написанию мода с помощью Регистрация на диалог системе
В onPlayerJoin
users[playerid].hkey <- 0;
В onPlayerSpawn
else if(Logged[playerid] == 1) {
local home = users[playerid].hkey;
if(home != 255) {
setPlayerCoordinates(playerid, hInfo[home].hExitX, hInfo[home].hExitY, hInfo[home].hExitZ);
setPlayerDimension(playerid, home+1);
displayPlayerText(playerid, 0.3, 0.8, "~y~Welcome Home", 5000);
}
}В onPlayerRegister
pFile.setKey("House", "hkey", "255");В onPlayerLogin
users[playerid].hkey = pFile.getKey("House", "hkey").tointeger();В savePlayers
pFile.setKey("House", "hkey", users[i].hkey.tostring());Добавим дома на карту
function addBlips()
{
for(local h = 0; h< hInfo.len(); h++)
{
local houseblip = createBlip(29, hInfo[h].hEntranceX, hInfo[h].hEntranceY, hInfo[h].hEntranceZ, true);
local housecp = createCheckpoint( 8, hInfo[h].hEntranceX, hInfo[h].hEntranceY, hInfo[h].hEntranceZ, 0.0, 0.0, 0.0, 0.05);
if(hInfo[h].hOwned == 0) {
setBlipColor(houseblip,0xFF0000AA,-1);
}
else {
setBlipColor(houseblip,0x00FF00AA,-1);
}
}
}
addEvent("scriptInit", addBlips);Ну вот и все. Файл расположить в папке files
Вот сам файл Ссылка


