Schwierigkeitsgrad: Mittel (aus der Sicht eines Anfängers)
Ich habe das Tutorial vor ein paar Wochen gemacht, bevor ich in der Arbeit war.
Da ich eben einen eher großen Zeitmangel habe, konnte ich das nicht früher posten.
Das wird auch einer meiner letzten Posts
P.S. Im Video wird sehr viel erklärt.. Es wird auch viel außerhalb einer dx Programmierung erklärt.. also wer sich dafür Zeit nimmt, verschwendet sie nicht (naja, MTA -> Lua, das ist einfach sinnlos :D)
Man macht's nur, weils einfach ist..
[video]
Externer Inhalt
www.youtube.com
Inhalte von externen Seiten werden ohne Ihre Zustimmung nicht automatisch geladen und angezeigt.
Durch die Aktivierung der externen Inhalte erklären Sie sich damit einverstanden, dass personenbezogene Daten an Drittplattformen übermittelt werden. Mehr Informationen dazu haben wir in unserer Datenschutzerklärung zur Verfügung gestellt.
Lua
## -- SOURCECODE FROM KRISCHKROS'S TUTORIAL -- ##
local scx, scy = guiGetScreenSize()
local max_distance = 20
local max_width = 100
local max_height = 50
local max_health = 100
local height_sub = 180
addEventHandler("onClientResourceStart", resourceRoot, function()
bindKey("k", "down", function()
local x,y,z = getElementPosition(localPlayer)
createPed(math.random(9, 100), x+3,y+3,z)
end)
end)
addEventHandler("onClientRender", root, function()
draw_healthbar_peds()
draw_healthbar_player()
end)
function draw_healthbar_peds()
for i, ped in pairs(getElementsByType("ped")) do
local px, py, pz = getElementPosition(ped)
local cx, cy, cz = getCameraMatrix()
local sx, sy = getScreenFromWorldPosition(px, py, pz)
local health = getElementHealth(ped)
if health < 0 then
health = 0
elseif health > max_health then
health = max_health
end
local dis = getDistanceBetweenPoints3D(px, py, pz, cx, cy, cz)
local alpha = 255 - (255/max_distance*dis)
if alpha <= 0 then alpha = 0 end
if sx and sy and scx and scy and health > 0 then
local rv, gv = 255 - (255/max_health*health), 255/max_health*health
local cheight_sub = height_sub - (height_sub/max_distance*dis)
dxDrawRectangle(sx-(max_width/2)-3, sy-cheight_sub-(max_height/2)-3, max_width+6, max_height+6, tocolor(0, 0, 0, alpha))
dxDrawRectangle((sx-max_width/2) , sy-cheight_sub-(max_height/2) , max_width/max_health*health , max_height , tocolor(rv, gv, 0, alpha))
dxDrawText("Ped Nummer. "..i.."\nHealth: "..math.floor(health), sx, sy-cheight_sub, sx, sy-cheight_sub, tocolor(255, 255, 255, alpha), 1, "default", "center", "center")
end
end
end
function draw_healthbar_player()
for i, ply in pairs(getElementsByType("player")) do
if ply ~= localPlayer then
local px, py, pz = getElementPosition(ply)
local cx, cy, cz = getCameraMatrix()
local sx, sy = getScreenFromWorldPosition(px, py, pz)
local health = getElementHealth(ply)
if health < 0 then
health = 0
elseif health > max_health then
health = max_health
end
local dis = getDistanceBetweenPoints3D(px, py, pz, cx, cy, cz)
local alpha = 255 - (255/max_distance*dis)
if alpha <= 0 then alpha = 0 end
if sx and sy and scx and scy and health > 0 then
local rv, gv = 255 - (255/max_health*health), 255/max_health*health
local cheight_sub = height_sub - (height_sub/max_distance*dis)
dxDrawRectangle(sx-(max_width/2)-3, sy-cheight_sub-(max_height/2)-3, max_width+6, max_height+6, tocolor(0, 0, 0, alpha))
dxDrawRectangle((sx-max_width/2) , sy-cheight_sub-(max_height/2) , max_width/max_health*health , max_height , tocolor(rv, gv, 0, alpha))
dxDrawText(getPlayerName(ply).."\nHealth: "..math.floor(health), sx, sy-cheight_sub, sx, sy-cheight_sub, tocolor(255, 255, 255, alpha), 1, "default", "center", "center")
setPlayerNametagShowing(ply, false)
end
end
end
end
Alles anzeigen
Wenn Fehler vorhanden sind, klärt das ruhig hier, rechnet aber nicht mit einer Antwort von mir, da ich zeitlich einen gewissen Mangel habe.
Viel Erfolg beim Lernen!