PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Variable "dynamisch" machen



lassdas
11.04.2012, 18:29
Hallo, ich habe eine Frage nämlich:

Wie kann ich eine Variable z.B.LocalPlayer():Health() also das Leben Dynamisch machen
also das wenn z.B.LocalPlayer():Health() Schnell sinkt von 100 zu 50 das er nicht gleich 50 anzeigt sondern 100,99,98,97...51,50 nur eben schneller.

Schon mal danke für die Hilfe.

gamerpaddy
11.04.2012, 18:43
Schau dir den Code vom Wire-Smoother an, da wirste fündig

lassdas
11.04.2012, 18:58
CJ[CSR];494047']Schau dir den Code vom Wire-Smoother an, da wirste fündig

Könntest du mir bitte ein link geben?

RP-01
11.04.2012, 20:48
CJ[CSR];494047']Schau dir den Code vom Wire-Smoother an, da wirste fündig
Grr.. ich hasse Codestealer.

local fHealth2 = -1
gHealth2 = fHealth2
local fOldTime = CurTime()
local fDecayRate = 0.05 --[[examples: 0 = no delay at all,
1 = -1HP every second,
0.5 = -1HP every half second/-2HP every second ]]

hook.Add( "Think", "HealthSubstractionSmoother",
function()
local ply = LocalPlayer()
local alive = ply:Alive()
local curHealth = ply:Health()

if ply and ply:IsValid() and alive and fHealth2 == -1 then fHealth2 = curHealth end
if fHealth2 > 0 and fHealth2 > curHealth and CurTime() > fOldTime + fDecayRate then
fHealth2 = fHealth2 - 1
fOldTime = CurTime()
elseif alive and fHealth2 < curHealth then
fHealth2 = curHealth
end
if gHealth2 != fHealth2 then gHealth2 = fHealth2 end
end
)

--for debugging purposes
hook.Add( "HUDPaint", "fHealth2", function() draw.DrawText("Health2: "..gHealth2, "ScoreboardText", ScrW()/2, ScrH()/2, Color(255, 0, 0, 255), TEXT_ALIGN_LEFT ) end )


Die globale Variable gHealth2 gibt nun das "Smoothed-Health" aus. (In diesem Zustand ist die Globale Variable nur Clientside verfügbar)
Die lokale Variable fDecayRate gibt an, wie schnell/langsam "gesmoothed wird".