Jump to content

Few questions


Recommended Posts

1. How to use target/self variables in mod? Got something like this 

	if (target:HasTag("tag")) then
	inst.components.combat:SetDefaultDamage(TUNING.DAMAGE*.1)

When i run it, it says target not defined or something like that. The idea is that it checks if the target has a specific tag, i can edit it to take more or less damage

2. How do i make trees/workable things drop different things? I tried many ways using lootdropper to make trees drop extra items but it never worked and always drops the default items. I can only do it by copying and editing the file into the mod file but that takes up space. Trying to learn how to do it in modmain

3. How edit crockpot recipes without having to copying and editing it like in my previous question (like change ingredient requirements to need less meat for example)

This is all vanilla stuff I'm trying to change, not custom mod items by the way

Link to comment
Share on other sites

On 5/23/2022 at 4:50 AM, jk68 said:

1. How to use target/self variables in mod? Got something like this 


	if (target:HasTag("tag")) then
	inst.components.combat:SetDefaultDamage(TUNING.DAMAGE*.1)

When i run it, it says target not defined or something like that. The idea is that it checks if the target has a specific tag, i can edit it to take more or less damage

I think you need to see some of the basics about programming, object orientation and lua in general. Where does "target" come from? What is it? The game doesn't understand what you want to do.

 

On 5/23/2022 at 4:50 AM, jk68 said:

2. How do i make trees/workable things drop different things? I tried many ways using lootdropper to make trees drop extra items but it never worked and always drops the default items. I can only do it by copying and editing the file into the mod file but that takes up space. Trying to learn how to do it in modmain

You can use the AddChanceLoot lootdropper component method to add a new chance-based loot, for example.

-- Add something to the Rock Boulder prefab after his construction. AddPrefabPostInit(prefab_name, function)
AddPrefabPostInit("rock1", function(inst)
    -- Add 50% of change of dropping a twig from Rock Boulder. AddChanceLoot(prefab_name, chance)
      inst.components.lootdropper:AddChanceLoot("twigs", 0.5)
end)

This is a simple example. The trees, in case, change their loot at each stage, and this should be taken into account, you will need to better understand how to use the AddPrefabPostInit, and "Hook" the functions that set these loots.

 

On 5/23/2022 at 4:50 AM, jk68 said:

3. How edit crockpot recipes without having to copying and editing it like in my previous question (like change ingredient requirements to need less meat for example)

The scripts/preparedfoods.lua file returns a table with everything needed to build the crockpot foods, so you can edit it using GLOBAL.require("preparedfoods")

Tables, in lua, are referential, when you assign it to a variable, like:
local foods = GLOBAL.require("preparedfoods")

All changes will be made directly to the original table, you don't create a copy of it, as with functions and variables.

The ingredients for each recipe are defined in: GLOBAL.require("preparedfoods")["recipe_name"].test

Test is a function that checks ingredients and determines if food can be cooked with them.

test = function(cooker, names, tags)
cooker = player
names = ingredients
tags = ingredients tags

 

I hope it helps.

Link to comment
Share on other sites

thanks for the help. i was able to implement the solutions except for 1 as I solved it by adding a immune tag. 

To avoid making another topic post, I have another question, how would one add or replace a preset loot table? To explain further, I am trying to edit the trawlnet prefab so that I can increase chance/add new items. In my modmain it looks like this

AddPrefabPostInit("trawlnet", function(inst)
--chance table
local loot =
{
--added this loot file which should only spawn manure foor testing, but it always skips and only spawns shallow loot
    mangrove =
    {
        {"manure", chance.high},
    },
--the rest is the shallow, med, deep loot from the prefab and i also put the dryloot and hurricaneloot just in case...

local function GetLootList(inst)
    local loottable = loot
--season checker code
    local pos = GetPlayer():GetPosition()
    local ground = GetWorld()
    local tile = GROUND.OCEAN_SHALLOW
    if ground and ground.Map then
        tile = ground.Map:GetTileAtPoint(pos:Get())
    end
--for the getlootlist function from the prefab, I added this so it checks the tile and gets the custom loot
    elseif tile == GROUND.MAGROVE then
        return loottable.mangrove
    else 
	return loottable.shallow
    end
end
end)

I commented out much as i basically took code from the trawlnet prefab and I just tried adding a new loot table and the tile checker to get the table. The game seems to run it properly and doesn't crash but in game, it generates shallow loot. 

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...