Jump to content

Mimicking Fryfocals but not working


SenL

Recommended Posts

Hi,
I'm trying to copy gogglesshoothat (Fryfocals) into my mod where it's an amulet that can attack at range (same as Fryfocals). However it's not working.

I copied the codes from the core file:
"
inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(25)
    inst.components.weapon:SetRange(8, 10)        
    inst.components.weapon:SetProjectile("fryfocals_charge")
    inst.components.weapon:SetOnAttack(onattack_shoot)

inst.components.equippable:SetOnEquip( mymod_onequip )
        inst.components.equippable:SetOnUnequip( mymod_onunequip )

"

The mymod_onequip has
"
inst.components.weapon:SetCanAttack(function() return true end)
"
The onattack_shoot only wakes up the target.

What is missing?

Thanks.

Link to comment
Share on other sites

Quote

local function onattack_shoot(inst, attacker, target)
    if target.components.sleeper and target.components.sleeper:IsAsleep() then
        target.components.sleeper:WakeUp()
    end
end

Original one has more like unfreeze, ignite but I don't need those.

Here is the entire mod:

Quote

local assets = {
    Asset("ANIM", "anim/mymod.zip"),
    Asset("ANIM", "anim/torso_amulets.zip"), --borrow

    Asset("IMAGE", "images/inventoryimages/mymod.tex"),    
    Asset("ATLAS", "images/inventoryimages/mymod.xml")
}

local function mymod_onequip(inst, owner)    
    owner.AnimState:OverrideSymbol("swap_body", "torso_amulets", "blueamulet") --borrow
    inst.components.weapon:SetCanAttack(function() return true end)
end

local function mymod_onunequip(inst, owner)
    owner.AnimState:ClearOverrideSymbol("swap_body")
    inst.components.weapon:SetCanAttack(function() return false end)
end

local function onattack_shoot(inst, attacker, target)
    if target.components.sleeper and target.components.sleeper:IsAsleep() then
        target.components.sleeper:WakeUp()
    end
end

local function fn(Sim)
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    MakeInventoryPhysics(inst)
    
    inst.AnimState:SetBank("mymod")
    inst.AnimState:SetBuild("mymod")
    inst.AnimState:PlayAnimation("idle")
    
    inst:AddComponent("inspectable")

    inst:AddComponent("equippable")
    
    if KnownModIndex:IsModEnabled("workshop-277517714") then
        print ("mod workshop-277517714 is available")
        inst.components.equippable.equipslot = EQUIPSLOTS.NECK
    else
        inst.components.equippable.equipslot = EQUIPSLOTS.BODY
    end
    
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.atlasname = "images/inventoryimages/mymod.xml"
    inst.components.inventoryitem.foleysound = "dontstarve/movement/foley/jewlery"
    inst.components.inventoryitem.keepondeath = true
    
    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(25)
    inst.components.weapon:SetRange(8, 10)        
    inst.components.weapon:SetProjectile("fryfocals_charge")
    inst.components.weapon:SetOnAttack(onattack_shoot)

    inst.components.equippable:SetOnEquip( mymod_onequip )
    inst.components.equippable:SetOnUnequip( mymod_onunequip )
    
    return inst
end

return Prefab("common/inventory/mymod", fn, assets)
 

 

I notice when playing as Wagstaff, I was able to hover over enemy (say a spider) with the original (Fryfocals) on and the cursor would allow me to attack. It also has this character animation and fx which are cool - but I don't know where they are stored (what lua script file) or how. Anyway, with mymod there is no "attack" so it feels like it's missing a lot of stuff.

Link to comment
Share on other sites

Well, I can't go into precise details right now. But animations and that kind of thing are done in the stategraphs, for the characters, in SGwilson.lua (SGwilsonboat too) look for a "doattack" EventHandler, there it is chosen which "state" will be played. Usually it's the "attack" (something like that), but I think wagstaff's glasses have a state of their own. Anyway, try to assimilate how the stategraph interacts with pushed events and executes PerformBufferentAction (see actions.lua), there it is defined how the action is called and executed. They are quite complex systems, but as the glasses are very similar to what you want to do, I believe you can find out..

Link to comment
Share on other sites

Thanks for the hints. I found it.

SGWilson.lua:

Quote

...

local weapon = inst.components.combat and inst.components.combat:GetWeapon()
...
if weapon and weapon:HasTag("goggles") then 
                inst.sg:GoToState("goggleattack")

...


State "goggleattack" is the one actually does the attack.
inst.components.combat:StartAttack()

So I needed to add "goggles" tag to my mod.
However it needed more as it was still not working.

I dug into combat component and found that its "GetWeapon" first finds item from EQUIPSLOTS.HANDS.
If none found, it finds item from EQUIPSLOTS.HEAD (such as Fryfocals).

So I needed to:

  1. Change EQUIPSLOTS from NECK/BODY to HEAD
    and
  2. Have absolutely no weapon in HANDS

Although it's working the animation is not there unless player is Wagstaff. "You" would go blank briefly.
I think this is because it's missing "goggle_fast" anim on the character (unless Wagstaff).


Additionally this is not ideal because my mod is an amulet so it should go to BODY or NECK (with certain mod installed).
Is there anyway to "add" to this combat component to check on BODY and/or NECK (with certain mod installed)?

 

Edit:
I got it to work! BUT! It's still no animation unless Wagstaff. Also it's replacing combat:GetWeapon() completely and that's not ideal. How do you adjust the original to avoid writing over it entirely?

In my mod's modmain.lua:

Quote

AddComponentPostInit("combat", function(component)
    --how to adjust original without writing over?
    
    function component:GetWeapon()
        local item
        if self.inst.components.inventory then
            --check NECK (with certain mod), then BODY, then HEAD, then HANDS
            if GLOBAL.KnownModIndex:IsModEnabled("workshop-277517714") then
                item = self.inst.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.NECK)
            else
                item = self.inst.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.BODY)
            end
            if item and item.components.weapon then
                return item
            end
            item = self.inst.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HEAD)
            if item and item.components.weapon then
                return item
            end        
            item = self.inst.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HANDS)
            if item and item.components.weapon then
                return item
            end
        end
    end
end)

 

Link to comment
Share on other sites

19 hours ago, SenL said:

Although it's working the animation is not there unless player is Wagstaff

Add this to modmain: (for have the anim)

Assets = { -- Or put this in your Assets table
	Asset("ANIM", "anim/player_wagstaff.zip")
}

AddPlayerPostInit(function(inst)
    inst.AnimState:AddOverrideBuild("player_wagstaff")
end)

 

19 hours ago, SenL said:

How do you adjust the original to avoid writing over it entirely?

AddComponentPostInit("combat", function(component)
	local _GetWeapon = component.GetWeapon
    function component:GetWeapon()
        if self.inst.components.inventory then
            if GLOBAL.EQUIPSLOTS.NECK then
                item = self.inst.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.NECK)
            else
                item = self.inst.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.BODY)
            end
            if item and item.components.weapon then
                return item
            end

			return _GetWeapon(component) -- If not equip in neck/body, return the original (Hand -> Head)
		end
	end
end)

For Head -> Hand you have to overwrite it.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...