SA-MP Forums Archive
More efficient way of doing this? - 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: More efficient way of doing this? (/showthread.php?tid=311332)



More efficient way of doing this? - Hoborific - 16.01.2012

pawn Код:
forward PrivatePriceChange();
public PrivatePriceChange()
{
    new PrivateCountdown;
    PrivateCountdown = PrivateCount;

    while(PrivateCountdown >= 0)
    {
        if(random(2) == 0)
        {
            new PRICECHANGE;
            PRICECHANGE = random(10);
            PrivateS[PrivateCountdown] = PrivateS[PrivateCountdown] + PRICECHANGE;

        }

        else

        {

            new PRICECHANGE2;
            new PRICECHANGE3;
            PRICECHANGE2 = random(10);
            PRICECHANGE3 = PRICECHANGE2 - PRICECHANGE2 * 2;
            PrivateS[PrivateCountdown] = PrivateS[PrivateCountdown] + PRICECHANGE3;

        }

        printf("%d : %d",PrivateCountdown,PrivateS[PrivateCountdown]);
        PrivateCountdown--;

    }

}
The concerns I have is the first random for the positive or negative value, and my second concern is the whole else math for the negative Private value change (taking random (1-10) from the value.

What the function does is adds or takes up to 10 from the privatevalue ( doing house RealEstate and shit )


Re: More efficient way of doing this? - ғαιιοцт - 16.01.2012

That should work, but it can be done a lot easier:

new pricechange = random(20)
privates = privates + random - 10.

This will generate a random number between -10 and +10
And add (or substract if it's a negative number) it to privates