/makehouse command doesnt work
#1

At first I made it so I typed /makehouse ID of house etc..
And that worked, but then I wanted to make it so I just typed /makehouse and it would take the next id that hadent been created allready automaticlly and I get Unknown Command..


How can I make it so the cmd will automaticlly check which ids allready been created and take the next one?
Example if I do /makehouse it will take first id 1, next time i use it will be id 2 etc..
Reply
#2

Loops are the answer to this.
pawn Код:
CMD:makehouse(playerid, params[])
{
    if((pInfo[playerid][Admin] < 2) || (!pInfo[playerid][AdminDuty] && pInfo[playerid][Admin] < 1337)) return 0;
    new name[48], price, level;
    if(sscanf(params, "s[48]ii", name, price, level)) return SCM(playerid, -1, "USAGE: /makehouse [Name] [Price] [Level]");
    new string[128];
    for(new h = 0; h < sizeof(House); h++)
    {
        format(string, sizeof(string), House_File, h);
        if(fexist(string)) continue;
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        CreateSaveHouse(name, h, price, level, h + 1, x, y, z);
        format(string, sizeof(string), "[Admin Info]: %s has created a House at their position. ID: %d | Coords: %f, %f, %f", name, h, x, y, z);
        SendAdminMessage(COLOR_LIGHTRED, string);
        return 1;
    }
    SendClientMessage(playerid, COLOR_LIGHTRED, "The server has reached the maximum number of houses. Please contact a Developer.");
    return 1;
}

stock CreateSaveHouse(name[], id, price, level, vw, Float:PosX, Float:PosY, Float:PosZ)
{
    new zone[64];
    format(zone, sizeof(zone), House_File, id);
    new INI:File = INI_Open(zone);
    INI_WriteFloat(File, "Enter_X", PosX);
    INI_WriteFloat(File, "Enter_Y", PosY);
    INI_WriteFloat(File, "Enter_Z", PosZ);
    INI_WriteFloat(File, "Exit_X", 223.42928466797);
    INI_WriteFloat(File, "Exit_Y", 1287.3064941406);
    INI_WriteFloat(File, "Exit_Z", 1082.14);
    INI_WriteString(File, "HouseName", name);
    INI_WriteString(File, "Owner", "Apartment");
    INI_WriteInt(File, "Price", price);
    INI_WriteInt(File, "Level", level);
    INI_WriteInt(File, "Interior", 1);
    INI_WriteInt(File, "VW", vw);
    INI_WriteInt(File, "On_Sell", 1);
    INI_WriteInt(File, "Lock", 0);
    GetHouse2DZone(id, zone, sizeof(zone));
    format(zone, sizeof(zone), "%s %i", zone, id);
    INI_WriteString(File, "Address", zone);
    INI_Close(File);

    House[id][Enter_X] = PosX;
    House[id][Enter_Y] = PosY;
    House[id][Enter_Z] = PosZ;
    House[id][Exit_X] = 223.42928466797;
    House[id][Exit_Y] = 1287.3064941406;
    House[id][Exit_Z] = 1082.14;
    format(House[id][HouseName], 48, "%s", name);
    format(House[id][Owner], 48, "Apartment");
    House[id][Price] = price;
    House[id][Level] = level;
    House[id][IntID] = 1;
    House[id][VW] = vw;
    House[id][On_Sell] = 1;
    House[id][Lock] = 0;
    format(House[id][Address], 32, "%s %i", zone, id);
    House[id][PickupU] = CreateDynamicPickup(1273, 23, PosX, PosY, PosZ, -1, -1, -1, 20.0);
    new string[245];
    format(string, sizeof(string), "{29CC3F}Owner: "COLOR_WHITE"Apartment\n{29CC3F}House name: "COLOR_WHITE"%s\n{29CC3F}Price: "COLOR_WHITE"%i\n{29CC3F}Level: "COLOR_WHITE"%i\n{29CC3F}Address: "COLOR_WHITE"%s %i\n (/buyhouse)", name, price, level, zone, id);
    House[id][DLabel] = CreateDynamic3DTextLabel(string, 0xFFFFFF,  PosX,PosY,PosZ, 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 20.0);
    House[id][Icon] = CreateDynamicMapIcon(PosX,PosY,PosZ, 31, 0, -1, -1, -1, 100.0);
    return 1;
}
Source:
https://sampwiki.blast.hk/wiki/Loops
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)