Every X on a var
#1

How could I get the following;

If I had a vehicle and wanted to find out if the miles were in calculation of 500

So for instance, my vehicle had 2499 miles, when it hit 2500 miles it would show a SendClientMessage how could I do it?

Like, for every 500 miles SendClientMessage happens?


I saw something on the SA-MP forums but can't find it again; but it looked something like this:

pawn Код:
stock Stock(var){
    if(var % 500)return true;
    else return false;
}
That's not exact I don't think, but if I could get some assistance it would be great.

PS: Don't tell me to do switch statements etc, as I want to be able to get it for EVERY 500 not just the ones I defined.


It's like, if the var can be divided by 500 with a whole number it will allow it, else it won't.

I don't know how to fully explain it lol, thanks in advance!
Reply
#2

var%500 returns 0-499 ( the remaining of the divide to 500), 0 meaning var is dividable by 500, therefore if you want to check if something is 500x, you should do !(var%500) or var%500==0
Reply
#3

Could you possibly put that into a stock for me with an example as I'm confused lol
Reply
#4

This is the modulus operator and it calculates the remainder of an integral division, e.g. 9 % 2 yields 1 because 9 = 4 x 2 + 1. You want to check that the remainder is 0.

PS: please refrain from using the "stock" keyword when not necessary. In many cases the right word to use is "function".
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
This is the modulus operator and it calculates the remainder of an integral division, e.g. 9 % 2 yields 1 because 9 = 4 x 2 + 1. You want to check that the remainder is 0.

PS: please refrain from using the "stock" keyword when not necessary. In many cases the right word to use is "function".
Sorry. Would you be able to help my by creating a example for me on this? It's much appreciated.
Reply
#6

MilageCheck(miles)
return (miles%500==0) ? (true) : (false);

^^ simplest example of a function of your needs
as simple as that, how do you check when something is dividable by something else ? (for example is 4 dividable by 2 ? Yes, because there is 0 (nothing) remaining when divided !) It's pure math, only the operator is somewhat new to you, which wouldn't be that hard to understand after 5 posts of explaining unless you can't understand English ..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)