Affect Object function for Swords and Spears

marceloSRmarceloSR REGISTERED Posts: 47 Seed
I was testing my mod and realized that even that the sword inherit from the equipable class and doesnt override the AffectObject on it, when I hit objects with it it doesnt trigger the AffectObject on the equipable class.

The same thing happens with spears. But I couldnt find which class spears are using.

Someone knows where the Sword and spear AffectObject functions are?

Comments

  • johnycilohoklajohnycilohokla REGISTERED Posts: 283 Developer
    edited December 2015
    The sword, spear and other melee weapons are using the data driven handler->event->effect system.

    All of the hit events (HitEv_PlaceableObject) execute:
    /Core/Data/Effects/EquipableEffects/DamagePlaceableObject.json

    Which is basically a wrapper for DamagePlaceableObject effect.

    The script that executes when an object is hit using a sword/spear is:
    DamagePlaceableObject:Callback
    located in:
    /Core/Scripts/Effects/DamagePlaceableObject.lua
    My Blog
    jc.png
      yt.png  t.png  
  • RawrRawr REGISTERED, Tester Posts: 510 Seed
    Johny, could you please explain that again. Didn't quite understand your answer.
    Programmer, designer, artist.
  • johnycilohoklajohnycilohokla REGISTERED Posts: 283 Developer
    Warning: this will be a long explanation...

    Sure, lets take the Bronze Sword as an example.

    It's txt object definition contains the Handlers and Events.
    Handlers define the way Bronze Sword behaves, for example when you left click(swing).
    Events contain a list of EffectGroups that will be executed when an Event is raised.
    Each EffectGroups is loaded from a JSON file, that contains one or more effects.

    When the players left clicks the SwingHandler determinates what happens.
    For the Bronze Sword it will use the HandlerAreaCollect handler to collect an object using sweepShape(ThinFrustumSweepShape).
    Then for each target it will check if it is a valid AffectedTarget.
    If it is, it will check EventNames for the event to execute.
    For the Bronze Sword hitting PlaceableObject, this will be HitEv_PlaceableObject.
    Then it will execute the HitEv_PlaceableObject Event.

    Object definition:
    Bronze Sword
    {
    Script
    {
    file = "Scripts/Objects/ModularSword.lua"
    class = "ModularSword"

    arguments
    {
    #Break/Creak info
    CreakingSound = "ItemCreak"
    BreakSound = "ItemBreak"

    dataMetricCategory = "Weapon"
    UBPcraft = 6
    LBPcraft = 8
    XPcraft = 14

    Handlers
    {
    SwingHandler
    {
    Default = 1
    handlerClass = "HandlerAreaCollect"

    arguments
    {
    sweepShape = "ThinFrustumSweepShape"
    maxTargets = 1
    equipEvent = "ApplySpeedBuff"
    unequipEvent = "RemoveSpeedBuff"

    AffectedTargets
    {
    "Character"
    "PlaceableObject"
    "Terrain"
    }

    EventNames
    {
    Character = "HitEv_Character"
    PlaceableObject = "HitEv_PlaceableObject"
    Terrain = "HitEv_Terrain"
    }

    SwingData
    {
    type = "oneshot"
    Animations
    {
    "ItemHSwing"
    "ItemVSwing"
    }
    }
    }
    }
    }

    Events
    {
    ApplySpeedBuff
    {
    TargetBuff
    {
    jsonFile = "Data/Effects/Buffs/SingleTargetApplyBuff.json"
    buffClass = "RunSpeedSwordBuff"
    BuffData
    {
    value = 1.4
    duration = 0.0
    }
    }
    }
    RemoveSpeedBuff
    {
    TargetBuff
    {
    jsonFile = "Data/Effects/Buffs/SingleTargetRemoveBuff.json"
    buffClass = "RunSpeedSwordBuff"
    }
    }
    HitEv_Character
    {
    Damage
    {
    jsonFile = "Data/Effects/EquipableEffects/WeaponDamageCharacter.json"
    }
    }

    HitEv_PlaceableObject
    {
    Damage
    {
    jsonFile = "Data/Effects/EquipableEffects/DamagePlaceableObject.json"

    affectResources = 0
    Affects
    {
    "Flesh" = 2
    }
    }
    }

    HitEv_Terrain
    {
    RemoveBillboards
    {
    jsonFile = "Data/Effects/EquipableEffects/TerrainRemoveBillboards.json"
    }
    }
    }

    ModificationInput
    {
    "modificationType" = "Swap"
    "dimensions" = <1.0,1.0,1.0>
    "radius" = 1.0
    "brushType" = "Cube"
    }
    }
    }
    # ...
    }
    The HitEv_PlaceableObject defines a single EffectGroup called Damage,
    with a jsonFile = "Data/Effects/EquipableEffects/DamagePlaceableObject.json"
    and few parameters.
    The system will then execute the JSON file containing the EffectGroup.

    EffectGroup data:
    (Core/Data/Effects/EquipableEffects/DamagePlaceableObject.json)
    {
    "type": "EffectGroup",
    "name": "DamagePlaceableObject",
    "description": "Used by handled equipables. Applies damage to a placeable object, filtering by tier and category. If damage, incorrectTierCap, or affectedCategories are not specified in the data file, they will be pulled from the hitting tool/weapon's script instead.",

    "effects": [
    {
    "effectScript": "DamagePlaceableObject",
    "affectResources": "@affectResources",
    "damage": "@damage",
    "incorrectTierCap": "@incorrectTierCap",
    "affectedCategories": "@Affects"
    },
    ]
    }
    The EffectGroup defines a single effect DamagePlaceableObject
    (which is also the name of the lua script file located in "Scripts/Effects/*")

    Effect Script: Core/Scripts/Effects/DamagePlaceableObject.lua

    This lua script will apply damage to placeable objects.
    My Blog
    jc.png
      yt.png  t.png  
  • marceloSRmarceloSR REGISTERED Posts: 47 Seed
    Nice, thank you very much for the detailed explanation Johny.

    So I'm using the DamagePlaceableObject to detect if the damage was done to a placeable object and WeaponDamageCharacter to check for damage applied to AI or Players.
    I can also do the check for terrain using the TerrainRemoveBillboards.

    I still couldnt test it, but as soon as I upload these changes to the server I'll let you know if its working.
  • johnycilohoklajohnycilohokla REGISTERED Posts: 283 Developer
    Cool, no problem.
    Hmm... checking TerrainRemoveBillboards will only work for Sword (removing billboards from voxels).
    Survival:VoxelsModifiedCallback would be a better place to add a check.
    My Blog
    jc.png
      yt.png  t.png  
  • marceloSRmarceloSR REGISTERED Posts: 47 Seed
    Im already using the voxelsModifiedCallback in Survival, but I dont think it works for swords.

    For the sword, I was also planning on using the VoxelsModifiedCallback in the Sword.lua script.
    I think this should overwrite the function in the survival script, right?
  • johnycilohoklajohnycilohokla REGISTERED Posts: 283 Developer
    No, all of the VoxelsModifiedCallback's will go through Survival:VoxelsModifiedCallback. Then Survival:VoxelsModifiedCallback calls VoxelsModifiedCallback on other objects if it is available.
    My Blog
    jc.png
      yt.png  t.png  
  • marceloSRmarceloSR REGISTERED Posts: 47 Seed
    Oh ok, nice. So I dont need to do anything else!
  • marceloSRmarceloSR REGISTERED Posts: 47 Seed
    Johny, I dont think I can actually use the function WeaponDamageCharacter:Callback

    When I try to overwrite it, it returns me a nil value.
    I looked at the function header and there is this note over there:
    This class is part of the Effects system.
    It can not be used outside of EffectsManager.
    All classes in this system are singleton classes.
    Do you know another place I can get this data?
  • johnycilohoklajohnycilohokla REGISTERED Posts: 283 Developer
    edited December 2015
    Heh yeah, I'm defining those classes as local.
    I don't need them to exist in the global slope and normally there should be no reason to override them.

    But your case is a bit different.

    You can get the singleton instance using:
    local WeaponDamageCharacter = EternusEngine.EffectsManager:GetEffect("WeaponDamageCharacter")
    And you can get the class using:
    include("Scripts/Effects/WeaponDamageCharacter.lua")
    local WeaponDamageCharacter = EternusEngine.EffectsManager.m_effects["WeaponDamageCharacter"]
    You will probably want the override the class.
    My Blog
    jc.png
      yt.png  t.png  
  • marceloSRmarceloSR REGISTERED Posts: 47 Seed
    Nice, this is working now.

    However, I dont know what callbackData.source is,
    On the script you have callbackData.source - Swinging character. I tried getting the player in all ways I know, but none of them worked.

    What class is this source object?
  • marceloSRmarceloSR REGISTERED Posts: 47 Seed
    edited December 2015
    Also, I dont know why it is returning nil on the hit object name when I use NKGetName()
    
    			local obj = hitData.object
    			if (not obj:IsDead()) then
    				if (obj:InstanceOf(AICharacter)) then
    					local valid = obj:OnHit(callbackData.source, effectHandler, damageOutput)
    					if valid then
    						local name = obj:NKGetName()
  • marceloSRmarceloSR REGISTERED Posts: 47 Seed
    Ok, I was being dumb.
    I was using the wrong variable name. Everything is working fine now!
Sign In or Register to comment.