DarkRP Entity Take Damage help

Hi, I’ve been trying to get a GM:EntityTakeDamage function to work in darkrp but no matter what I try I can’t get it to work and I keep getting lua errors. This is what I have so far.


	PlayerLoadout = function(ply) 
	  function GM:EntityTakeDamage( target, dmginfo )

		if ( target:IsPlayer() and dmginfo:IsBulletDamage() ) then

			dmginfo:ScaleDamage( 0.5 ) // Damage is now half of what you would normally take.

		end
		

	end,

this is my whole job code


TEAM_TORRENTTROOPERHEAVY = DarkRP.createJob("501st Torrent Trooper Heavy", {
    color = Color(0, 0, 255, 255),
    model = {
        "models/player/501p2c/cgi 501.mdl"
        },
    description = [[None yet]],
    weapons = {"weapon_752_dlt19", "weapon_lasermgun"},
    command = "501st_torrentheavy",
    max = 30, -- at most 70% of the players can have this job. Set to a whole number to set an absolute limit.
    salary = 100,
    admin = 0,
    vote = false,
    hasLicense = false,
    category = "501st Legion",
    sortOrder = 11,
    PlayerSpawn = function(ply) GAMEMODE:SetPlayerSpeed(ply, GAMEMODE.Config.walkspeed * 0.75, GAMEMODE.Config.runspeed * 0.75) ply:SetHealth("450") ply:SetMaxHealth("450") ply:SetArmor("250") ply:SetGravity(1) return CLIENT end,
    PlayerDeath = function(ply) GAMEMODE:SetPlayerSpeed(ply, GAMEMODE.Config.walkspeed * 1, GAMEMODE.Config.runspeed * 1) return CLIENT end,
	PlayerLoadout = function(ply) 
	  function GM:EntityTakeDamage( target, dmginfo )

		if ( target:IsPlayer() and dmginfo:IsBulletDamage() ) then

			dmginfo:ScaleDamage( 0.5 ) // Damage is now half of what you would normally take.

		end
		

	end,
})

Can anyone help me get this function working properly? The goal is to get this job to the 20% less damage than any other job. Thanks!

Without lua errors, it’s hard to fix them in the first place, also I fail to understand what does “get x to the 20% less damage than any other job”, you mean inflicted damage or received damage?

  1. I prefer hooks on GM functions. I think mostly you should use those.
  2. Putting a function inside another function usually won’t do much on it’s own.
  3. The function you made will scale the damage by 50% and to any team, given the target (the entity that got damaged[shot by a bullet to be specific]) is a player.

I assume you’ve just started ‘lua’ ie. you just recently found out how to edit the jobs list of DarkRP. Check out some tutorials and reverse-engineer some scripts out there to gain some experience. Or, you can pay 1-5$ for every single 10 line script to a developer.

Get away from DarkRP files as far as you can, and have the player’s team checked inside EntityTakeDamage.

I dont think the job files get run multiple times though so as kiro said its best to hook it here i fixed it and commented it for you and next time post the lua error i know it looks like just some mumbo jumbo but giving it closer inspection will help.
[lua]
hook.Add( “EntityTakeDamage”, “DamageModifierSoldier”, function(target, dmg) //run anytime dmg happens
if target:Team() == “TEAM_TORRENTTROOPERHEAVY” and target:IsPlayer() and dmg:IsBulletDamage() then // not sure if correct but it checks if their team is your wanted team and some checks
dmg:ScaleDamage(0.5) // scale damage by %50
end
end )
[/lua]
put this in addons/InsertCustomName/lua/autorun/InsertCustomName.lua
i hope i could help im unsure of the 2nd line as i dont know the correct way to get a darkrp team

Everything seems to work the only difference is I put it in my
addons/darkrpmodification-master/lua/darkrp_modules/damagev3/damage.lua
Also I edited the code just a tiny bit :stuck_out_tongue:
[lua]
hook.Add( “EntityTakeDamage”, “DamageModifierSoldier”, function(target, dmg) – is ran anytime damage is taken
if target:Team() == TEAM_TORRENTTROOPERHEAVY and target:IsPlayer() then – the first team must be an if
dmg:ScaleDamage(0.1) – negates 90% of damage (for testing)
elseif target:Team() == TEAM_GENERALSKYWALKER and target:IsPlayer() then – any other additional team must be a elseif
dmg:ScaleDamage(0.1) – negates 90% of damage (for testing)
end
end )
[/lua]