Kulegg
Wiek: 46 Na forum: 3125 dni Posty: 283
Piwa : 20
Siemka,
Mam problem gdy? mam kod na hud, ale problem jest w tym ?e nie mam poj?cia jak naprawi? to aby nie pojawia? si? w panelu logowania, tylko dopiero gdy zrespimy si? ju? w grze.
Kod:
local hud = {}
hud . state = true
hud . gui = false
hud . background = nil
hud . pos = nil
hud . x = nil
hud . y = nil
hud . font = dxCreateFont ( "files/font.ttf" , 12 )
pricedown = dxCreateFont ( "files/pricedown.ttf" , 14 )
pricedown2 = dxCreateFont ( "files/pricedown.ttf" , 16 )
local screen = { guiGetScreenSize ()}
local screenX = screen [ 1 ]
local screenY = screen [ 2 ]
local scmp = ( screenX / 1920 )
if screenX < 1680 then
scmp = scmp * 0.9
elseif screenX < 1367 then
scmp = scmp * 0.92
elseif screenX < 1281 then
scmp = scmp * 0.94
end
local ddx , ddy = guiGetScreenSize ()
function inbox ( ddx , ddy , bx , by )
if isCursorShowing () then
local mx , my = getCursorPosition ()
mx , my = mx * screenX , my * screenY
bx , by = ddx + bx , ddy + by
return ddx <= mx and bx >= mx and ddy <= my and by >= my
end
end
local dotCounter = 0
function createHUD ()
showPlayerHudComponent ( "clock" , false )
showPlayerHudComponent ( "health" , false )
showPlayerHudComponent ( "wanted" , false )
showPlayerHudComponent ( "money" , false )
showPlayerHudComponent ( "weapon" , false )
showPlayerHudComponent ( "ammo" , false )
showPlayerHudComponent ( "armour" , false )
if hud . state then
if not hud . gui then
hud . background = guiCreateWindow ( screenX - 350 * scmp , screenY - 1220 * scmp , 500 * scmp , 35 * scmp , "" , false )
guiSetAlpha ( hud . background , 0 )
guiWindowSetSizable ( hud . background , false )
hud . gui = true
end
color1 , color2 , color3 , alpha = getElementData ( localPlayer , "guiColor" ) or 0 , 0 , 0 , 255
hud . pos = { guiGetPosition ( hud . background , false )}
hud . x = hud . pos [ 1 ]
hud . y = hud . pos [ 2 ]
time = getRealTime ()
name = getPlayerName ( localPlayer ): gsub ( "_" , " " )
bartext = ""
br , bg , bb , ba = 255 , 255 , 255 , 255
maxnulls = 12
local money = string . format ( "%08d" , getPlayerMoney ( getLocalPlayer ()))
finalnulls = 12 - string . len ( tostring ( money ))
finalString = ""
for i = 1 , finalnulls , 1 do
finalString = finalString .. "0"
end
dxDrawRectangle ( hud . x + 20 * scmp , hud . y + 45 * scmp , 65 * scmp , 65 * scmp , tocolor ( 0 , 0 , 0 , 100 )) -- HP bg
dxDrawBorder ( hud . x + 20 * scmp , hud . y + 45 * scmp , 65 * scmp , 65 * scmp , tocolor ( 0 , 0 , 0 , 255 ))
dxDrawRectangle ( hud . x + 100 * scmp , hud . y + 45 * scmp , 65 * scmp , 65 * scmp , tocolor ( 0 , 0 , 0 , 100 )) -- Armor bg
dxDrawBorder ( hud . x + 100 * scmp , hud . y + 45 * scmp , 65 * scmp , 65 * scmp , tocolor ( 0 , 0 , 0 , 255 ))
dxDrawRectangle ( hud . x + 180 * scmp , hud . y + 45 * scmp , 65 * scmp , 65 * scmp , tocolor ( 0 , 0 , 0 , 100 )) -- food bg
dxDrawBorder ( hud . x + 180 * scmp , hud . y + 45 * scmp , 65 * scmp , 65 * scmp , tocolor ( 0 , 0 , 0 , 255 ))
dxDrawRectangle ( hud . x + 260 * scmp , hud . y + 45 * scmp , 65 * scmp , 65 * scmp , tocolor ( 0 , 0 , 0 , 100 )) -- drink bg
dxDrawBorder ( hud . x + 260 * scmp , hud . y + 45 * scmp , 65 * scmp , 65 * scmp , tocolor ( 0 , 0 , 0 , 255 ))
health = math . floor ( getElementHealth ( localPlayer )* 1 )
dxDrawRectangle ( hud . x + 20 * scmp , hud . y + 45 * scmp , 65 * scmp , 0.65 * health * scmp , tocolor ( 255 , 67 , 67 , 150 )) -- HP
if health < 100 then
dxDrawText ( health .. "%" , hud . x + 30 * scmp , hud . y + 62 * scmp , 65 * scmp , 65 * scmp , tocolor ( 255 , 255 , 255 , 255 ), 0.9 , hud . font )
else
dxDrawText ( health .. "%" , hud . x + 25.8 * scmp , hud . y + 62 * scmp , 65 * scmp , 65 * scmp , tocolor ( 255 , 255 , 255 , 255 ), 0.9 , hud . font )
end
armor = math . floor ( getPedArmor ( localPlayer )* 1 )
dxDrawRectangle ( hud . x + 100 * scmp , hud . y + 45 * scmp , 65 * scmp , 0.65 * armor * scmp , tocolor ( 80 , 156 , 200 , 150 )) -- Armor
if armor < 100 then
dxDrawText ( armor .. "%" , hud . x + 110 * scmp , hud . y + 62 * scmp , 65 * scmp , 65 * scmp , tocolor ( 255 , 255 , 255 , 255 ), 0.9 , hud . font )
else
dxDrawText ( armor .. "%" , hud . x + 105.8 * scmp , hud . y + 62 * scmp , 65 * scmp , 65 * scmp , tocolor ( 255 , 255 , 255 , 255 ), 0.9 , hud . font )
end
dxDrawRectangle ( hud . x + 180 * scmp , hud . y + 45 * scmp , 65 * scmp , 65 * scmp , tocolor ( 255 , 144 , 0 , 150 )) -- food
dxDrawText ( "100%" , hud . x + 185 * scmp , hud . y + 62 * scmp , 65 * scmp , 65 * scmp , tocolor ( 255 , 255 , 255 , 255 ), 0.9 , hud . font )
dxDrawRectangle ( hud . x + 260 * scmp , hud . y + 45 * scmp , 65 * scmp , 65 * scmp , tocolor ( 124 , 197 , 118 , 150 )) -- drink
dxDrawText ( "100%" , hud . x + 265 * scmp , hud . y + 62 * scmp , 65 * scmp , 65 * scmp , tocolor ( 255 , 255 , 255 , 255 ), 0.9 , hud . font )
weapon = getPedWeapon ( localPlayer )
if weapon then
dxDrawImage ( hud . x + 80 * scmp , hud . y + 160 * scmp , 256 * scmp , 128 * scmp , "files/" .. tonumber ( weapon ).. ".png" , 0 , 0 , 0 , tocolor ( 255 , 255 , 255 , 255 ))
end
dxDrawText ( finalString .. "#7CC576" .. money .. " $" , hud . x + 74 * scmp , hud . y + 120 * scmp , 20 * scmp , 20 * scmp , tocolor ( 255 , 255 , 255 , 255 ), 1 , pricedown2 , "left" , "top" , false , false , false , true )
end
end
addEventHandler ( "onClientRender" , getRootElement (), createHUD )
--[[ bindKey ( "M" , "down" ,
function()
showCursor ( not isCursorShowing ())
end
)]]
function toggleHUD ()
hud . state = ( not hud . state )
outputChatBox ( "Hud on/off" )
end
addCommandHandler ( "toghud" , toggleHUD )
addCommandHandler ( "Toghud" , toggleHUD )
addCommandHandler ( "togglehud" , toggleHUD )
function setData ( cmd , data , value )
if data and value then
data = tostring ( data )
value = tonumber ( value )
setElementData ( localPlayer , data , value )
outputChatBox ( data .. " to " .. value )
end
end
addCommandHandler ( "setdata" , setData )
function resetHUD ()
if isElement ( hud . background ) then
destroyElement ( hud . background )
hud . gui = false
outputChatBox ( "Hud reseted." )
end
end
addCommandHandler ( "resethud" , resetHUD )
addCommandHandler ( "Resethud" , resetHUD )
addCommandHandler ( "reshud" , resetHUD )
function dxDrawBorder ( left , top , width , height )
-- dxDrawRectangle ( left , top , width , height , tocolor ( 124 , 197 , 118 , 150 ))
dxDrawRectangle ( left - 1 , top - 1 , 1 , height + 2 , tocolor ( 0 , 0 , 0 , 255 ))
dxDrawRectangle ( left + width , top - 1 , 1 , height + 2 , tocolor ( 0 , 0 , 0 , 255 ))
dxDrawRectangle ( left , top - 1 , width , 1 , tocolor ( 0 , 0 , 0 , 255 ))
dxDrawRectangle ( left , top + height , width , 1 , tocolor ( 0 , 0 , 0 , 255 ))
end