Crie outro script do lado server e cole o seguinte código:
addEventHandler( "onPlayerLogin", root, function()
triggerClientEvent( source, "onRequestShowPlayerHUD", source, true )
end, true, "low" )
No meta.xml deixe como type="server", exemplo:
<script src="script.Lua" type="server"/>
O script client que você postou, substitua por este novo:
local screenH, screenW = guiGetScreenSize()
local x, y = (screenH/1366), (screenW/768)
local fonte = dxCreateFont("files/fonts/fonte.ttf", 10)
local rendering = false
--[[
dxDrawRectangle(451, 298, 186, 97, tocolor(0, 0, 0, 122), false)
dxDrawRectangle(461, 308, 166, 77, tocolor(229, 112, 17, 208), false)
]]
function HUD ()
if getElementData(getLocalPlayer(), "isPolice") then
jobPolice = "Policial"
else
jobPolice = nil
end
local showammo1 = getPedAmmoInClip (localPlayer,getPedWeaponSlot(localPlayer))
local showammo2 = getPedTotalAmmo(localPlayer)-getPedAmmoInClip(localPlayer)
local showammo3 = getPedTotalAmmo(getLocalPlayer())
local clip = getPedAmmoInClip (getLocalPlayer())
local weapon = getPedWeapon ( getLocalPlayer() )
local arma = getWeaponNameFromID ( weapon )
local SaldoBanco = getElementData(localPlayer,"banco:Saldo") or 0
local Procurado = getPlayerWantedLevel(localPlayer)
local Level = getElementData(localPlayer,"Level") or 0
local Emp = jobPolice or (getElementData(getLocalPlayer(), "Emprego") or "Desempregado")
local dinheiro1 = ("%008d"):format(getPlayerMoney(getLocalPlayer()))
local color1 = tocolor(0,0,0,178)
local color2 = tocolor(0,0,0,178)
local color3 = tocolor(0,0,0,178)
dxDrawImage(x*920, y*-25, x*215, y*112, "files/img/RetanguloHud.png", 0, 0, 0, tocolor(0, 0, 0, 255), true)
dxDrawImage(x*1110, y*-25, x*215, y*112, "files/img/RetanguloHud.png", 0, 0, 0, tocolor(0, 0, 0, 255), true)
dxDrawImage(x*1110, y*25, x*215, y*112, "files/img/RetanguloHud.png", 0, 0, 0, tocolor(0, 0, 0, 255), true)
dxDrawImage(x*920, y*25, x*215, y*112, "files/img/RetanguloHud.png", 0, 0, 0, tocolor(0, 0, 0, 255), true)
dxDrawImage(x*1020, y*70, x*215, y*112, "files/img/RetanguloHud.png", 0, 0, 0, tocolor(0, 0, 0, 255), false)
dxDrawImage(x*944, y*18, x*26, y*30, "files/img/IconeMala.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
dxDrawImage(x*1134, y*15, x*31, y*38, "files/img/IconeDinheiro.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
dxDrawImage(x*1139, y*70, x*23, y*26, "files/img/IconeCartao.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
dxDrawImage(x*1050, y*116, x*23, y*21, "files/img/EstrelaIcone.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
dxDrawText("Level: "..Level, x*944, y*-9, x*1202, y*173, tocolor(255, 255, 255, 255), x*1.00, fonte, "left", "center", false, false, true, false, false)
dxDrawText(""..SaldoBanco, x*1175, y*40, x*1195, y*128, tocolor(255, 255, 255, 255), x*1.00, fonte, "left", "center", false, false, true, false, false)
dxDrawText(""..Procurado, x*1090, y*36, x*1189, y*219, tocolor(255, 255, 255, 255), x*1.00, fonte, "left", "center", false, false, true, false, false)
dxDrawText("$"..dinheiro1, x*1175, y*-16, x*1195, y*82, tocolor(255, 255, 255, 255), x*1.00, fonte, "left", "center", false, false, true, false, false)
dxDrawText(Emp, x*985, y*-16, x*1195, y*82, tocolor(255, 255, 255, 255), x*1.00, fonte, "left", "center", false, false, true, false, false)
dxDrawText("Arma: "..arma.. " || Pente: " ..tostring (showammo1).." / "..tostring (showammo2), x*1075, y*250, x*1195, y*82, tocolor(255, 255, 255, 255), x*0.9, fonte, "left", "center", false, false, true, false, false)
end
-- função exportada
function setPlayerDXHudVisible( bool )
if bool == rendering then return end
--
if bool == true then
addEventHandler("onClientRender", getRootElement(), HUD)
rendering = bool
elseif bool == false then
removeEventHandler("onClientRender", getRootElement(), HUD)
rendering = bool
end
end
addEvent( "onRequestShowPlayerHUD", true )
addEventHandler( "onRequestShowPlayerHUD", root, setPlayerDXHudVisible )
function OnStop ()
setPlayerHudComponentVisible("armour", true)
setPlayerHudComponentVisible("wanted", true)
setPlayerHudComponentVisible("weapon", true)
setPlayerHudComponentVisible("money", true)
setPlayerHudComponentVisible("health", true)
setPlayerHudComponentVisible("clock", true)
setPlayerHudComponentVisible("breath", true)
setPlayerHudComponentVisible("ammo", true)
end
addEventHandler("onClientResourceStop", getResourceRootElement(getThisResource()), OnStop)
function OnStart ()
setPlayerHudComponentVisible("armour", false)
setPlayerHudComponentVisible("wanted", false)
setPlayerHudComponentVisible("weapon", false)
setPlayerHudComponentVisible("money", false)
setPlayerHudComponentVisible("health", false)
setPlayerHudComponentVisible("clock", false)
setPlayerHudComponentVisible("breath", false)
setPlayerHudComponentVisible("ammo", false)
end
addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), OnStart )
local hudTable =
{
"ammo",
"armour",
"clock",
"health",
"money",
"weapon",
"wanted",
"area_name",
"vehicle_name",
"breath",
"clock"
}
addEventHandler("onClientResourceStart", resourceRoot,
function()
for id, hudComponents in ipairs(hudTable) do
showPlayerHudComponent(hudComponents, false)
end
end
)
addEventHandler("onClientResourceStop", resourceRoot,
function()
for id, hudComponents in ipairs(hudTable) do
showPlayerHudComponent(hudComponents, true)
end
end
)
Adicione a função no meta.xml para exportá-la:
<export function="setPlayerDXHudVisible" type="client"/>
Vai ser útil se você precisar ocultar o hud quando necessário.
Obs: não testei o código; lembre-se de fazer o teste com o debug ativado (/debugscript 3).