PDA

View Full Version : encode_tires


ScIrUsna
18/04/2016, 07:19 AM
Hi,

new restreturn = encode_tires( 0, 1, 1,1 );
printf("%d", restreturn);



stock encode_tires(tires1, tires2, tires3, tires4) {

return tires1 | (tires2 << 1) | (tires3 << 2) | (tires4 << 3);
}


https://wiki.sa-mp.com/wiki/TireStates

as 0111 should return 7 but return 14


new restreturn = encode_tires( 1,1,1,0 );
printf("%d", restreturn);

as 1110 should return 14 but return 7

It's a bug and how to fix it?

AbyssMorgan
18/04/2016, 07:29 AM
stock encode_tires(tires1, tires2, tires3, tires4) {
return tires1 | (tires2 << 1) | (tires3 << 2) | (tires4 << 3);
}


encode_tires(1,0,0,1);
1001

ScIrUsna
18/04/2016, 07:32 AM
I don't understand what you want to say it's corrent my way or no?

Vince
18/04/2016, 07:45 AM
You're simply performing the shifting in reverse order. First parameter should be shifted by 3, next by 2 and so on.

ScIrUsna
18/04/2016, 07:54 AM
stock encode_tires(tires1, tires2, tires3, tires4) {

return (tires4 << 3) | (tires3 << 2) | (tires2 << 1) | tires1;
}

?

But i get still same

introzen
18/04/2016, 08:17 AM
Wrong post, thought too fast.

Vince
18/04/2016, 09:03 AM
I think I clearly said "first parameter". The first parameter is tires1, not tires4.