SA-MP Forums Archive
house buy problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: house buy problem (/showthread.php?tid=656141)



house buy problem - div - 08.07.2018

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


Re: house buy problem - Trevor19012 - 08.07.2018

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.


Re: house buy problem - Florin48 - 08.07.2018

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);
}



Re: house buy problem - Rolux - 08.07.2018

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);
}



Re: house buy problem - Florin48 - 08.07.2018

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?


Re: house buy problem - div - 08.07.2018

didnt work :/

Please help, till the time im finding a solution too


Re: house buy problem - Rolux - 08.07.2018

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


Re: house buy problem - div - 08.07.2018

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..


Re: house buy problem - Florin48 - 08.07.2018

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


Re: house buy problem - div - 08.07.2018

But there's a problem..


It isn't storing Owner's name..