SA-MP Forums Archive
MOD to Pawn - 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: MOD to Pawn (/showthread.php?tid=586170)



MOD to Pawn - SumX - 19.08.2015

Hello!
I want to check if a number is even or uneven.
For those who don't understand: 1 - uneven, 2 - even, 3 - uneven ... etc.

In c++ I am doing this at school by using this:
PHP код:
if(x%2
PHP код:
if(x%== 0
how can I do this in PAWN?


Re: MOD to Pawn - Abagail - 19.08.2015

Do they teach you how to use the search function at school aswell? If not, I think it'd be great if you got that class, because you apparently need it sir.
https://sampforum.blast.hk/showthread.php?tid=70747


Re: MOD to Pawn - SumX - 19.08.2015

I searched only for MOD samp on ******. thank you!


Re: MOD to Pawn - Alex Magaсa - 19.08.2015

I searched on samp wiki and this is the only way i found but the script will look a mess xd:
https://sampwiki.blast.hk/wiki/Control_Structures#else
With ELSE & IF.


AW: MOD to Pawn - Nero_3D - 19.08.2015

Just use that instead of MOD
pawn Код:
#define IsOdd(%0) (%0 & 1)



Re: MOD to Pawn - Crayder - 20.08.2015

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Just use that instead of MOD
pawn Код:
#define IsOdd(%0) (%0 & 1)
This, with this for even:
pawn Код:
#define IsEven(%0) (!IsOdd(%0))
Quote:
Originally Posted by SumX
Посмотреть сообщение
PHP код:
if(x%2
PHP код:
if(x%== 0
Those should work too, but binary (thus, the binary AND above) is better.


Re: AW: MOD to Pawn - Mauzen - 20.08.2015

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Just use that instead of MOD
pawn Код:
#define IsOdd(%0) (%0 & 1)
FIY this checks if the last bit is set, so if the binary numbers contains a 1. A clever method, dont think the compiler optimizes this by itself.