So I recently started a Deathrun server. A friend pointed me into Facepunch's direction for help. I put a hovering name above the Death's and the Runnner's head. I used this script in the client side file (cl_init.lua) and it worked accordingly.
[CODE]function HoveringNames()
for _, target in pairs(player.GetAll()) do
if target:Alive() and target != LocalPlayer() then
local targetPos = target:GetPos() + Vector(0,0,84)
local targetDistance = math.floor((LocalPlayer():GetPos():Distance( targetPos ))/40)
local targetScreenpos = targetPos:ToScreen()
draw.SimpleText(target:Nick(), "BudgetLabel", tonumber(targetScreenpos.x), tonumber(targetScreenpos.y), Color(196,0,225,230), TEXT_ALIGN_CENTER)
end
end
end
hook.Add("HUDPaint", "HoveringNames", HoveringNames)[/CODE]
I was wondering if it is possible to make it so it also displays the Health of the player and so ONLY deaths can see the names of deaths and ONLY runners can see the name of runners. I assume I have to set up some "if then" statements with teams somehow involved. I only know a tad bit of coding so don't expect too much knowledge from me.
EDIT: I have looked all over the internet and I can't find one single tutorial on how to set something like this up. Hopefully it will be helpful to others at my skill level as well.
To make it only show for people on the same team simply add a check on to this line:
[lua]if target:Alive() and target != LocalPlayer() then[/lua]
so it becomes
[lua]if target:Alive() and target != LocalPlayer() and target:Team()==LocalPlayer():Team() then[/lua]
To show their health instead of their name change [B]target:Nick()[/B] to [B]tostring(target:Health())[/B]
What if I want to show both name and health......? I will see if your suggestion for teams works.
EDIT: BTW The line of code worked for teams.
Now I wanted to show health so I added this line of code below
[CODE]draw.SimpleText(target:Nick(), "Deathrun_SmoothMed", tonumber(targetScreenpos.x), tonumber(targetScreenpos.y), Color(0,0,225,230), TEXT_ALIGN_CENTER)[/CODE]
With an end result of
[CODE]function HoveringNames()
for _, target in pairs(player.GetAll()) do
if target:Alive() and target != LocalPlayer() and target:Team()==LocalPlayer():Team() then
local targetPos = target:GetPos() + Vector(0,0,84)
local targetDistance = math.floor((LocalPlayer():GetPos():Distance( targetPos ))/40)
local targetScreenpos = targetPos:ToScreen()
draw.SimpleText(target:Nick(), "Deathrun_SmoothMed", tonumber(targetScreenpos.x), tonumber(targetScreenpos.y), Color(0,0,225,230), TEXT_ALIGN_CENTER)
draw.SimpleText(tostring(target:Health()), "Deathrun_SmoothMed", tonumber(targetScreenpos.x), tonumber(targetScreenpos.y), Color(255,0,0,230), TEXT_ALIGN_CENTER)
end
end
end
hook.Add("HUDPaint", "HoveringNames", HoveringNames)
[/CODE]
This resulted with the health text overlapping the Name text(Makes sense). I also tried TEXT_ALIGN_RIGHT for the health text. This only made minimal changes to the alignment of the text. How would I make it so it aligns to the right more or to the left more?
Screenpos.y
So after Screenpos.y I added + 30 for line 10
Example:
draw.SimpleText(tostring(target:Health()), "Deathrun_SmoothMed", tonumber(targetScreenpos.x), tonumber(targetScreenpos.y + 30), Color(255,0,0,230), TEXT_ALIGN_CENTER)
It did not align to the right instead it went below the name text. I like it much better though!
Thank you for everyone's cooperation! :dance:
Sorry, you need to Log In to post a reply to this thread.