Scaling a players damage with a entity?

Hey,

How would I go around scaling a players damage when he spawns an entity, only using entity hooks and autorun files, without using any sort of gamemode.

My Intention is to make an entity that when it spawns the owner will resist damage on specific hitboxes,

Much Appreciated.

E.g. On Entity Initial spawn (function ENT:Initialize()) I want a autorun command to run and set that players Hitbox so he will take no damage on a certain hitbox, Then when you undo the entity it stops the autorun command and the player returns so that all his hitboxes are normal.

[editline]10:46PM[/editline]

Just a update of what I am trying to achieve, here is a picture of a model and the entity I have made so far

http://img705.imageshack.us/img705/2439/bodyarmour.jpg http://img705.imageshack.us/img705/bodyarmour.jpg/1/w610.png

Just all I need is a way for it to ignore hitbox damage on my character if you know a easier way to do it, other than editing a gamemode it would be greatly appreciated.

Wow, This looks pretty good.

Could be used for a number of gamemodes. RP or Fretta etc. Keep it up!

Thanks :stuck_out_tongue: Thought it was something different, but lets hope I get some replys, in order to release it.

Example code :slight_smile:
[lua]function entityLookingGood( ply, hitgroup, dmg )
– Is he a player, and is he protected by entity?
if(hitgroup == HIT_GROUP_STOMACH and ent:GetNetworkedBool(“protected”) then
dmg:SetDamage(0) – Well set damage to zero then :open_mouth:
end
end
hook.Add(“ScalePlayerDamage”, “lolzHookz”, entityLookingGood)
[/lua]

Oh cheers Aualin :smiley: problem is I need it for hitboxes but its still cool :stuck_out_tongue: Ive just done a autorun file:

[lua] if (SERVER) then //server

local function DoDamage(ply, hitgroup, dmginfo)
	if (ply:GetArmour()) then
 	if ( hitgroup == HITGROUP_CHEST ) then

	dmginfo:ScaleDamage( 0 )

 end


	end
end
hook.Add("ScalePlayerDamage", "DoDamage", DoDamage);

else //client

end [/lua]

Would this work? if so how would I make the entity run this autorun file?

By including it of course, and also when doing ifs it’s nicer looking if you do it like this
[lua]
if ( ply:GetArmour() and hitgroup == HITGROUP_CHEST )
[/lua]
Entities can also hook things…
(You can actually have this code in the entity file)

Oh I see, Ive been going about this the completely wrong way D:, Ill give it a test now and ill post results.

Much appreciated Aualin :smiley:

No problems :slight_smile:
On a side note you are the first to spell my name right on the first try!

lol I feel honored :stuck_out_tongue: I had a try with it, I didnt include the autorun file, so It came up with errors, is there a much neater way to do it without the autorun?

That’s the whole point of having all the code inside the the init.lua entity file.
(Not in a separate file :smile: )

lol This is my ENT:Think()

[lua]
function ENT:Think( )
if ( self.Entity:GetOwner():GetArmour() and hitgroup == HITGROUP_CHEST ) then
dmg:SetDamage(0)
end
end
[/lua]

Have I placed this in the right place? Also to scrap the autorun code, how would I define it so that it knows it needs to look for the Owners hitgroup?

[lua]
function entityLookingGood( ply, hitgroup, dmg )
– Is he a player, and is he protected by entity?
if(hitgroup == HIT_GROUP_STOMACH and ent:GetNetworkedBool(“protected”) then
dmg:SetDamage(0) – Well set damage to zero then :open_mouth:
end
end
hook.Add(“ScalePlayerDamage”, “lolzHookz”, entityLookingGood)
[/lua]
Put the whole shit in the file!
When he equips the armor set a networked variable to true, and opposite when taken off.
The function entityLookingGood gets called every time the player gets damaged by something, then you check if he has the entity equipped, if he has remove the damage!

Thanks Aualin, much appreciated!

Hmmm I am still taking damage, yet I made it do a msg in console to what damage is being taken, here is the script has anyone got any ideas why I am still taking damage?

[lua]
AddCSLuaFile(“cl_init.lua”)
AddCSLuaFile(“shared.lua”)

include(‘shared.lua’)

function ENT:SpawnFunction( pl , tr )

local headcrabs , m = ents.FindByClass( "ba_chest", "conehat" );
for _ , m in pairs( headcrabs ) do
	if ( m && m:IsValid( ) && m:GetOwner( ) == pl ) then
		return;
	end
end

    pl:SetNWBool(	"protected",			true)


local eyes = pl:LookupAttachment( 'chest' );

if ( eyes == 0 ) then return; end


local bdemo = ents.Create( 'ba_chest' );


bdemo:SetOwner( pl );
bdemo:SetParent( pl );
bdemo:SetModel("models/vest.mdl")


bdemo:Spawn( );
bdemo:Activate( );


bdemo:SetMoveType( MOVETYPE_NONE )
bdemo:SetSolid( SOLID_NONE )
bdemo:SetCollisionGroup( COLLISION_GROUP_NONE )
bdemo:DrawShadow( false )



return bdemo;

end

function ENT.Initialize()
end

function ENT:OnRemove( )
self.Entity:GetOwner():SetNWBool( “protected”, false)
end

function ENT:Think( )
if self.Entity:GetOwner():GetViewEntity():GetClass() == “gmod_cameraprop” then
self.Entity:GetOwner():SetNWBool( “Camera”, true)
else
self.Entity:GetOwner():SetNWBool( “Camera”, false)
end
end

function entityLookingGood( ply, hitgroup, dmginfo )
– Is he a player, and is he protected by entity?
if(hitgroup == HITGROUP_CHEST or hitgroup == HITGROUP_STOMACH ) then
if (ply:GetNetworkedBool(“protected”)) then
dmginfo:ScaleDamage( 0 )
Msg ("Player “…ply:Name()…” took “…dmginfo:GetDamage()…” damage from fast-flying small rocks
")
end
end
end
hook.Add(“ScalePlayerDamage”, “lolzHookz”, entityLookingGood)

[/lua]

And does it print something in console?

Don’t scale the damage. Use dmginfo:SetDamage(0).

Sorry for the late reply, yes it does do a msg in console saying I have taken no damage, also I have already tried dmginfo:SetDamage(0) still no luck :S

Also there is no error messages, and as it says in the script it prints this message :
“Player Jazora [FTRP] took 0 damage from fast-flying small rocks”

[editline]04:19PM[/editline]

Just a quick update, I did another test which I wanted to see if its actually scaling the damage so I made it pick up to see if NPC’s attack me that it will do no damage, Yet it still did damage, Any ideas guys where its going wrong?

[lua]
AddCSLuaFile(“cl_init.lua”)
AddCSLuaFile(“shared.lua”)

include(‘shared.lua’)

function ENT:SpawnFunction( pl , tr )

local headcrabs , m = ents.FindByClass( "ba_chest", "conehat" );
for _ , m in pairs( headcrabs ) do
	if ( m && m:IsValid( ) && m:GetOwner( ) == pl ) then
		return;
	end
end

    pl:SetNWBool(	"protected",			true)


local eyes = pl:LookupAttachment( 'chest' );

if ( eyes == 0 ) then return; end


local bdemo = ents.Create( 'ba_chest' );


bdemo:SetOwner( pl );
bdemo:SetParent( pl );
bdemo:SetModel("models/vest.mdl")


bdemo:Spawn( );
bdemo:Activate( );


bdemo:SetMoveType( MOVETYPE_NONE )
bdemo:SetSolid( SOLID_NONE )
bdemo:SetCollisionGroup( COLLISION_GROUP_NONE )
bdemo:DrawShadow( false )



return bdemo;

end

function ENT.Initialize()
end

function ENT:OnRemove( )
self.Entity:GetOwner():SetNWBool( “protected”, false)
end

function ENT:Think( )
if self.Entity:GetOwner():GetViewEntity():GetClass() == “gmod_cameraprop” then
self.Entity:GetOwner():SetNWBool( “Camera”, true)
else
self.Entity:GetOwner():SetNWBool( “Camera”, false)
end
end

function entityLookingGood( ply, hitgroup, dmginfo )
if dmginfo:GetAttacker():IsNPC() then
dmginfo:SetDamage (0)
end
end
hook.Add(“ScalePlayerDamage”, “lolzHookz”, entityLookingGood)

[/lua]

Bumpity Bump, Just so that people can see my thread and Ive been waiting for awhile :S Also a update it appears to not change the damage yet it does anything else any reason why?