[ad_1]

I’m growing a third-person capturing type sport and I wish to implement an armor system. The system that I’ve envisioned doesn’t scale back the harm to 0, however by half. So the incoming harm is 50%. The armor takes the opposite 50% of harm and is diminished by that quantity. Gamers choose up armor objects from the map.

The problem that I am encountering is an edge case the place the harm > armor. This is what I’ve tried up to now:

Try 1:

-- Performs harm discount based mostly on armor, if any.  Robotically
-- provides the armor attribute to the humanoid if it does not already
-- exist.
native operate processArmor(goal, harm)
    -- Verify if the participant really has armor.  If not
    -- then return full harm.
    native armor = goal.human:GetAttribute("Armor")
    if armor == nil or armor == 0 then
        if armor == nil then
            goal.human:SetAttribute("Armor", 0)
        finish
        return harm
    finish

    -- If the participant does have armor > 0, then scale back the incoming
    -- harm.
    native d2 = harm / 2
    native t = d2
    d2 -= armor
    armor -= t - d2
    harm = d2

    -- Replace armor stat and return.
    goal.human:SetAttribute("Armor", armor)
    return harm
finish

Try 2:

-- Performs harm discount based mostly on armor, if any.  Robotically
-- provides the armor attribute to the humanoid if it does not already
-- exist.
native operate processArmor(goal, harm)
    -- Verify if the participant really has armor.  If not
    -- then return full harm.
    native armor = goal.human:GetAttribute("Armor")
    if armor == nil or armor == 0 then
        if armor == nil then
            goal.human:SetAttribute("Armor", 0)
        finish
        return harm
    finish

    -- If the participant does have armor > 0, then scale back the incoming
    -- harm.
    if harm == armor then
        armor = 0
    elseif harm < armor then
        armor -= harm
    elseif harm > (armor * 2) then
    else
        native t = harm - armor * 2
        harm -= armor
    finish

    -- Replace armor stat and return.
    goal.human:SetAttribute("Armor", armor)
    return harm
finish

Try 3:

-- Performs harm discount based mostly on armor, if any.  Robotically
-- provides the armor attribute to the humanoid if it does not already
-- exist.
native operate processArmor(goal, harm)
    -- Verify if the participant really has armor.  If not
    -- then return full harm.
    native armor = goal.human:GetAttribute("Armor")
    if armor == nil or armor == 0 then
        if armor == nil then
            goal.human:SetAttribute("Armor", 0)
        finish
        return harm
    finish
    
    -- If the participant does have armor > 0, then scale back the incoming
    -- harm.
    native d2 = harm / 2
    if armor == d2 then
        harm = d2
        armor = 0
    elseif armor > d2 then
        harm = d2
        armor -= d2
    else
        -- harm / 2 > armor
        harm = ((d2 - armor) * 2) + armor
        armor = 0
    finish

    -- Replace armor stat and return.
    goal.human:SetAttribute("Armor", armor)
    return harm
 finish

Goal is only a desk that comprises references to the elements of the participant that was hit. On this case, I am utilizing the Humanoid beneath the participant’s character mannequin. Try 3 appears to be the most effective guess, however beneath testing, the method beneath the else appears to scale back to harm -= armor.

I’ve achieved some analysis on the topic, however every little thing that I’ve discovered up to now includes RPG type video games. At this level, I am on the lookout for strategies.

Thanks.

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *