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