Jump to content

Requesting Help For Writing A Code


pwhampton

Recommended Posts

Almost done with this character of mine, but I have no idea how to go about creating her unique power. Basically if she does not have enough nightmare fuel to create an item then she will use 20 hunger to make up for any missing nightmare fuel needed to complete the recipe. If I do have the fuel, then it will use that up first before converting my hunger. Example: I have one living log in my inventory. So I create a nightmare sword with the 1 living log and loose 100 hunger since I had no nightmare fuel.

 

I think one way to try to get this working is to have it check the recipe I am using, compare the amount of fuel it needs to the amount in my inventory, and then attempt to have it fill in the missing fuel for 20 hunger each. (I am a bad programmer so I am just assuming here.)

 

Would this idea be even possible to pull off using the method described or a different approach? If so, what would I need to use to create a working code?

 

And thanks to anyone willing to assist me.

Link to comment
Share on other sites

This would certainly be doable, but I would suggest a compromise. Instead of automatically draining 20 sanity per thingy, I would recommend you just have a character-unique recipe that creates 1 nightmare fuel for 20 hunger. This would be much less intrusive into the functions of the game, which means you won't have to worry about maintaining the code between updates.

 

If you're happy with that, I can contribute the code.

Link to comment
Share on other sites

This would certainly be doable, but I would suggest a compromise. Instead of automatically draining 20 sanity per thingy, I would recommend you just have a character-unique recipe that creates 1 nightmare fuel for 20 hunger. This would be much less intrusive into the functions of the game, which means you won't have to worry about maintaining the code between updates.

 

If you're happy with that, I can contribute the code.

 

Figured I would have to make a custom recipe, main reason I wanted to avoid that was because it felt more broken then having to create the item then and there.

 

As for the code, I would appreciate a simple guide on what I should do and not just a copy paste solution, trying to learn this whole coding thing, thanks!

Link to comment
Share on other sites

Figured I would have to make a custom recipe, main reason I wanted to avoid that was because it felt more broken then having to create the item then and there.

 

As for the code, I would appreciate a simple guide on what I should do and not just a copy paste solution, trying to learn this whole coding thing, thanks!

Problem here, @pwhampton, is that there is no simple guide to modding most things.  It's usually trial and error, even if you know what you're doing.  It usually quicker for someone who even knows how to do it, to just supply the code and tell you where it goes.

 

The best advice is what you probably already know: Dig into existing mods that do something similar. Learn how they actually function and then you can take baby steps to creating your own.  Then, when you get to a stumbling block, stop in and they'll be folks glad to help you.

 

When people come and ask to be taught.. well, that's a lot to ask and also why they have teachers teaching this stuff.  Takes weeks and months to know your way around it.

Link to comment
Share on other sites

Put the following inside the local fn function in your character prefab file:

        STRINGS.TABS.HUNGERFORNIGHTMAREFUEL = "Nightmare Fuel"    local booktab = {str = STRINGS.TABS.HUNGERFORNIGHTMAREFUEL, sort=999, icon = "tab_book.tex"}    inst.components.builder:AddRecipeTab(booktab)    local temprecipeX = Recipe( "hungerfornightmarefuel", {}, booktab, {})    temprecipeX.image = "nightmarefuel.tex"    STRINGS.NAMES.HUNGERFORNIGHTMAREFUEL = "Nightmare Fuel"    STRINGS.RECIPE_DESC.HUNGERFORNIGHTMAREFUEL = "Exchange Hunger for Nightmare Fuel"

then create a new file in your mod/scripts/prefabs/ folder called hungerfornightmarefuel.lua and put this code in

require "prefabutil"local assets ={}local function fn(Sim)    local inst = CreateEntity()    inst.entity:AddTransform()    if GetPlayer() and GetPlayer().components.hunger.current < 20 then        GetPlayer().components.talker:Say("I'm too hungry to do that!")    end    if GetPlayer() and GetPlayer().components.hunger.current >= 20 then        local nightmarefuelinst = SpawnPrefab("nightmarefuel")        local GetPlayerInst = GetPlayer()        GetPlayerInst.components.inventory:GiveItem(nightmarefuelinst, nil, TheInput:GetScreenPosition())        GetPlayerInst:PushEvent("builditem", {item=nightmarefuelinst, recipe = GetRecipe("hungerfornightmarefuel")})        GetPlayerInst.components.hunger:DoDelta(-20)            end    inst:DoTaskInTime(0.01, function () inst:Remove() end)    return instendreturn Prefab( "common/objects/hungerfornightmarefuel", fn, assets)

finally make sure you add hungerfornightmarefuel to your PrefabFiles table in modmain.lua

"hungerfornightmarefuel",
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...