Jump to content
  • 0

Problema salvare mysql


seveigibaibi

Question

Salut, cand cumpar o casa sau un business nu se salveaza in baza de date, am modificat ceva prin script dar nu-mi mai amintesc ce.

Poze:

image.png.727ba96e4ce209fffbec5ebda5ef93a5.png Si eu n-am niciun business.

Cand cumpar o casa imi arata ca am cumparat-o si pot s-o cumpar de mai multe ori.

CMD:buy(playerid, params[])
{
	static
		id = -1;

	if ((id = House_Nearest(playerid)) != -1)
	{
		if (House_GetCount(playerid) >= MAX_OWNABLE_HOUSES)
			return SendErrorMessage(playerid, "You can only own %d houses at a time.", MAX_OWNABLE_HOUSES);

		if (HouseData[id][houseOwner] != 0)
		    return SendErrorMessage(playerid, "This house is already owned at the moment.");

		if (HouseData[id][housePrice] > GetMoney(playerid))
		    return SendErrorMessage(playerid, "You have insufficient funds for the purchase.");

	    HouseData[id][houseOwner] = GetPlayerSQLID(playerid);

		House_Refresh(id);
		House_Save(id);

	    GiveMoney(playerid, -HouseData[id][housePrice]);
	    SendServerMessage(playerid, "Ai cumparat casa \"%s\" pentru %s!", HouseData[id][houseAddress], FormatNumber(HouseData[id][housePrice]));

		SendClientMessageEx(playerid, COLOR_GREEN, "Ai cumparat aceasta casa!");
	    Log_Write("logs/house_log.txt", "[%s] %s a cumparat casa ID: %d pentru %s.", ReturnDate(), ReturnName(playerid), id, FormatNumber(HouseData[id][housePrice]));
	}
	if ((id = Garage_Nearest(playerid)) != -1)
	{
		if (Garage_GetCount(playerid) >= MAX_OWNABLE_GARAGES)
			return SendErrorMessage(playerid, "You can only own %d garages at a time.", MAX_OWNABLE_GARAGES);

		if (GarageData[id][garageOwner] != 0)
		    return SendErrorMessage(playerid, "This garage is already owned at the moment.");

		if (GarageData[id][garagePrice] > GetMoney(playerid))
		    return SendErrorMessage(playerid, "You have insufficient funds for the purchase.");

	    GarageData[id][garageOwner] = GetPlayerSQLID(playerid);

		Garage_Refresh(id);
		Garage_Save(id);

	    GiveMoney(playerid, -GarageData[id][garagePrice]);
	    SendServerMessage(playerid, "Ai cumparat garajul \"%s\" pentru %s!", GarageData[id][garageAddress], FormatNumber(GarageData[id][garagePrice]));

		SendClientMessageEx(playerid, COLOR_GREEN, "Ai cumparat aceast garaj!");
	    Log_Write("logs/garage_log.txt", "[%s] %s a cumparat garajul ID: %d pentru %s.", ReturnDate(), ReturnName(playerid), id, FormatNumber(GarageData[id][garagePrice]));
	}
	else if ((id = Business_Nearest(playerid)) != -1)
	{
	    if (Business_GetCount(playerid) >= MAX_OWNABLE_BUSINESSES)
			return SendErrorMessage(playerid, "You can only own %d businesses at a time.", MAX_OWNABLE_BUSINESSES);

		if (BusinessData[id][bizOwner] != 0)
		    return SendErrorMessage(playerid, "This business is already owned at the moment.");

		if (BusinessData[id][bizPrice] > GetMoney(playerid))
		    return SendErrorMessage(playerid, "You have insufficient funds for the purchase.");

	    BusinessData[id][bizOwner] = GetPlayerSQLID(playerid);

		Business_Refresh(id);
		Business_Save(id);

	    GiveMoney(playerid, -BusinessData[id][bizPrice]);
	    SendServerMessage(playerid, "Ai cumparat business-ul \"%s\" pentru %s!", BusinessData[id][bizName], FormatNumber(BusinessData[id][bizPrice]));

		SendClientMessageEx(playerid, COLOR_GREEN, "Ai cumparat acest business!");
	    Log_Write("logs/biz_log.txt", "[%s] %s a cumparat business ID: %d pentru %s.", ReturnDate(), ReturnName(playerid), id, FormatNumber(BusinessData[id][bizPrice]));
	}
	else if ((id = Business_Inside(playerid)) != -1)
	{
		if (BusinessData[id][bizLocked] != 0 || !BusinessData[id][bizOwner])
		    return SendErrorMessage(playerid, "This business is closed!");

		if (BusinessData[id][bizType] == 5) {
		    Business_CarMenu(playerid, id);
		} else {
			Business_PurchaseMenu(playerid, id);
		}
	}
	return 1;
}

 

Edited by seveigibaibi
Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 1
House_IsOwner(playerid, houseid)
{
	if (!PlayerData[playerid][pLogged] || PlayerData[playerid][pID] == -1)
	    return 0;

    if ((HouseData[houseid][houseExists] && HouseData[houseid][houseOwner] != 0) && HouseData[houseid][houseOwner] == PlayerData[playerid][pID])
		return 1;

	return 0;
}

 

House_IsOwner(playerid, houseid) { if (!PlayerData[playerid][pLogged] || PlayerData[playerid][pID] == -1) return 0; if ((HouseData[houseid][houseExists] && HouseData[houseid][houseOwner] != 0) && HouseData[houseid][houseOwner] == GetPlayerSQLID(playerid))

) return 1; return 0; }

 

1859311972_BANNER-GIREADAcopy-min.thumb.png.48e5e420ae2185dce5b244965a1d2601.png

 

Link to comment
Share on other sites

  • 0

Poftim:

House_Refresh(houseid)
{
	if (houseid != -1 && HouseData[houseid][houseExists])
	{
		if (IsValidDynamic3DTextLabel(HouseData[houseid][houseText3D]))
		    DestroyDynamic3DTextLabel(HouseData[houseid][houseText3D]);

		if (IsValidDynamicPickup(HouseData[houseid][housePickup]))
		    DestroyDynamicPickup(HouseData[houseid][housePickup]);

		static
		    string[128];

		if (!HouseData[houseid][houseOwner]) {
			format(string, sizeof(string), "Casa de vanzare!\n{AA7F64}Pret:{FFFFFF} %s\n{AA7F64}Numar:{FFFFFF} %d", FormatNumber(HouseData[houseid][housePrice]), HouseData[houseid][houseID]);
            HouseData[houseid][houseText3D] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseData[houseid][housePos][0], HouseData[houseid][housePos][1], HouseData[houseid][housePos][2], 15.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, HouseData[houseid][houseExteriorVW], HouseData[houseid][houseExterior]);
		}
		else {
			format(string, sizeof(string), "{AA7F64}Numar:{FFFFFF} %d", HouseData[houseid][houseID]);
			HouseData[houseid][houseText3D] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseData[houseid][housePos][0], HouseData[houseid][housePos][1], HouseData[houseid][housePos][2], 15.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, HouseData[houseid][houseExteriorVW], HouseData[houseid][houseExterior]);
		}
        HouseData[houseid][housePickup] = CreateDynamicPickup(1273, 23, HouseData[houseid][housePos][0], HouseData[houseid][housePos][1], HouseData[houseid][housePos][2], HouseData[houseid][houseExteriorVW], HouseData[houseid][houseExterior]);
	}
	return 1;
}
House_Save(houseid)
{
	static
	    query[1536];

	format(query, sizeof(query), "UPDATE `houses` SET `houseOwner` = '%d', `housePrice` = '%d', `houseAddress` = '%s', `housePosX` = '%.4f', `housePosY` = '%.4f', `housePosZ` = '%.4f', `housePosA` = '%.4f', `houseIntX` = '%.4f', `houseIntY` = '%.4f', `houseIntZ` = '%.4f', `houseIntA` = '%.4f', `houseInterior` = '%d', `houseExterior` = '%d', `houseExteriorVW` = '%d'",
	    HouseData[houseid][houseOwner],
	    HouseData[houseid][housePrice],
	    SQL_ReturnEscaped(HouseData[houseid][houseAddress]),
	    HouseData[houseid][housePos][0],
	    HouseData[houseid][housePos][1],
	    HouseData[houseid][housePos][2],
	    HouseData[houseid][housePos][3],
	    HouseData[houseid][houseInt][0],
	    HouseData[houseid][houseInt][1],
	    HouseData[houseid][houseInt][2],
	    HouseData[houseid][houseInt][3],
        HouseData[houseid][houseInterior],
        HouseData[houseid][houseExterior],
        HouseData[houseid][houseExteriorVW]
	);
	for (new i = 0; i < 10; i ++) {
		format(query, sizeof(query), "%s, `houseWeapon%d` = '%d', `houseAmmo%d` = '%d'", query, i + 1, HouseData[houseid][houseWeapons][i], i + 1, HouseData[houseid][houseAmmo][i]);
	}
	format(query, sizeof(query), "%s, `houseLocked` = '%d', `houseMoney` = '%d' WHERE `houseID` = '%d'",
	    query,
	    HouseData[houseid][houseLocked],
	    HouseData[houseid][houseMoney],
        HouseData[houseid][houseID]
	);
	return mysql_tquery(g_iHandle, query);
}
House_GetCount(playerid)
{
	new
		count = 0;

	for (new i = 0; i != MAX_HOUSES; i ++)
	{
		if (HouseData[i][houseExists] && House_IsOwner(playerid, i))
   		{
   		    count++;
		}
	}
	return count;
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.