Vehicle health label -
Face9000 - 28.03.2013
Hello, im trying to show at ALL vehicles a textlabel with the vehicle health, i did in this way:
pawn Код:
public OnVehicleSpawn(vehicleid)
{
new Float:vx, Float:vy, Float:vz, Float:vHealth,string[10];
GetVehicleHealth(vehicleid, vHealth);
new Text3D:V3D = Create3DTextLabel(string,COLOR_RED,vx,vy,vz, 50, 0,0);
Attach3DTextLabelToVehicle(V3D,vehicleid,vx, vy, vz+1.5);
format(string, sizeof(string), "%.0f", vHealth);
return 1;
}
But doesnt work, the textlabel doesn't show.
AW: Vehicle health label -
Nero_3D - 28.03.2013
OnVehicleSpawn isnt called when the vehicles spawn, it's called when the respawn
Since you can only create 1024 labels and you could have 2000 vehicles we also need to stream them with the vehicles
pawn Код:
stock
PlayerText3D: gPlayerVehicleLabel[MAX_PLAYERS][MAX_VEHICLES + 1]
;
pawn Код:
public OnVehicleStreamIn(vehicleid, forplayerid) {
new
tmp[16],
Float: health
;
GetVehicleHealth(vehicleid, health);
format(tmp, sizeof tmp, "%.0f", health);
gPlayerVehicleLabel[forplayerid][vehicleid] = CreatePlayer3DTextLabel(forplayerid, tmp, COLOR_RED, 0.0, 0.0, 0.0, 50, INVALID_PLAYER_ID, vehicleid, 0);
gPlayerVehicleLabel[forplayerid][0]++;
return true;
}
pawn Код:
public OnVehicleStreamOut(vehicleid, forplayerid) {
DeletePlayer3DTextLabel(forplayerid, gPlayerVehicleLabel[forplayerid][vehicleid]);
gPlayerVehicleLabel[forplayerid][vehicleid] = PlayerText3D: INVALID_3DTEXT_ID;
gPlayerVehicleLabel[forplayerid][0]--;
return true;
}
pawn Код:
// OnGameModeInit
SetTimer("UpdatePVLabel", 1000, true);
for(new i, v; i != sizeof gPlayerVehicleLabel; ++i) {
gPlayerVehicleLabel[i][0] = PlayerText3D: 0;
for(v = 1; v != sizeof gPlayerVehicleLabel[]; ++v) {
gPlayerVehicleLabel[i][v] = PlayerText3D: INVALID_3DTEXT_ID;
}
}
pawn Код:
forward UpdatePVLabel();
public UpdatePVLabel() {
new
i,
v,
tmp[16],
Float: health
;
for(; i != sizeof gPlayerVehicleLabel; ++i) {
if(gPlayerVehicleLabel[i][0]) {
for(v = 1; v != sizeof gPlayerVehicleLabel[]; ++v) {
if(gPlayerVehicleLabel[i][v] != PlayerText3D: INVALID_3DTEXT_ID) {
GetVehicleHealth(v, health);
format(tmp, sizeof tmp, "%.0f", health);
UpdatePlayer3DTextLabelText(i, gPlayerVehicleLabel[i][v], COLOR_RED, tmp);
}
}
}
}
}
That will create and destroy a player label if the vehicle gets streamed in and out
Compiles fine, I hope it works
Re: Vehicle health label -
Face9000 - 28.03.2013
Thank you very much!
+rep!