01.02.2014, 13:29
pawn Код:
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;
}