SA-MP Forums Archive
SendClientMessage spam in loop - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SendClientMessage spam in loop (/showthread.php?tid=562141)



SendClientMessage spam in loop - nezo2001 - 07.02.2015

As the title say, The messages spams
PHP Code:
CMD:buybiz(playeridparams[])
{
    new 
string[128];
    new 
id IsPlayerNearBusiness(playerid);
    if(
id == -|| id == 0) return SendClientMessage(playeridCOLOR_RED"You aren't near in any business");
    for(new 
0;sizeof(BusinessInfo);i++)
    {
        if(
BusinessInfo[i][bPrice] < GetPlayerMoney(playerid))
        {
            if(
BusinessInfo[i][bOwned] == 0)
            {
                
BusinessInfo[i][bOwned] = 1;
                
BusinessInfo[i][bOwner] = PlayerName(playerid);
                
BusinessInfo[i][bLocked] = 0;
                
BusinessInfo[i][bMoney] = 0;
                
GivePlayerMoney(playerid, -BusinessInfo[i][bPrice]);
            }
            else
            {
                
format(string,sizeof(string),"This business is already owned by: %s",BusinessInfo[i][bOwner]);
                
SendClientMessage(playeridCOLOR_REDstring);
            }
        }
        else
        {
            
SendClientMessage(playeridCOLOR_RED"You don't have enough money");
        }
    }
    return 
1;




Re: SendClientMessage spam in loop - HazardouS - 07.02.2015

pawn Code:
CMD:buybiz(playerid, params[])
{
    new string[128];
    new id = IsPlayerNearBusiness(playerid);
    if(id == -1 || id == 0) return SendClientMessage(playerid, COLOR_RED, "You aren't near in any business");
    if(BusinessInfo[id][bPrice] < GetPlayerMoney(playerid))
    {
        if(BusinessInfo[id][bOwned] == 0)
        {
            BusinessInfo[id][bOwned] = 1;
            BusinessInfo[id][bOwner] = PlayerName(playerid);
            BusinessInfo[id][bLocked] = 0;
            BusinessInfo[id][bMoney] = 0;
            GivePlayerMoney(playerid, -BusinessInfo[id][bPrice]);
        }
        else
        {
            format(string,sizeof(string),"This business is already owned by: %s",BusinessInfo[id][bOwner]);
            SendClientMessage(playerid, COLOR_RED, string);
        }
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED, "You don't have enough money");
    }
    return 1;
}
There is no need for a loop since you already know the id of the business you are near to. Just check the price and the owner for that particular business and that's it.