Command doesnt do what it is supposed to do. -
Ahrim - 09.11.2013
Hello, here is a command that I was doing last night.
pawn Код:
CMD:haddress(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] < 4)
{
SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use that command!");
return 1;
}
new string[128], houseid, des[30];
if(sscanf(params, "ds[30]", houseid, des)) return SendClientMessageEx(playerid, COLOR_WHITE, "{1AB7D6}USAGE:{FFFFFF}: /haddress [House ID] [House Address]");
if( !( 0 <= houseid < MAX_HOUSES ) ) return SendClientMessageEx(playerid, COLOR_WHITE, "Invalid House ID");
for(new h = 0; h < MAX_HOUSES; h++)
{
if(strcmp(des, "none", true) == 0)
{
format(HouseInfo[houseid][hAddress], 30, "");
format(string, sizeof(string), "You have removed the house address.");
print("test1");
}
else if(strcmp(des, "Private Address", true) == 0)
{
format(HouseInfo[houseid][hAddress], 30, "Private Address");
format(string, sizeof(string), "You have set the house address to %s", HouseInfo[houseid][hAddress]);
print("test2");
}
else
{
if(!strcmp(HouseInfo[h][hAddress], des, false))
{
format(string, sizeof(string), "ERROR: A house with the same address is already existed! House ID: %d", h);
print("test3");
}
else
{
format(HouseInfo[houseid][hAddress], 30, "%s", des);
format(string, sizeof(string), "You have changed the house address to %s.", des);
print("test4");
}
}
}
SendClientMessageEx(playerid, COLOR_WHITE, string);
DestroyDynamicPickup(HouseInfo[houseid][hPickupID]);
DestroyDynamic3DTextLabel( HouseInfo[ houseid ][ hTextID ]);
CreateHouse( houseid );
format(string, sizeof(string), "%s has edited House ID %d's Address to %s.", GetPlayerNameEx(playerid), houseid, des);
Log("RP/Logs/haddress.log", string);
print("test last");
return 1;
}
Question is, whenever I do a house with the same address as other house, for example.
House ID 1: Troll
and then I do house ID 2's Address to:
House ID 2: Troll
it should say Error: A house with the same address is already existed. HID: 1.
But no, it would change House ID 2's Address to what I said, instead of saying error. It does check the strcmp tho, like, it would spam test3 in console and then it would go to test4.
pawn Код:
if(!strcmp(HouseInfo[h][hAddress], des, false))
{
format(string, sizeof(string), "ERROR: A house with the same address is already existed! House ID: %d", h);
print("test3");
}
else
{
format(HouseInfo[houseid][hAddress], 30, "%s", des);
format(string, sizeof(string), "You have changed the house address to %s.", des);
print("test4");
}
Any Idea how to fix it, or I did it wrong?
Re: Command doesnt do what it is supposed to do. - Patrick - 09.11.2013
I'm not really sure if this code would work, but at least have a try
pawn Код:
CMD:haddress(playerid, params[])
{
new
string[128], houseid, des[30];
if(sscanf(params, "ds[30]", houseid, des))
return SendClientMessageEx(playerid, COLOR_WHITE, "{1AB7D6}USAGE:{FFFFFF}: /haddress [House ID] [House Address]");
if(PlayerInfo[playerid][pAdmin] <= 4)
return SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use that command!");
if( !( 0 <= houseid < MAX_HOUSES ) )
return SendClientMessageEx(playerid, COLOR_WHITE, "Invalid House ID");
for(new h = 0; h < MAX_HOUSES; h++)
{
if(strcmp(des, "none", true) == 0)
{
format(HouseInfo[houseid][hAddress], 30, "");
format(string, sizeof(string), "You have removed the house address.");
print("test1");
}
else if(strcmp(des, "Private Address", true) == 0)
{
format(HouseInfo[houseid][hAddress], 30, "Private Address");
format(string, sizeof(string), "You have set the house address to %s", HouseInfo[houseid][hAddress]);
print("test2");
}
else if(!strcmp(HouseInfo[h][hAddress], des, false))
{
format(string, sizeof(string), "ERROR: A house with the same address is already existed! House ID: %d", h);
print("test3");
}
else
{
format(HouseInfo[houseid][hAddress], 30, "%s", des);
format(string, sizeof(string), "You have changed the house address to %s.", des);
print("test4");
}
break;
}
SendClientMessageEx(playerid, COLOR_WHITE, string), DestroyDynamicPickup(HouseInfo[houseid][hPickupID]),
DestroyDynamic3DTextLabel( HouseInfo[ houseid ][ hTextID ]), CreateHouse( houseid );
format(string, sizeof(string), "%s has edited House ID %d's Address to %s.", GetPlayerNameEx(playerid), houseid, des);
Log("RP/Logs/haddress.log", string);
print("test last");
return 1;
}
Re: Command doesnt do what it is supposed to do. -
Ahrim - 09.11.2013
nope, even if I do a random address like no other houses have it, it would go on test3 and then to test last. It doesn't even go to test4 now.
Or is it the strcmp is making the problem? Im not sure if it's wrong or not, Im kinda confused in strcmp.
Re: Command doesnt do what it is supposed to do. - Patrick - 09.11.2013
How about this code
pawn Код:
CMD:haddress(playerid, params[])
{
new
string[128], houseid, des[30];
if(sscanf(params, "ds[30]", houseid, des))
return SendClientMessageEx(playerid, COLOR_WHITE, "{1AB7D6}USAGE:{FFFFFF}: /haddress [House ID] [House Address]");
if(PlayerInfo[playerid][pAdmin] <= 4)
return SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use that command!");
if( !( 0 <= houseid < MAX_HOUSES ) )
return SendClientMessageEx(playerid, COLOR_WHITE, "Invalid House ID");
for(new h = 0; h < MAX_HOUSES; h++)
{
if(!strcmp(HouseInfo[houseid][hAddress], des, false))
return format(string, sizeof(string), "ERROR: A house with the same address is already existed! House ID: %d", h), print("test3");
if(strcmp(des, "none", true) == 0)
{
format(HouseInfo[houseid][hAddress], 30, "");
format(string, sizeof(string), "You have removed the house address.");
print("test1");
}
else if(strcmp(des, "Private Address", true) == 0)
{
format(HouseInfo[houseid][hAddress], 30, "Private Address");
format(string, sizeof(string), "You have set the house address to %s", HouseInfo[houseid][hAddress]);
print("test2");
}
else
{
format(HouseInfo[houseid][hAddress], 30, "%s", des);
format(string, sizeof(string), "You have changed the house address to %s.", des);
print("test4");
}
break;
}
SendClientMessageEx(playerid, COLOR_WHITE, string), DestroyDynamicPickup(HouseInfo[houseid][hPickupID]),
DestroyDynamic3DTextLabel( HouseInfo[ houseid ][ hTextID ]), CreateHouse( houseid );
format(string, sizeof(string), "%s has edited House ID %d's Address to %s.", GetPlayerNameEx(playerid), houseid, des);
Log("RP/Logs/haddress.log", string);
print("test last");
return 1;
}
Re: Command doesnt do what it is supposed to do. -
Ahrim - 09.11.2013
Nope, doesn't work. :/