GTAOnline.net
San Andreas Multiplayer (sa:mp) => Scripting SA-MP [Pawn center] => Discussion démarrée par: scott1 le 19 Décembre 2010, 15:25:27
-
Bonjour à toutes et à tous,
j'aimerais savoir comment diviser un nombre binnaire en 4 partie.
Exemple:
00000001000000100000001100000100
Donnerais ceci
00000001 00000010 00000011 00000100
merci d'avance
-
Salut,
tu peut utiliser les bit shift operator ( << et >>) pour récupérer seulement la partie du 32 bit voulu.
exemple: 00001000 << 3 donne 01000000
En faisant par exemple (tavariable << 23) >> 24, tu peut isoler le 24e bit de ta variable (ou 23e je ne suis pas sûr)
++Sim++
-
Comme j'aime les codes barbares car je ne connais vraiment pas le binaire, j'ai travaillais directement avec une chaîne de caractères.
http://pastebin.gtaonline.fr/pastebin.php?show=978 (http://pastebin.gtaonline.fr/pastebin.php?show=978)
-
en fait s'est pour utiliser avec
GetVehicleDamageStatus
mais je vois pas bien comment récupérer le binaire des porte voir si elle sont casé ou pas
:s
-
en fait s'est pour utiliser avec
GetVehicleDamageStatus
mais je vois pas bien comment récupérer le binaire des porte voir si elle sont casé ou pas
:s
C'est assez simple, sachant que les variables en pawn sont sur 4octets ( 32 bit ) et que le dégâts des portes sont stocké sur 4 octets ( 1 pour chaque porte ), tu peut faire ça.
new Degats = 0;
// ici tu prend les dégats de la porte avec GetVehicleDamageStatus
// et la tu sépare
new porte1 = ( Degats >> 24 );
new porte2 = ( Degats >> 16 );
new porte3 = ( Degats >> 8 );
new porte4 = ( Degats ) & 0x01;
-
Non sasuke
Which bit stores what?
The damage of each door (note that the hood and the trunk are also doors) will be saved in 1 byte (which is 8 bits). You can only change the state of one bit for every door at each time - so you have to call the function twice if you want to damage and open the door.
* The first bit stores whether the door is opened(1) or not(0) (the door will still lock (and change the first bit to 0) if closed - its just open)
* The second bit stores whether the door is damaged(1) or not(0) (If you want a damaged door to turn normal you have to remove and re-attach it undamaged)
* The third bit stores whether the door is removed(1) or attached(0)
* The rest of the bits are empty
It seems like there is no bit which stores if the door will lock or not.
Notice that you count the bits from behind - so the first is the rightmost bit
[edit]
Which byte stores what?
* The first byte stores the state of the hood
* The second byte stores the state of the trunk
* The third byte stores the state of the drivers door
* The fourth byte stores the state of the co-drivers door
The states of the 2 rear doors cannot be handled by GetVehicleDamageStatus and UpdateVehicleDamageStatus.
Notice that I count the bytes from behind - so the first is the rightmost byte
-
bah quoi ? ça confirme ce que je dit.
The damage of each door (note that the hood and the trunk are also doors) will be saved in 1 byte (which is 8 bits).
Les dégâts de chaque porte sont stockés dans 1 octets ( qui est composé de 8bits )
-
Je ne vois pas bien comment goupiller tout ça donc je pense que je vais abandonner xD
-
http://wiki.sa-mp.com/wiki/DoorStates (http://wiki.sa-mp.com/wiki/DoorStates)
j'ai fait un truc de ce genre
IsDoorBroken( vehicleid, &driver, &codriver, &trunk, &hood )
{
new panels = 0, doors = 0, lights = 0, tires = 0;
GetVehicleDamageStatus( vehicleid, panels, doors, lights, tires );
driver = ( doors >> 16 ) & 10;
codriver = ( doors >> 24 ) & 10;
trunk = ( doors >> 8 ) & 10;
hood = doors & 10;
}
Mais je ne suis pas sûr que cela est bon, car je ne fait jamais de comparaison bit à bit ni de déplacement d'octets
-
Salut,
ça semble bon, par contre pour le 10, je ne suis pas sur, je pense que c'est plutôt 6:
Le 1er bit: 0 ou 1
Le 2e : 2 ou 0
Le 3e: 4 ou 0
Comme l'on veut tester le 2e et le 3e bit, ça devrait être 6 je pense.
Je peut me tromper bien sur.
peut-être on devrait écrire 0b110
++Sim++
-
ah je me suis complétement trompe, c'est pas 6, ni 10 mais 2 lol
quand j'avais écris 10 je pensais l'écrire en binaire --'
-
Salut,
ça dépend, on peut considéré que si la porte est tombée, c'est comme endommagée (car trop endommagée = tombée)
après ça dépend de l'interprétation que l'on veut.
++Sim++
-
Merci, j'ai plus qu'a essayer de voir pourquoi il met 2 quand elle est abimié et 0 quand elle est detachée.