Setting damage rate of an npc??

Ok, i want to make a defence turret where you can set the turrets health and damage rate in lua. I want to know if thats possible first before making this script.

Anything is possible. What do you mean by Damage “Rate”?

Spawn a : npc_turret_floor ; name it as a local variable: bob



local test = ents.Create("sent_turretcontroller") 
    test:SetPos(bob:GetPos())
    test:SetParent(bob)
    test:Spawn()
    test:Activate()
    test:SetOwner(self.Owner)
    bob.Controller = test
    bob:SetNWInt("health",test.Shealth)


Like you know that when turrets fire at you they damage you. Well they have a damage rate right? This is the amount of damage they do to you. Now how do you modify that damage rate of the turret?

Yes done now what?

Define “Rate” because clearly you are misusing the word. This isn’t WoW where you do so much damage a second. You do a set damage each time.

[editline]14th July 2012[/editline]

What is the “sent_turretcontroller” I have never seen, nor heard of this, and google isn’t pulling up anything other than an entity from Onslaught

To specify the performance limits of (a machine, for example)

My example im trying to get across to you…

Ok the damage rate of a turret is 30 hp per a bullet. How can this be lowered? (This is an example)

I don’t care if i’m misusing words, all i want is you to understand is what i mean by ‘damage rate’.

Ok that’s not a “Rate” that’s just straight up Damage.

Your Answer: You set the damage dealt before the bullet is fired.

Its just the name of the sent which is an example it could be an npc.

Wait a second you may have an answer to one of my answers.

[lua]function GM:EntityTakeDamage( ent, inflictor, attacker, amount )

if ( ent:GetClass() == "npc_turret_floor") then
	ent.health = (ent.health or 100) - amount
	if ent.health <= 0 then
		ent:Remove()
	end
end

end [/lua]

That assumes you are making a gamemode though…

So i could add this hook to the gamemode for my turret to take damage? If this is the case is there any other code i could get an get so that this can work on any gamemode. Also i want this turret to explode and remove itself.

You just awnsered your own question… add a hook.

and you already are removing it… just spawn an effect to make it explode.

Ok so i put the script into the gamemode right? But in which file cl_init.lua, init.lua or shared

and the turret will be able to have hp.

[editline]15th July 2012[/editline]

Bump.

Init.lua