SA-MP Forums Archive
Mathematics question - 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: Mathematics question (/showthread.php?tid=380526)



Mathematics question - 2KY - 25.09.2012

How would I go about doing this? (Refer mostly to the tax = ... part)

pawn Код:
forward UpdatePlayTime( );
public UpdatePlayTime ( )
{
    for( new u; u < MAX_PLAYERS; u ++ )
    {
        if( plLoggedIn [ u ] == true )
        {
            plStats [ u ] [ TimePlayedMins ] ++;
           
            if( plStats [ u ] [ TimePlayedMins ] >= 60 )
            {
                // Payday!
                new
                    wage = plStats [ u ] [ LumberjackWage ] + plStats [ u ] [ QuarryworkerWage ],
                    tax = plStats [ u ] [ LumberjackWage ] + plStats [ u ] [ QuarryworkerWage ] / 0.07,
                                    // tag mismatch ^
                    str [ 128 ];
                   
                plStats [ u ] [ Money ] += wage;
                plStats [ u ] [ LumberjackWage ] = 0, plStats [ u ] [ QuarryworkerWage ] = 0, plStats [ u ] [ TimePlayedMins ] = 0;
                plStats [ u ] [ TimePlayedHours ] ++;
               
                format( str, 128, "* You have earned $%d this paycheck. $%d in taxes were taken out.", wage, tax );
                SendClientMessage( u, Colour_LimeGreen, str );
            }
        }
    }
    return true;
}



Re : Mathematics question - Varkoll_ - 25.09.2012

What do you want to do ?


Re: Mathematics question - 2KY - 25.09.2012

Sorry if I didn't make myself clear.

pawn Код:
tax = plStats [ u ] [ LumberjackWage ] + plStats [ u ] [ QuarryworkerWage ] / 0.07,
I'm trying to divide an integer (say... 2000 for example) by a float (0.07 in this example), and it's giving me a tag mismatch because I can't do that with standard math functions apparently.


Re: Mathematics question - vIBIENNYx - 25.09.2012

Try storing 0.07 in a variable.


Re : Mathematics question - Varkoll_ - 25.09.2012

You have floatdiv function (for divide)
floadsub (for substract)
floatadd (for add)
floatmul (for multiply)
...


Re: Mathematics question - Babul - 25.09.2012

i want to mention that dividing any number by another number smaller than 1, results in multiplying by a large number:
A=1 / 0.07
where 0.07, as divisor, is the same as using a multiplier of 14.2
A=1 * 14.2
so change
pawn Код:
tax = plStats [ u ] [ LumberjackWage ] + plStats [ u ] [ QuarryworkerWage ] / 0.07,
to
pawn Код:
tax = plStats [ u ] [ LumberjackWage ] + plStats [ u ] [ QuarryworkerWage ] * 0.07,
or incase you want the base amount including taxes, then simply add the 100 percent base as 1.00 added to the tax rate float:
pawn Код:
tax = plStats [ u ] [ LumberjackWage ] + plStats [ u ] [ QuarryworkerWage ] * 1.07,
... this way you avoid a "divsion by zero" error when (if?) your taxes are set to 0


Re : Mathematics question - Varkoll_ - 25.09.2012

Hmmmmm...
I think rather than trying to keep the variable "tax" to an integer. It would not be better in this case to use as I said a floatdiv, then floatround to round the value and to keep "tax" as an integer ?

(Sorry for my bad english)