Need Help: What lines do I edit

Here is the code for the TTT Health Station. I wanted to make it do damage instead of giving you health. I’ve been messing with this for a week and still can’t figure it out. Id really really appreciate some help on this!

[lua]

ENT.Type = “anim”
ENT.Model = Model(“models/props/cs_office/microwave.mdl”)

ENT.CanUseKey = true
ENT.CanHavePrints = true
ENT.MaxHeal = 25
ENT.MaxStored = 200
ENT.RechargeRate = 1
ENT.RechargeFreq = 2 – in seconds

AccessorFuncDT(ENT, “StoredHealth”, “StoredHealth”)

function ENT:SetupDataTables()
self:DTVar(“Int”, 0, “StoredHealth”)
end

function ENT:Initialize()
self.Entity:SetModel(self.Model)

self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
self.Entity:SetSolid(SOLID_VPHYSICS)
self.Entity:SetCollisionGroup(COLLISION_GROUP_NONE)
if SERVER then
self.Entity:SetMaxHealth(200)

  local phys = self.Entity:GetPhysicsObject()
  if IsValid(phys) then
     phys:SetMass(200)
  end

end
self.Entity:SetHealth(200)

self.Entity:SetColor(180, 180, 255, 255)

self:SetStoredHealth(200)

self.fingerprints = {}
end

function ENT:UseOverride(activator)
if ValidEntity(activator) and activator:IsPlayer() and activator:IsActive() then
self:GiveHealth(activator)
end
end

function ENT:AddToStorage(amount)
self:SetStoredHealth(math.min(self.MaxStored, self:GetStoredHealth() + amount))
end

function ENT:TakeFromStorage(amount)
– if we only have 5 healthpts in store, that is the amount we heal
amount = math.min(amount, self:GetStoredHealth())
self:SetStoredHealth(math.max(0, self:GetStoredHealth() - amount))
return amount
end

local healsound = Sound(“items/medshot4.wav”)
local failsound = Sound(“items/medshotno1.wav”)
function ENT:GiveHealth(ply)
if self:GetStoredHealth() > 0 then
local dmg = ply:GetMaxHealth() - ply:Health()
if dmg > 0 then
– constant clamping, no risks
local healed = self:TakeFromStorage(math.min(self.MaxHeal, dmg))
local new = math.min(ply:GetMaxHealth(), ply:Health() + healed)

     ply:SetHealth(new)

     self:EmitSound(healsound)

     if not table.HasValue(self.fingerprints, ply) then
        table.insert(self.fingerprints, ply)
     end
  else
     ply:ChatPrint("Your health is full.")
     self:EmitSound(failsound)
  end

else
ply:ChatPrint(“The health station is empty!”)
self:EmitSound(failsound)
end
end

– traditional equipment destruction effects
local zapsound = Sound(“npc/assassin/ball_zap1.wav”)
function ENT:OnTakeDamage(dmginfo)
self:TakePhysicsDamage(dmginfo)

self:SetHealth(self:Health() - dmginfo:GetDamage())
if self:Health() < 0 then
self:Remove()

  local effect = EffectData()
  effect:SetOrigin(self:GetPos())
  util.Effect("cball_explode", effect)
  WorldSound(zapsound, self:GetPos())

  if IsValid(self:GetOwner()) then
     TraitorMsg(self:GetOwner(), "YOUR HEALTH STATION HAS BEEN DESTROYED!")
  end

end
end

if CLIENT then
– flash effect
local nextflash = 0
function ENT:Think()
if nextflash < CurTime() then
local dlight = CLIENT and DynamicLight(self:EntIndex())
if dlight then
dlight.Pos = self:GetPos()
dlight.r = 0
dlight.g = 0
dlight.b = 255
dlight.Brightness = 1
dlight.Size = 100
dlight.Decay = 120
dlight.DieTime = CurTime() + 0.3
end

     nextflash = CurTime() + 3
  end

end
elseif SERVER then
– recharge
local nextcharge = 0
function ENT:Think()
if nextcharge < CurTime() then
self:AddToStorage(self.RechargeRate)

     nextcharge = CurTime() + self.RechargeFreq
  end

end
end
[/lua]


(User was banned for this post ("Wrong section" - mahalis))

You could start by looking around line 60 and did you not make a thread about this a while back?

I’ve been tinkering around between lines 60-66 but I am not sure what I am doing wrong. Yes I did make a post about this before due to me not knowing what lua tags were and posting the wrong code it got very sloppy and hard to read. So sorry for the repost!

ANY help on this would be VERY much appreciated!

The change you need to make is on line 66, and it involves basic math. If you are having this much trouble, I suggest you read some Lua documentation.

Well good to know I was in the right area :stuck_out_tongue: I was wondering if you could tell me what I should read up on to achieve this. I know you are going to say wiki but what should I read up on?

Change the plus to a minus.

Are you shitting me that’s all I have to do? I tried changing MaxHeal to -25 but that didn’t work. Then I thought I would have to add kind of damage function and it would destroy the health station on +use. I will give this a shot once our server is back up thank you very much!

It will take what ‘health’ (determined by ENT.StoredHealth) is in the station.

You know it would of taken less effort to actually type the solution than it did to be type your asshole comment. Good job going out of your way to be a douche.


(User was banned for this post ("Flaming (wow, great first post)" - mahalis))

He’s not being a douche though, he’s simply stating that if Swiftone doesn’t know what to do after the hint, he clearly doesn’t know lua.

Yeah I’m not being a douche. I’m just saying, if he’s struggling with that, maybe he should look at a few Lua tutorials. He won’t learn anything if we always spoon-feed the answers.

I would suggest reading the whole tutorial on the wiki. Start Here and work your way through the whole series, even if you think you know it already.

Awesome that’s all I needed I didn’t even know where to start off. Thanks for the help everyone I really appreciate it!.

Woohoo made some progress finally although its a little buggy I’m not sure if gmod has some sort of override.

This is what its doing:

You need to have below 100hp in order for it to do any damage to you. Also once you reach 0hp you sink into the ground at eye level but you are still alive. If another player is looking at you, you look normal and are just “Near Death”.

Whats I Changed:

I deleted line 65
Then I changed line 66 to:
local new = math.min(ply:GetMaxHealth(), ply:Health() - 25)

Any ideas why you don’t die?

Remove lines 61-63 and 75-82 inclusive.

Awesome it now does damage to people with 100hp, I should have seen that, I was tired as hell :p. Now its still not killing people and I can’t code what so ever but would it be something like this?

function ENT:GiveHealth(ply)
– constant clamping, no risks
local new = math.min(ply:GetMaxHealth(), ply:Health() - 25)
If ply.Health() > 1 then
ply.Kill

And thank you very much for your help Undefined

They’re meta-functions. Use a : instead of a (dot)

Oh ok would it be metaply: then? Also I can’t code at all I just made it up real quick. Is this the right path to make the kill station kill you?

[lua]function ENT:GiveHealth(ply) – constant clamping, no risks
local new = math.min(ply:GetMaxHealth(), ply:Health() - 25)
if ply:Health() > 1 then
ply:Kill()
end
end[/lua]

Thanks for editing what I did it still didn’t work though. Anyone have any other ideas?

Define didn’t work. Errors?