SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 07/08/2019, 02:59 PM   #1
KamilPolska
Huge Clucker
 
Join Date: May 2016
Location: Poland
Posts: 374
Reputation: 2
Default Problem HouseInfo

Why doesn't the w /houseinfo price update after changing the price of the house?

Code:
CMD:editprice(playerid, params[])
{
	new houseid, price;

	if(sscanf(params, "dd", houseid, price)) return SendClientMessage(playerid, -1, "/editprice [House ID] [Price]");

	new query[128];

	mysql_format(g_SQL, query, sizeof(query), "select Price from houses where ID = %d", houseid);
	mysql_query(g_SQL, query);

	if(!cache_num_rows()) return SendClientMessage(playerid, -1, "No house found with this ID.");

	HouseInfo[houseid][hPrice] = price;

	mysql_format(g_SQL, query, sizeof(query), "update houses set Price = %d where ID = %d", price, houseid);
	mysql_query(g_SQL, query);
	return 1;
}

CMD:houseinfo(playerid, params[])
{
	mysql_query(g_SQL, "select * from houses");

	new cache = cache_num_rows();

	for(new i = 0; i < cache; i++)
	{
		if(IsPlayerInRangeOfPoint(playerid, 2.5, HouseInfo[i][hExt_X], HouseInfo[i][hExt_Y], HouseInfo[i][hExt_Z]))
		{
			new string[256];

	        format(string, sizeof(string), "Owner: %s\nHouse ID: %d\nInterior: %d\nPrice: %d$", HouseInfo[i][hWlasciciel], HouseInfo[i][hID], HouseInfo[i][hInt], HouseInfo[i][hPrice]);
	        ShowPlayerDialog(playerid, 5555, DIALOG_STYLE_MSGBOX, "House Info", string, "OK", "");
		}
	}
	return 1;
}
__________________
Poland / PAWN Amateur
KamilPolska is offline   Reply With Quote
Old 07/08/2019, 03:34 PM   #2
moura98
Huge Clucker
 
moura98's Avatar
 
Join Date: Jul 2015
Location: Brasil
Posts: 327
Reputation: 17
Default Re: Problem HouseInfo

try
PHP Code:
CMD:editprice(playeridparams[])
{
    new 
houseidprice;

    if(
sscanf(params"dd"houseidprice)) return SendClientMessage(playerid, -1"/editprice [House ID] [Price]");

    new 
query[128];

    
mysql_format(g_SQLquerysizeof(query), "select Price from houses where ID = %d"houseid);
    
mysql_query(g_SQLquery);

    if(!
cache_num_rows()) return SendClientMessage(playerid, -1"No house found with this ID.");

    
HouseInfo[houseid][hPrice] = price;

    
mysql_format(g_SQLquerysizeof(query), "update houses set Price = %d where ID = %d"HouseInfo[houseid][hPrice], houseid);
    
mysql_query(g_SQLquery);
    return 
1;
}

CMD:houseinfo(playeridparams[])
{
    
mysql_query(g_SQL"select * from houses");

    new 
cache cache_num_rows();

    for(new 
0cachei++)
    {
        if(
IsPlayerInRangeOfPoint(playerid2.5HouseInfo[i][hExt_X], HouseInfo[i][hExt_Y], HouseInfo[i][hExt_Z]))
        {
            new 
string[256];

            
format(stringsizeof(string), "Owner: %s\nHouse ID: %d\nInterior: %d\nPrice: %d$"HouseInfo[i][hWlasciciel], HouseInfo[i][hID], HouseInfo[i][hInt], HouseInfo[i][hPrice]);
            
ShowPlayerDialog(playerid5555DIALOG_STYLE_MSGBOX"House Info"string"OK""");
        }
    }
    return 
1;

__________________
moura98 is offline   Reply With Quote
Old 08/08/2019, 12:42 AM   #3
KamilPolska
Huge Clucker
 
Join Date: May 2016
Location: Poland
Posts: 374
Reputation: 2
Default Re: Problem HouseInfo

Did not help. The database is updating but not at /houseinfo
__________________
Poland / PAWN Amateur
KamilPolska is offline   Reply With Quote
Old 08/08/2019, 05:05 AM   #4
SiaReyes
Huge Clucker
 
SiaReyes's Avatar
 
Join Date: Mar 2019
Location: Coordinates X,Y,Z
Posts: 299
Reputation: 20
Default Re: Problem HouseInfo

pawn Code:
CMD:editprice(playerid, params[])
{
    new houseid, price;

    if(sscanf(params, "dd", houseid, price)) return SendClientMessage(playerid, -1, "/editprice [House ID] [Price]");

    new query[128];

    for(new i; i < MAX_HOUSES; i++)
    {
         if(houseid == i)
         {
                HouseInfo[houseid][hPrice] = price;
                printf("House id: %i, Price Updated: %i", houseid, price);
                mysql_format(g_SQL, query, sizeof(query), "UPDATE houses SET Price = %d WHERE ID = %d", price, houseid);
                mysql_query(g_SQL, query);
                return 1;
         }
    }
    SendClientMessage(playerid, -1, "No house found with this ID.");
    return 1;
}

CMD:houseinfo(playerid, params[])
{
    new storestring[300], string[300];
    for(new i; i<MAX_HOUSES; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 2.5, HouseInfo[i][hExt_X], HouseInfo[i][hExt_Y], HouseInfo[i][hExt_Z]))
        {
            format(string, sizeof(string), "Owner: %s\nHouse ID: %d\nInterior: %d\nPrice: %d$", HouseInfo[i][hWlasciciel], HouseInfo[i][hID], HouseInfo[i][hInt], HouseInfo[i][hPrice]);
            strcat(storestring, string);
        }
        else SendClientMessage(playerid, -1, "Your are not near any house");
       
    }
    ShowPlayerDialog(playerid, 5555, DIALOG_STYLE_MSGBOX, "House Info", storestring, "OK", "");
    return 1;
}
__________________
Hey guys,
We've just started up our own hosting company and we are offering cheap game hosting. Our SAMP servers start at only $0.50 cents for 32 slots per month, or $1.50 for 64. We have ONE FREE spot left for a first month free subscription for any game host of your choice. We host most many major games such as SAMP, Call of Duty, 7 Days to Die, Minecraft, CounterStrike, ARK: Survival Evolved, and many more!

Cheapest hosting company official site : http://main-hosts.com/

Cheap Hosting Company is looking for an experience staff.

Sign up to our forums and Control Panel and order one of our cheap game servers. First to sign up will receive a free SA:MP server! Join on discord https://discord.gg/J82JgQJ for more information!

Quote:
Originally Posted by Toroi View Post
blackmail people that join your server using their ip address as hostage

or get a job and play sa-mp for fun
SiaReyes is offline   Reply With Quote
Old 09/08/2019, 06:26 PM   #5
KamilPolska
Huge Clucker
 
Join Date: May 2016
Location: Poland
Posts: 374
Reputation: 2
Default Re: Problem HouseInfo

It did not help. I have created 2 houses with ID 1 and 2. When I want to change the price for a house with ID 1, it is updated in the database for ID 1 and when I enter the command /houseinfo, the price has updated for a house with ID 2.
Code:
CMD:createhouse(playerid, params[])
{
	new int, price;

	if(sscanf(params, "dd", int, price)) return SendClientMessage(playerid, -1, "/createhouse [Int] [Price]");

	new Float:extX, Float:extY, Float:extZ;

	GetPlayerPos(playerid, extX, extY, extZ);

	new HouseID = Iter_Free(Houses);

        format(HouseInfo[HouseID][hOwner], 24, "No owner");
	HouseInfo[HouseID][hPrice] = price;
	HouseInfo[HouseID][hExt_X] = extX;
	HouseInfo[HouseID][hExt_Y] = extY;
	HouseInfo[HouseID][hExt_Z] = extZ;
	HouseInfo[HouseID][hInt] = int;
	//HouseInfo[HouseID][hPickup] = HOUSE_GREEN_PICKUP;
	//HouseInfo[HouseID][hIcon] = HOUSE_GREEN_ICON;
	HouseInfo[HouseID][hPickup] = CreateDynamicPickup(HOUSE_GREEN_PICKUP, 1, extX, extY, extZ, -1, -1, -1, 100.0);
	HouseInfo[HouseID][hIcon] = CreateDynamicMapIcon(extX, extY, extZ, HOUSE_GREEN_ICON, -1, -1, -1, -1, 100.0);

	CreateHouse(HouseID);

	Iter_Add(Houses, HouseID);

	return 1;
}

CreateHouse(HouseID)
{
	new query[1024];

	mysql_format(g_SQL, query, sizeof(query), "INSERT INTO `houses` (`Owner`, `Price`, `ExtX`, `ExtY`, `ExtZ`, `Int`, `Pickup`, `Icon`) VALUES \
	('%s', '%d', %f', '%f', '%f', '%d', '%d', '%d')", HouseInfo[HouseID][hOwner],HouseInfo[HouseID][hPrice],HouseInfo[HouseID][hExt_X],HouseInfo[HouseID][hExt_Y],HouseInfo[HouseID][hExt_Z],
	HouseInfo[HouseID][hInt],HouseInfo[HouseID][hPickup],HouseInfo[HouseID][hIcon]);
	mysql_query(g_SQL, query);

	HouseInfo[HouseID][hID] = cache_insert_id();

	return 1;
}

CMD:editprice(playerid, params[])
{
	new houseid, price;

	if(sscanf(params, "dd", houseid, price)) return SendClientMessage(playerid, -1, "/editprice [House ID] [Price]");

	new query[128];

	mysql_format(g_SQL, query, sizeof(query), "select Price from houses where ID = %d", houseid);
	mysql_query(g_SQL, query);

	if(!cache_num_rows()) return SendClientMessage(playerid, -1, "No house found with this ID.");

	HouseInfo[houseid][hPrice] = price;

	mysql_format(g_SQL, query, sizeof(query), "update houses set Price = %d where ID = %d", price, houseid);
	mysql_query(g_SQL, query);
	return 1;
}

CMD:houseinfo(playerid, params[])
{
	mysql_query(g_SQL, "select * from houses");

	new cache = cache_num_rows();

	for(new i = 0; i < cache; i++)
	{
		if(IsPlayerInRangeOfPoint(playerid, 2.5, HouseInfo[i][hExt_X], HouseInfo[i][hExt_Y], HouseInfo[i][hExt_Z]))
		{
			new string[256];

	        format(string, sizeof(string), "Owner: %s\nHouse ID: %d\nInterior: %d\nPrice: %d$", HouseInfo[i][hOwner], HouseInfo[i][hID], HouseInfo[i][hInt], HouseInfo[i][hPrice]);
	        ShowPlayerDialog(playerid, 5555, DIALOG_STYLE_MSGBOX, "House Info", string, "OK", "");
		}
	}
	return 1;
}
__________________
Poland / PAWN Amateur
KamilPolska is offline   Reply With Quote
Old 10/08/2019, 07:31 AM   #6
GTLS
High-roller
 
GTLS's Avatar
 
Join Date: Aug 2014
Location: India
Posts: 1,049
Reputation: 115
Default Re: Problem HouseInfo

Database indices starts from '0'. So if you change the price of house id '1', it will be counted as second house.

Also, your way of doing is wrong.

1> Use Threaded Queries
2> In your houseinfo command, you call the query without even checking if player is actually near to a house. Use this function:

PHP Code:
stock GetNearestHouse(playerid)
{
        for(new 
0MAX_HOUSESi++)
    {
                 if(!
HouseInfo[i][hID]) continue; //Set the default value of hID -1 in your enum.
        
if(IsPlayerInRangeOfPoint(playerid2.5HouseInfo[i][hExt_X], HouseInfo[i][hExt_Y], HouseInfo[i][hExt_Z])) return i;
    }
return -
1;

Then inside your command:

PHP Code:
CMD:houseinfo(playeridparams[])
{
   new 
GetNearestHouse(playerid);

   if(
== -1) return SCM(playerid, -1"You are not near a house");
   
   new 
string[256];

   
format(stringsizeof(string), "Owner: %s\nHouse ID: %d\nInterior: %d\nPrice: %d$"HouseInfo[i][hOwner], HouseInfo[i][hID], HouseInfo[i][hInt], HouseInfo[i][hPrice]);
   
ShowPlayerDialog(playerid5555DIALOG_STYLE_MSGBOX"House Info"string"OK""");


   return 
1;

You dont have to always call sql queries while getting data. Otherwise, whats the use of those variables you declare.
__________________

I don't help for rep. I help cuz I was helped in the past.


Retired from SAMP Scene. Might open SAMP Forums once in a while.

Some treats for ya. Click em
Basic House System
Simple Speedo
Base Login/Register Script


Last edited by GTLS; 10/08/2019 at 01:40 PM.
GTLS is offline   Reply With Quote
Old 10/08/2019, 08:30 AM   #7
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 660
Reputation: 96
Default Re: Problem HouseInfo

The reason it does not show the new price is this:
pawn Code:
HouseInfo[houseid][hPrice] = price;
You need the house index and not the id of the database. You can use a loop and check if houseid is equal to HouseInfo[i][hID] so you can find the index and update the variable HouseInfo[i][hPrice] = price;

A better solution if you use streamer is to store in E_STREAMER_EXTRA_ID the house index so you can avoid unnecessary loops.

There is however a more important problem and that is memory leak. You keep executing queries with mysql_query without deleting the cache from the memory.

For instance, why do you execute a SELECT query to see if the house exists and then an UPDATE query when you can just execute an UPDATE query and check affected rows?

Last in /houseinfo command, you execute a SELECT query to select EVERYTHING just to get the number of rows and use a loop with variables, really bad.
Calisthenics is offline   Reply With Quote
Old 10/08/2019, 04:31 PM   #8
KamilPolska
Huge Clucker
 
Join Date: May 2016
Location: Poland
Posts: 374
Reputation: 2
Default Re: Problem HouseInfo

The database is set for ID as AUTO_INCREMENT... Good code?
Code:
CMD:editprice(playerid, params[])
{
	new houseid, price;

	if(sscanf(params, "dd", houseid, price)) return SendClientMessage(playerid, -1, "/editprice [House ID] [Price]");

	new query[64];

	mysql_format(g_SQL, query, sizeof(query), "select * from houses where ID = %d", houseid);
	mysql_query(g_SQL, query);

	if(!cache_num_rows()) return SendClientMessage(playerid, -1, "No house found with this ID.");

	for(new a; a < MAX_HOUSES; a++)
	{
		if(HouseInfo[a][hID] == houseid)
		{
			HouseInfo[a][hPrice] = price;
		}
	}

	mysql_format(g_SQL, query, sizeof(query), "UPDATE houses SET Price = %d WHERE ID = %d", price, houseid);
	mysql_tquery(g_SQL, query, "", "");

	SendClientMessage(playerid, -1, "Price updated.");
	return 1;
}
__________________
Poland / PAWN Amateur
KamilPolska is offline   Reply With Quote
Old 12/08/2019, 05:38 PM   #9
GTLS
High-roller
 
GTLS's Avatar
 
Join Date: Aug 2014
Location: India
Posts: 1,049
Reputation: 115
Default Re: Problem HouseInfo

Quote:
Originally Posted by KamilPolska View Post
The database is set for ID as AUTO_INCREMENT... Good code?
No.

Quote:
Originally Posted by Calisthenics View Post
The reason it does not show the new price is this:

For instance, why do you execute a SELECT query to see if the house exists and then an UPDATE query when you can just execute an UPDATE query and check affected rows?
What he meant was, ONLY execute UPDATE query, and call a function inside tquery. Check there if any rows were affected or not. If no rows were affected then show house doesnt exist. And in ELSE code, set your variables.
__________________

I don't help for rep. I help cuz I was helped in the past.


Retired from SAMP Scene. Might open SAMP Forums once in a while.

Some treats for ya. Click em
Basic House System
Simple Speedo
Base Login/Register Script

GTLS is offline   Reply With Quote
Old 12/08/2019, 05:54 PM   #10
KamilPolska
Huge Clucker
 
Join Date: May 2016
Location: Poland
Posts: 374
Reputation: 2
Default Re: Problem HouseInfo

Well? I tested this code and it shows the message "ELSE".
Code:
CMD:editprice(playerid, params[])
{
	new houseid, price;

	if(sscanf(params, "dd", houseid, price)) return SendClientMessage(playerid, -1, "/editprice [House ID] [Price]");

	new query[64];

	mysql_format(g_SQL, query, sizeof(query), "SELECT * FROM houses WHERE ID = %d", houseid);
	mysql_query(g_SQL, query);

	if(!cache_num_rows()) return SendClientMessage(playerid, -1, "No house found with this ID.");

	mysql_format(g_SQL, query, sizeof(query), "UPDATE houses SET Price = %d WHERE ID = %d", price, houseid);
	mysql_tquery(g_SQL, query, "SetPriceHouse", "ddd", playerid, price, houseid);

	SendClientMessage(playerid, -1, "Price updated.");
	return 1;
}

forward SetPriceHouse(playerid, price, houseid);
public SetPriceHouse(playerid, price, houseid)
{
	if(cache_num_rows())
	{
		HouseInfo[houseid][hPrice] = price;
		SendClientMessage(playerid, -1, "IF");
	}
	else
	{
		HouseInfo[houseid][hPrice] = price;
		SendClientMessage(playerid, -1, "ELSE");
	}
	return 1;
}
__________________
Poland / PAWN Amateur
KamilPolska is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Password Hash Problem & MYSQL Saving Problem Faqahat Scripting Help 3 18/04/2016 11:54 AM
error 032: array index out of bounds (variable "HouseInfo") HardRock Scripting Help 2 07/10/2013 10:29 PM
[Ajuda] HouseInfo Jorge_Braz PortuguÍs/Portuguese 1 21/02/2012 10:38 PM
Houseinfo problem Razvann Help Archive 3 23/02/2010 12:20 PM


All times are GMT. The time now is 12:22 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.