Jump to content

Recommended Posts

Hello, everyone! I'd like to make a craftable follower using a creature I have (that works properly). But first things first : I can't make him appear.

Right now this is the code I have in the modmain :

-- Make a Wurm
local Ingredient = GLOBAL.Ingredient
local af_rec = AddRecipe("wurm_thibaud", 
{Ingredient("cutgrass", 1), Ingredient("berries", 1)}, 
GLOBAL.RECIPETABS.SURVIVAL, GLOBAL.TECH.NONE, 
nil, nil, nil, nil, "wurm_thibaud_builder",
"images/inventoryimages/pencil_thibaud.xml", "pencil_thibaud.tex")
af_rec.sortkey = -3

and I added the right tag for my character to be able to craft this mob. And I do get the crafting in-game. Unfotunately, the crafting only takes up the ressources without any creature appearing. Does anyone know how to make this work? Maybe the problem is the game doesn't know where to spawn the creature and therefore something should be changed in its prefab's lua?

 

Edit: I'd like to point out that the creature does appear when using the console, in case anyone was wondering about that.

Edited by Thibooms

I haven't tested it and took DarkXero's code as example from another post:

-- wurm.lua

local function onbuilt(inst, builder)
	inst.Transform:SetPosition(builder.Transform:GetWorldPosition())
end

-- in the main function

inst.OnBuiltFn = onbuilt

 

28 minutes ago, Aquaterion said:

I haven't tested it and took DarkXero's code as example from another post:


-- wurm.lua

local function onbuilt(inst, builder)
	inst.Transform:SetPosition(builder.Transform:GetWorldPosition())
end

-- in the main function

inst.OnBuiltFn = onbuilt

 

Great! That works!

I was actually using this from maxwell : (but it didn't work)

local function onbuilt(inst, builder)
    local theta = math.random() * 2 * PI
    local pt = builder:GetPosition()
    local radius = math.random(3, 6)
    local offset = FindWalkableOffset(pt, theta, radius, 12, true)
    if offset ~= nil then
        pt.x = pt.x + offset.x
        pt.z = pt.z + offset.z
    end
    builder.components.petleash:SpawnPetAt(pt.x, 0, pt.z, inst.pettype)
    inst:Remove()
end

 

Just now, Thibooms said:

Great! That works!

I was actually using this from maxwell : (but it didn't work)


local function onbuilt(inst, builder)
    local theta = math.random() * 2 * PI
    local pt = builder:GetPosition()
    local radius = math.random(3, 6)
    local offset = FindWalkableOffset(pt, theta, radius, 12, true)
    if offset ~= nil then
        pt.x = pt.x + offset.x
        pt.z = pt.z + offset.z
    end
    builder.components.petleash:SpawnPetAt(pt.x, 0, pt.z, inst.pettype)
    inst:Remove()
end

 

well that 1 removes the inst at the end, because it has a "placer" prefab as well for some reason

Just now, Aquaterion said:

well that 1 removes the inst at the end, because it has a "placer" prefab as well for some reason

Ok :) 

 

Do you also know anything about maxwell's pet leash? I've been trying to apply it to my character and creature

Edited by Thibooms
Just now, Aquaterion said:

you'd have to add the component petleash to every character. You're probably better off making it a follower, since all characters have the "leader" component for it, if making it a follower is what you're looking for

Yeah but the really attractive thing is that with the petleash component it seems like you can set the max amount of pets. Unless there's an easier way... ^^'

 

Also, how do you make the creature follow you once it's been crafted?

1 minute ago, Thibooms said:

Yeah but the really attractive thing is that with the petleash component it seems like you can set the max amount of pets. Unless there's an easier way... ^^'

 

Also, how do you make the creature follow you once it's been crafted?

you'd have to make the builder it's leader, and to actually follow you have to add it to the brain

Edit: Technically you could add the petleash component to the builder when you build it, making sure that he doesn't have it first but it wouldn't work with maxwell I believe as petleash seems to be for characters that can spawn their own certain "creature".

Edited by Aquaterion
1 minute ago, Aquaterion said:

you'd have to make the builder it's leader, and to actually follow you have to add it to the brain

I think the brain is ok for following. I'm not quite clear how to make the builder its leader. But I'm asking a lot from you right now so if you know any files I could look at I'll probably find my way :)

 

Wait one second, maybe this will work in the onbuild function (found it from another mod)

data.builder.components.leader:AddFollower(inst, true)

 

Yeah thought so, variable "data" not declared xD... Well, I'm gonna dig some more into that mod and also in the leader's component

Edited by Thibooms
2 minutes ago, Aquaterion said:

in the onbuilt function:


inst.components.follower:SetLeader(builder)
inst.components.follower:StartLeashing() -- makes it teleport to its leader and such

and in the main function of the creature put


inst:AddComponent("follower")

 

Awesome! :D

I'm thinking now I should really look into the follower component... ^^'

 

Any way to limit the amount I can craft as well? (But seriously, take a break first, you're so helpful all the time ^^)

6 minutes ago, Thibooms said:

Awesome! :D

I'm thinking now I should really look into the follower component... ^^'

 

Any way to limit the amount I can craft as well? (But seriously, take a break first, you're so helpful all the time ^^)

im not sure if this would work, but maybe you could try this; (BTW if it does work, it would only work if you lose your followers on log out)

modmain.lua

AddPlayerPostInit(function(inst) if not inst:HasTag("wurmcrafter") then inst:AddTag("wurmcrafter") end end)

--also change the recipe to require this tag to be crafted

then in the onbuilt function

if builder:CountFollowers("wurm") >= 4 then -- inst:AddTag("wurm") to the creature
	builder:RemoveTag("wurmcrafter")
end

And that way, if recipe tag requirement updates how I think it does, then that should not allow you to craft more when you have 4 or more.

Edited by Aquaterion
15 minutes ago, Aquaterion said:

im not sure if this would work, but maybe you could try this; (BTW if it does work, it would only work if you lose your followers on log out)

I want to make me lose them when logging out, in fact in that case I want them to despawn. :)

 

I will try this in a while, thanks! :D

8 minutes ago, Aquaterion said:

my bad it's builder.components.leader:CountFollowers("wurm") not builder:Countfollowers("wurm")

Ok thanks that works! :D

 

Now, how do I do the opposite? When one of these guys get killed I should get the tag allowing me to build back.

I tried this but it doesn't work :

if builder.components.leader:CountFollowers("wurm") >= 4 then -- inst:AddTag("wurm") to the creature
        builder:RemoveTag("wurm_thibaud_builder")
    else
        builder:AddTag("wurm_thibaud_builder")
end

 

Edited by Thibooms
6 minutes ago, Thibooms said:

Ok thanks that works! :D

 

Now, how do I do the opposite? When one of these guys get killed I should get the tag allowing me to build back.

I tried this but it doesn't work :


if builder.components.leader:CountFollowers("wurm") >= 4 then -- inst:AddTag("wurm") to the creature
        builder:RemoveTag("wurm_thibaud_builder")
    else
        builder:AddTag("wurm_thibaud_builder")
    end

 

hmm you could try;

--wurm.lua

local function ondeath(inst)
	local leader = inst.components.follower:GetLeader()

	if leader ~= nil then
		local wurms = leader.components.leader:CountFollowers("wurm")

		if not leader:HasTag("wurm_thibaud_builder") and wurms < 4 then
    			leader:AddTag("wurm_thibaud_builder")                                                       
		end
    	end
end

--main function
inst:ListenForEvent("death", ondeath)

 

Edited by Aquaterion
inst:ListenForEvent("death", 
	function()
      local wurmleader = inst.components.follower:GetLeader()

      if wurmleader ~= nil and not wurmleader:HasTag("wurm_thibaud_builder") then
		local wurms = wurmleader.components.leader:CountFollowers("wurm")

		if wurmleader.components.leader:CountFollowers("wurm") < 4 then
			wurmleader:AddTag("wurm_thibaud_builder")
		end
      end
	end)

just put that whole thing in the main function, and remove the stuff i gave you before, srry bout the non organized code, but putting a "<" in the forum code thing **** everything up

Edited by Aquaterion
Just now, Aquaterion said:

just put that whole thing in the main function, and remove the stuff i gave you before, srry bout the non organized code, but putting a "<" in the forum code thing **** everything up

Why did it do that? Maybe I can easily fix it and that way it's less messy :)

At least one reason to use the temporary placer/builder prefab that gets removed, spawning the minion itself, is because if the minion has a lootdropper component, it automatically drops stuff from its recipe, if it has one. By having the recipe for the builder, it avoids that. His minions don't actually have a lootdropper component, though, so perhaps there's another reason I overlooked.

Just now, Thibooms said:

Why did it do that? Maybe I can easily fix it and that way it's less messy :)

huh? its just the indentation, its a forum issue, not something you could fix really, did you try the new code?

I just updated a small fix for it

Edited by Aquaterion
4 minutes ago, Aquaterion said:

I just updated a small fix for it

Yeah I thought it was weird you mixed wurmleader and leader ^^

I'm trying it now! :)

 

4 minutes ago, rezecib said:

At least one reason to use the temporary placer/builder prefab that gets removed, spawning the minion itself, is because if the minion has a lootdropper component, it automatically drops stuff from its recipe, if it has one. By having the recipe for the builder, it avoids that. His minions don't actually have a lootdropper component, though, so perhaps there's another reason I overlooked.

I wish I knew what you're talking about

#Reallybadatcoding #Needtolearnitproperly :'(

Edit:

Nope, doesn't seem to work, sorry

Edited by Thibooms
3 minutes ago, Thibooms said:

Yeah I thought it was weird you mixed wurmleader and leader ^^

I'm trying it now! :)

 

I wish I knew what you're talking about

#Reallybadatcoding #Needtolearnitproperly :'(

Nope, doesn't seem to work, sorry

Basically what he's saying is, when a prefab is destroyed/killed, it will drop some items that its crafted from, so by making a "placer", it puts that drop table on the placer, and leaves the actual prefab untouched.

 

And what didn't work? whats the error?

Edited by Aquaterion
Just now, Thibooms said:

I wish I knew what you're talking about

Lootdropper is a component that controls items being dropped when something is destroyed. It automatically checks if the prefab it's attached to has a recipe, and if so, drops half of the ingredients. So for Maxwell's minions, the example you were using, instead of having a recipe for shadowlumber, it has a recipe for a shadowlumber_builder. In the code you were looking at initially, the idea is that the shadowlumber_builder gets created, spawns a shadowlumber, and then removes itself. This means that (if shadowlumber had a lootdropper component, which it doesn't) when shadowlumber dies, it doesn't try to drop half of the ingredients of its recipe.

If you don't want your wurm to drop half of its recipe on dying, then you should use the same strategy.

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