Soo, I've been trying to find out how to show the amount of damage you're dealing by painting the number over the npc's head each time you shoot it.
Can't figure it out. Could someone point me in the right direction?
Video of concept (from WoW, pretty much the same thing):
[url]http://www.youtube.com/watch?v=O2Rj6liwp5k[/url] <--- 1:30ish
I know you weren't asking for an entire script, but I was bored and decided to make it.
[lua]if SERVER then
hook.Add("EntityTakeDamage", "FloatingDamage", function(ent, inflictor, attacker, amount, dmginfo)
if attacker:IsPlayer() then
umsg.Start("Floating Damage", attacker);
umsg.Short(amount);
umsg.Entity(ent);
umsg.End();
end
end);
else
local Floats = {};
usermessage.Hook("Floating Damage", function(um)
table.insert(Floats, {Damage = um:ReadShort(), Entity = um:ReadEntity(), Offset = {x=math.random(-50, 50), y=math.random(-50, 50)}, Time = math.random(1, 3), StartTime = CurTime()});
end);
hook.Add("Initialize", "CreateFont", function()
surface.CreateFont("coolvetica", ScreenScale(12), 400, true, false, "CV12Scaled");
end);
hook.Add("HUDPaint", "DrawFloatingDamage", function()
for i, fl in ipairs(Floats) do
if ValidEntity(fl.Entity) then
local frac = (CurTime() - fl.StartTime) / fl.Time;
local alpha = frac * 255;
local pos = fl.Entity:GetPos():ToScreen();
pos.x = pos.x + fl.Offset.x;
pos.y = pos.y + fl.Offset.y;
draw.SimpleText("-"..fl.Damage, "CV12Scaled", pos.x, pos.y - frac*100, Color(255, 0, 0, 255 - alpha), 1, 1);
if CurTime() >= fl.StartTime + fl.Time - 0.05 then
table.remove(Floats, i);
end
else
table.remove(Floats, i);
end
end
end);
end[/lua]
Simply put it in autorun.
[b]UNTESTED[/b]
I just tested it, its working...
NullPoint, I love you!
Thanks so much
It was my pleasure.
This is actually so nice that im gonna keep it :)
Thanks.
I found a problem with the one I posted earlier. Here is a fix, I've also changed the font size and colour.
[lua]if SERVER then
hook.Add("EntityTakeDamage", "FloatingDamage", function(ent, inflictor, attacker, amount, dmginfo)
if attacker:IsPlayer() then
umsg.Start("Floating Damage", attacker);
umsg.Short(amount);
umsg.Vector(ent:LocalToWorld(ent:OBBCenter()));
umsg.End();
end
end);
else
local Floats = {};
usermessage.Hook("Floating Damage", function(um)
local dmg = um:ReadShort();
local pos = um:ReadVector();
local off = {x=math.random(-50, 50), y=math.random(-50, 50)};
local time = math.random(1, 3);
table.insert(Floats, {Damage = dmg, Position = pos, Offset = off, Time = time, StartTime = CurTime()});
end);
hook.Add("Initialize", "CreateFont", function()
surface.CreateFont("coolvetica", ScreenScale(12), 400, true, false, "CV12Scaled");
end);
hook.Add("HUDPaint", "DrawFloatingDamage", function()
for i, fl in ipairs(Floats) do
local frac = (CurTime() - fl.StartTime) / fl.Time;
local alpha = frac * 255;
local pos = fl.Position:ToScreen();
pos.x = pos.x + fl.Offset.x;
pos.y = pos.y + fl.Offset.y;
draw.SimpleText("-"..fl.Damage, "CV12Scaled", pos.x, pos.y - frac*100, Color(255, 0, 0, 255 - alpha), 1, 1);
if CurTime() >= fl.StartTime + fl.Time - 0.05 then
table.remove(Floats, i);
end
end
end);
end[/lua]
[editline]02:46PM[/editline]
I thought I would make a video for it:
[media]http://www.youtube.com/watch?v=7lbP1FgPga4[/media]
Sorry, you need to Log In to post a reply to this thread.