Jump to content

Upgrade like system.


Recommended Posts

Hello!

 

So i'm working on a character, and I am having some sort of upgrade system. he finds these souls and can consume them to gain more power. How would i go around making each soul give different things, Ex. Red soul gives more max health, Green soul gives more max sanity etc. etc.

Link to comment
Share on other sites

modmain.lua:

GLOBAL.FOODTYPE.SOULS = "SOULS"

prefabs/souls.lua:

    inst:AddComponent("edible")
    inst.components.edible.foodtype = FOODTYPE.SOULS
    inst.components.edible.healthvalue = #
    inst.components.edible.hungervalue = #
    inst.components.edible.sanityvalue = #

Change the #s depending on the souls type to give +stats to, not max stats that's next.

prefabs/yourcustomcharacter.lua's master_postinit function callback:

local eater = inst.components.eater
table.insert(eater.preferseating, FOODTYPE.SOULS)
table.insert(eater.caneat, FOODTYPE.SOULS)
eater:SetOnEatFn(
    function(inst, food)
        inst.SoundEmitter:PlaySound("some_sound_here_for_consuming_souls")
        -- Other code if you want other enhancements based on soul type here like +max stats
        -- See wx78's applyupgrades function for sample code on upgrading a stat.
    end
)
inst:AddTag(FOODTYPE.SOULS.."_eater")

Should get you a start on what you want.

Link to comment
Share on other sites

12 hours ago, CarlZalph said:

modmain.lua:


GLOBAL.FOODTYPE.SOULS = "SOULS"

prefabs/souls.lua:


    inst:AddComponent("edible")
    inst.components.edible.foodtype = FOODTYPE.SOULS
    inst.components.edible.healthvalue = #
    inst.components.edible.hungervalue = #
    inst.components.edible.sanityvalue = #

Change the #s depending on the souls type to give +stats to, not max stats that's next.

prefabs/yourcustomcharacter.lua's master_postinit function callback:


local eater = inst.components.eater
table.insert(eater.preferseating, FOODTYPE.SOULS)
table.insert(eater.caneat, FOODTYPE.SOULS)
eater:SetOnEatFn(
    function(inst, food)
        inst.SoundEmitter:PlaySound("some_sound_here_for_consuming_souls")
        -- Other code if you want other enhancements based on soul type here like +max stats
        -- See wx78's applyupgrades function for sample code on upgrading a stat.
    end
)
inst:AddTag(FOODTYPE.SOULS.."_eater")

Should get you a start on what you want.

So the souls.lua will control every soul? how would i get certain couls to increase certain things like red soul - health etc etc.. or does that do that and i'm just stupid?

Link to comment
Share on other sites

The way  he told you, you would do something like this in your character.lua

eater:SetOnEatFn(
    function(inst, food)
		if food.components.edible and food.components.edible.foodtype == FOODTYPE.SOULS then
        	inst.SoundEmitter:PlaySound("some_sound_here_for_consuming_souls")
		
			if food.prefab == "redsoul" then
				local percent = inst.components.health:GetPercent()
				inst.components.health:SetMaxHealth(inst.components.health.maxhealth + 20)
				inst.components.health:SetPercent(percent)
			elseif food.prefab == "bluesoul" then
				--other code
			end
        end
    end
)
Edited by Aquaterion
Link to comment
Share on other sites

5 hours ago, Aquaterion said:

The way  he told you, you would do something like this in your character.lua


eater:SetOnEatFn(
    function(inst, food)
		if food.components.edible and food.components.edible.foodtype == FOODTYPE.SOULS then
        	inst.SoundEmitter:PlaySound("some_sound_here_for_consuming_souls")
		
			if food.prefab == "redsoul" then
				local percent = inst.components.health:GetPercent()
				inst.components.health:SetMaxHealth(inst.components.health.maxhealth + 20)
				inst.components.health:SetPercent(percent)
			elseif food.prefab == "bluesoul" then
				--other code
			end
        end
    end
)

Ok, so i started to make the souls.lua, but some things:

I have seperate anim files for each soul since they have different textures.

therefore i imported all of the anim files into the souls.lua, as i am assuming one .lua file will control every soul.

 

That looks like this:

	--Red Soul
    Asset("ANIM", "anim/determination.zip"),
    Asset("ANIM", "anim/swap_determination.zip"),
	
	--Orange Soul
    Asset("ANIM", "anim/bravery.zip"),
    Asset("ANIM", "anim/swap_bravery.zip"),
	
	--Red Soul
    Asset("ANIM", "anim/integrity.zip"),
    Asset("ANIM", "anim/swap_integrity.zip"),
	
	--Red Soul
    Asset("ANIM", "anim/kindness.zip"),
    Asset("ANIM", "anim/swap_kindness.zip"),
	
	--Red Soul
    Asset("ANIM", "anim/patience.zip"),
    Asset("ANIM", "anim/swap_patience.zip"),
	
	--Red Soul
    Asset("ANIM", "anim/perseverance.zip"),
    Asset("ANIM", "anim/swap_perseverance.zip"),
	
	--Red Soul
    Asset("ANIM", "anim/revenge.zip"),
    Asset("ANIM", "anim/swap_revenge.zip"),
	
	Asset("ATLAS", "images/inventoryimages/determination.xml"),
    Asset("IMAGE", "images/inventoryimages/determination.tex"),
		
	Asset("ATLAS", "images/inventoryimages/bravery.xml"),
    Asset("IMAGE", "images/inventoryimages/bravery.tex"),
		
	Asset("ATLAS", "images/inventoryimages/integrity.xml"),
    Asset("IMAGE", "images/inventoryimages/integrity.tex"),
		
	Asset("ATLAS", "images/inventoryimages/kindness.xml"),
    Asset("IMAGE", "images/inventoryimages/kindness.tex"),
		
	Asset("ATLAS", "images/inventoryimages/patience.xml"),
    Asset("IMAGE", "images/inventoryimages/patience.tex"),
		
	Asset("ATLAS", "images/inventoryimages/perseverance.xml"),
    Asset("IMAGE", "images/inventoryimages/perseverance.tex"),
	
	Asset("ATLAS", "images/inventoryimages/revenge.xml"),
    Asset("IMAGE", "images/inventoryimages/revenge.tex"),

so in the onequip, I just copied this from my trident but the code will do for the sake of explanation, i have:

	owner.AnimState:OverrideSymbol("swap_object", "swap_trident", "swap_spear")

so if I am using multiule anim files, what would I do here?

 

also, I have returning just:

return Prefab("souls", fn, assets)

But that doesn't seem right about anything, and I am not sure if using these anim files the way I am using them is a good way of doing things.

 

Hopefully i explained this well, sorta late and I am very confused haha.

 

Thanks for replying!

 

Also, if you want to see for yourself here is the souls.lua just in case:

souls.lua

Link to comment
Share on other sites

Since the soul benefits are gonna be on the player, all the souls will basically be the same, just look different.

Wait are you going to have a consumable wearable item?

I did some code here but I didn't test anything, so there are bound to be some typos and such

 

local function CreateSoul(color, power)
	local assets = 
	{
		Asset("ANIM", "anim/".. power ..".zip"),
		Asset("ANIM", "anim/swap_".. power ..".zip"),
		Asset("ATLAS", "images/inventoryimages/".. power ..".xml"),
		Asset("IMAGE", "images/inventoryimages/".. power ..".tex"),
	}
	
    local function fn()
        local inst = CreateEntity()

        inst.entity:AddTransform()
        inst.entity:AddAnimState()
        inst.entity:AddNetwork()
        inst.entity:AddSoundEmitter()
		
        MakeInventoryPhysics(inst)

        inst.AnimState:SetBank(power)
        inst.AnimState:SetBuild(power)
        inst.AnimState:PlayAnimation("idle") --dunno?

        inst:AddTag("soul")
		inst:AddTag(power)

        if not TheWorld.ismastersim then
            return inst
        end

        inst:AddComponent("inspectable")
		
        inst:AddComponent("inventoryitem")
        inst.components.inventoryitem.atlasname = "images/inventoryimages/".. power ..".xml"
        inst.components.inventoryitem.imagename = power
		
        inst:AddComponent("equippable")
        inst.components.equippable:SetOnEquip(function(inst, owner)
            owner.AnimState:OverrideSymbol("swap_object", "swap_trident", "swap_spear")
            owner.AnimState:Show("ARM_carry") 
            owner.AnimState:Hide("ARM_normal") 
        end)
        inst.components.equippable:SetOnUnequip(function(inst, owner)
            owner.AnimState:Show("ARM_normal") 
            owner.AnimState:Hide("ARM_carry") 
        end)
		
        inst:AddComponent("edible")--wait.. an equppable edible item?
        inst.components.edible.foodtype = FOODTYPE.SOULS
        inst.components.edible.healthvalue = 0
        inst.components.edible.hungervalue = 0
        inst.components.edible.sanityvalue = 0

        return inst
    end
    return Prefab(prefab.."soul", fn, assets)
end

local souldata = {
	red = "determination",
	orange = "bravery",
	yellow = "integrity",
	green = "kindness",
	blue = "patience",
	purple = "perseverance",
	grey = "revenge"
}

local souls = {}
for color, power in ipairs(souldata) do
    table.insert(souls, CreateSoul(color, power))
end

return unpack(souls)

 

Edited by Aquaterion
Link to comment
Share on other sites

5 hours ago, Aquaterion said:

Since the soul benefits are gonna be on the player, all the souls will basically be the same, just look different.

Wait are you going to have a consumable wearable item?

I did some code here but I didn't test anything, so there are bound to be some typos and such

  Hide contents


local function CreateSoul(color, power)
	local assets = 
	{
		Asset("ANIM", "anim/".. power ..".zip"),
		Asset("ANIM", "anim/swap_".. power ..".zip"),
		Asset("ATLAS", "images/inventoryimages/".. power ..".xml"),
		Asset("IMAGE", "images/inventoryimages/".. power ..".tex"),
	}
	
    local function fn()
        local inst = CreateEntity()

        inst.entity:AddTransform()
        inst.entity:AddAnimState()
        inst.entity:AddNetwork()
        inst.entity:AddSoundEmitter()
		
        MakeInventoryPhysics(inst)

        inst.AnimState:SetBank(power)
        inst.AnimState:SetBuild(power)
        inst.AnimState:PlayAnimation("idle") --dunno?

        inst:AddTag("soul")
		inst:AddTag(power)

        if not TheWorld.ismastersim then
            return inst
        end

        inst:AddComponent("inspectable")
		
        inst:AddComponent("inventoryitem")
        inst.components.inventoryitem.atlasname = "images/inventoryimages/".. power ..".xml"
        inst.components.inventoryitem.imagename = power
		
        inst:AddComponent("equippable")
        inst.components.equippable:SetOnEquip(function(inst, owner)
            owner.AnimState:OverrideSymbol("swap_object", "swap_trident", "swap_spear")
            owner.AnimState:Show("ARM_carry") 
            owner.AnimState:Hide("ARM_normal") 
        end)
        inst.components.equippable:SetOnUnequip(function(inst, owner)
            owner.AnimState:Show("ARM_normal") 
            owner.AnimState:Hide("ARM_carry") 
        end)
		
        inst:AddComponent("edible")--wait.. an equppable edible item?
        inst.components.edible.foodtype = FOODTYPE.SOULS
        inst.components.edible.healthvalue = 0
        inst.components.edible.hungervalue = 0
        inst.components.edible.sanityvalue = 0

        return inst
    end
    return Prefab(prefab.."soul", fn, assets)
end

local souldata = {
	red = "determination",
	orange = "bravery",
	yellow = "integrity",
	green = "kindness",
	blue = "patience",
	purple = "perseverance",
	grey = "revenge"
}

local souls = {}
for color, power in ipairs(souldata) do
    table.insert(souls, CreateSoul(color, power))
end

return unpack(souls)

The soul's are not wearable,they are only consumable lol, I'll test out the code now.

 

Link to comment
Share on other sites

Well you did the override symbol thing, which is only used for equipping things, as well as the swap_soul art.

I modified it to not have the equippable stuff:

 

 


local function CreateSoul(color, power)
	local assets = 
	{
		Asset("ANIM", "anim/".. power ..".zip"),
		Asset("ATLAS", "images/inventoryimages/".. power ..".xml"),
		Asset("IMAGE", "images/inventoryimages/".. power ..".tex"),
	}
	
    local function fn()
        local inst = CreateEntity()

        inst.entity:AddTransform()
        inst.entity:AddAnimState()
        inst.entity:AddNetwork()
        inst.entity:AddSoundEmitter()
		
        MakeInventoryPhysics(inst)

        inst.AnimState:SetBank(power)
        inst.AnimState:SetBuild(power)
        inst.AnimState:PlayAnimation("idle") --dunno?

        inst:AddTag("soul")
        inst:AddTag(power)

        inst.entity:SetPristine()
		
        if not TheWorld.ismastersim then
            return inst
        end

        inst:AddComponent("inspectable")
		
        inst:AddComponent("inventoryitem")
        inst.components.inventoryitem.atlasname = "images/inventoryimages/".. power ..".xml"
        inst.components.inventoryitem.imagename = power
		
        inst:AddComponent("edible")--wait.. an equppable edible item?
        inst.components.edible.foodtype = FOODTYPE.SOULS
        inst.components.edible.healthvalue = 0
        inst.components.edible.hungervalue = 0
        inst.components.edible.sanityvalue = 0

        return inst
    end
    return Prefab(prefab.."soul", fn, assets)
end

local souldata = {
	red = "determination",
	orange = "bravery",
	yellow = "integrity",
	green = "kindness",
	blue = "patience",
	purple = "perseverance",
	grey = "revenge"
}

local souls = {}
for color, power in ipairs(souldata) do
    table.insert(souls, CreateSoul(color, power))
end

return unpack(souls)

 

Edited by Aquaterion
Link to comment
Share on other sites

5 minutes ago, Aquaterion said:

Well you did the override symbol thing, which is only used for equipping things, as well as the swap_soul art.

I modified it to not have the equippable stuff:

  Hide contents

 



local function CreateSoul(color, power)
	local assets = 
	{
		Asset("ANIM", "anim/".. power ..".zip"),
		Asset("ATLAS", "images/inventoryimages/".. power ..".xml"),
		Asset("IMAGE", "images/inventoryimages/".. power ..".tex"),
	}
	
    local function fn()
        local inst = CreateEntity()

        inst.entity:AddTransform()
        inst.entity:AddAnimState()
        inst.entity:AddNetwork()
        inst.entity:AddSoundEmitter()
		
        MakeInventoryPhysics(inst)

        inst.AnimState:SetBank(power)
        inst.AnimState:SetBuild(power)
        inst.AnimState:PlayAnimation("idle") --dunno?

        inst:AddTag("soul")
        inst:AddTag(power)

        inst.entity:SetPristine()
		
        if not TheWorld.ismastersim then
            return inst
        end

        inst:AddComponent("inspectable")
		
        inst:AddComponent("inventoryitem")
        inst.components.inventoryitem.atlasname = "images/inventoryimages/".. power ..".xml"
        inst.components.inventoryitem.imagename = power
		
        inst:AddComponent("edible")--wait.. an equppable edible item?
        inst.components.edible.foodtype = FOODTYPE.SOULS
        inst.components.edible.healthvalue = 0
        inst.components.edible.hungervalue = 0
        inst.components.edible.sanityvalue = 0

        return inst
    end
    return Prefab(prefab.."soul", fn, assets)
end

local souldata = {
	red = "determination",
	orange = "bravery",
	yellow = "integrity",
	green = "kindness",
	blue = "patience",
	purple = "perseverance",
	grey = "revenge"
}

local souls = {}
for color, power in ipairs(souldata) do
    table.insert(souls, CreateSoul(color, power))
end

return unpack(souls)

 

Ah, yeah probably just because i copied it from my trident, and probably just forgot to delete that, sorry about that.

Link to comment
Share on other sites

Ok, so i typed this all out, but it deleted itself, lets try this again...

 

So i added all the code and stuff but in the modmain.lua in prefab files i added "souls", worked no crash, but I couldn't spawn in the item's using the console, so the game doesn't even recognize their existence. So I tried to add a prefab for each soul, adding determination, bravery, etc etc... to the prefab list, and when i loaded the game it then crashed saying that it couldn't find determination.lua and so on.

So there is that problem.

 

Also, in the character.lua file. i did the eating part like so: 

	local eater = inst.components.eater
	table.insert(eater.preferseating, FOODTYPE.SOULS)
	table.insert(eater.caneat, FOODTYPE.SOULS)
	eater:SetOnEatFn(
    function(inst, food)
		if food.components.edible and food.components.edible.foodtype == FOODTYPE.SOULS then
        	--inst.SoundEmitter:PlaySound("some_sound_here_for_consuming_souls")
		
			if food.prefab == "determination" then
				local percent = inst.components.health:GetPercent()
				inst.components.health:SetMaxHealth(inst.components.health.maxhealth + 20)
				inst.components.health:SetPercent(percent)
			elseif food.prefab == "bravery" then
				local percent = inst.components.health:GetPercent()
				inst.components.health:SetMaxHealth(inst.components.health.maxhealth + 20)
				inst.components.health:SetPercent(percent)
			elseif food.prefab == "integrity" then
				local percent = inst.components.health:GetPercent()
				inst.components.health:SetMaxHealth(inst.components.health.maxhealth + 20)
				inst.components.health:SetPercent(percent)
			elseif food.prefab == "kindness" then
				local percent = inst.components.health:GetPercent()
				inst.components.health:SetMaxHealth(inst.components.health.maxhealth + 20)
				inst.components.health:SetPercent(percent)
			elseif food.prefab == "patience" then
				local percent = inst.components.health:GetPercent()
				inst.components.health:SetMaxHealth(inst.components.health.maxhealth + 20)
				inst.components.health:SetPercent(percent)
			elseif food.prefab == "perseverance" then
				local percent = inst.components.health:GetPercent()
				inst.components.health:SetMaxHealth(inst.components.health.maxhealth + 20)
				inst.components.health:SetPercent(percent)
			elseif food.prefab == "revenge" then
				local percent = inst.components.health:GetPercent()
				inst.components.health:SetMaxHealth(inst.components.health.maxhealth + 20)
				inst.components.health:SetPercent(percent)
			end
        end
    end
)
	inst:AddTag(FOODTYPE.SOULS.."_eater")

 

But obvoiusly not all of them are going to increase your health, so would:

sanity = maxsanity

damage = maxdamage

hunger = maxhunger

just wanted to make sure and mot break everything.

 

Thanks once more for replying, I attached some files below if you wanted to see all of the stuff.

souls.lua

asgore.lua

modmain.lua

Link to comment
Share on other sites

the soul names are color+soul, so "redsoul", "bluesoul" and stuff. I had to place some placeholder colors since u didnt provide all of them, you can change them in the table "souldata"

i'll re-edit this post with the sanity/damage/hunger stuff

Link to comment
Share on other sites

5 minutes ago, Aquaterion said:

the soul names are color+soul, so "redsoul", "bluesoul" and stuff. I had to place some placeholder colors since u didnt provide all of them, you can change them in the table "souldata"

i'll re-edit this post with the sanity/damage/hunger stuff

Yeah i saw that, you were actually right on all but one of them, good guessing lol.

Thanks once more, i'll go and look at if it works now.

Link to comment
Share on other sites

--sanity
local percent = inst.components.sanity:GetPercent()
inst.components.sanity:SetMax(inst.components.sanity.max + 20)
inst.components.sanity:SetPercent(percent)
--hunger
local percent = inst.components.hunger:GetPercent()
inst.components.hunger:SetMax(inst.components.hunger.max + 20)
inst.components.hunger:SetPercent(percent)
--damage mult
if inst.components.combat.damagemultiplier == nil then
	inst.components.combat.damagemultiplier = 1
end
inst.components.combat.damagemultiplier = inst.components.combat.damagemultiplier + 0.25

 

As for the colors, I followed the rainbow xD

Link to comment
Share on other sites

14 minutes ago, Aquaterion said:

--sanity
local percent = inst.components.sanity:GetPercent()
inst.components.sanity:SetMax(inst.components.sanity.max + 20)
inst.components.sanity:SetPercent(percent)
--hunger
local percent = inst.components.hunger:GetPercent()
inst.components.hunger:SetMax(inst.components.hunger.max + 20)
inst.components.hunger:SetPercent(percent)
--damage mult
if inst.components.combat.damagemultiplier == nil then
	inst.components.combat.damagemultiplier = 1
end
inst.components.combat.damagemultiplier = inst.components.combat.damagemultiplier + 0.25

 

As for the colors, I followed the rainbow xD

Alright, i changed the sanity and stuff, but I'm still not sure what to put in the modmain prefabs, i did the redsoul and bluesoul etc etc, still says it cannot find the prefab.

Link to comment
Share on other sites

Oh I forgot to change 1 thing in souls.lua, you gotta change it;

 

--change this line: (should be like line 45/46/47)
    return Prefab(prefab.."soul", fn, assets)
--to this:
    return Prefab(color.."soul", fn, assets)

 

 

 

Edited by Aquaterion
Link to comment
Share on other sites

10 minutes ago, Aquaterion said:

Oh I forgot to change 1 thing in souls.lua, you gotta change it;

 


--change this line: (should be like line 45/46/47)
    return Prefab(prefab.."soul", fn, assets)
--to this:
    return Prefab(color.."soul", fn, assets)

 

Still says it can't find the prefabs.

Edited by TheBigDeal
Link to comment
Share on other sites

Yeah that was the problem, I changed that, works fine now in that sense, but now it crashes with no ingame error, the client log says the following:

[00:00:59]: ..\source\animlib\animmanager.cpp(505) :: Tried to add build [determination] from file [../mods/Asgore/anim/determination.zip] but we've already added a build with that name!
 

client_log.txt

Link to comment
Share on other sites

same issue as before with tridents, you gotta get build renamer and use it to rename each build internally.

Btw, if you wanna change the soul names to their power:

--change:
    return Prefab(color.."soul", fn, assets)
--to:
    return Prefab(power, fn, assets)

 

Link to comment
Share on other sites

50 minutes ago, Aquaterion said:

same issue as before with tridents, you gotta get build renamer and use it to rename each build internally.

Btw, if you wanna change the soul names to their power:


--change:
    return Prefab(color.."soul", fn, assets)
--to:
    return Prefab(power, fn, assets)

 

Alright, everything seems to load atleast with only a few problems.

Firstly, the souls do show up in the crafting menu, but once i craft them the character says "I cannot do that" and then it takes the items for crafting, but gives nothing back.

 

Secondly, Eating the souls do not seem to do anything, maybe I missed a step i'll go back and look to make sure I have everything but i don't think I do at the time of writing this.

Lastly, my tab doesn't seem to want to load the icon, no idea why sense it is setup exactly like the last one.

the files down below should be everything for the hud.

modmain.lua

soultab.xml

Link to comment
Share on other sites

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
 Share

×
  • Create New...