Prop break alert help



  • I need some help with a alert system I have, basically I want it to print to console when someone breaks a prop. It works so far but if a player breaks a generic map prop such as a vent or boards covering a hole it reports it and another issue if you break a prop with a shotgun it spams the report for every bullet that hit the prop when it was broken.

    Here is my current code

    hook.Add( "PropBroken", "PropBroken.Alert", function(ent, attacker)
    	local bCooldown
    
    	if attacker:IsValid() and attacker:IsPlayer() then
    		if attacker:Team() == TEAM_HUMAN and not bCooldown then
    			bCooldown = true
    			PrintTranslatedMessage(HUD_PRINTCONSOLE, " "..attacker:Name().." broke prop "..ent:GetModel().." ")
    			timer.Simple(0.1, function() bCooldown = false end)
    		end
    	end 
    end )
    

    I tried to remedy this issue with a timer but it failed



  • I need some help with a alert system I have, basically I want it to print to console when someone breaks a prop. It works so far but if a player breaks a generic map prop such as a vent or boards covering a hole it reports it and another issue if you break a prop with a shotgun it spams the report for every bullet that hit the prop when it was broken.

    Here is my current code

    hook.Add( "PropBroken", "PropBroken.Alert", function(ent, attacker)
    	local bCooldown
    
    	if attacker:IsValid() and attacker:IsPlayer() then
    		if attacker:Team() == TEAM_HUMAN and not bCooldown then
    			bCooldown = true
    			PrintTranslatedMessage(HUD_PRINTCONSOLE, " "..attacker:Name().." broke prop "..ent:GetModel().." ")
    			timer.Simple(0.1, function() bCooldown = false end)
    		end
    	end 
    end )
    

    I tried to remedy this issue with a timer but it failed


  • Game Admins

    This occurs because GM:PropBroken is called in GM:EntityTakeDamage, which is called multiple times if each bullet has enough damage to reduce the prop health to less than 0 as in your shotgun case. GM:PropBroken is used as a replacement of GM:PropBreak so that it includes all entities that take damage.

    The simplest solution is to add a latch variable to the entity, i.e.

    if not ent.HasAlerted then  
       ent.HasAlerted = true
       {code}
    end
    ```   
    
    I'll probably stop propbroken bring called more than once when I have the time.
    
    You should filter the entity's classname for prop_* since you're triggering off entities like func_breakable (your vent/boards).
    
    

    if string.sub(ent:GetClass(), 1, 5) == “prop_” then



  • Interesting, thanks for the help. Also I was considering doing a table of ignored prop models and thing check if the props model was the same but checking the class is better


Log in to reply
 

10
Online

10975
Users

15257
Topics

297326
Posts

Looks like your connection to NoXiousNet was lost, please wait while we try to reconnect.