PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Gamemode: Advanced HealthBar



Mentos
25.01.2014, 21:10
Hy... schön zu sehen das die GMod.de community wieder lebt :D

Auch ich bin nach kurzer Pause wieder am Scripten und kam auf die Idee das eine andere Art von Healthbar doch was schönes wäre.
In meinem Denkstübchen sieht die Idee so aus, wie die Lebens und Mana Kugeln in Diablo II... nur halt übereinander!

Natürlich strebe ich höhere Ziele an aber dazu dann eventuell später.
Das ganze würde ich gerne so umsetzen, das sich die Bilder/Texturen überlappen, so das vorne Leben und dahinter Mana/Rüstung oder sonst was ist.
Zu diesem Thema habe ich DAS (http://facepunch.com/showthread.php?t=1026117) gefunden...
Bevor ich aber 2 Stunden Texturen entwerfe, welche dann aufgrund von bekannten Pixelbeschrenkungen grottig hingerichtet werden, würde ich lieber erst erfahren ob es überhaupt so geht und falls ja eventuell auch mit PNG oder BMP oder so ;)

Hintergrund ist eine entfernte Erinnerung an einen PropHunt Server der eine Art Kreis hatte der mit dem Leben abnahm.

Vielen dank für alle Überlegungen!

PS: Ich will keinen ganzen code oder so! Nur die Aussage ob es geht und mit welchen Befehlen besagtes Problem umgesetzt werden kann 8)

Gruß Mentos

Mentos
26.01.2014, 23:23
PUSH+

habe jetzt doch schonmal angefangen...
Ich habe das Script das ich oben angegeben hatte eingefelchtet und bin nun auch dazu gekommen die textur mit Material einzubinden.
Jetzt bekomm ich allerdings einen Fehler, der mir noch nie unter kam

--- Missing Vgui material 010000materials/body
--- Missing Vgui material 010000body
(es kommen 2 texturen, da ich testweise versuche welches von beiden funktioniert!)
Habe dafür die body.png auf dem Client in materials\body.png und auf dem Server im gamemodecontentordner\materials\body.png
(da es irgendwann mal runtergeladen werden soll)

eventuell könnt ihr mich aufklären D;

CODE:


--- //// ---

local HUDMAT = Material ( "materials/body.png", "nocull" )
local THUDMAT = HUDMAT:GetTexture( "$basetexture" )

if(THUDMAT) then
print("THUDMAT")
else
print("not 1")
end

local HUDMATT = Material ( "body.png", "nocull" )
local THUDMATT = HUDMATT:GetTexture( "$basetexture" )

if(THUDMATT) then
print("THUDMATT")
else
print("not 2")
end

--- //// --- im HUDDraw

draw.DrawPartialTexturedRect( 100.0, 100.0, 50.0, 75.0, 0.0, 0.0, 2000.0, 3000.0, THUDMAT:GetName() )
draw.DrawPartialTexturedRect( 200, 100, 50, 75, 0, 0, 2000, 3000, THUDMATT:GetName() )

--- //// ---


IMaterial ist insgesamt nicht wirklich alles in allem nicht so gut erklärt...

IMaterial:GetTexture( string materialTexture )
...-> string materialTexture
........The name of the material texture.
:shock:

gamerpaddy
26.01.2014, 23:39
Printe mal THUDMAT und THUDMAT:GetName()
ohne die " "

pack zur not mal die png files in den Materials ordner (im hauptordner, nicht content)

Mentos
27.01.2014, 13:44
das png habe ich schon auf dem client in den materials ordner gepackt...



print(THUDMAT)
-- userdata: 0x29343d48
print(THUDMAT:GetName())
-- 010000materials/body


print(THUDMATT)
-- userdata: 0x29343dc8
print(THUDMATT:GetName())
-- 010000body

gamerpaddy
27.01.2014, 14:43
Probier mal das hier:

http://facepunch.com/showthread.php?t=1218490

Zitat:
Use Material() instead of surface.GetTextureID(), and surface.SetMaterial() instead of surface.SetTexture()
Also den DrawPartialTexturedRect code umschreiben.

Edit:
hab den code mal umgeschrieben, dass er funktioniert (Den drawpartialtexturedrect code, nicht deiner. Hab aber ein beispiel unter TEST CODE gelegt.

-- Check if we are being run on the server and add this file to the client
if( SERVER )then
AddCSLuaFile( "textureSheet.lua" );

-- We don't need these functions on the server
return;
end;


--- TEST CODE
hook.Add("HUDPaint", "testhudpaint", function()
draw.DrawPartialTexturedRect( 512, 512, 256, 256, 0, 0, CurTime(), CurTime(), "spawnicons/models/alyx_intro.png" );
end);
--- TEST CODE

-- A function to draw a certain part of a texture
function surface.DrawPartialTexturedRect( x, y, w, h, partx, party, partw, parth, texw, texh )
--[[
Arguments:
x: Where is it drawn on the x-axis of your screen
y: Where is it drawn on the y-axis of your screen
w: How wide must the image be?
h: How high must the image be?
partx: Where on the given texture's x-axis can we find the image you want?
party: Where on the given texture's y-axis can we find the image you want?
partw: How wide is the partial image in the given texture?
parth: How high is the partial image in the given texture?
texw: How wide is the texture?
texh: How high is the texture?
]]--

-- Verify that we recieved all arguments
if not( x && y && w && h && partx && party && partw && parth && texw && texh ) then
ErrorNoHalt("surface.DrawPartialTexturedRect: Missing argument!");

return;
end;

-- Get the positions and sizes as percentages / 100
local percX, percY = partx / texw, party / texh;
local percW, percH = partw / texw, parth / texh;

-- Process the data
local vertexData = {
{
x = x,
y = y,
u = percX,
v = percY
},
{
x = x + w,
y = y,
u = percX + percW,
v = percY
},
{
x = x + w,
y = y + h,
u = percX + percW,
v = percY + percH
},
{
x = x,
y = y + h,
u = percX,
v = percY + percH
}
};

surface.DrawPoly( vertexData );
end;

-- A function to draw a certain part of a texture
function draw.DrawPartialTexturedRect( x, y, w, h, partx, party, partw, parth, texture )
--[[
Arguments:
- Also look at the arguments of the surface version of this
texturename: What is the name of the texture?
]]--

-- Verify that we recieved all arguments
if not( x && y && w && h && partx && party && partw && parth && texture ) then
ErrorNoHalt("draw.DrawPartialTexturedRect: Missing argument!");

return;
end;


-- Get the positions and sizes as percentages / 100
local mat = Material( texture, "nocull" );
local texW = mat:Height()
local texH = mat:Width()
local percX, percY = partx / texW, party / texH;
local percW, percH = partw / texW, parth / texH;

-- Process the data
local vertexData = {
{
x = x,
y = y,
u = percX,
v = percY
},
{
x = x + w,
y = y,
u = percX + percW,
v = percY
},
{
x = x + w,
y = y + h,
u = percX + percW,
v = percY + percH
},
{
x = x,
y = y + h,
u = percX,
v = percY + percH
}
};

surface.SetMaterial( mat );
surface.SetDrawColor( 255, 255, 255, 255 );
surface.DrawPoly( vertexData );
end;

http://s14.directupload.net/images/140127/apvgttjs.jpg
(er zoomt langsam aus, in dem beispiel)

Mentos
27.01.2014, 23:03
Danke! ich versuche es gleich mal :D

EDIT:
Top! Klappt bestens.
Es ist unglaublich wie einfach man hochqualitative Bilder damit darstellen kann...

Ich lade bei gelegenheit mal ein paar "Finished" Bilder hoch ;D

EDIT2:
So ergebnis ist verfügbar ;D
4283
Vielen Dank für die Hilfe

Gruß Mentos