Housing dialog using /houses
#1

I want it so if I type /houses it shows me a dialog of all houses that exist, but it only shows me the latest house created.

pawn Код:
CMD:houses(playerid, params[])
{
    new string[500];
    if(!IsPlayerLoggedIn(playerid))
    {
        SendClientMessage(playerid, COLOR_RED, "Error"White": You are restricted from using commands until you log in.");
        return 1;
    }
    if(PlayerInfo[playerid][pAdminLevel] < 1)
    {
        SendClientMessage(playerid, COLOR_RED, "Error"White": You do not have the authority to use this command.");
        return 1;
    }
    if(!AdminDuty[playerid])
    {
        SendClientMessage(playerid, COLOR_RED, "Error"White": You are not on duty as an Administrator (/aduty).");
        return 1;
    }
    for(new i = 1; i < MAX_HOUSES; i++)
    {
        if(HouseInfo[i][hHouseID] == i)
        {
            format(string, sizeof(string), "ID: %d - Address: %s - Owner: %s", HouseInfo[i][hHouseID], HouseInfo[i][hAddress], HouseInfo[i][hOwner]);
            ShowPlayerDialog(playerid, DIALOG_HOUSES, DIALOG_STYLE_LIST, ""Lightblue"House List", string, "", "Cancel");
        }
    }
    return 1;
}
Reply
#2

First of all what's the point of this line? If the system is dynamic, the chances of it to have both same House ID and slot in the array are minimum.
pawn Код:
if(HouseInfo[i][hHouseID] == i)
Also showing the dialog inside the loop will only show for the last house. You need to format the string with the previous text and then show the dialog out of the loop
pawn Код:
for (...)
{
    format(string, sizeof (string), "%s ...", string, ...);
}
ShowPlayerDialog(...);
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
First of all what's the point of this line? If the system is dynamic, the chances of it to have both same House ID and slot in the array are minimum.
pawn Код:
if(HouseInfo[i][hHouseID] == i)
Also showing the dialog inside the loop will only show for the last house. You need to format the string with the previous text and then show the dialog out of the loop
pawn Код:
for (...)
{
    format(string, sizeof (string), "%s ...", string, ...);
}
ShowPlayerDialog(...);
Without using the if statement, the one line that displays the latest created house shows blank formatted information.

Sounded like it would work.. Tried this:

pawn Код:
CMD:houses(playerid, params[])
{
    new string[500];
    if(!IsPlayerLoggedIn(playerid))
    {
        SendClientMessage(playerid, COLOR_RED, "Error"White": You are restricted from using commands until you log in.");
        return 1;
    }
    if(PlayerInfo[playerid][pAdminLevel] < 1)
    {
        SendClientMessage(playerid, COLOR_RED, "Error"White": You do not have the authority to use this command.");
        return 1;
    }
    if(!AdminDuty[playerid])
    {
        SendClientMessage(playerid, COLOR_RED, "Error"White": You are not on duty as an Administrator (/aduty).");
        return 1;
    }
    for(new i = 1; i < MAX_HOUSES; i++)
    {
        if(HouseInfo[i][hHouseID] == i)
        {
            format(string, sizeof(string), "ID: %d - Address: %s - Owner: %s", HouseInfo[i][hHouseID], HouseInfo[i][hAddress], HouseInfo[i][hOwner]);
        }
    }
    ShowPlayerDialog(playerid, DIALOG_HOUSES, DIALOG_STYLE_LIST, ""Lightblue"House List", string, "", "Cancel");
    return 1;
}
But it is still only showing the one line.
Reply
#4

I told you to pass "string" as the first argument in format so you will concatenate the previous text with the current one.

pawn Код:
for(new i = 1; i < MAX_HOUSES; i++)
{
    if(HouseInfo[i][hHouseID] == i)
    {
        format(string, sizeof(string), "%sID: %d - Address: %s - Owner: %s", string, HouseInfo[i][hHouseID], HouseInfo[i][hAddress], HouseInfo[i][hOwner]);
    }
}
ShowPlayerDialog(playerid, DIALOG_HOUSES, DIALOG_STYLE_LIST, ""Lightblue"House List", string, "", "Cancel");
I think I know why you used that if statement; however, you can store to a variable how many houses exist and loop through loaded houses instead of max houses.
Reply
#5

Thanks man, you're a legend. I'd rep if it let me, I'll do it later or tomorrow
Reply
#6

How do I store the latest house ID in the database into a variable?

pawn Код:
cache_get_field_content(id, "HouseID", temp);
            x = strval(temp);
            cache_get_row(id, 0, temp, g_Handle), HouseInfo[x][hHouseID] = strval(temp);
I use this to load the house ID's but say the biggest house ID is 5 I need to store it in a variable
Reply
#7

Your way doing it is a bit complicated. You should consider changing it to a dynamic system without doing some pointless checks and assignments.

For example, I'm not sure if you execute a query for each house ID instead of selecting all the results and then you retrieve the house ID so you can use it as index in the array. With a loop (after selecting all the results about the house table), you can use that as index in the array and hHouseID would only store the unique house ID in the database (auto-increment is used).

Anyways, I hope you think about my recommendation but if you don't want to - it's fine. About what you asked, you need a global variable and assign the "x" to it. If we assume that the last house ID is the one with the highest value as well, then it will assign that house ID.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)