Jump to content

Need Help With Custom Item Recipes


Recommended Posts

Hi this is actually my first time using the forums (just never was comfortable with others for a long time but even i started to change after 5 years or so after making a friend) so i dont know much about anything revolving around it , so if i end up breaking a rule or screwing up please keep in mind its out of ignorance rather than being outright inconsiderate(also as long as you can make out what im saying just fine, please ignore the grammar).

Question 1

Im still not too good at scripting and my knowledge is very limited so i would like some help...I wanted to know if it's possible to make a custom item with a custom recipe that costs HUNGER. ive been trying to make something cost some hunger but i just cant do it, and now i started to doubt its actually possible. Mainly due to the fact everything else works, ive tried health sanity flint etc but hunger is the only thing that wont work. sois it possible to make recipes cost hunger? and if so how? 

Question 2

So ive really taken up an interest in leveling characters but i just seem to be too incompetent to be able to do it, i tried doing it myself but that didnt work out at all. so i tried taking other people's mods and taking their leveling systems but i can never make it work so obviously im missing some kind of knowledge to make this work. on top of that im more interested in leveling up off of killing but it always either crashes or sometimes runs completely fine except it wont level up. of course i tried to fix the things the crash message was pointing out but it always would get to a point where things they never pointed out to starts becoming an issue like some things that worked completely fine before would start getting the error "inst is missing a variable" and i just deleted the line to see what happens and then now the next line says the exact same thing. also is it possible to get a Summoned thing a level up system?? this is something i REALLY want to do and hoping its possible.

just in case ur wondering, im trying to make a (low dmg)mob master type of character who summons bunch of  1 hp weaklings who gets tiny buffs per kill and costs some hunger to summon.(hunger instead of sanity because i made the character have 2xhunger rate so that i have hunger problems, so by making the summons costs hunger i thought that would be an effective way to not make it op by making the player restrain from spam summoning as much).well that and also if i go with sanity cost, my friend use a mod character all about helping teammates with sanity, making it op.  i know its probably beyond my reach and i should be working on more simple things but i have always been looking through all the scripts of the mods i use and sometimes changing them up a little.

Also just in case u refuse to help me because it seems like im seeking for results with no hard work applied to it(and thats fine ofc, since getting upset over that in unfair of me). I just want to tell u that i too have been trying to do these scripts myself for some time. i honestly dont know if this is much in ur eyes or how long an average person works on for a mod but i too have been trying these scripts for the past 4+ days (since im on break) and i have added 80+ hours of gameplay on dst from only testing if my scripts work or not(lvl sys and hunger cost mainly) .and then after some hesitation on if i should go the forums(for the first time) or continue my script, test, eat, bit of sleep routine, i decided to rely on someone.

Question 3

tbh i didnt even work on this yet and dont know how hard it is compared to others but ive seen some mods out there with things i need here and there so im pretty sure its possible and im planning on making a character like it once im done with the current one. i realize its not a good habit to ask before trying or putting any work into it yet but i thought i might as well get help while im asking questions about the other things. I want to make a sword that gains bit of strength per kills and cost hp to per hit. i think i can do the latter myself but not too sure about upgrading/leveling weapons. so I would like help on applying  i guess u would call it a level up system once again but for weapons.

well considering im still a noob(?) at this i still have plenty of questions on some things from what ive seen in other mods.... abilities, transformations ,key binding on abilties/transfromation etc but i guess that will make this already too long topic(?, msg?question?idk what people call forum's first msg/topic/question  sorry) even longer. I realize i put way too many worthless information u guys probably dont care about or even find a nuisance but i just didnt want to represent myself as someone purposely rude or something along the line. also if anyone can give me tips on how i can learn how to script better or figure out how to do things or rules in it or anythings like that i would love any advice.  but ofc if this is the kind of thing where u cant really get advice for and have to stack experience through self learning, thats completely fine. i was just hoping if there is any tricks/things i should look out for or a set of rules it will always follow so that i can maybe figure more things out myself more often
 

Link to comment
Share on other sites

Question 1 Im still not too good at scripting and my knowledge is very limited so i would like some help...I wanted to know if it's possible to make a custom item with a custom recipe that costs HUNGER. ive been trying to make something cost some hunger but i just cant do it, and now i started to doubt its actually possible. Mainly due to the fact everything else works, ive tried health sanity flint etc but hunger is the only thing that wont work. sois it possible to make recipes cost hunger? and if so how?

 

Hunger isn't implemented as a character ingredient.

There's an image for it though, and we can use it.

 

modmain.lua:

local AllRecipes = GLOBAL.AllRecipeslocal CHARACTER_INGREDIENT = GLOBAL.CHARACTER_INGREDIENTlocal RECIPETABS = GLOBAL.RECIPETABSlocal require = GLOBAL.requirelocal STRINGS = GLOBAL.STRINGSlocal TECH = GLOBAL.TECH-- The basics for the recipe to work-- The character ingredient-- decrease_hunger.tex is a valid image in inventoryimages.xmlCHARACTER_INGREDIENT.HUNGER = "decrease_hunger"-- The nameSTRINGS.NAMES.DECREASE_HUNGER = "Hunger"-- The server builder functionalitylocal function NewIngredientConsume(self)	-- The consumption	local _RemoveIngredients = self.RemoveIngredients	self.RemoveIngredients = function(self, ingredients, recname)		local recipe = AllRecipes[recname]		if recipe then			for k, v in pairs(recipe.character_ingredients) do				if v.type == CHARACTER_INGREDIENT.HUNGER then					self.inst.components.hunger:DoDelta(-v.amount)				end			end		end		_RemoveIngredients(self, ingredients, recname)	end	-- The value checking	local _HasCharacterIngredient = self.HasCharacterIngredient	self.HasCharacterIngredient = function(self, ingredient)		if ingredient.type == CHARACTER_INGREDIENT.HUNGER then			if self.inst.components.hunger ~= nil then				local current = math.ceil(self.inst.components.hunger.current)				return current >= ingredient.amount, current			end		end		return _HasCharacterIngredient(self, ingredient)	endendAddComponentPostInit("builder", NewIngredientConsume)-- The client builder functionalitylocal builder_replica = require("components/builder_replica")local __HasCharacterIngredient = builder_replica.HasCharacterIngredientfunction builder_replica:HasCharacterIngredient(ingredient)    if self.inst.components.builder ~= nil then        return self.inst.components.builder:HasCharacterIngredient(ingredient)    elseif self.classified ~= nil then        if ingredient.type == CHARACTER_INGREDIENT.HUNGER then            local hunger = self.inst.replica.hunger            if hunger ~= nil then                local current = math.ceil(hunger:GetCurrent())                return current >= ingredient.amount, current            end        end    end    return __HasCharacterIngredient(self, ingredient)end-- Our test recipe, meat on the refine tablocal myrecipe = AddRecipe("meat",{Ingredient(CHARACTER_INGREDIENT.HUNGER, 20)},RECIPETABS.REFINE, TECH.NONE)myrecipe.sortkey = 0STRINGS.RECIPE_DESC.MEAT = "Turn hunger into food."
Link to comment
Share on other sites

Question 2, it is all possible, but we need something more specific.

 

Question 3, characters get an event pushed when they kill stuff, so they must interact with the weapon in order to upgrade it.

 

modmain.lua:

local function IsValidVictim(victim)	return victim ~= nil		and not (victim:HasTag("prey") or				victim:HasTag("veggie") or				victim:HasTag("structure") or				victim:HasTag("wall") or				victim:HasTag("companion"))		and victim.components.health ~= nil		and victim.components.combat ~= nilendlocal function onkilled(inst, data)	local victim = data.victim	if IsValidVictim(victim) then		local weapon = inst.components.combat:GetWeapon()		if weapon and weapon:HasTag("exp_weapon") then			weapon.killcount = weapon.killcount + 1			weapon:applyupgrades()		end	endendlocal function ShareKillsWithWeapon(inst)	if not GLOBAL.TheWorld.ismastersim then		return	end	inst:ListenForEvent("killed", onkilled)endAddPlayerPostInit(ShareKillsWithWeapon)GLOBAL.STRINGS.NAMES.EXP_SPEAR = "Experience Spear"

I borrowed stuff from Wigfrid so when you kill something, you up the killcount and apply upgrades on your weapon, if you have one and it has the exp_weapon tag.

 

exp_spear.lua:

local assets = {	Asset("ANIM", "anim/spear.zip"),	Asset("ANIM", "anim/swap_spear.zip"),}local function onequip(inst, owner)	owner.AnimState:OverrideSymbol("swap_object", "swap_spear", "swap_spear")	owner.AnimState:Show("ARM_carry")	owner.AnimState:Hide("ARM_normal")endlocal function onunequip(inst, owner)	owner.AnimState:Hide("ARM_carry")	owner.AnimState:Show("ARM_normal")endlocal function applyupgrades(inst)    local max_upgrades = 15    inst.killcount = math.min(inst.killcount, max_upgrades)    inst.components.weapon:SetDamage((inst.killcount + 1) * TUNING.SPEAR_DAMAGE)endlocal function onattack(inst, attacker, target)	attacker.components.health:DoDelta(-2, true, "exp_spear")endlocal function OnSave(inst, data)	data.killcount = inst.killcountendlocal function OnLoad(inst, data)	if data then		inst.killcount = data.killcount or 0		applyupgrades(inst)	endendlocal function fn()    local inst = CreateEntity()    inst.entity:AddTransform()    inst.entity:AddAnimState()    inst.entity:AddNetwork()    MakeInventoryPhysics(inst)    inst.AnimState:SetBank("spear")    inst.AnimState:SetBuild("spear")    inst.AnimState:PlayAnimation("idle")	inst:AddTag("exp_weapon")    inst:AddTag("sharp")    inst.entity:SetPristine()    if not TheWorld.ismastersim then        return inst    end    inst:AddComponent("equippable")    inst.components.equippable:SetOnEquip(onequip)    inst.components.equippable:SetOnUnequip(onunequip)    inst:AddComponent("finiteuses")    inst.components.finiteuses:SetMaxUses(TUNING.SPEAR_USES)    inst.components.finiteuses:SetUses(TUNING.SPEAR_USES)    inst.components.finiteuses:SetOnFinished(inst.Remove)    inst:AddComponent("inspectable")    inst:AddComponent("inventoryitem")	inst.components.inventoryitem.imagename = "spear"    inst:AddComponent("weapon")    inst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE)	inst.components.weapon:SetOnAttack(onattack)	inst.killcount = 0	applyupgrades(inst)	inst.OnSave = OnSave	inst.OnLoad = OnLoad	inst.applyupgrades = applyupgrades    return instendreturn Prefab("exp_spear", fn, assets)

A spear that updates its damage based on its killcount number.

inst.killcount and inst.applyupgrades make it easy to access these methods from outside the file, like from modmain.

Each kill gives the spear the strength of a spear, so with 15 kills you got a spear 15 times stronger than a spear.

 

Also, on attack, your hp drains.

Link to comment
Share on other sites

DarkXero

 

Thank you very much, I didnt read too deeply on the question 2 and 3 answers yet but the first one worked perfectly for me. i also wanted to ask about the perishing if u dont mind me asking... I suddenly started getting a problem on the minions, i been doing the same thing as before but they stareted dying as soon as night time reached regardles of what tiem of day i made them. so i made the perish thing on slow as a placeholder but i wanted to know if i can make the perish rate to like NONE or if there is a fix to this? 

Edited by PetDollofMonsters
Link to comment
Share on other sites

Im sorry darkxero... i think i just accidentally sent u a Private msg. anyways thank you very much for your help and can u also help me on what i said in the PM? also i saw a like tab beside ur msg so i clicked it assuming it gives you a good rep or something like that so i hope that would do good to u.

sorry if i confused u darkxero.. i didnt know admins gives delay on my posts so i assumed i gave u  a pm or something like that >_<(this is an edit)

Edited by PetDollofMonsters
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...