How would I go about increasing the damage of whichever weapon the player is holding for a short duration?
Here's what I have so far:
In this case I'm checking if the weapon is valid, and if so, is the weapon a crowbar? Then I'm checking if the player has hit G, and from there I'm lost on what to do next
[code]
hook.Add("KeyPress", "ExtraDamage", function(ply, key)
if ply:GetActiveWeapon():IsValid() then
if ply:GetActiveWeapon():GetClass() == "weapon_crowbar" then
if ply:KeyDown(KEY_G) then
end
end
end
[/code]
Your can only override the damage from EntityTakeDamage hook.
[QUOTE=Robotboy655;52264656]Your can only override the damage from EntityTakeDamage hook.[/QUOTE]
Okay so if I were to just change the hook to "EntityTakeDamage" from "KeyPress" then what would I do?
[QUOTE=Thane;52264667]Okay so if I were to just change the hook to "EntityTakeDamage" from "KeyPress" then what would I do?[/QUOTE]
Here look on these wiki pages :
[url]http://wiki.garrysmod.com/page/GM/EntityTakeDamage[/url]
[url]http://wiki.garrysmod.com/page/Category:CTakeDamageInfo[/url]
there are some examples shown on how to use them.
CTakeDamageInfo is basically the class that will allow to you modify damageinfo
I tried that and I think I'm doing it wrong
[code]
hook.Add("EntityTakeDamage", "ExtraDamage", function(ply, target, dmginfo)
if ply:GetActiveWeapon():IsValid() then
if ply:GetActiveWeapon():GetClass() == "weapon_crowbar" then
if ply:KeyDown(KEY_H) then
if (target:IsNPC()) then
dmginfo:ScaleDamage( 3 )
print("Damge Scaled by 3")
end
end
end
end
end)
[/code]
[editline]23rd May 2017[/editline]
oh and btw it's not printing
[QUOTE=Thane;52264735]I tried that and I think I'm doing it wrong
[code]
hook.Add("EntityTakeDamage", "ExtraDamage", function(ply, target, dmginfo)
if ply:GetActiveWeapon():IsValid() then
if ply:GetActiveWeapon():GetClass() == "weapon_crowbar" then
if ply:KeyDown(KEY_H) then
if (target:IsNPC()) then
dmginfo:ScaleDamage( 3 )
print("Damge Scaled by 3")
end
end
end
end
end)
[/code][/QUOTE]
OK first of all, "ply" isn't defined in the "EntityTakeDamage" hook you can only know what Entity is being attacked and what dmginfo is given with this attack.
You will get a lua error saying that ply = nil or something like this.
In Order to know who the attacker is use dmginfo:GetAttacker() and set it to ply before using "ply" as a variable.
Second, ply:KeyDown(KEY_H) is wrong. Take a look at it's wiki page :[url]http://wiki.garrysmod.com/page/Player/KeyDown[/url]
you will see that it only accepts "IN_Enums" you can click on it to see what kind of input it wants.
KEY_H is therefore invalid.
Other than that it should be fine or i'm missing out something.
[editline]23rd May 2017[/editline]
[CODE]
hook.Add("EntityTakeDamage", "ExtraDamage", function( target, dmginfo)
local ply = dmginfo:GetAttacker()
if !IsValid(ply) then return end
if !ply:IsPlayer() then return end
if ply:GetActiveWeapon():GetClass() == "weapon_crowbar" then
--if ply:KeyDown(KEY_H) then
if (target:IsNPC()) then
dmginfo:ScaleDamage( 3 )
print("Damge Scaled by 3")
end
--end
end
end)
[/CODE]
-- Why checking if his weapon is valid ?
BTW its -> IsValid(arg)
The code should look something similar to this
[QUOTE=ZarusNat;52264754]OK first of all, "ply" isn't defined in the "EntityTakeDamage" hook you can only know what Entity is being attacked and what dmginfo is given with this attack.
You will get a lua error saying that ply = nil or something like this.
In Order to know who the attacker is use dmginfo:GetAttacker() and set it to ply before using "ply" as a variable.
Second, ply:KeyDown(KEY_H) is wrong. Take a look at it's wiki page :[url]http://wiki.garrysmod.com/page/Player/KeyDown[/url]
you will see that it only accepts "IN_Enums" you can click on it to see what kind of input it wants.
KEY_H is therefore invalid.
Other than that it should be fine or i'm missing out something.[/QUOTE]
lol I literally fixed all of these things just before I refreshed and saw your reply lmao. But from what I can tell it's not actually scaling the damage at all
[QUOTE=Thane;52264777]lol I literally fixed all of these things just before I refreshed and saw your reply lmao. But from what I can tell it's not actually scaling the damage at all[/QUOTE]
Is it just doing nothing or is there an error showing or such ? If it's doing nothing i suggest you using the
print("bla") function in order to "debug" your work. just put in a print("id") after each "if condition then".
Execute it once and by the output you get you will be able to see where it stops
No, no errors, but it's printing now but no actual damage scaling. It goes all the way through the block of code perfectly fine it just doesn't scale the damage
I can't help you out sorry since I never experienced this issue.
Could it be that the base damage output is so low that multiplying it by 3 doesnt matter ?
Try to go overkill with numbers to see if it affects at all.
or try to set the dmg with dmginf:SetDamage(int)
[editline]23rd May 2017[/editline]
Or maybe adding damage
Okay so I was testing it on the Father Grigori NPC and the damage wasn't scaling, but then I tried it on a normal npc and it scaled fine. But sometimes I get the error
[code]
[ERROR] addons/lokimod/lua/autorun/server/sv_lokimod.lua:94: attempt to call method 'GetActiveWeapon' (a nil value)
1. v - addons/lokimod/lua/autorun/server/sv_lokimod.lua:94
2. unknown - lua/includes/modules/hook.lua:84
[/code]
I know why It's happening but I can't seem to fix it. Here's the cleaner version of the code
[code]
hook.Add("EntityTakeDamage", "ExtraDamage", function(target, dmginfo)
if !IsValid(dmginfo:GetAttacker()) then return end
local ply = dmginfo:GetAttacker()
if !IsValid(ply) then return end
if !IsValid(ply:GetActiveWeapon()) then return end
if ply:GetActiveWeapon():GetClass() ~= "weapon_crowbar" then return end
if ply:KeyDown(IN_DUCK) then
if (target:IsNPC() or target:IsPlayer()) then
dmginfo:ScaleDamage( 3 )
print("Damge Scaled by 3")
print(dmginfo:GetDamage())
end
end
end)
[/code]
Your code is pretty messy, some if statements are called twice and it's very weirdly structured.
Try this (I grouped if statements based on their main subject to make the code easier to read):
[lua]hook.Add( "EntityTakeDamage", "ExtraDamage", function( target, dmginfo )
local ply = dmginfo:GetAttacker()
if IsValid( ply ) and ply:IsPlayer() and ply:KeyDown( IN_DUCK ) then
local wep = ply:GetActiveWeapon()
if wep and wep:GetClass() == "weapon_crowbar" then
if target:IsNPC() or target:IsPlayer() then
dmginfo:ScaleDamage( 3 )
print( "Damge Scaled by 3" )
print( dmginfo:GetDamage() )
end
end
end
end )[/lua]
By the way, which line is line 94 in your code that caused the error?
Idk I used your code and no more error.
Thanks
Sorry, you need to Log In to post a reply to this thread.