Getting tire damage states -
MP2 - 11.07.2012
Hi. I'm not good with binary and stuff. I need to know whether both the back tires are popped on a vehicle, from GetVehicleDamageStatus.
To pop the back two tires, I do this:
pawn Код:
UpdateVehicleDamageStatus(GetPlayerVehicleID(playerid), Panels, Doors, Lights, 1 | (0 << 1) | (1 << 2) | (0 << 3));
But I didn't write that, so I don't understand how to 'reverse' it for GETTING the states.
Re: Getting tire damage states -
Vince - 11.07.2012
I use this. I don't know who originally wrote this, but I don't take credit for it;
pawn Код:
encode_tires(tires1, tires2, tires3, tires4) {
return tires1 | (tires2 << 1) | (tires3 << 2) | (tires4 << 3);
}
Using this page you can see which values to set:
https://sampwiki.blast.hk/wiki/TireStates
Re: Getting tire damage states -
MP2 - 11.07.2012
That converts 4 tire states in to the binary number, I need the opposite.
Re: Getting tire damage states -
clarencecuzz - 11.07.2012
Maybe...
pawn Код:
new panels,doors,lights,tires;
GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
if(tires == 0101)
return SendClientMessage(playerid, 0xFF0000AA, "Your back tires are popped brah.");
just my guess.
Re: Getting tire damage states -
MP2 - 11.07.2012
No, not JUST the back ones.
I have a feeling it will be something like
if(tires & 1 && tires & 3) // Back tires are popped
EDIT: Just tested, that doesn't work :/
Re: Getting tire damage states -
Kar - 11.07.2012
Ah okay, this is simple. I've done it. Well not with tyres but with panels.
wait are you sure that code pops back and not front tyres? from logic it seems 1010 would pop back front and 0101 would pop back tyres
pawn Код:
new panels, doors, lights, tires;
GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
if(tires & 0101)//or in this weird case.. if(tires & 1010)
{
//back tyres are poped
}
//or it might be done by index which it seems like on the wiki
if(tires == 5) //or in this weird case.. if(tires == 10)
{
//back tyres are poped
}
also note you can't do tires & 3 with a bitwise operator, 3 is no a bit
I'm sorry for not using American English for tyres / tires.
Re: Getting tire damage states -
clarencecuzz - 11.07.2012
Read
https://sampwiki.blast.hk/wiki/TireStates
According to this, 0101 is popped back tires.
Re: Getting tire damage states -
MP2 - 11.07.2012
Well I did this to test:
pawn Код:
if(Tires & 1000) SendClientMessage(playerid, -1, "Tire 0 popped.");
if(Tires & 0100) SendClientMessage(playerid, -1, "Tire 1 popped.");
if(Tires & 0010) SendClientMessage(playerid, -1, "Tire 2 popped.");
if(Tires & 0001) SendClientMessage(playerid, -1, "Tire 3 popped.");
But when I pop tire 0 it says I popped 0 AND 2.
EDIT: Ah, managed to fix it with 0b prefix:
pawn Код:
if(Tires & 0b1000) SendClientMessage(playerid, -1, "FL tire popped.");
if(Tires & 0b0100) SendClientMessage(playerid, -1, "BL tire popped.");
if(Tires & 0b0010) SendClientMessage(playerid, -1, "FR tire popped.");
if(Tires & 0b0001) SendClientMessage(playerid, -1, "BR tire popped.");
Thank you, Kar <3
Re: Getting tire damage states -
Vince - 11.07.2012
Binary values need to be prefixed with 0b (like 0x for hex) otherwise the compiler will just read it as decimal.
Edit: Meh, too late.
Re: Getting tire damage states -
MP2 - 11.07.2012
So, to check if both back tires are blown, should I do
pawn Код:
if(Tires & 0b0100 && Tires & 0b0001)
or