CMD:buybizz(playerid, params[])
{
if(pInfo[playerid][OwnedBizz] == 1) return SendClientMessage(playerid,COLOR_PINK2,"Error: You already own a business");
for(new i; i < MAX_BUSINESSES; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 10.0, bInfo[i][Position][0], bInfo[i][Position][1], bInfo[i][Position][2]))
{
if(pInfo[playerid][pMoney] >= bInfo[i][Price])
{
if(strcmp(bInfo[i][bOwner], "Nobody", true) == 0)
{
new query[500],query2[500];
format(bInfo[i][bOwner], MAX_PLAYER_NAME, "%s", GetName(playerid));
pInfo[playerid][pMoney] -= bInfo[i][Price];
pInfo[playerid][pBizz] = bInfo[i][ID];
pInfo[playerid][OwnedBizz] = 1;
format(query,sizeof(query),"UPDATE businesses SET `owner` = '%s' WHERE `id` =%d",bInfo[i][bOwner],bInfo[i][ID]);
mysql_query(query);
format(query2,sizeof(query2),"UPDATE `accounts` SET `BusinessID` =%i,`OwnedBizz` = %i WHERE `id` =%d LIMIT 1", pInfo[playerid][pBizz],pInfo[playerid][OwnedBizz], pInfo[playerid][ID]);
mysql_query(query2);
print(query2);
print(query);
new string2[500];
format(string2, sizeof(string2), "%s\nOwner: %s\nPrice: %i\n ID: %i\nEntry Fee: %i",bInfo[i][bName],bInfo[i][bOwner], bInfo[i][Price],bInfo[i][ID],bInfo[i][bEntryFee]);
Update3DTextLabelText(bInfo[i][LabelID], 0xB0D5E8FF, string2);
SendClientMessage(playerid,0x9EC7DEFF,"Congratulations!, You have successfully bought the business");
}
else
{
SendClientMessage(playerid,COLOR_PINK2,"Error: This business is already owned");
}
}
else
{
SendClientMessage(playerid,COLOR_PINK2,"Error: You do not have enough cash");
}
}
else
{
SendClientMessage(playerid,COLOR_PINK2,"Error: You are not near any property");
}
}
return 1;
}
new i = 0;
for(new a; a < MAX_BUSINESSES; a++)
{
if(!IsPlayerInRangeOfPoint(playerid, 10.0, bInfo[a][Position][0], bInfo[a][Position][1], bInfo[a][Position][2]))
continue;
i= a;
}
if(!i)
return SendClientMessage(playerid, COLOR_PINK2, "Error: you are not near any property");
CMD:buybizz(playerid, params[])
{
if(pInfo[playerid][OwnedBizz] == 1)
return SendClientMessage(playerid,COLOR_PINK2,"Error: You already own a business");
new bizzid = 0;
for(new a; a < MAX_BUSINESSES; a++)
{
if(!IsPlayerInRangeOfPoint(playerid, 10.0, bInfo[a][Position][0], bInfo[a][Position][1], bInfo[a][Position][2]))
continue;
bizzid = a;
}
if(!bizzid)
return SendClientMessage(playerid, COLOR_PINK2, "Error: you are not near any property.");
if(pInfo[playerid][pMoney] < bInfo[bizzid][Price])
return SendClientMessage(playerid, COLOR_PINK2, "Error: you don't have money.");
if(strcmp(bInfo[bizzid][bOwner], "Nobody", true))
return SendClientMessage(playerid, COLOR_PINK2, "Error: this already belongs to someone"); //note that there could be a player named nobody!!
new query[128],query2[128];
format(bInfo[bizzid][bOwner], MAX_PLAYER_NAME, "%s", GetName(playerid));
pInfo[playerid][pMoney] -= bInfo[bizzid][Price];
pInfo[playerid][pBizz] = bInfo[bizzid][ID];
pInfo[playerid][OwnedBizz] = 1;
format(query,sizeof(query),"UPDATE businesses SET `owner` = '%s' WHERE `id` =%d",bInfo[bizzid][bOwner],bInfo[bizzid][ID]);
mysql_query(query);
format(query2,sizeof(query2),"UPDATE `accounts` SET `BusinessID` =%i,`OwnedBizz` = %i WHERE `id` =%d LIMIT 1", pInfo[playerid][pBizz],pInfo[playerid][OwnedBizz], pInfo[playerid][ID]);
mysql_query(query2);
print(query2);
print(query);
new string2[144];
format(string2, sizeof(string2), "%s\nOwner: %s\nPrice: %i\n ID: %i\nEntry Fee: %i",bInfo[bizzid][bName],bInfo[bizzid][bOwner], bInfo[bizzid][Price],bInfo[bizzid][ID],bInfo[bizzid][bEntryFee]);
Update3DTextLabelText(bInfo[bizzid][LabelID], 0xB0D5E8FF, string2);
SendClientMessage(playerid,0x9EC7DEFF,"Congratulations!, You have successfully bought the business");
return 1;
}
pInfo[playerid][pMoney] = GetPlayerMoney(playerid);
hmm lemme just switch something around and see.
P.S Is there any kind of variable to determine whether the bizz is not set or not? What do you mean by that? |
Ye you were right, i needed to get the players money , i added
pawn Код:
|
Well, in the loop you're looping thru the max business number availble. If MAX_BUSINESS is 50 and you have only set 40 you would be wasting 10 loop iterations; Scale that to 1000 and you get 960 wasted iterations, where you would be checking 960 times if the player is in range of x0.0 y0.0 z0.0. If Businesses ID's are incremental then you could check if the ID is not 0 (starting from 1), if it is it is mean that the business is not set and then skip it.
There's no need for pMoney variable if you're not using a scriptside Money system. Just save into the file with GetPlayerMoney and load it with GivePlayerMoney; |