House Address -
Danijel. - 10.04.2014
So i am making a house system and i want to make when you create a house it creates a house address with city zones and number. i dont know how to make numbering system to check there are no same numbers in same city zone, but there can be same number in other zone.
Re: House Address -
Conradus - 10.04.2014
You can save the house number and zone in an enumerator like this:
Код:
#define MAX_HOUSES 1000
enum hInfo {
..., // other house variables
hNumber,
hZone
};
new HouseInfo[MAX_HOUSES][hInfo];
And something to check if a number exists in a zone:
Код:
stock DoesNumberExistInZone(zone, number) {
for(new h = 0; h < MAX_HOUSES; h++) {
if(HouseInfo[h][hZone] == zone && HouseInfo[h][hNumber] = number) {
return true;
}
}
return false;
}
So now you can use this anywhere in your code to check if a house number exists in a particular zone:
Код:
DoesNumberExistInZone(zone, number)
hope it helped
Re: House Address -
Danijel. - 10.04.2014
Код:
stock HouseAddress(houseid)
{
for(new h = 0; h < MAX_HOUSES; h++)
{
new number = 1;
if(HouseInfo[houseid][hZone] == HouseInfo[h][hZone] && number == HouseInfo[h][hNumber])
{
number++;
}
else
{
HouseInfo[houseid][hNumber] = number;
format(HouseInfo[h][hAdresa], 32, "%s %d", HouseInfo[houseid][hZone], HouseInfo[houseid][hNumber]);
SavePlayerHouse(houseid);
return 1;
}
}
return false;
}
I did it like this, it should work.
Thank you, you helped me a bit
Re: House Address -
Danijel. - 10.04.2014
pawn Код:
stock OdrediAdresu(houseid, number)
{
new string[128];
for(new h = 0; h < MAX_HOUSES; h++)
{
if(HouseInfo[houseid][hZone] == HouseInfo[h][hZone] && number == HouseInfo[h][hNumber])
{
OdrediAdresu(houseid, number+1);
}
else
{
HouseInfo[houseid][hNumber] = number;
format(string, sizeof string, "%d", number);
print(string);
format(string, sizeof string, "%s", HouseInfo[houseid][hZone]);
print(string);
format(HouseInfo[houseid][hAdresa], 32, "%s %d", HouseInfo[houseid][hZone], HouseInfo[houseid][hNumber]);
format(string, sizeof string, "%s", HouseInfo[houseid][hAdresa]);
print(string);
new Query[384];
format(Query, sizeof(Query), "UPDATE HOUSES SET ADRESA = '%s' WHERE ID = %d ", HouseInfo[houseid][hAdresa], houseid);
db_query(Database, Query);
return 1;
}
}
return false;
}
I made this but it always puts the number 1
(
Re: House Address -
Conradus - 10.04.2014
Maybe this works:
Код:
stock OdrediAdresu(houseid, number)
{
new string[128];
for(new h = 0; h < MAX_HOUSES; h++)
{
if(HouseInfo[houseid][hZone] == HouseInfo[h][hZone] && number == HouseInfo[h][hNumber])
{
number++;
OdrediAdresu(houseid, number);
}
else
{
HouseInfo[houseid][hNumber] = number;
format(string, sizeof string, "%d", number);
print(string);
format(string, sizeof string, "%s", HouseInfo[houseid][hZone]);
print(string);
format(HouseInfo[houseid][hAdresa], 32, "%s %d", HouseInfo[houseid][hZone], HouseInfo[houseid][hNumber]);
format(string, sizeof string, "%s", HouseInfo[houseid][hAdresa]);
print(string);
new Query[384];
format(Query, sizeof(Query), "UPDATE HOUSES SET ADRESA = '%s' WHERE ID = %d ", HouseInfo[houseid][hAdresa], houseid);
db_query(Database, Query);
return 1;
}
}
return false;
}
Re: House Address -
Danijel. - 10.04.2014
Still not working, the number is always 1
Re: House Address -
BroZeus - 10.04.2014
"new number=1;" this line should be out of loop on top | You placed it in inside loop plz change that
Re: House Address -
Danijel. - 10.04.2014
it is not inside the loop
Re: House Address -
BroZeus - 10.04.2014
this...
pawn Код:
stock OdrediAdresu(houseid, number)
{
new string[128];
for(new h = 0; h < MAX_HOUSES; h++)
{
if(HouseInfo[houseid][hZone] == HouseInfo[h][hZone] && number == HouseInfo[h][hNumber])
{
number++;
return OdrediAdresu(houseid, number);
}
}
HouseInfo[houseid][hNumber] = number;
format(string, sizeof string, "%d", number);
print(string);
format(string, sizeof string, "%s", HouseInfo[houseid][hZone]);
print(string);
format(HouseInfo[houseid][hAdresa], 32, "%s %d", HouseInfo[houseid][hZone], HouseInfo[houseid][hNumber]);
format(string, sizeof string, "%s", HouseInfo[houseid][hAdresa]);
print(string);
new Query[384];
format(Query, sizeof(Query), "UPDATE HOUSES SET ADRESA = '%s' WHERE ID = %d ", HouseInfo[houseid][hAdresa], houseid);
db_query(Database, Query);
return 1;
}