PuppyKun icon

Untitled

PuppyKun | PRO | 02/13/20 09:14:44 PM UTC | 0 ⭐ | 262 👁️ | Never ⏰ | []
Lua |

7.12 KB

|

None

|

0 👍

/

0 👎

local PLUGIN = PLUGIN
 
PLUGIN.name = "Nibbly's Loyalist Cards"
PLUGIN.author = "Nibbly"
PLUGIN.license = "All rights reserved."
PLUGIN.description = "Adds tiered loyalists cards for Anti-Citizen RP."
 
ix.util.Include("sh_uac_cards.lua")
ix.util.Include("sh_loyalist_cards.lua")
 
-- View Merit
do
    local COMMAND = {}
 
    COMMAND.description = "View someone's current Merit."
    COMMAND.arguments = bit.bor(ix.type.character, ix.type.optional)
    COMMAND.argumentNames = "target character"
 
    function COMMAND:OnRun(client, target)
        local clientChar = client:GetCharacter()
        local clientCharInventory = clientChar:GetInventory()
        local items = clientCharInventory:GetItems()
        local allowed = false
        local targetMerit = 0
        for _, v in pairs(items) do
            if (string.match(v.uniqueID, "Department_of_S.C.") or v.uniqueID == "City_Administrator_ID" or v.uniqueID == "UAC_Representative_ID") then
                allowed = true
                break
            end
        end
        if (target) then
            if (target:GetOwner():IsCombine()) then
                return "Combine do not have Merit."
            end
            if ((target == clientChar) or allowed) then
                targetMerit = target:GetData("merit", 0)
                return string.format("%s has %s Merit.", target:GetName(), targetMerit)
            else
                return "You are not allowed to view other's merit."
            end
        end
 
        local data = {}
            data.start = client:GetShootPos()
            data.endpos = data.start + client:GetAimVector() * 96
            data.filter = client
 
        local aimTarget = util.TraceLine(data).Entity
 
        if (IsValid(aimTarget) and aimTarget:IsPlayer() and allowed) then
            if (aimTarget:IsCombine() == false) then
                return "Combine do not have Merit."
            end
            local char = aimTarget:GetCharacter()
            local charName = char:GetName()
            targetMerit = char:GetData("merit", 0)
            return string.format("%s has %s Merit.", charName, targetMerit)
        end
        
        targetMerit = clientChar:GetData("merit", 0)
        return string.format("%s has %s Merit.", clientChar:GetName(), targetMerit)
    end
 
    function COMMAND:OnCheckAccess(client)
        return true
    end
 
    ix.command.Add("ViewMerit", COMMAND)
end
 
-- Add Merit
do
    local COMMAND = {}
 
    COMMAND.description = "Add Merit to someone."
    COMMAND.arguments = {
        bit.bor(ix.type.character, ix.type.optional),
        ix.type.number,
    }
    COMMAND.argumentNames = {
        "target character",
        "amount"
    }
 
    function COMMAND:OnRun(client, target, amount)
        local clientChar = client:GetCharacter()
        local clientCharInventory = clientChar:GetInventory()
        local items = clientCharInventory:GetItems()
        local allowed = client:IsCombine()
        local oldMerit = 0
        for _, v in pairs(items) do
            if (string.match(v.uniqueID, "Department_of_S.C." or v.uniqueID == "City_Administrator_ID" or v.uniqueID == "UAC_Representative_ID") then
                allowed = true
                break
            end
        end
        if (allowed == false) then
            return "You are not allowed to add Merit."
        end
        if (target) then
            if (target:GetOwner():IsCombine()) then
                return "Combine do not have Merit."
            end
            oldMerit = target:GetData("merit", 0)
            newMerit = oldMerit + amount
            target:SetData("merit", newMerit)
            return string.format("Added %s Merit to %s. They now have %s Merit", amount, target:GetName(), newMerit)
        end
 
        local data = {}
            data.start = client:GetShootPos()
            data.endpos = data.start + client:GetAimVector() * 96
            data.filter = client
 
        local aimTarget = util.TraceLine(data).Entity
 
        if (IsValid(aimTarget) and aimTarget:IsPlayer()) then
            if (aimTarget:IsCombine() == false) then
                return "Combine do not have Merit."
            end
            local char = aimTarget:GetCharacter()
            local charName = char:GetName()
            oldMerit = char:GetData("merit", 0)
            newMerit = oldMerit + amount
            target:SetData("merit", newMerit)
            return string.format("Added %s Merit to %s. They now have %s Merit", amount, charName, newMerit)
        end
 
        return "No name specified and you are not looking at a valid target!"
    end
 
    function COMMAND:OnCheckAccess(client)
        return true
    end
 
    ix.command.Add("AddMerit", COMMAND)
end
 
-- Deduct Merit
do
    local COMMAND = {}
 
    COMMAND.description = "Deduct Merit from someone."
    COMMAND.arguments = {
        bit.bor(ix.type.character, ix.type.optional),
        ix.type.number,
    }
    COMMAND.argumentNames = {
        "target character",
        "amount"
    }
 
    function COMMAND:OnRun(client, target, amount)
        local clientChar = client:GetCharacter()
        local clientCharInventory = clientChar:GetInventory()
        local items = clientCharInventory:GetItems()
        local allowed = client:IsCombine()
        local oldMerit = 0
        for _, v in pairs(items) do
            if (string.match(v.uniqueID, "Department_of_S.C." or v.uniqueID == "City_Administrator_ID" or v.uniqueID == "UAC_Representative_ID") then
                allowed = true
                break
            end
        end
        if (allowed == false) then
            return "You are not allowed to deduct Merit."
        end
        if (target) then
            if (target:GetOwner():IsCombine()) then
                return "Combine do not have Merit."
            end
            oldMerit = target:GetData("merit", 0)
            newMerit = math.max(oldMerit - amount, 0)
            target:SetData("merit", newMerit)
            return string.format("Deducted %s Merit from %s. They now have %s Merit", amount, target:GetName(), newMerit)
        end
 
        local data = {}
            data.start = client:GetShootPos()
            data.endpos = data.start + client:GetAimVector() * 96
            data.filter = client
 
        local aimTarget = util.TraceLine(data).Entity
 
        if (IsValid(aimTarget) and aimTarget:IsPlayer()) then
            if (aimTarget:IsCombine() == false) then
                return "Combine do not have Merit."
            end
            local char = aimTarget:GetCharacter()
            local charName = char:GetName()
            oldMerit = char:GetData("merit", 0)
            newMerit = math.max(oldMerit - amount, 0)
            target:SetData("merit", newMerit)
            return string.format("Deducted %s Merit from %s. They now have %s Merit", amount, charName, newMerit)
        end
 
        return "No name specified and you are not looking at a valid target!"
    end
 
    function COMMAND:OnCheckAccess(client)
        return true
    end
 
    ix.command.Add("DeductMerit", COMMAND)
end

Comments