Mysql support "Business System"
#1

Good evening, I have a problem with a Business System script, when I type "/creabusiness" to create biz after id 1 of the BIZ as if they were non-existent when you type "/comprabusiness" to buy the business, even if it correctly loads the business from mysql, probably I have not yet well understood how to use the id set on the mysql table, so I use ids chosen by the "for" cycle.
pwn Business system.
Код:
define MAX_BUSINESS 					9000
new Total_Business_Created;
new tmp_conto_biz;
new tmp_virwor_biz;
new Create_New_Biz_ID[MAX_PLAYERS];
enum binfo
{
	SQLID,
	Name[128],
	Status,
	AccIDO,
	Owner[128],
	Float:EnterX,
	Float:EnterY,
	Float:EnterZ,
	Text3D:biztext,
	Pickup, 
	MateriePrime,
	Float:ExitX,
	Float:ExitY,
	Float:ExitZ,
	WorldInterior,
	WorldExterior,
	InteriorIn,
	InteriorOut,
	Creato,
	Bank,
	Owner2[128],
	Owner3[128],
	Owner4[128],
	AccIDO2,
	AccIDO3,
	AccIDO4,
	Ristrutturazione,
	Type,
	Price

}
new Biz[MAX_BUSINESS][binfo];

forward SaveBusiness();
public SaveBusiness()
{
	for(new id = 1; id < MAX_BUSINESS; id++)
	{
			MYSQL_Update_Interger(Biz[id][SQLID], "Business", "SQLID", Biz[id][SQLID]);
			MYSQL_Update_String(Biz[id][SQLID], "Business", "Name", Biz[id][Name]);
			MYSQL_Update_Interger(Biz[id][SQLID], "Business", "Status", Biz[id][Status]);
			MYSQL_Update_Interger(Biz[id][SQLID], "Business", "Account0ID", Biz[id][AccIDO]);
			MYSQL_Update_String(Biz[id][SQLID], "Business", "Owner", Biz[id][Owner]);
			MYSQL_Update_Float(Biz[id][SQLID], "Business", "EntrataX", Biz[id][EnterX]);
			MYSQL_Update_Float(Biz[id][SQLID], "Business", "EntrataY", Biz[id][EnterY]);
			MYSQL_Update_Float(Biz[id][SQLID], "Business", "EntrataZ", Biz[id][EnterZ]);
			MYSQL_Update_Interger(Biz[id][SQLID], "Business", "Materiali", Biz[id][MateriePrime]);
			MYSQL_Update_Float(Biz[id][SQLID], "Business", "UscitaX", Biz[id][ExitX]);
			MYSQL_Update_Float(Biz[id][SQLID], "Business", "UscitaY", Biz[id][ExitY]);
			MYSQL_Update_Float(Biz[id][SQLID], "Business", "UscitaZ", Biz[id][ExitZ]);
			MYSQL_Update_Interger(Biz[id][SQLID], "Business", "WorldInterior", Biz[id][WorldInterior]);
			MYSQL_Update_Interger(Biz[id][SQLID], "Business", "WorldExterior", Biz[id][WorldExterior]);
			MYSQL_Update_Interger(Biz[id][SQLID], "Business", "InteriorIn", Biz[id][InteriorIn]);
			MYSQL_Update_Interger(Biz[id][SQLID], "Business", "InteriorOut", Biz[id][InteriorOut]);
			MYSQL_Update_Interger(Biz[id][SQLID], "Business", "Creato", Biz[id][Creato]);
			MYSQL_Update_Interger(Biz[id][SQLID], "Business", "BancaBusiness", Biz[id][Bank]);
			MYSQL_Update_String(Biz[id][SQLID], "Business", "Owner2", Biz[id][Owner2]);
			MYSQL_Update_String(Biz[id][SQLID], "Business", "Owner3", Biz[id][Owner3]);
			MYSQL_Update_String(Biz[id][SQLID], "Business", "Owner4", Biz[id][Owner4]);
			MYSQL_Update_Interger(Biz[id][SQLID], "Business", "OwnerID2", Biz[id][AccIDO2]);
			MYSQL_Update_Interger(Biz[id][SQLID], "Business", "OwnerID3", Biz[id][AccIDO3]);
			MYSQL_Update_Interger(Biz[id][SQLID], "Business", "OwnerID4", Biz[id][AccIDO4]);
			MYSQL_Update_Interger(Biz[id][SQLID], "Business", "Redefine", Biz[id][Ristrutturazione]);
			MYSQL_Update_Interger(Biz[id][SQLID], "Business", "Type", Biz[id][Type]);
			MYSQL_Update_Interger(Biz[id][SQLID], "Business", "Price", Biz[id][Price]);
	}	
	return 1;
}
forward SaveIdBusiness(id);
public SaveIdBusiness(id)
{
	MYSQL_Update_Interger(Biz[id][SQLID], "Business", "SQLID", Biz[id][SQLID]);
	MYSQL_Update_String(Biz[id][SQLID], "Business", "Name", Biz[id][Name]);
	MYSQL_Update_Interger(Biz[id][SQLID], "Business", "Status", Biz[id][Status]);
	MYSQL_Update_Interger(Biz[id][SQLID], "Business", "Account0ID", Biz[id][AccIDO]);
	MYSQL_Update_String(Biz[id][SQLID], "Business", "Owner", Biz[id][Owner]);
	MYSQL_Update_Float(Biz[id][SQLID], "Business", "EntrataX", Biz[id][EnterX]);
	MYSQL_Update_Float(Biz[id][SQLID], "Business", "EntrataY", Biz[id][EnterY]);
	MYSQL_Update_Float(Biz[id][SQLID], "Business", "EntrataZ", Biz[id][EnterZ]);
	MYSQL_Update_Interger(Biz[id][SQLID], "Business", "Materiali", Biz[id][MateriePrime]);
	MYSQL_Update_Float(Biz[id][SQLID], "Business", "UscitaX", Biz[id][ExitX]);
	MYSQL_Update_Float(Biz[id][SQLID], "Business", "UscitaY", Biz[id][ExitY]);
	MYSQL_Update_Float(Biz[id][SQLID], "Business", "UscitaZ", Biz[id][ExitZ]);
	MYSQL_Update_Interger(Biz[id][SQLID], "Business", "WorldInterior", Biz[id][WorldInterior]);
	MYSQL_Update_Interger(Biz[id][SQLID], "Business", "WorldExterior", Biz[id][WorldExterior]);
	MYSQL_Update_Interger(Biz[id][SQLID], "Business", "InteriorIn", Biz[id][InteriorIn]);
	MYSQL_Update_Interger(Biz[id][SQLID], "Business", "InteriorOut", Biz[id][InteriorOut]);
	MYSQL_Update_Interger(Biz[id][SQLID], "Business", "Creato", Biz[id][Creato]);
	MYSQL_Update_Interger(Biz[id][SQLID], "Business", "BancaBusiness", Biz[id][Bank]);
	MYSQL_Update_String(Biz[id][SQLID], "Business", "Owner2", Biz[id][Owner2]);
	MYSQL_Update_String(Biz[id][SQLID], "Business", "Owner3", Biz[id][Owner3]);
	MYSQL_Update_String(Biz[id][SQLID], "Business", "Owner4", Biz[id][Owner4]);
	MYSQL_Update_Interger(Biz[id][SQLID], "Business", "OwnerID2", Biz[id][AccIDO2]);
	MYSQL_Update_Interger(Biz[id][SQLID], "Business", "OwnerID3", Biz[id][AccIDO3]);
	MYSQL_Update_Interger(Biz[id][SQLID], "Business", "OwnerID4", Biz[id][AccIDO4]);
	MYSQL_Update_Interger(Biz[id][SQLID], "Business", "Redefine", Biz[id][Ristrutturazione]);
	MYSQL_Update_Interger(Biz[id][SQLID], "Business", "Type", Biz[id][Type]);	
	MYSQL_Update_Interger(Biz[id][SQLID], "Business", "Price", Biz[id][Price]);
	return 1;
}
forward LoadBusiness();
public LoadBusiness()
{
	if(cache_num_rows())
    {
        for(new id = 1; id<cache_num_rows(); id++)
        {
        	Biz[id][SQLID] = cache_get_field_content_int(id, "SQLID", SQL_CONNECTION);
        	cache_get_field_content(id, "Name", Biz[id][Name], SQL_CONNECTION, 64);
        	Biz[id][Status] = cache_get_field_content_int(id, "Status", SQL_CONNECTION);
        	Biz[id][AccIDO] = cache_get_field_content_int(id, "Account0ID", SQL_CONNECTION);
        	cache_get_field_content(id, "Owner", Biz[id][Owner], SQL_CONNECTION, 64);
        	Biz[id][EnterX] = cache_get_field_content_float(id, "EntrataX", SQL_CONNECTION);
        	Biz[id][EnterY] = cache_get_field_content_float(id, "EntrataY", SQL_CONNECTION);
        	Biz[id][EnterZ] = cache_get_field_content_float(id, "EntrataZ", SQL_CONNECTION);
        	Biz[id][MateriePrime] = cache_get_field_content_int(id, "Materiali", SQL_CONNECTION);
        	Biz[id][ExitX] = cache_get_field_content_float(id, "UscitaX", SQL_CONNECTION);
        	Biz[id][ExitY] = cache_get_field_content_float(id, "UscitaY", SQL_CONNECTION);
        	Biz[id][ExitZ] = cache_get_field_content_float(id, "UscitaY", SQL_CONNECTION);
        	Biz[id][WorldInterior] = cache_get_field_content_int(id, "WorldInterior", SQL_CONNECTION);
        	Biz[id][WorldExterior] = cache_get_field_content_int(id, "WorldExterior", SQL_CONNECTION);
        	Biz[id][InteriorIn] = cache_get_field_content_int(id, "InteriorIn", SQL_CONNECTION);
        	Biz[id][InteriorOut] = cache_get_field_content_int(id, "InteriorOut", SQL_CONNECTION);
        	Biz[id][Creato] = cache_get_field_content_int(id, "Creato", SQL_CONNECTION);
        	Biz[id][Bank] = cache_get_field_content_int(id, "BancaBusiness", SQL_CONNECTION);
        	cache_get_field_content(id, "Owner2", Biz[id][Owner2], SQL_CONNECTION, 64);
        	cache_get_field_content(id, "Owner3", Biz[id][Owner3], SQL_CONNECTION, 64);
        	cache_get_field_content(id, "Owner4", Biz[id][Owner4], SQL_CONNECTION, 64); 
        	Biz[id][AccIDO2] = cache_get_field_content_int(id, "OwnerID2", SQL_CONNECTION);
        	Biz[id][AccIDO3] = cache_get_field_content_int(id, "OwnerID3", SQL_CONNECTION);
        	Biz[id][AccIDO4] = cache_get_field_content_int(id, "OwnerID4", SQL_CONNECTION);
        	Biz[id][Ristrutturazione] = cache_get_field_content_int(id, "Redefine", SQL_CONNECTION);
        	Biz[id][Type] = cache_get_field_content_int(id, "Type", SQL_CONNECTION);
        	Biz[id][Price] = cache_get_field_content_int(id, "Price", SQL_CONNECTION);

        	if(Biz[id][Creato] == 1)
        	{	
	        	new str[128];
		        format(str, sizeof(str), "%s\n Id: %d\n Proprietario %s", Biz[id][Name], id, Biz[id][Owner]);	
		        Biz[id][biztext] = CreateDynamic3DTextLabel(str, COLOR_INFO, Biz[id][EnterX], Biz[id][EnterY] ,Biz[id][EnterZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, -1, -1, -1, 10.0);
		        if(Biz[id][AccIDO] == INVALID_PLAYER_ID)
		        {
		        	Biz[id][Pickup] = CreateDynamicPickup(19522, 1, Biz[id][EnterX], Biz[id][EnterY] ,Biz[id][EnterZ], 0, 0, -1, 250);
		        }	
		        else
		        {
		        	Biz[id][Pickup] = CreateDynamicPickup(1239, 1, Biz[id][EnterX], Biz[id][EnterY] ,Biz[id][EnterZ], 0, 0, -1, 250);
		        }	
		    }    
        	Total_Business_Created++;
        }
    }
    printf("[MYSQL]: %d Business caricati correttamente dal database.", Total_Business_Created);
	return 1;
}        	
stock Reload_Businesss()
{
	for(new id = 1; id < MAX_BUSINESS; id++)
	{
        Remove_Businesss(id);
	}
	Total_Business_Created = 0;
	Fetch_Business();
	return 1;
}
Remove_Businesss(id)
{
	id = id;
	Total_Business_Created --;
	return 1;
}
Fetch_Business()
{
	mysql_tquery(SQL_CONNECTION, "SELECT * FROM `Business` ORDER BY SQLID ASC", "LoadBusiness");
	return 1;
}
forward InRangeOfBiz(playerid);
public InRangeOfBiz(playerid)
{
	for(new id = 1; id < MAX_BUSINESS; id++)
	{
		if(IsPlayerInRangeOfPoint(playerid, 3.0, Biz[id][EnterX], Biz[id][EnterY], Biz[id][EnterZ]))
		{
		    return id;
		}

	}
	return 0;
}
CMD:creabusiness(playerid, params[])
{
	if(Account[playerid][Admin] >= 4)
	{
			new query1[128];
		    mysql_format(SQL_CONNECTION,query1,sizeof(query1),"SELECT SQLID FROM business");
			new Cache:result = mysql_query(SQL_CONNECTION,query1);

			for(new id = 1; id < cache_get_row_count(); id++)
			{
			    tmp_conto_biz = cache_get_field_content_int(id,"SQLID");
			    tmp_virwor_biz = cache_get_field_content_int(id,"SQLID");
			}
			cache_delete(result);
			tmp_virwor_biz++;
			tmp_conto_biz++;
        	Biz[tmp_conto_biz][SQLID] = tmp_conto_biz;
        	format(Biz[tmp_conto_biz][Name], 128, "Sales Business");
        	Biz[tmp_conto_biz][Status] = 0;
        	Biz[tmp_conto_biz][AccIDO] = INVALID_PLAYER_ID;
        	format(Biz[tmp_conto_biz][Owner], 128, "Governament Of Los Santos");
        	new Float:UX, Float:UY, Float:UZ;
        	GetPlayerPos(playerid, UX, UY, UZ);
        	Biz[tmp_conto_biz][EnterX] = UX;
        	Biz[tmp_conto_biz][EnterY] = UY;
        	Biz[tmp_conto_biz][EnterZ] = UZ;
        	Biz[tmp_conto_biz][ExitX] = 0.0;
        	Biz[tmp_conto_biz][ExitY] = 0.0;
        	Biz[tmp_conto_biz][ExitZ] = 0.0;
       		Biz[tmp_conto_biz][MateriePrime] = 0;
       		Biz[tmp_conto_biz][WorldInterior] = random(99999);
			Biz[tmp_conto_biz][WorldExterior] = 0;
			Biz[tmp_conto_biz][InteriorIn] = random(99999);
			Biz[tmp_conto_biz][InteriorOut] = 0;
			Biz[tmp_conto_biz][Creato] = 1;
			Biz[tmp_conto_biz][Bank] = 0;
			format(Biz[tmp_conto_biz][Owner2], 128, "N/A"); 
			format(Biz[tmp_conto_biz][Owner3], 128, "N/A");
			format(Biz[tmp_conto_biz][Owner4], 128, "N/A");
			Biz[tmp_conto_biz][AccIDO2] = INVALID_PLAYER_ID;
			Biz[tmp_conto_biz][AccIDO3] = INVALID_PLAYER_ID;
			Biz[tmp_conto_biz][AccIDO4] = INVALID_PLAYER_ID;
			Biz[tmp_conto_biz][Ristrutturazione] = 0;
			Biz[tmp_conto_biz][Type] = 0;
			Biz[tmp_conto_biz][Price] = 45000;
	        new str[128];
	        format(str, sizeof(str), "%s\n Id: %d\n Proprietario %s", Biz[tmp_conto_biz][Name], tmp_conto_biz, Biz[tmp_conto_biz][Owner]);
	        Biz[tmp_conto_biz][biztext] = CreateDynamic3DTextLabel(str, COLOR_INFO, Biz[tmp_conto_biz][EnterX], Biz[tmp_conto_biz][EnterY] ,Biz[tmp_conto_biz][EnterZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, -1, -1, -1, 10.0);
	        if(Biz[tmp_conto_biz][AccIDO] == INVALID_PLAYER_ID)
	        {
	        	Biz[tmp_conto_biz][Pickup] = CreateDynamicPickup(19522, 1, Biz[tmp_conto_biz][EnterX], Biz[tmp_conto_biz][EnterY] ,Biz[tmp_conto_biz][EnterZ], 0, 0, -1, 250);
	        }	
	        else
	        {
	        	Biz[tmp_conto_biz][Pickup] = CreateDynamicPickup(1239, 1, Biz[tmp_conto_biz][EnterX], Biz[tmp_conto_biz][EnterY] ,Biz[tmp_conto_biz][EnterZ], 0, 0, -1, 250);
	        }	
	        static query[1000];
	        mysql_format(SQL_CONNECTION, query, sizeof(query), "INSERT INTO `business`(`SQLID`, `Name`, `Status`, `Account0ID`, `Owner`, `EntrataX`, `EntrataY`, `EntrataZ`, `Materiali`, `UscitaX`, `UscitaY`, `UscitaZ`, `WorldInterior`, `WorldExterior`, `InteriorIn`, `InteriorOut`, `Creato`, `BancaBusiness`, `Owner2`, `Owner3`, `Owner4`, `OwnerID2`, `OwnerID3`, `OwnerID4`, `Redefine`, `Type`, `Price`) VALUES (%d,'%s',%d,%d,'%s',%f,%f,%f, %d,%f,%f,%f,%d,%d,%d,%d,%d,%d,'%s','%s','%s',%d,%d,%d,%d,%d,%d)",
				Biz[tmp_conto_biz][SQLID],
				Biz[tmp_conto_biz][Name],
				Biz[tmp_conto_biz][Status],
				Biz[tmp_conto_biz][AccIDO],
				Biz[tmp_conto_biz][Owner],
				Biz[tmp_conto_biz][EnterX],
				Biz[tmp_conto_biz][EnterY],
				Biz[tmp_conto_biz][EnterZ],
				Biz[tmp_conto_biz][MateriePrime],
				Biz[tmp_conto_biz][ExitX],
				Biz[tmp_conto_biz][ExitY],
				Biz[tmp_conto_biz][ExitZ],
				Biz[tmp_conto_biz][WorldInterior],
				Biz[tmp_conto_biz][WorldExterior],
				Biz[tmp_conto_biz][InteriorIn],
				Biz[tmp_conto_biz][InteriorOut],
				Biz[tmp_conto_biz][Creato],
				Biz[tmp_conto_biz][Bank],
				Biz[tmp_conto_biz][Owner2],
				Biz[tmp_conto_biz][Owner3],
				Biz[tmp_conto_biz][Owner4],
				Biz[tmp_conto_biz][AccIDO2],
				Biz[tmp_conto_biz][AccIDO3],
				Biz[tmp_conto_biz][AccIDO4],
				Biz[tmp_conto_biz][Ristrutturazione],
				Biz[tmp_conto_biz][Type],
				Biz[tmp_conto_biz][Price]);
			mysql_tquery(SQL_CONNECTION, query, "GetBizID", "i", playerid);
			new string[128];
			format(string, sizeof(string), ""COL_GRAY"[!] "COL_WHITE"Hai creato il business id: %d", tmp_conto_biz);
			SendClientMessage(playerid, COLOR_GRAY, string);
			mysql_tquery(SQL_CONNECTION, "SELECT * FROM `business` ORDER BY SQLID ASC", "LoadBusiness");
	}
	else
	{
		SendErrorMessage(playerid, ERROR_ADMIN);
	}
	return 1;	
}
forward GetBizID(playerid);
public GetBizID(playerid)
{
	Create_New_Biz_ID[playerid] = cache_insert_id();
	return 1;
}
CMD:comprabusiness(playerid, params[])
{
	for (new i = 1; i < MAX_BUSINESS; ++i)
	{			
			if(IsPlayerInRangeOfPoint(playerid, 1, Biz[i][EnterX], Biz[i][EnterY] ,Biz[i][EnterZ]))
			{
				if(GetPlayerMoney(playerid) >= Biz[i][Price])
				{	
					if(Biz[i][AccIDO] == INVALID_PLAYER_ID ) //Primo Business
					{
						if(Character[playerid][Business_1] == 0)
						{
							new string[128];
							Biz[i][AccIDO] = Character[playerid][ID];
							format(Biz[i][Owner], 128, "%s", Character[playerid][Username]);
							Character[playerid][Business_1] = i;
							format(string, sizeof(string), ""COL_DGREEN"[!] "COL_WHITE"Hai acquistato il Negozio (%d) con successo - %d $. [SLOT 1]", Biz[i][SQLID], Biz[i][Price]);
							SendClientMessage(playerid, COLOR_INFO, string);
							SaveIdBusiness(i);
							Reload_Businesss();
							MYSQL_Update_Character(playerid, "Negozio1", Character[playerid][Business_1]);
						}
						else
						{
							SendErrorMessage(playerid, "Possiedi giа un negozio.");
						}	
					}
					
					else
					{
						SendErrorMessage(playerid, "Negozio giа acquistato.");
					}	
				}
				else
				{
					SendErrorMessage(playerid, "Non possiedi denaro a sufficenza.");
				}	
			}
			else
			{
				SendErrorMessage(playerid, "Non ti trovi nei pressi di un Negozio.");
			}
			break;		
	}
	return 1;
}
Reply
#2

up....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)