SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 07/09/2019, 05:44 PM   #1
ArWin14
Little Clucker
 
Join Date: Mar 2015
Posts: 5
Reputation: 0
Default Business only load id 1

Excuse me, Sir.

I have problem with business system, i really don't know when a business has an owner, why only load business with id 1,

Load code
Code:
Server:SQL_LoadBusinesses()
{
	if(cache_num_rows() == 0)return print("Loading - No businesses were available to load.");

	new rows, fields, str[256];
	cache_get_data(rows, fields, m_Handle);

	for(new i = 0; i < rows && i < MAX_BUSINESS; i++){

		BusinessData[i+1][businessID] = cache_get_field_content_int(i, "id", m_Handle);
		BusinessData[i+1][businessOwnerSQL] = cache_get_field_content_int(i, "OwnerSQL", m_Handle);

		BusinessData[i+1][businessInt][0] = cache_get_field_content_float(i, "InteriorX", m_Handle);
		BusinessData[i+1][businessInt][1] = cache_get_field_content_float(i, "InteriorY", m_Handle);
		BusinessData[i+1][businessInt][2] = cache_get_field_content_float(i, "InteriorZ", m_Handle);
		BusinessData[i+1][businessInt][3] = cache_get_field_content_float(i, "InteriorA", m_Handle);

		BusinessData[i+1][businessWorld] = cache_get_field_content_int(i, "World", m_Handle);
		BusinessData[i+1][businessIntID] = cache_get_field_content_int(i, "InteriorID", m_Handle);

		BusinessData[i+1][businessExt][0] = cache_get_field_content_float(i, "ExteriorX", m_Handle);
		BusinessData[i+1][businessExt][1] = cache_get_field_content_float(i, "ExteriorY", m_Handle);
		BusinessData[i+1][businessExt][2] = cache_get_field_content_float(i, "ExteriorZ", m_Handle);

		BusinessData[i+1][businessBankPickupLoc][0] = cache_get_field_content_float(i, "BankPX", m_Handle);
		BusinessData[i+1][businessBankPickupLoc][1] = cache_get_field_content_float(i, "BankPY", m_Handle);
		BusinessData[i+1][businessBankPickupLoc][2] = cache_get_field_content_float(i, "BankPZ", m_Handle);
		BusinessData[i+1][businessBankPickupIntID] = cache_get_field_content_int(i, "BankPIntID", m_Handle);
		BusinessData[i+1][businessBankPickupWorld] = cache_get_field_content_int(i, "BankPWorld", m_Handle);

		cache_get_field_content(i, "Name", BusinessData[i+1][businessName], m_Handle, 128);
		BusinessData[i+1][businessType] = cache_get_field_content_int(i, "Type", m_Handle);
		cache_get_field_content(i, "Address", BusinessData[i+1][businessAddress], m_Handle, 32);
		BusinessData[i+1][businessMarketPrice] = cache_get_field_content_int(i, "MarketPrice", m_Handle);
		BusinessData[i+1][businessLocked] = cache_get_field_content_int(i, "Locked", m_Handle);
		BusinessData[i+1][businessFee] = cache_get_field_content_int(i, "Fee", m_Handle);
		BusinessData[i+1][businessCashbox] = cache_get_field_content_int(i, "Cashbox", m_Handle);
		BusinessData[i+1][businessLevel] = cache_get_field_content_int(i, "Level", m_Handle);
		BusinessData[i+1][businessProduct] = cache_get_field_content_int(i, "Product", m_Handle);

		for(new w = 0; w < 21; w++){
			format(str, sizeof(str), "Weapons%d", w);
			BusinessData[i+1][businessWeapons][w] = cache_get_field_content_int(i, str, m_Handle);

			format(str, sizeof(str), "Ammo%d", w);
			BusinessData[i+1][businessWeaponsAmmo][w] = cache_get_field_content_int(i, str, m_Handle);
  		}
  		if(BusinessData[i+1][businessOwnerSQL] == 0)
		{
  			format(str, sizeof(str), "[id:%d]\nThis business is for sale!\nType: %s\nPrice:$%s\nAddress: %s\nUse '/buybiz' for purchase this business", i+1, BusinessTypeLabel(i+1), MoneyFormat(BusinessData[i+1][businessMarketPrice]), BusinessData[i+1][businessAddress]);
		}
		else
		{
		    format(str, sizeof(str), "[id:%d]\n%s\nOwner: %s\nAddress: %s", i+1, BusinessData[i+1][businessName], ReturnSQLName(BusinessData[i+1][businessOwnerSQL]), BusinessData[i+1][businessAddress]);
		}

		if(BusinessData[i+1][businessType] == BIZ_BANK){
			BusinessData[i+1][businessBankPickup] = CreateDynamicPickup(1274, 2, BusinessData[i+1][businessBankPickupLoc][0], BusinessData[i+1][businessBankPickupLoc][1], BusinessData[i+1][businessBankPickupLoc][2], BusinessData[i+1][businessBankPickupWorld]);
		}
		BusinessData[i+1][businessLabel] = CreateDynamic3DTextLabel(str, COLOR_YELLOW, BusinessData[i+1][businessExt][0], BusinessData[i+1][businessExt][1], BusinessData[i+1][businessExt][2], 15.0);
  		BusinessData[i+1][businessPickup] = CreateDynamicPickup(1272, 14, BusinessData[i+1][businessExt][0], BusinessData[i+1][businessExt][1], BusinessData[i+1][businessExt][2], 0);
		TotalBusinessesLoaded++;
	}
	printf("Loading - %i businesses from MySQL database.", TotalBusinessesLoaded);

	return true;
}
Saving code
Code:
Server:SaveBusiness(id)
{
	new query[450];

	mysql_format(m_Handle, query, sizeof(query), "UPDATE businesses SET OwnerSQL = %i, InteriorX = %f, InteriorY = %f, InteriorZ = %f, InteriorA = %f WHERE id = %i", BusinessData[id][businessOwnerSQL],
		BusinessData[id][businessInt][0], BusinessData[id][businessInt][1], BusinessData[id][businessInt][2], BusinessData[id][businessInt][3], BusinessData[id][businessID]);
	mysql_tquery(m_Handle, query);

	mysql_format(m_Handle, query, sizeof(query), "UPDATE businesses SET World = %i, InteriorID = %i, ExteriorX = %f, ExteriorY = %f, ExteriorZ = %f WHERE id = %i", BusinessData[id][businessWorld],
		BusinessData[id][businessIntID], BusinessData[id][businessExt][0], BusinessData[id][businessExt][1], BusinessData[id][businessExt][2], BusinessData[id][businessID]);
	mysql_tquery(m_Handle, query);

	mysql_format(m_Handle, query, sizeof(query), "UPDATE businesses SET BankPX = %f, BankPY = %f, BankPZ = %f, BankPIntID = %i, BankPWorld = %i WHERE id = %i", BusinessData[id][businessBankPickupLoc][0],
		BusinessData[id][businessBankPickupLoc][1], BusinessData[id][businessBankPickupLoc][2], BusinessData[id][businessBankPickupIntID], BusinessData[id][businessBankPickupWorld], BusinessData[id][businessID]);
	mysql_tquery(m_Handle, query);

	mysql_format(m_Handle, query, sizeof(query), "UPDATE businesses SET Name = '%e', Type = %i, Address = '%e', MarketPrice = %i, Locked = %i, Fee = %i, Cashbox = %i, Level = %i, Product = %i WHERE id = %i", BusinessData[id][businessName],
		BusinessData[id][businessType], BusinessData[id][businessAddress], BusinessData[id][businessMarketPrice], BusinessData[id][businessLocked], BusinessData[id][businessFee], BusinessData[id][businessCashbox], BusinessData[id][businessLevel],
		BusinessData[id][businessProduct], BusinessData[id][businessID]);

	mysql_tquery(m_Handle, query);

	for(new i = 0; i < 21; i++){

		mysql_format(m_Handle, query, sizeof(query), "UPDATE businesses SET Weapons%d = %i, Ammo%d = %i WHERE id = %i", i, BusinessData[id][businessWeapons][i], i, BusinessData[id][businessWeaponsAmmo][i], BusinessData[id][businessID]);
		mysql_tquery(m_Handle, query);
	}

	printf("[WARNING]: Business %d was saved.", id);
	return true;
}
Screenshot from server log and database


ArWin14 is offline   Reply With Quote
Old 07/09/2019, 07:07 PM   #2
Jonny
Huge Clucker
 
Jonny's Avatar
 
Join Date: Nov 2009
Location: Italy
Posts: 280
Reputation: 38
Default Re: Business only load id 1

You mean that it loads only the business which has an owner?
What if you got 2 businesses with owner and 1 without?
Because there the screenshot shows that you actually loaded 2 business, i can't understand what's the problem
Also, i don't get the point of saving the owner id (Probably from MySQL?) instead of just his playername as owner
__________________
Jonny is offline   Reply With Quote
Old 07/09/2019, 08:25 PM   #3
ArWin14
Little Clucker
 
Join Date: Mar 2015
Posts: 5
Reputation: 0
Default Re: Business only load id 1

Quote:
Originally Posted by darkdrago View Post
You mean that it loads only the business which has an owner?
What if you got 2 businesses with owner and 1 without?
Because there the screenshot shows that you actually loaded 2 business, i can't understand what's the problem
Also, i don't get the point of saving the owner id (Probably from MySQL?) instead of just his playername as owner
Example:
I made 3 business then when it was bought and the server was restarted, the business that was loaded only id 1 and other id is spawned on blueberry with invalid ID but on server log total business loading is 3. (Screenshot for more information)

Sorry for my bad english.
ArWin14 is offline   Reply With Quote
Old 07/09/2019, 09:21 PM   #4
Private200
High-roller
 
Private200's Avatar
 
Join Date: May 2012
Posts: 1,176
Reputation: 211
Default Re: Business only load id 1

Why setting your business data ID to [i+1] instead of simply [i]? You are not even setting it to the database ID, which makes it even weirder. I assume that when looping through the business, you are actually starting from 0 and going to 1 (as the number of businesses loaded). If that is the case, you will go through "0; 1", while your business ID's are "1; 2".

Your loop most likely is like "for (new i = 0; i < TotalBusinessesLoaded; i ++)", which basically will loop 0 and 1 for the two loaded businesses.

Change "i+1" to just "i" and see how that goes.
Private200 is offline   Reply With Quote
Old 08/09/2019, 01:20 AM   #5
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,738
Reputation: 1686
Default Re: Business only load id 1

What Private200 said. Also:

Code:
BusinessData[i+1][businessID] = cache_get_field_content_int(i, "id", m_Handle);
So that would be, if you'd be at the first loop:

BusinessData[1][businessID] = cache_get_field_content_int(0, "id", m_Handle);

I haven't done anything with MySQL in a long time, but row 1 is actually row 1, am I right people? If so you should switch the 'i' and 'i+1' basically everywhere. If not ignore this entire post please.
This however would explain why one business is loaded in blueberry (0,0,0 xyz).
Aaand I just read that Private200 also said that. Now I am sure. You really need to check all your IDs
Kwarde is offline   Reply With Quote
Old 10/09/2019, 10:47 PM   #6
ArWin14
Little Clucker
 
Join Date: Mar 2015
Posts: 5
Reputation: 0
Default Re: Business only load id 1

Excuse me, sir. Another system are not problem with i+1, for example Factions or Vehicle system.

When I change i+1 to i, businessLabel is showing [id:0] then the system detect as invalid id while I use command '/goto business 0'.
ArWin14 is offline   Reply With Quote
Old 11/09/2019, 07:23 AM   #7
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,177
Reputation: 73
Default Re: Business only load id 1

I think that you're trying to load a business in exactly ordering, I mean that you want to make i to be a businessID, which is totally wrong.
in MySQL table, removing one of these row, will wipe-out whole number from that table, so remove i+1 from array, let it start from 0.

now, show us a command /goto business and "system" which detects a house ID as an invalid id.
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.
Mugala is offline   Reply With Quote
Old 12/09/2019, 08:40 AM   #8
ArWin14
Little Clucker
 
Join Date: Mar 2015
Posts: 5
Reputation: 0
Default Re: Business only load id 1

Excuse me, Sir. I got the problem, when I delete these code, system working properly but when I add these code, system are not working properly.
Code:
if(BusinessData[i+1][businessOwnerSQL] == 0)
{
  	format(str, sizeof(str), "[id:%d]\nThis business is for sale!\nType: %s\nPrice:$%s\nAddress: %s\nUse '/buybiz' for purchase this business", i+1, BusinessTypeLabel(i+1), MoneyFormat(BusinessData[i+1][businessMarketPrice]), BusinessData[i+1][businessAddress]);
}
else
{
        format(str, sizeof(str), "[id:%d]\n%s\nOwner: %s\nAddress: %s", i+1, BusinessData[i+1][businessName], ReturnSQLName(BusinessData[i+1][businessOwnerSQL]), BusinessData[i+1][businessAddress]);
}
ArWin14 is offline   Reply With Quote
Old 12/09/2019, 09:44 AM   #9
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 918
Reputation: 89
Default Re: Business only load id 1

Because that's a bad way to check if a business is owned or not.

First, your checking if businessonwerSQL (which i guess is player's account ID saved in players table) is 0, which is totally wrong.

You have businessMarketPrice, use it.

pawn Code:
if(BusinessData[i+1][businessMarketPrice])
{
    format(str, sizeof(str), "[id:%d]\nThis business is for sale!\nType: %s\nPrice:$%s\nAddress: %s\nUse '/buybiz' for purchase this business", i+1, BusinessTypeLabel(i+1), MoneyFormat(BusinessData[i+1][businessMarketPrice]), BusinessData[i+1][businessAddress]);
}
else
{
        format(str, sizeof(str), "[id:%d]\n%s\nOwner: %s\nAddress: %s", i+1, BusinessData[i+1][businessName], ReturnSQLName(BusinessData[i+1][businessOwnerSQL]), BusinessData[i+1][businessAddress]);
}

Also i don't understand why setting i+1 when you could just use [i].
Symon 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
mysql business load bug Stormalle Scripting Help 1 25/08/2018 05:49 PM
Business Load&Save TFreemen Scripting Help 1 13/10/2014 03:12 PM
Business Save&Load TFreemen Scripting Help 1 09/10/2014 11:51 PM
Business Save&Load TFreemen Scripting Help 1 06/10/2014 07:21 PM
Load business from MYSQL Naruto4 Help Archive 0 30/03/2010 10:20 AM


All times are GMT. The time now is 02:29 AM.


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