/houseedit command
#1

Hello, I was trying to create cmd to edit Level and Price of houses on my server. I used this code, but it doesn't work well, I can't find a problem, maybe someone else can help me with this please?

Код:
if(strcmp(cmd, "/houseedit", true) == 0)
    {
	if(UserInfo[playerid][uAdmin] < 4)
	{
		SendClientMessage(playerid, COLOR_GRAD2, "   You are not an Admin!");
		return 1;
	}

	new string[128], choice[32], amount;
	if(sscanf(cmdtext, "s[20]d", choice, amount))
	{
	SendClientMessage(playerid, COLOR_LIGHTRED, "/houseedit  | Level/Price | ammount");
	}
	for(new i = 0; i < sizeof(HouseInfo); i++)
	{
		if (IsPlayerInRangeOfPoint(playerid,3,HouseInfo[i][hEntranceX], HouseInfo[i][hEntranceY], HouseInfo[i][hEntranceZ]))
		{
			format(string, sizeof(string), "House: %d", i);
			SendClientMessage(playerid, COLOR_GRAD2, string);
			if(amount > 0)
			{
				if(strcmp(choice,"level",true) == 0)
				{
					HouseInfo[i][hLevel] = amount;
					format(string, sizeof(string), "You have changed House ID(%d)'s price to %d!", i, amount);
			        SendClientMessage(playerid, COLOR_YELLOW, string);
					SaveHouse(i);
			        LoadHouse();
				}
				else if(strcmp(choice,"price",true) == 0)
				{
					HouseInfo[i][hPrice] = amount;
					format(string, sizeof(string), "You have changed House ID(%d)'s price to %d!", i, amount);
			        SendClientMessage(playerid, COLOR_YELLOW, string);
					SaveHouse(i);
			        LoadHouse();
				}
			}
		}
	}
	return 1;
    }
So here is this command, every time when I write down this commands I get just this txt back '/houseedit | Level/Price | ammount' and nothing else happens. Ty
Reply
#2

First of all this two functions if(strcmp(choice,"level",true) == 0) and if(strcmp(choice,"price",true) == 0) won't work.
Reply
#3

pawn Код:
if(sscanf(cmdtext, "s[20]d", choice, amount))
{
    return SendClientMessage(playerid, COLOR_LIGHTRED, "/houseedit  | Level/Price | ammount");
}
You might want to put "return" here to prevent the rest of the code to be executed if your parameters are wrong.

pawn Код:
LoadHouse();
Don't you need to supply the houseID to load in that function?
Or do you load all houses again by using that function?

pawn Код:
new string[128], choice[32], amount;
if(sscanf(cmdtext, "s[20]d", choice, amount))
First you define "choice" as a string of 32 characters long, then using sscanf, you only use 20 of them.
Either increase the size in sscanf "s[32]", or lower the size in the "new" line to 20 to make them match.

pawn Код:
if(amount > 0)
Why check the amount for every house, to see if it's valid.
Use that just below the sscanf statement, before you begin the loop and use "return SendClientMessage..." to notify the player he entered a wrong amount.

Also, add "return 1;" to every if-statement (the ones that use strcmp), to stop processing the rest of the houses. Otherwise, when adjusting the price of HouseID 1, you'll be checking the other houses as well (2000 if your HouseInfo array is that large).

pawn Код:
if(strcmp(choice,"level",true) == 0)
{
        HouseInfo[i][hLevel] = amount;
        format(string, sizeof(string), "You have changed House ID(%d)'s price to %d!", i, amount);
    SendClientMessage(playerid, COLOR_YELLOW, string);
        SaveHouse(i);
        LoadHouse();
                return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)