house buy problem
#1

Hello, it's about a house system..

When i type a command /buyhouse [id]

if I type a house, first time will work fine.. but after that, it will say it is already owned

Код:
CMD:buyhouse(playerid, params[])
{
	{
	    if(sscanf(params, "i", hInfo[playerid][HouseID]))
	    {
	    
     	Error(playerid, "Invalid house ID.");
		}
		
		else if(hInfo[playerid][HouseOwned] == 1)
		return Error(playerid, "This house is already owned by someone else");


		else
		BuyHouse(playerid);
	}
	return 1;
}

BuyHouse(playerid)
{
	hInfo[playerid][HouseOwned] = 1;
	new pqname[24];
	GetPlayerName(playerid, pqname, 24);
	new queryq[96];
	format(queryq, sizeof(queryq), "UPDATE `houses` SET `HouseOwner` = '%s', `HouseOwned` = '1' WHERE `HouseID` = '%d' ", pqname, hInfo[playerid][HouseID]);
	mysql_tquery(dbHandle, queryq);
}
Like i type /buyhouse 1

If I type /buyhouse 2 then, it will say its already bought, while its not
Reply
#2

Your hinfo before the query. Try deleting that. Because in your cmd you have it where if it is owned it will return the error whereas in your BuyHouse function you have it set to 1 in two places. Try and remove the one not in the query, the one at the top. See if that works.
Reply
#3

try this but I do not know exactly how your home system is


CMD:buyhouse(playerid, params[])
{
new id;
if(sscanf(params, "i", id)) return Error(playerid, "Invalid house ID.");
if(hInfo[id][HouseOwned] == 1) Error(playerid, "This house is already owned by someone else");
else BuyHouse(playerid, id);
return 1;
}

BuyHouse(playerid, id)
{
hInfo[id][HouseOwned] = 1;
new pqname[24];
GetPlayerName(playerid, pqname, sizeof(pqname));
new queryq[96];
format(queryq, sizeof(queryq), "UPDATE `houses` SET `HouseOwner` = '%s', `HouseOwned` = '1' WHERE `HouseID` = '%d' ", pqname, id);
mysql_tquery(dbHandle, queryq);
}
Reply
#4

Your whole code is a mess.

Try it like this:
Код:
CMD:buyhouse(playerid, params[])
{
	new _house;
	if(sscanf(params, "i", _house)) return Error(playerid, "Invalid house ID.");
	if(hInfo[_house][HouseOwned] == 1) return Error(playerid, "This house is already owned by someone else");
	BuyHouse(playerid,_house);
	return 1;
}

BuyHouse(playerid,house)
{
	hInfo[house][HouseOwned] = 1;
	new pqname[24];
	GetPlayerName(playerid, pqname, 24);
	new queryq[96];
	format(queryq, sizeof(queryq), "UPDATE `houses` SET `HouseOwner` = '%s', `HouseOwned` = '1' WHERE `HouseID` = '%d' ", pqname, hInfo[house][HouseID]);
	mysql_tquery(dbHandle, queryq);
}
Reply
#5

Quote:
Originally Posted by Rolux
Посмотреть сообщение
Your whole code is a mess.

Try it like this:
Код:
CMD:buyhouse(playerid, params[])
{
	new _house;
	if(sscanf(params, "i", _house)) return Error(playerid, "Invalid house ID.");
	if(hInfo[_house][HouseOwned] == 1) return Error(playerid, "This house is already owned by someone else");
	BuyHouse(playerid,_house);
	return 1;
}

BuyHouse(playerid,house)
{
	hInfo[house][HouseOwned] = 1;
	new pqname[24];
	GetPlayerName(playerid, pqname, 24);
	new queryq[96];
	format(queryq, sizeof(queryq), "UPDATE `houses` SET `HouseOwner` = '%s', `HouseOwned` = '1' WHERE `HouseID` = '%d' ", pqname, hInfo[house][HouseID]);
	mysql_tquery(dbHandle, queryq);
}
why my code is a mess?
Reply
#6

didnt work :/

Please help, till the time im finding a solution too
Reply
#7

Quote:
Originally Posted by Florin48
Посмотреть сообщение
why my code is a mess?
I meant div's code,not yours.
Reply
#8

Made some changes

Код:
CMD:buyhouse(playerid, params[])
{
	new hid, pqname[24], queryq[69], queryqq[96];
	
	{
	    if(sscanf(params, "i", hid))
	    {
	    
     	Error(playerid, "Invalid house ID.");
		}
		
		
		else if(hInfo[houseid][HouseOwned] == 1)
		{
		cache_get_field_content_int(hid, "HouseID", hInfo[houseid][HouseID]);
		Error(playerid, "This house is already owned by someone else");
		}

		else
		GetPlayerName(playerid, pqname, 24);
		format(queryq, sizeof(queryq), "UPDATE `houses` SET `HouseOwned` = '1' WHERE `HouseID` = '%d' ", hInfo[houseid][HouseID]);
		format(queryqq, 96, "INSERT * INTO `houses` (`HouseOwner`) VALUES ('%s') WHERE `HouseID` = '%d'", pqname, hInfo[houseid][HouseID]);
		mysql_tquery(dbHandle, queryq);
	}
	return 1;
}
But the owner's name isn't even being inserted in the MySQL


Nor the HouseOwned value is being updated to 1..
Reply
#9

Quote:
Originally Posted by Florin48
Посмотреть сообщение
mysql_format(dbHandle, queryq, sizeof(queryq), "UPDATE `houses` SET `HouseOwned` = '1' WHERE `HouseID` = '%d' ", hid);
mysql_tquery(dbHandle, queryq);
mysql_format(dbHandle, queryqq, sizeof(queryqq), "INSERT INTO `houses` (`HouseOwner`) VALUES ('%s') WHERE `HouseID` = '%d'", pqname, hid);
mysql_tquery(dbHandle, queryq);
try this to save
Reply
#10

But there's a problem..


It isn't storing Owner's name..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)