Pivity

Creating a Damage Ban Command | NEED HELP

Last read Never
#1

Hi! I am trying to make a SAM admin mod command that will stop a player from doing any damage to others when they are "damaged banned", this is the code that I have so far. The command itself works, but I am stuck on how to actually stop the player from doing damage, I believe I got the hook correct but it does not work. Any support would go a long way, Thanks!


command.new("dmgban")
:SetPermission("dmgban", "head-developer")


:AddArg("player", {optional = false, single_target = true, cant_target_self = false, allow_higher_target = true})
:AddArg("length", {optional = false})


:GetRestArgs()


:Help("NOT DONE YET - TCSMASKED WILL DO IT SOON")


:OnExecute(function(ply, targets, length, reason)
    for i = 1, #targets do
        local target = targets[i]
        target.sam_dmgbanned = true
        if length ~= 0 then
            timer.Create("SAM.UnDmgBan" .. target:SteamID64(), length * 60, 1, function()
                RunConsoleCommand("sam", "undmgban", "#" .. target:EntIndex())
            end)
        end
    end


    sam.player.send_message(nil, "{A} dmgbanned {T} for {V}.", {
        A = ply, T = targets, V = sam.format_length(length), V_2 = reason
    })
end)
:End()


command.new("undmgban")
:SetPermission("undmgban", "head-developer")
:AddArg("player", {optional = false, single_target = true, cant_target_self = false, allow_higher_target = true})
:Help("NOT DONE YET - TCSMASKED WILL DO IT SOON")
:OnExecute(function(ply, targets)
    for i = 1, #targets do
        local target = targets[i]
        target.sam_dmgbanned = nil
        timer.Remove("SAM.UnDmgBan" .. target:SteamID64())
    end


    sam.player.send_message(nil, "{A} undmgbanned {T}.", {
        A = ply, T = targets
    })
end)
:End()


if SERVER then

--- THIS IS THE PART THAT I BELIEVE NEEDS FIXING TO ACTUALLY WORK ---
hook.Add("PlayerShouldTakeDamage", "SAM.Chat.Dmgban", function( ply, attacker )
    if attacker == ply:sam_dmgbanned then
        return false
    end
end)
--- THIS IS THE PART THAT I BELIEVE NEEDS FIXING TO ACTUALLY WORK ---


hook.Add("PlayerInitialSpawn", "SAM.Dmgban", function(ply)
    local dmgban_time = ply:sam_get_pdata("dmgbanned")
    if dmgban_time then
        ply:sam_set_pdata("dmgbanned", nil)
        RunConsoleCommand("sam", "dmgban", "#" .. ply:EntIndex(), dmgban_time / 60, "LTAP")
    end
end)


hook.Add("PlayerDisconnected", "SAM.Dmgban", function(ply)
    if ply.sam_dmgbanned then
        ply:sam_set_pdata("dmgbanned", timer.TimeLeft("SAM.UnDmgBan" .. ply:SteamID64()) or 0)
    end
end)
end
#2

you should be getting an error.

but you should also refactor your approach to this, seems like a very flawed nonsensical approach.

if i were you i'd go for something like:

sam_damage_bans = sam_damage_bans or {}

-- add damage ban

sam_damage_bans[player_steamid] = CurTime() + duration

-- playershoudltakedamage

if sam_damage_bans[player_steamid] and sam_damage_bans[player_steamid] > CurTime() then

return false

end

just a little something for you to think about ig, makes it far easier to work with

#3

Hi! Thanks for replying. I see what your trying to do but how would the undmgban command work, and secondly how would Iadd a player to the list in the dmgban command. Thanks.

#4
hook.Add("PlayerShouldTakeDamage", "SAM.Chat.Dmgban", function( ply, attacker )

    if attacker == ply.sam_dmgbanned then

        return false

    end

end)
Users viewing this thread
Nobody