SA-MP Forums Archive
i dont know if it work - 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: i dont know if it work (/showthread.php?tid=369369)



i dont know if it work - avivelkayam - 16.08.2012

Hello, Sorry about my bad english

i started to built script that the have a message with a random color
so i did this:

SendClientMessage(playerid, random(0xffffffff), "doesnt matter..");

than i wanted to do script that the color dont close to the dark
so i did this:

SendClientMessage(playerid, random(0xfffffff | 1), "doesn't matter");

does it works ?


Re: i dont know if it work - TaLhA XIV - 16.08.2012

I think no.


Re: i dont know if it work - avivelkayam - 16.08.2012

why??

because if you take bit
0 that is close to the dark

and you do it the bitwise operator OR
it will get it to white

because

1 | 0 = 1
1 | 1 = 1

and only 0 | 0 = 0
think about it


Re: i dont know if it work - _Vortex - 16.08.2012

I cant see this working at all unless you make a function that randomizes the colors each time the message is sent, but the code you're showing us makes no sense at all.


Re: i dont know if it work - avivelkayam - 16.08.2012

why does my code does'nt work can you explane me?


Re: i dont know if it work - _Vortex - 16.08.2012

You cannot simply put random(0xfffffff) as a color.


Re: i dont know if it work - Vince - 16.08.2012

Well actually, yes, you can. A hexadecimal number is as good a number as any other. Although anything greater than 0x7FFFFFFF will turn out as a negative number when converted to decimal. I don't know how the random() function responds to negative number. I would suggest going with 0xffffff (6 times f, rather than 8). Then shift left. Alpha is unimportant in client message so that can be omitted.

pawn Код:
new color = random(0xffffff) << 8;



Re: i dont know if it work - avivelkayam - 17.08.2012

if i do this its just moves the bit why i need to do this
its dont do random with all colors

i dont understand can you explane me agin?


Re: i dont know if it work - avivelkayam - 17.08.2012

Bump!


AW: Re: i dont know if it work - Nero_3D - 17.08.2012

Quote:
Originally Posted by avivelkayam
Посмотреть сообщение
if i do this its just moves the bit why i need to do this
its dont do random with all colors

i dont understand can you explane me agin?
As said before, pawn is a 32 bit language, also there is by default only sign numbers ( + and - )
That means if the number is greater than ((2 ^ 31) - 1) [constant cellmax / in hex: 0x7FFFFFFF] it goes negative
Also the random function can only take positive values

Than to your problem, you want a random color, the format in pawn is RGBA (Red - Green - Blue - Alpha)
Means that only the first three RGB tell what color comes out, the Alpha only tells how good you can see it
Since there is no transparency in SendClientMessage you can always use 0xFF as alpha

pawn Код:
new color = random(0xFFFFFF) << 8 | 0xFF;
This randomly generates a color, shift it by 8 bits to the left so they are on the correct position and add full opaque