Draw hud for specific person.

Hey guys, I know I have been asking alot of questions now, but im now currently working with my final SWEP. Only I have one problem,

Ok, so i got this HUD found in one of the TTT Files for the knife, when knife is instand kill and you look at a person you see a X with Instant Kill

Code:

[lua]
if CLIENT then
function SWEP:DrawHUD()
local tr = self.Owner:GetEyeTrace(MASK_SHOT)

  if tr.HitNonWorld and IsValid(tr.Entity) and tr.Entity:IsPlayer()
     and tr.Entity:Health() < (self.Primary.Damage + 10) then

     local x = ScrW() / 2.0
     local y = ScrH() / 2.0

     surface.SetDrawColor(255, 0, 0, 255)

     local outer = 20
     local inner = 10
     surface.DrawLine(x - outer, y - outer, x - inner, y - inner)
     surface.DrawLine(x + outer, y + outer, x + inner, y + inner)

     surface.DrawLine(x - outer, y + outer, x - inner, y + inner)
     surface.DrawLine(x + outer, y - outer, x + inner, y - inner)

     draw.SimpleText("INSTANT KILL", "TabLarge", x, y - 30, COLOR_RED, TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)
  end         

  return self.BaseClass.DrawHUD(self)

end
end
[/lua]

But I made a SWEP what looks like a healthstation. Its a prop (Microwave) from Css office and it gives you health.

But my SWEP is a painstation what kills you instantly when used (Traitors equipment :D)

Anyways, How can i make so when you look at that prop (The microwave) and you are a Traitor that it says with the X “Painstation” you must be traitor to see it.

Something like this:

[lua]
if CLIENT then
function SWEP:DrawHUD()
local tr = self.Owner:GetEyeTrace(MASK_SHOT)

  if tr.HitWorld and IsValid(tr.Entity) and tr.Entity:IsPlayer()
     and tr.Entity:IsActiveTraitor and  tr.Entity:Health() < (self.Primary.Damage + 10) then

     local x = ScrW() / 2.0
     local y = ScrH() / 2.0

     surface.SetDrawColor(255, 0, 0, 255)

     local outer = 20
     local inner = 10
     surface.DrawLine(x - outer, y - outer, x - inner, y - inner)
     surface.DrawLine(x + outer, y + outer, x + inner, y + inner)

     surface.DrawLine(x - outer, y + outer, x - inner, y + inner)
     surface.DrawLine(x + outer, y - outer, x + inner, y - inner)

     draw.SimpleText("PAINSTATION", "TabLarge", x, y - 30, COLOR_RED, TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)
  end         

  return self.BaseClass.DrawHUD(self)

end
end
[/lua]

But that Code doesnt seem to work, I tried add ply:IsActiveTraitor but that dint fit so it dint work either.

I hope you guys know what I mean

Much appriciated :slight_smile:

Edit: Maybe we can leave the [lua]tr.Entity:Health() < (self.Primary.Damage + 10)[/lua] line out because the Painstation doesnt take ur health below 100 it just does ply:Kill for the person who use it. Maybe that doesnt matter but im not sure of that.

So your wanting the pain-station to show up like the normal health station for everyone except the traitors? if thats the case you could try putting () after IsActiveTraitor. If that doesn’t work i think that you can use ply:GetTraitor() not sure though.

The problem is mostly that you have not got () at the end of your function.

Also, ply is not defined in the function so you are checking a non existent entity.

[editline]24th March 2011[/editline]

Player is defined, my bad but still dont forget ()

Yes thats exacly what i want :smiley:

Alright so basicly acording to Beast too

It would be

[lua]
if tr.HitWorld and IsValid(tr.Entity) and ply:IsActiveTraitor() and tr.Entity:Health() < (self.Primary.Damage + 10) then
[/lua]

I took the tr.Entity:IsPlayer() Out because that only works when you look at a player right or is that wrong?

Also does this works when you look at the prop itself?

Edit: Doesnt work says:

[weapons\weapon_ttt_pain_station\shared.lua:138] attempt to index global ‘ply’ (a nil value)
[weapons\weapon_ttt_pain_station\shared.lua:138] attempt to index global ‘ply’ (a nil value)

(Orange letters if that matters)

Code:

[lua]
if CLIENT then
function SWEP:DrawHUD()
local tr = self.Owner:GetEyeTrace(MASK_SHOT)

  if tr.HitNonWorld and IsValid(tr.Entity) and ply:IsActiveTraitor() then

     local x = ScrW() / 2.0
     local y = ScrH() / 2.0

     surface.SetDrawColor(255, 0, 0, 255)

     local outer = 20
     local inner = 10
     surface.DrawLine(x - outer, y - outer, x - inner, y - inner)
     surface.DrawLine(x + outer, y + outer, x + inner, y + inner)

     surface.DrawLine(x - outer, y + outer, x - inner, y + inner)
     surface.DrawLine(x + outer, y - outer, x + inner, y - inner)

     draw.SimpleText("PAIN STATION", "TabLarge", x, y - 30, COLOR_RED, TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)
  end         

  return self.BaseClass.DrawHUD(self)

end
end

[/lua]

As i said already, ply is not defined.

You are checking an non existant variable.

[editline]24th March 2011[/editline]

Change:

ply:IsActiveTraitor()

to

LocalPlayer():IsActiveTraitor()

Doesnt give a LUA error now but it doesnt show for Traitors “X Painstation” when you look at it?

You do realise this is a weapon, there for you need the painstation weapon to see that a painstation is actually a painstation.

Wait… What I read now is kinda confusting, TTT Knows its a weapon because its from “weapon_tttbase” It all works fine just not the Hud? If thats what you ment?

Edit: What the output is, is that when the painstation is on the ground and a traitor look at it, it shows a red cross with then text in the middle of that cross saying Painstation, so traitors know not to use it.

Oh yeah forgot this code is too in the actual script itself, just if thats nessasary

Wouldnt it be better just to block traitors using it and when try try and use it deny it and notify them. Or make painstations heal traitors and damage others.

That way it stops minge traitors making others loose karma when they kill themself on the machine.

Already made a Medkit for traitors, I could block traitors from useing it… I think, but I think the Hud is better, just looks better but If i would make it denie for traitors it would have been this:

[lua]
function ENT:Use(ply)
if IsValid(ply) and ply:IsPlayer() and ply:IsActive() then
local t = CurTime()
if t > self.NextHeal then
ply:Kill()
elseif ply:IsActiveTraitor() then
return false
end
end
end
end
[/lua]

Something like that, Not really sure how the return thing works

Also, don’t recall self.BaseClass.DrawHUD() - the SWEP:DrawHUD() function takes care of the HUD for JUST that weapon, it doesn’t take over the HUD for your base class, so calling it again is redundant and a waste of framerate.

Alright, removed it, but I still have no clue why it isent working (the hud when you look at the painstation)

The code should work… I think…

Remove the traitor check and try it.

That code has some major logic errors. First you’re checking if it can kill someone and if it can’t see if they are a traitor. You don’t need the ply:IsActive() check replace it with !ply:WhatEverTheTraitorCheckIs(). That will only let non-traitors use the sent. Also you want to make it so that if t >= self.NextHeal other wise it will actually have a bit longer cool down time.

The Charge stays at 200 so that should be alright, Well then the code would be:

[lua]
function ENT:Use(ply)
if IsValid(ply) and ply:IsPlayer() and !ply:IsActiveTraitor() then
local t = CurTime()
if t > self.NextHeal then
ply:Kill()
end
end
end
[/lua]

Edit: Works, traitors cant use it now, but is there really no way to draw that Hud for the painstation? Because I think that would be better somewhere?

I think i need to make the HUD that it locks on the Painstation itself and not on a player as seen in “ply:IsPlayer()” but is there a way how to do that?

Sloved, Got it working :smiley: