TTT-2 / TTT2

Trouble in Terrorist Town 2 for Garry's Mod (gmod)
https://steamcommunity.com/sharedfiles/filedetails/?id=1357204556
179 stars 77 forks source link

Featurerequest: Prevent Friendly Fire #1185

Closed TimGoll closed 11 months ago

TimGoll commented 11 months ago

[Taken from SMORE]

Don't allow roles to hurt other people with the exact same role as themselves. For example, to prevent Infected zombies from killing their companions or masters.

Would be a nice setting that should be disabled by default. My suggestion would be a global convar, not one per role, but I need feedback from the community / the dev team on this one

Histalek commented 11 months ago

i'm not sure if this is generally useful as it can't be applied to the three base roles ever.

Infected zombies are definitely an outlier for this usecase.

I don't think this should be done in the gamemode. Roles should take of this themselves if it would useful for them.

TimGoll commented 11 months ago

i'm not sure if this is generally useful as it can't be applied to the three base roles ever.

Infected zombies are definitely an outlier for this usecase.

I don't think this should be done in the gamemode. Roles should take of this themselves if it would useful for them.

fair point, I have to gree with you here. I'll close this. If someone has a valid argument to keep it, then we can reopen it

sbzlzh commented 11 months ago

Kind of the same type of thing you're talking about, the explosion when that Hanf Role dies doesn't damage nearby teammates.

    local entities = ents.FindInSphere(pos, R_OUTER)

    for k, ent in ipairs(entities) do
        -- If the entity is a player and not on the same team as the player who triggered the explosion
        if IsValid(ent) and ent:IsPlayer() and ent:GetTeam() ~= ply:GetTeam() then
            -- Calculate distance and damage
            local distance = pos:Distance(ent:GetPos())
            local damage = DMG_EXPLOSION * (1 - (distance / R_OUTER))
            -- Deal damage to the player
            local dmginfo = DamageInfo()

            dmginfo:SetDamage(damage)
            dmginfo:SetAttacker(ply)
            dmginfo:SetInflictor(ply)
            dmginfo:SetDamageType(DMG_BLAST)
            ent:TakeDamageInfo(dmginfo)
        end
    end

The code is located at:

https://github.com/sbzlzh/ttt2-role_hanfei/blob/1bd7f6e4c5a0744ee940715dbd68ad892a1a1b90/lua/terrortown/entities/roles/hanfei/shared.lua#L66