• Damage system
    3 replies, posted
I am trying to create my own damage system by disabling the current one with the hook playershouldtakedamage, but it doesn't want to work... [code]function PlayerShouldTakeDamage( victim, pl ) if pl:IsPlayer() == 1 then -- check the attacker is player Victim = FindPlayer(victim:Name()) Attacker = FindPlayer(attacker:Name()) print("Success") Hit() return false -- do not damage the player end print("Fail") return true -- damage the player end hook.Add( "PlayerShouldTakeDamage", "PlayerShouldTakeDamage", playershouldtakedamage) function Hit(attacker, victim) local Att = Attacker local Vic = Victim DMG = Att:GetNWInt("Damage") + Att:GetNWInt("Damage+") ArmorDmg = Vic:GetNWInt("Armor") - Att:GetNWInt("ArmorDmg") if ArmorDmg <= 0 then Vic:SetNWInt("Armor", 0) print("Armor Blocked Damage") else ArmorLeft = Vic:GetNWInt("Armor") - ArmorDmg Vic:SetNWInt("Armor", ArmorLeft) end DamageDealt = DMG - Vic:GetNWInt("Armor") if DamageDealt <= 0 then DamageDealt = 0 ArmorLeft2 = Vic:GetNWInt("Armor") - DMG Vic:SetNWInt("Armor", ArmorLeft2) else Vic:SetNWInt("Armor", 0) print("Taking Damage") HP = ply:Health() - DamageDealt ply:SetHealth(HP) end end[/code] I set the 4 variables on the initial spawn (just for testing) dmg is 1 and armor is 5 the other 2 are 0. What it does is: Doesn't print anything Damages player (it should hit him 5 times then bring his hp down by 1 each time) Error codes: None I might be taking a noob approach to this, but it was the only way that seemed logical to me. The Networked integers will be set somehow by the weapon the person has and the armor will be set by the armor the person has... Thanks, FpsGlock
Lua is case sensitive, you have function PlayerShouldTakeDamage (victim, pl) and in your hook.Add you have it playershouldtakedamage they need to match
nope I changed it and still doesn't do anything, like it's not even there. (it is in init.lua)
You need to pass the variables into the hit function. Call it like Hit(ent1,ent2). Also IsPlayer() returns a boolean no need for the == 1 part.
Sorry, you need to Log In to post a reply to this thread.