how is this coded?

t

GM/EntityTakeDamage
Basicly check if the dmginfo:GetAttacker():GetActiveWeapon():GetClass() == SWEP and if attacker got the perk. If you hook the metatable for it, its up to you.
Then just scale the dmginfo with

CTakeDamageInfo:ScaleDamage to the point you wanna.

thanks :slight_smile: i got it :o , but umm

how do i make it check if ply uses swep <namehere?> then

local Player = LocalPlayer();
local Weapon = Player:GetActiveWeapon();
if( Weapon:IsValid() && Weapon:GetClass() == “weapon_bianchi” ) then
CTakeDamageInfo:ScaleDamage(2.5)
end
is this right q.q

[editline]17th March 2015[/editline]

help :confused:

no. The correct way would be: dmginfo:GetAttacker():GetActiveWeapon():GetClass()
[lua]function GM:EntityTakeDamage( target, dmginfo )[/lua]
take the dmginfo, which is an local variable which contains the CTakeDamageInfo.
from there we can reference the Player who attacked with

CTakeDamageInfo:GetAttacker.
From the Player (dmginfo:GetAttacker()) we can use

Player:GetActiveWeaponto get the Weapon.
From the Weapon (dmginfo:GetAttacker():GetActiveWeapon()) we finally can use

Entity:GetClass to get the SWEP Class as an String to compare it.

also you should read http://wiki.garrysmod.com/page/Hook_Library_Usage to ultilize the

GM/EntityTakeDamage from ealier correctly.

thanks :slight_smile: i kinda understood what you say but for being 100% sure can you check if i did it righT?

LocalPlayer does not exist on the server, so no.

Use dmginfo:GetAttacker, make sure it’s a player, then do your checks. http://wiki.garrysmod.com/page/Category:CTakeDamageInfo

[ERROR] addons/darkrpmodification-master/lua/weapons/weapon_bianchi/shared.lua:572: attempt to index global ‘GM’ (a nil value)

  1. unknown - addons/darkrpmodification-master/lua/weapons/weapon_bianchi/shared.lua:572

[editline]17th March 2015[/editline]

how do i do it right please :confused:

[editline]17th March 2015[/editline]

how do i do it right please tell me :frowning: im bad at lua atm just trying to learn would be awesome if u could help

i tried reading it …i dont understand anything :confused: , could you just fix the code for me please …

Do not use GM:Func outside of the gamemode to do hooking, use hook.Add instead. LocalPlayer is nil on server, so instead use dmginfo:GetAttacker() to set the Player variable. Not going to code it for you, but here’s an example:

[lua]

local function HookEntityTakeDamage( victim, dmg )
if( IsValid( dmg:GetAttacker() ) && dmg:GetAttacker():IsPlayer() ) then
//Do code
end
end

hook.Add( “EntityTakeDamage”, “hook_name”, HookEntityTakeDamage );
[/lua]


local function HookEntityTakeDamage( victim, dmg )
	if( IsValid( dmg:GetAttacker() ) && dmg:GetAttacker():IsPlayer() ) then
		dmg:ScaleDamage( 5.0 ) 

		
	end
end

hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );
 

this :)?

While that should work, it’s just going to scale the damage anytime a player shoots another player, regardless of which weapon is used. Set a variable to dmg:GetAttacker() after the if statement, this will be the player who is shooting, then do your checks for the weapon.

ermm… i put that inside the shared.lua of my SWEP

will that still make all guns do it? , and if im not supposed to place it inside my swep do i put it in autorun :D? , also

if i want to add dmg:SetDamageType(DMG_SHOCK) do i just add it after dmg:ScaleDamage(5.0) or i have to make something else for it? thanks <3

[editline]17th March 2015[/editline]

nvm i figured it out <3 (the DMG_Type part:) , but umm what about the weapon specification… i didnt kinda understand it :confused: could you give me example

[editline]17th March 2015[/editline]

also another question : How to make it so if you shoot someone you slow their movement speed for ex. 80% for 5seconds…?

Tbh try to learn the basics first. i linked the hook usage tutorial 2 times and mentioned it, and you still refuse imo to read it properly.

i am reading it… but i still dont understand how i make it weapon specific q.q

man i know that. but im not sure where to put it in my code


local function HookEntityTakeDamage( victim, dmg )
	if( IsValid( dmg:GetAttacker() ) && dmg:GetAttacker():IsPlayer() ) then
		dmg:ScaleDamage( 5.0 ) 

		
	end
end

hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );

This should work for you. If not, then i don’t know:



local function HookEntityTakeDamage( victim, dmg )
	if( IsValid( dmg:GetAttacker() ) && dmg:GetAttacker():IsPlayer() && dmg:GetAttacker():GetActiveWeapon():GetClass() == "INSERT WEAPON NAME HERE") then
		dmg:ScaleDamage( 5.0 ) 

		
	end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );