• DIsable CP team damage, but keep self inflicted damage.
    6 replies, posted
Hey guys. I made a little script using "ply:isCP()" to stop team damage between Cops on DarkRP, but because of the way I have it set up how could I disable team damage, but keep self inflicted damage like fall damage, missed grenades, rockets etc. Here is my code: [CODE] function GM:PlayerShouldTakeDamage(ply,victim) if ply:isCP() then if ply:isCP() and victim:isCP() then return false end end return true end [/CODE] Any help is appreciated. Thanks guys.
[QUOTE=YakS;48124848]Hey guys. I made a little script using "ply:isCP()" to stop team damage between Cops on DarkRP, but because of the way I have it set up how could I disable team damage, but keep self inflicted damage like fall damage, missed grenades, rockets etc. Here is my code: [CODE] function GM:PlayerShouldTakeDamage(ply,victim) if ply:isCP() then if ply:isCP() and victim:isCP() then return false end end return true end [/CODE] Any help is appreciated. Thanks guys.[/QUOTE] A tip, you should be using hooks for your GM functions....not sure if I set it up properly but give it a try. As for your question I have no idea as I am a lua noob but I wanted to give you advice :D [CODE]hook.Add( "PlayerShouldTakeDamage", "Team Damage Kek", function(ply,victim) if ply:isCP() then if ply:isCP() and victim:isCP() then return false end end return true end[/CODE] EDIT: Sorry forgot to say you could do it this way too: [CODE]function InsertCustomFuncNameHere(ply,victim) if ply:isCP() then if ply:isCP() and victim:isCP() then return false end end return true end hook.Add( "PlayerShouldTakeDamage", "Dat Damage tho", InsertCustomFuncNameHere )[/CODE]
change "if ply:isCP() and victim:isCP() then" to "if ply:isCP() and victim:isCP() and ply != victim then"
Don't return true, because it may conflict with other 'PlayerShouldTakeDamage' hooks. [CODE]hook.Add("PlayerShouldTakeDamage", "Civil Protection", function(victim, attacker) if victim:isCP() and attacker:isCP() and victim != attacker then return false end end)[/CODE]
[QUOTE=krekeris;48125365]Don't return true, because it may conflict with other 'PlayerShouldTakeDamage' hooks. [CODE]hook.Add("PlayerShouldTakeDamage", "Civil Protection", function(victim, attacker) if victim:isCP() and attacker:isCP() and victim != attacker then return false end end)[/CODE][/QUOTE] Could you explain why it would conflict if it returned true ? I am actually genuinely interested for future reference :P
[QUOTE=BeZerk;48125414]Could you explain why it would conflict if it returned true ? I am actually genuinely interested for future reference :P[/QUOTE] The hook library loops through all of the event's hooks and checks to see if they return anything before it moves on to the next one. If the hook returns something, it stops the loop. Since the hook you posted always returns something, no hook that is scheduled to run after your hook is ran. It's fine if you're doing it in a gamemode, but with an addon using hook.Add, you don't need to define such default behaviors, since the gamemode takes care of that. I might have explained that poorly. If I did, maybe someone else can elaborate or you can figure it out by looking at the source code. [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/includes/modules/hook.lua#L67[/url]
[QUOTE=man with hat;48125575]The hook library loops through all of the event's hooks and checks to see if they return anything before it moves on to the next one. If the hook returns something, it stops the loop. Since the hook you posted always returns something, no hook that is scheduled to run after your hook is ran. It's fine if you're doing it in a gamemode, but with an addon using hook.Add, you don't need to define such default behaviors, since the gamemode takes care of that. I might have explained that poorly. If I did, maybe someone else can elaborate or you can figure it out by looking at the source code. [url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/includes/modules/hook.lua#L67[/url][/QUOTE] Ahh what I'm seeing is, A-Ok for gamemodes, Nah for addons...not needed :)
Sorry, you need to Log In to post a reply to this thread.