• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Making sense of onHealthChange

BloodGauntlet

Member
Joined
Jul 27, 2016
Messages
45
Reaction score
18
Could anyone explain (what and how) to manipulate this data? I'm reworking how damage is dealt and I need to get the type of damage and amount of the incoming damage.

Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)


function print_r ( t ) --you can ignore reading this function, mimics php print_r
    local print_r_cache={}
    local function sub_print_r(t,indent)
        if (print_r_cache[tostring(t)]) then
            print(indent.."*"..tostring(t))
        else
            print_r_cache[tostring(t)]=true
            if (type(t)=="table") then
                for pos,val in pairs(t) do
                    if (type(val)=="table") then
                        print(indent.."["..pos.."] => "..tostring(t).." {")
                        sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
                        print(indent..string.rep(" ",string.len(pos)+6).."}")
                    else
                        print(indent.."["..pos.."] => "..tostring(val))
                    end
                end
            else
                print(indent..tostring(t))
            end
        end
    end
    sub_print_r(t,"  ")
end


    local returnValues = {
        ["creature"] = creature,
        ["attacker"] = attacker,
        ["primaryDamage"] = primaryDamage,
        ["primaryType"] = primaryType,
        ["secondaryDamage"] = secondaryDamage,
        ["secondaryType"] = secondaryType,
        ["origin"] = origin
    }
    print_r(returnValues)
end

Some output data:
Code:
[creature] => userdata: 0x2f51d490
  [primaryType] => 8
  [secondaryType] => 0
  [attacker] => userdata: 0x2f51d4b8
  [secondaryDamage] => 0
  [primaryDamage] => 3
  [origin] => 3
 
I think you can only change primary damage and primary type and secondary damage and secondary type.
I suggest to loose the secondary values anyway and never use them in your game.

the return values for onHealthChange functions are: prime damage and type

so when inside the script you manipulate the damage and return the new dam, the rseult is sent to next onHealthChange script or used as final output

I use origins to define the core places where damage is coming from, because i also execute new combat damages inside the onHealthChange script.
 
Back
Top