Zaloguj się by uzyskać pełen dostęp. Nie masz jeszcze konta? Założ je już teraz w kilka sekund.

Wysłany: 2020-03-21, 09:53


Pro3west1







Wiek: 26
Na forum: 2524 dni
Posty: 37
Nick w MP: hjkh



Respekt: 50

Witam, ucz? si? lua pomo?e mi kto? dorobi? paliwo do tego licznika?
Pr?bowa?em z dxdrawtext ale mi nie wysz?o.

Kod:

local scx,scy = guiGetScreenSize()
local px = scx/1920

local sizeX,sizeY = 350*px,350*px
local posX,posY = scx-sizeX,scy-sizeY

local font1 = dxCreateFont( "files/AEROMATICSBOLD.ttf",17*px )
local font2 = dxCreateFont( "files/AEROMATICSBOLDITALIC.ttf" )
local font3 = dxCreateFont( "files/AEROMATICSITALIC.ttf",50*px )
local font4 = dxCreateFont( "files/AEROMATICSITALIC.ttf",18*px )

function math.lerp(a, b, k)
local result = a * (1-k) + b * k
if result >= b then
result = b
elseif result <= a then
result = a
end
return result
end

local alpha = 255
local side = true
local pulsing = true

function drawSpeedometer()
local veh = getPedOccupiedVehicle(localPlayer)
if veh then
local speedx, speedy, speedz = getElementVelocity ( veh )
local actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5)
local kmh = math.floor(actualspeed * 180)
local rotation = math.lerp(-152,90,kmh/300)
if rotation >= 90 then rotation = math.random(88,92) end

local gear = getVehicleCurrentGear( veh )
if gear == 0 then
if kmh <= 1 then
gear = "N"
else
gear = "R"
end
elseif gear == 1 then
if kmh <= 2 then
gear = "N"
end
end

dxDrawText(gear,posX,posY,posX+sizeX,posY+sizeY,tocolor(0,100,100),1,font1,"center","center")
dxDrawText(kmh,posX+60*px,posY+250*px,posX+sizeX,posY+250*px,tocolor(255,255,255),1,font3,"center","center")

dxDrawImage(posX,posY,sizeX,sizeY,"files/Spedo.png")
dxDrawImage(posX,posY,sizeX,sizeY,"files/strelkaspedo.png",rotation) -- -150 to 90




if getVehicleEngineState( veh ) then
dxDrawImage(posX-100*px,posY-140*px,512*px,512*px,"files/engine.png",0,0,0,tocolor(200,0,0))
else
dxDrawImage(posX-100*px,posY-140*px,512*px,512*px,"files/engine.png",0,0,0,tocolor(255,255,255))
end

if getVehicleOverrideLights( veh ) == 2 then
dxDrawImage(posX-60*px,posY-140*px,512*px,512*px,"files/light.png",0,0,0,tocolor(200,0,0))
elseif getVehicleOverrideLights( veh ) == 1 then
dxDrawImage(posX-60*px,posY-140*px,512*px,512*px,"files/light.png",0,0,0,tocolor(255,255,255))
else
local h,m = getTime()
if h >= 7 and h <= 21 then
dxDrawImage(posX-60*px,posY-140*px,512*px,512*px,"files/light.png",0,0,0,tocolor(255,255,255))
else
dxDrawImage(posX-60*px,posY-140*px,512*px,512*px,"files/light.png",0,0,0,tocolor(200,0,0))
end
end

if isVehicleLocked(veh) then
dxDrawImage(posX-20*px,posY-120*px,512*px,512*px,"files/lock.png",0,0,0,tocolor(200,0,0))
else
dxDrawImage(posX-20*px,posY-120*px,512*px,512*px,"files/lock.png",0,0,0,tocolor(255,255,255))
end

if ccEnabled then
dxDrawImage(posX-140*px,posY-120*px,512*px,512*px,"files/kruiz.png",0,0,0,tocolor(200,0,0))
else
dxDrawImage(posX-140*px,posY-120*px,512*px,512*px,"files/kruiz.png",0,0,0,tocolor(255,255,255))
end
end
end
addEventHandler("onClientRender",root,drawSpeedometer)

bindKey("lctrl","down",function()
triggerServerEvent( "triggerVehicleSystem", localPlayer, "engine" )
end)

bindKey("lalt","down",function()
triggerServerEvent( "triggerVehicleSystem", localPlayer, "lights" )
end)

bindKey("l","down",function()
triggerServerEvent( "triggerVehicleSystem", localPlayer, "lock" )
end)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-03-21, 09:56


Wilq







Wiek: 24
Na forum: 4429 dni
Posty: 3410

Piwa: 739

Respekt: 1225,8
Respekt: 1225,8

Pobierasz stan paliwa za pomoc?

Więcej informacji znajdziesz w Wikipedii MTA:

getElementData


i jako tekst wy?wietlasz za pomoc?

Więcej informacji znajdziesz w Wikipedii MTA:

dxDrawText


Pr?buj co? samemu i jak nie b?dzie dzia?a? to wklejaj ewentualne b??dy DB3.

Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
Pro3west1
Wysłany: 2020-03-21, 10:19


Pro3west1







Wiek: 26
Na forum: 2524 dni
Posty: 37
Nick w MP: hjkh



Respekt: 50

"Wilq" napisał/a:

Pobierasz stan paliwa za pomoc?

Więcej informacji znajdziesz w Wikipedii MTA:

getElementData


i jako tekst wy?wietlasz za pomoc?

Więcej informacji znajdziesz w Wikipedii MTA:

dxDrawText


Pr?buj co? samemu i jak nie b?dzie dzia?a? to wklejaj ewentualne b??dy DB3.



https://imgur.com/OhaX6P2
tutaj kod wiem ?e pewnie ?le to zrobi?em ale mia?em do?? du?? przerw? z lua.

Kod:

local scx,scy = guiGetScreenSize()
local px = scx/1920

local sizeX,sizeY = 350*px,350*px
local posX,posY = scx-sizeX,scy-sizeY

local font1 = dxCreateFont( "files/AEROMATICSBOLD.ttf",17*px )
local font2 = dxCreateFont( "files/AEROMATICSBOLDITALIC.ttf" )
local font3 = dxCreateFont( "files/AEROMATICSITALIC.ttf",50*px )
local font4 = dxCreateFont( "files/AEROMATICSITALIC.ttf",18*px )

function math.lerp(a, b, k)
local result = a * (1-k) + b * k
if result >= b then
result = b
elseif result <= a then
result = a
end
return result
end

local alpha = 255
local side = true
local pulsing = true

function drawSpeedometer()
local veh = getPedOccupiedVehicle(localPlayer)
if veh then
local speedx, speedy, speedz = getElementVelocity ( veh )
local actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5)
local kmh = math.floor(actualspeed * 180)
local rotation = math.lerp(-152,90,kmh/300)
if rotation >= 90 then rotation = math.random(88,92) end
dxDrawText(string.format('%.0f', paliwo).."/"..bak.." "..jednostka, 1701/scale, 1151/scale, 1945/scale, 884/scale, tocolor(0,0,0, 255), 1.00, fonts[1], "center", "center", false, false, false, false, false)

local gear = getVehicleCurrentGear( veh )
if gear == 0 then
if kmh <= 1 then
gear = "N"
else
gear = "R"
end
elseif gear == 1 then
if kmh <= 2 then
gear = "N"
end
end

dxDrawText(gear,posX,posY,posX+sizeX,posY+sizeY,tocolor(0,100,100),1,font1,"center","center")
dxDrawText(kmh,posX+60*px,posY+250*px,posX+sizeX,posY+250*px,tocolor(255,255,255),1,font3,"center","center")

dxDrawImage(posX,posY,sizeX,sizeY,"files/Spedo.png")
dxDrawImage(posX,posY,sizeX,sizeY,"files/strelkaspedo.png",rotation) -- -150 to 90




if getVehicleEngineState( veh ) then
dxDrawImage(posX-100*px,posY-140*px,512*px,512*px,"files/engine.png",0,0,0,tocolor(200,0,0))
else
dxDrawImage(posX-100*px,posY-140*px,512*px,512*px,"files/engine.png",0,0,0,tocolor(255,255,255))
end

if getVehicleOverrideLights( veh ) == 2 then
dxDrawImage(posX-60*px,posY-140*px,512*px,512*px,"files/light.png",0,0,0,tocolor(200,0,0))
elseif getVehicleOverrideLights( veh ) == 1 then
dxDrawImage(posX-60*px,posY-140*px,512*px,512*px,"files/light.png",0,0,0,tocolor(255,255,255))
else
local h,m = getTime()
if h >= 7 and h <= 21 then
dxDrawImage(posX-60*px,posY-140*px,512*px,512*px,"files/light.png",0,0,0,tocolor(255,255,255))
else
dxDrawImage(posX-60*px,posY-140*px,512*px,512*px,"files/light.png",0,0,0,tocolor(200,0,0))
end
end

if isVehicleLocked(veh) then
dxDrawImage(posX-20*px,posY-120*px,512*px,512*px,"files/lock.png",0,0,0,tocolor(200,0,0))
else
dxDrawImage(posX-20*px,posY-120*px,512*px,512*px,"files/lock.png",0,0,0,tocolor(255,255,255))
end

if ccEnabled then
dxDrawImage(posX-140*px,posY-120*px,512*px,512*px,"files/kruiz.png",0,0,0,tocolor(200,0,0))
else
dxDrawImage(posX-140*px,posY-120*px,512*px,512*px,"files/kruiz.png",0,0,0,tocolor(255,255,255))
end
end
end

local bak = getElementData(pojazd, "bak") or 100

local paliwo = getElementData(pojazd, "vehicle:fuel") or 100


addEventHandler("onClientRender",root,drawSpeedometer)

bindKey("lctrl","down",function()
triggerServerEvent( "triggerVehicleSystem", localPlayer, "engine" )
end)

bindKey("lalt","down",function()
triggerServerEvent( "triggerVehicleSystem", localPlayer, "lights" )
end)

bindKey("l","down",function()
triggerServerEvent( "triggerVehicleSystem", localPlayer, "lock" )
end)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-03-21, 11:14


Wilq







Wiek: 24
Na forum: 4429 dni
Posty: 3410

Piwa: 739

Respekt: 1225,8
Respekt: 1225,8

Jaki cel ma sprawdzanie stanu poza funkcj? od wy?wietlania danych? Zmienna pojazdy si? nie zgadza. Musisz to zawrze? w funkcji kilka linijek wy?ej.

Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
Pro3west1
Tagi: dorobienie :: paliwa :: licznika
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA Ten temat jest zablokowany bez możliwości zmiany postów lub pisania odpowiedzi

Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Dodaj temat do Ulubionych
Wersja do druku