05.08.2011, 15:11
I have a problem with my current textdraw - based HUD.
Basically it bugs when the hud gets initialized for more players.
I got two types of hud: one to be shown on vehicle and one to be shown on foot.
For some reason, sometimes an EMPTY (without data/info) ON FOOT HUD gets in the way of every player's hud. So basically we have two overlapping huds, which gets behind the current player's hud.
The hud on vehicle uses a speedometer, and sometimes it mixes someone's else speed with the current player's speed, getting all f*ck*d up. every hud has textdraws that are shown ONLY for a specific player, and they're all hidden and destroyed (I've also tried to just destroy instead of also hiding, but no success).
Forgive the loose identation.
Pastebin is currently offline so I will just paste it here:
And the callbacks in which they're used:
I've added double checks on the delete functions just because they weren't working , still have the same problem.
It'd be helpful to help me on this issue. I won't accept suggestions / comments about the code which is 1) partially pasted here, only the necessary bits were copied 2) completely fine besides this textdraw issue.
So if someone wants to help just focus on the issue at hand, not other things . I do not need scripting suggestions.
Basically it bugs when the hud gets initialized for more players.
I got two types of hud: one to be shown on vehicle and one to be shown on foot.
For some reason, sometimes an EMPTY (without data/info) ON FOOT HUD gets in the way of every player's hud. So basically we have two overlapping huds, which gets behind the current player's hud.
The hud on vehicle uses a speedometer, and sometimes it mixes someone's else speed with the current player's speed, getting all f*ck*d up. every hud has textdraws that are shown ONLY for a specific player, and they're all hidden and destroyed (I've also tried to just destroy instead of also hiding, but no success).
Forgive the loose identation.
Pastebin is currently offline so I will just paste it here:
Код:
initPlayerOnFootHUD(playerid) { deleteVehicleFuelTextDraw(playerid); deleteOnFootHUD(playerid); new hudStr[64]; format(hudStr,sizeof(hudStr),"FOD~n~H20~n~Radio ~y~%d",pRadioChan[playerid]); HUD_Text[playerid][0] = TextDrawCreate(490.0, 168.0, hudStr); //TextDrawAlignment(FuelText[vehicleid],3); TextDrawTextSize(HUD_Text[playerid][0], 620.0,5.0); TextDrawLetterSize(HUD_Text[playerid][0], 0.5 ,2.4); TextDrawUseBox(HUD_Text[playerid][0],2); TextDrawBoxColor(HUD_Text[playerid][0],0x100F0F66); TextDrawSetOutline(HUD_Text[playerid][0],1); TextDrawShowForPlayer(playerid,HUD_Text[playerid][0]); ///////////////////////////////////////////////////////// HUD_Text[playerid][1] = TextDrawCreate(540.0, 180.0, " "); //TextDrawAlignment(FuelText[vehicleid],3); TextDrawTextSize(HUD_Text[playerid][1], 590.0,0.5); TextDrawLetterSize(HUD_Text[playerid][1], 0.5 ,2.4); TextDrawUseBox(HUD_Text[playerid][1],2); TextDrawBoxColor(HUD_Text[playerid][1],0xCD2121AA); TextDrawSetOutline(HUD_Text[playerid][1],1); TextDrawShowForPlayer(playerid,HUD_Text[playerid][1]); ///////////////////////////////////////////////////////// HUD_Text[playerid][2] = TextDrawCreate(540.0, 180.0, " "); //TextDrawAlignment(FuelText[vehicleid],3); TextDrawTextSize(HUD_Text[playerid][2], 590.0-float(100-PlayerFamine[playerid]),0.5); TextDrawLetterSize(HUD_Text[playerid][2], 0.5 ,2.4); TextDrawUseBox(HUD_Text[playerid][2],2); TextDrawBoxColor(HUD_Text[playerid][2],0x1AB414AA); TextDrawSetOutline(HUD_Text[playerid][2],1); TextDrawShowForPlayer(playerid,HUD_Text[playerid][2]); ///////////////////////////////////////////////////////// HUD_Text[playerid][3] = TextDrawCreate(540.0, 200.0, " "); //TextDrawAlignment(FuelText[vehicleid],3); TextDrawTextSize(HUD_Text[playerid][3], 590.0,0.5); TextDrawLetterSize(HUD_Text[playerid][3], 0.5 ,2.4); TextDrawUseBox(HUD_Text[playerid][3],2); TextDrawBoxColor(HUD_Text[playerid][3],0xCD2121AA); TextDrawSetOutline(HUD_Text[playerid][3],1); TextDrawShowForPlayer(playerid,HUD_Text[playerid][3]); ///////////////////////////////////////////////////////// HUD_Text[playerid][4] = TextDrawCreate(540.0, 200.0, " "); //TextDrawAlignment(FuelText[vehicleid],3); TextDrawTextSize(HUD_Text[playerid][4], 590.0-float(100-PlayerThirst[playerid]),0.5); TextDrawLetterSize(HUD_Text[playerid][4], 0.5 ,2.4); TextDrawUseBox(HUD_Text[playerid][4],2); TextDrawBoxColor(HUD_Text[playerid][4],0x1AB414AA); TextDrawSetOutline(HUD_Text[playerid][4],1); TextDrawShowForPlayer(playerid,HUD_Text[playerid][4]); ///////////////////////////////////////////////////////// return 1; } updateGeneralTextDraw(playerid,string[]) { TextDrawSetString(playerid,string); TextDrawShowForPlayer(playerid,generalText[playerid]); ///////////////////////////////////////////////////////// return 1; } initGeneralTextDraw(playerid,string[]) { deleteGeneralTextDraw(playerid); generalText[playerid] = TextDrawCreate(150.0, 158.0, string); //TextDrawAlignment(generalText[playerid],2); //TextDrawTextSize(generalText[playerid], 520.0,5.0); TextDrawLetterSize(generalText[playerid], 0.5 ,2.4); //TextDrawShowForPlayer(playerid,generalText[playerid]); ///////////////////////////////////////////////////////// return 1; } deleteGeneralTextDraw(playerid) { if (generalText[playerid]) { TextDrawDestroy(generalText[playerid]); generalText[playerid] = Text:INVALID_TEXT_DRAW; } return 1; } deleteOnFootHUD(playerid) { return 1; if (HUD_Text[playerid][0] != Text:INVALID_TEXT_DRAW) { TextDrawHideForPlayer(playerid,HUD_Text[playerid][0]); TextDrawDestroy(HUD_Text[playerid][0]); HUD_Text[playerid][0] = Text:INVALID_TEXT_DRAW; } if (HUD_Text[playerid][1] != Text:INVALID_TEXT_DRAW) { TextDrawHideForPlayer(playerid,HUD_Text[playerid][1]); TextDrawDestroy(HUD_Text[playerid][1]); HUD_Text[playerid][1] = Text:INVALID_TEXT_DRAW; } if (HUD_Text[playerid][2] != Text:INVALID_TEXT_DRAW) { TextDrawHideForPlayer(playerid,HUD_Text[playerid][2]); TextDrawDestroy(HUD_Text[playerid][2]); HUD_Text[playerid][2] = Text:INVALID_TEXT_DRAW; } if (HUD_Text[playerid][3] != Text:INVALID_TEXT_DRAW) { TextDrawHideForPlayer(playerid,HUD_Text[playerid][3]); TextDrawDestroy(HUD_Text[playerid][3] && HUD_Text[playerid][0] > 0); HUD_Text[playerid][3] = Text:INVALID_TEXT_DRAW; } if (HUD_Text[playerid][4] != Text:INVALID_TEXT_DRAW) { TextDrawHideForPlayer(playerid,HUD_Text[playerid][4]); TextDrawDestroy(HUD_Text[playerid][4]); HUD_Text[playerid][4] = Text:INVALID_TEXT_DRAW; } return 1; } initVehicleFuelText(playerid) { deleteVehicleFuelTextDraw(playerid); deleteOnFootHUD(playerid); if (PlayerJobTask[playerid][0] == 4 || GetPlayerVehicleSeat(playerid)!=0 || GetPlayerState(playerid)!=PLAYER_STATE_DRIVER) return 1; FuelText[playerid][2] = TextDrawCreate(490.0, 168.0, "FUEL~n~KM/H 0"); //TextDrawAlignment(FuelText[vehicleid],3); TextDrawTextSize(FuelText[playerid][2], 620.0,5.0); TextDrawLetterSize(FuelText[playerid][2], 0.5 ,2.4); TextDrawUseBox(FuelText[playerid][2],2); TextDrawBoxColor(FuelText[playerid][2],0x100F0F66); TextDrawSetOutline(FuelText[playerid][2],1); TextDrawShowForPlayer(playerid,FuelText[playerid][2]); ///////////////////////////////////////////////////////// FuelText[playerid][1] = TextDrawCreate(540.0, 178.0, " "); //TextDrawAlignment(FuelText[vehicleid],3); TextDrawTextSize(FuelText[playerid][1], 590.0,0.5); TextDrawLetterSize(FuelText[playerid][1], 0.5 ,2.4); TextDrawUseBox(FuelText[playerid][1],2); TextDrawBoxColor(FuelText[playerid][1],0xCD2121AA); TextDrawSetOutline(FuelText[playerid][1],1); TextDrawShowForPlayer(playerid,FuelText[playerid][1]); ///////////////////////////////////////////////////////// FuelText[playerid][0] = TextDrawCreate(540.0, 178.0, " "); //TextDrawAlignment(FuelText[vehicleid],3); TextDrawTextSize(FuelText[playerid][0], 590.0-float(100-VehFuel[playerid]),0.5); TextDrawLetterSize(FuelText[playerid][0], 0.5 ,2.4); TextDrawUseBox(FuelText[playerid][0],2); TextDrawBoxColor(FuelText[playerid][0],0x1AB414AA); TextDrawSetOutline(FuelText[playerid][0],1); TextDrawShowForPlayer(playerid,FuelText[playerid][0]); ///////////////////////////////////////////////////////// return 1; } deleteVehicleFuelTextDraw(playerid) { if (FuelText[playerid][0] != Text:INVALID_TEXT_DRAW) { TextDrawHideForPlayer(playerid,FuelText[playerid][0]); TextDrawDestroy(FuelText[playerid][0]); FuelText[playerid][0] = Text:INVALID_TEXT_DRAW; } if (FuelText[playerid][1] != Text:INVALID_TEXT_DRAW) { TextDrawHideForPlayer(playerid,FuelText[playerid][1]); TextDrawHideForAll(FuelText[playerid][1]); TextDrawDestroy(FuelText[playerid][1]); FuelText[playerid][1] = Text:INVALID_TEXT_DRAW; } if (FuelText[playerid][2] != Text:INVALID_TEXT_DRAW) { TextDrawHideForPlayer(playerid,FuelText[playerid][2]); TextDrawHideForAll(FuelText[playerid][2]); TextDrawDestroy(FuelText[playerid][2]); FuelText[playerid][2] = Text:INVALID_TEXT_DRAW; } return 1; }
Код:
public OnPlayerExitVehicle(playerid, vehicleid) { deleteVehicleFuelTextDraw(playerid); ........... ........... } public OnPlayerStateChange(playerid, newstate, oldstate) { if (newstate == PLAYER_STATE_DRIVER) { IsPlayerInVeh[playerid] = GetPlayerVehicleID(playerid); checkVehicleAllowed(playerid); //// FUEL TEXTDRAW/////////////////////////////// deleteOnFootHUD(playerid); deleteVehicleFuelTextDraw(playerid); initVehicleFuelText(playerid); } else if (newstate == PLAYER_STATE_ONFOOT) { deleteVehicleFuelTextDraw(playerid); deleteOnFootHUD(playerid); deleteGeneralTextDraw(playerid); initPlayerOnFootHUD(playerid); } } //// USING HUD / SPEEDOMETER IN THIS CALLBACK //// public OnPlayerUpdate(playerid) { if (IsPlayerInAnyVehicle(playerid)) { //// SPEED /// if (GetTickCount()-SpeedTime[playerid] >= 1000) { TextDrawSetProportional(FuelText[playerid][0],true); TextDrawTextSize(FuelText[playerid][0], 590.0-(100.0-(float(VehFuel[IsPlayerInVeh[playerid]])))*0.55,0.5); TextDrawSetString(FuelText[playerid][0], " "); TextDrawShowForPlayer(playerid,FuelText[playerid][0]); new vehicleid; vehicleid = GetPlayerVehicleID(playerid); new Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,speed_string[24],final_speed_int; GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z); final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*136.666667; final_speed_int = floatround(final_speed,floatround_round); format(speed_string,sizeof(speed_string),"FUEL~n~KM/H %d",final_speed_int); TextDrawSetString(FuelText[playerid][2],speed_string); TextDrawShowForPlayer(playerid,FuelText[playerid][2]); } } }
It'd be helpful to help me on this issue. I won't accept suggestions / comments about the code which is 1) partially pasted here, only the necessary bits were copied 2) completely fine besides this textdraw issue.
So if someone wants to help just focus on the issue at hand, not other things . I do not need scripting suggestions.