Jump to content

(Scripting) Looking for code: "check if builder"


Recommended Posts

Well, on the builder component, inside the DoBuild function, you have:

self.onBuild(self.inst, prod)prod.OnBuilt(prod, self.inst)

For both items and structures, that you can define and use.

local function onBuild(inst, prod)   if prod.prefab == "ThisThing" and inst.prefab == "ThisCharacter" then      -do something   else      -do something else   endendAddPlayerPostInit(function(inst)    inst.components.builder.onBuild = onBuildend
Link to comment
Share on other sites

 

Well, on the builder component, inside the DoBuild function, you have:

self.onBuild(self.inst, prod)prod.OnBuilt(prod, self.inst)

For both items and structures, that you can define and use.

local function onBuild(inst, prod)   if prod.prefab == "ThisThing" and inst.prefab == "ThisCharacter" then      -do something   else      -do something else   endendAddPlayerPostInit(function(inst)    inst.components.builder.onBuild = onBuildend

 

Thanks! I think this could work. 

 

On a related note:

local Combatable = GetModConfigData("Combatable ")local function RemoveCombatable(inst, doer)   -- maybe doer here?	if inst and inst.components.combat and (Combatable == 1) then--error--->>>>	if doer:HasTag("player") then		inst:RemoveComponent('combat')		end			endend

Any idea what the other:HasTag("player") then should be here? it works fine except for that bit. Its likely something simple but my brain is on standby mode and i can't figure it out.

I've had something similar working before so i know it's almost right..

I think it's like doer or actions maybe.

 

context: I'm trying to make a placed item unattackable by players, but still attackable by monsters.

Edited by Mertaan
Link to comment
Share on other sites

Because there is no "other" variable.

If you remove the combat component then nothing will destroy it unless it's workable.

 

Instead of removing combat, you will have to edit something from combat or combat_replica, like:

AddComponentPostInit("combat_replica", function(self)   local old = self.CanBeAttacked   function self:CanBeAttacked(attacker)      if self.inst:HasTag("MyModTag") and attacker:HasTag("player") then         return false      end      old(self, attacker)   endend)

But I take you don't want to make things not attackable, you want to make them non hammerable, yes?

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