hook.Add("Think","Check_Player_Health",function()
for k, v in pairs(player.GetAll()) do
if v:TakeDamage( 15, NPC, NPC:ActiveWeapon() )
then v:AddHealth (16 )
end
end
end)
I just want to make a lifesteal script so you shoot a npc and you get health back. Could i please have some help with whats wrong and right and how to fix my error. Its a shared file.
You should use a GM/EntityTakeDamage hook and check if the target is an NPC and if CTakeDamageInfo/GetAttacker is a player then give the attacker health.
function EntityTakeDamage( target, dmginfo )
if (target:IsNPC() )
then
local ply = CTakeDamageInfo:GetAttacker()
if ( target:GetDamage() * 0.05 )
then ply:SetHealth(Player:Health() + CTakeDamageInfo/GetDamage() * 0.05 )
end
end
end
Im not sure what I got wrong but it doesnt make script errors and if I kill npcs it doesnt give me health.
That’s because all you did was make a function, you didn’t hook it to anything
[ERROR] lua/autorun/mynamejeff.lua:2: attempt to call global 'EntityTakeDamage' (a nil value)
1. v - lua/autorun/mynamejeff.lua:2
2. unknown - lua/includes/modules/hook.lua:84
hook.Add("Think","epic",
function() if EntityTakeDamage ( target, dmginfo ) then
if target:IsNPC()
then
local ply = CTakeDamageInfo:GetAttacker()
if target:GetDamage( 10 )
then ply:SetHealth(Player:Health() + CTakeDamageInfo/GetDamage() * 0.05 )
end
end
end
end)
Can i get some more help please.
GM/EntityTakeDamage is a hook, not a function.
hook.Add( "EntityTakeDamage", "epic", function( ent, inflictor, attacker, amount, dmginfo )
if ent:IsNPC() and ent:GetDamage()
then CTakeDamageInfo:GetAttacker():IsPlayer()
Player:SetHealth(Player:Health() + 1)
if CTakeDamageInfo:GetDamage() * 0.05 then
end
end
end)
[ERROR] lua/autorun/gay.lua:2: attempt to call method 'GetDamage' (a nil value)
1. v - lua/autorun/gay.lua:2
2. unknown - lua/includes/modules/hook.lua:84
Been playing around with it for a while no luck. More more help please.
you really need to learn lua first
i'd pay people to do it for me but for this I couldnt find anyone so im doing it myself
It's kinda rude to post somebody else's code and not give them credits. @Badger
Credit: My Highschool Teacher from Information Processing Technology
Sorry, you need to Log In to post a reply to this thread.