i dont know if it work
#1

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 ?
Reply
#2

I think no.
Reply
#3

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
Reply
#4

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.
Reply
#5

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

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

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;
Reply
#8

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?
Reply
#9

Bump!
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)