Jump to content

Recommended Posts

local function IsFuel(item)
    return item.prefab == "nightmarefuel"
end

local function GetStackSize(item)
    return item.components.stackable ~= nil and item.components.stackable:StackSize() or 1
end

local function SortByStackSize(l, r)
    return GetStackSize(l) < GetStackSize(r)
end

local function GetFuels(inst)
    local fuel = inst.components.inventory:FindItems(IsFuel)
    local count = 0
    for i, v in ipairs(fuel) do
        count = count + GetStackSize(v)
    end
    return fuel, count
end

local function NightmareFuelCheck(inst)
    local fuelmin = 1
	local fuelcount = GetFuels(inst)
    if fuelcount < fuelmin then
	    return false
    end
return true
end


local function HealFunc(inst, target)
    print(inst, target)
    local caster = inst.components.inventoryitem.owner
    if not caster then caster = target or caster end
	local impactfx = SpawnPrefab("impact")
	if impactfx ~= nil then
        local follower = impactfx.entity:AddFollower()
        follower:FollowSymbol(target.GUID, target.components.combat.hiteffectsymbol, 0, 0, 0)
        end
	
	if NightmareFuelCheck and target:HasTag("hostile") and target:HasTag("shadow_aligned") or target:HasTag("nightmarecreature") then
        target.components.health:DoDelta(-300)
		caster.components.sanity:DoDelta(-20)
	    inst.components.talker:Say("Exterreri expulso!")
	    caster.components.inventory:ConsumeByName("nightmarefuel", 1)
	elseif NightmareFuelCheck and target:HasTag("hostile") then 
        target.components.health:DoDelta(-100)
		caster.components.sanity:DoDelta(-15)
	    inst.components.talker:Say("Exterreri maledictio!")
	    caster.components.inventory:ConsumeByName("nightmarefuel", 1)
	elseif NightmareFuelCheck and target:HasTag("player") or target:HasTag("pig") or target:HasTag("companion") then
        target.components.health:DoDelta(40)
		caster.components.sanity:DoDelta(-15)
		inst.components.talker:Say("Exterreri ad sanguinem!")
		caster.components.inventory:ConsumeByName("nightmarefuel", 1)
    else
		inst.components.talker:Say("My mind... Is breaking!")
		caster.components.sanity:DoDelta(-10)
    end
end

This is the code I have so far but it doesn't seem to work as intended, my character can still use the spell under healfunc even if he has no nightmare fuel in his inventory. I would really appreciate some guidance, I'm losing my mind here :\

I am an amateur with Lua code and have been sifting through bits and pieces of others mods and game prefabs to try to learn enough to create this custom weapon for a custom character. This is the last piece of the puzzle and my character will be ready for a playthrough with some friends, currently he's just too OP without the cheese nightmare tax.
 

Edited by sorrynameused
more blah

You're checking for "NightmareFuelCheck" instead of "NightmareFuelCheck(inst)". Without parenthesis, the function isn't running and returning its value. What you're effectively checking for is that the local variable itself isn't nil or false, which it obviously will never be since it's a function, that's why the check always passes.

Edited by ClumsyPenny
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...