Jump to content

Changing prototyper.trees


Recommended Posts

I'm trying to make prototyper, that will be able to change prototyper.trees, but if it's activeted, game crashes with 

[00:00:45]: [string "scripts/components/builder.lua"]:191: attempt to index field 'accessible_tech_trees' (a function value)
LUA ERROR stack traceback:
scripts/components/builder.lua:191 in (method) EvaluateTechTrees (Lua) <135-243>
   self =
      exclude_tags = table: 4F6DDBB0
      buffered_builds = table: 4F6DDB88
      recipes = table: 4F6DD7C8
      station_recipes = table: 5503ED20
      bonus_tech_level = 0
      accessible_tech_trees = function - ../mods/Bo energy/scripts/prefabs/researchlab_1.lua:157
      inst = 108359 - wilson (valid:true)
      _ = table: 4F6DD228
      current_prototyper = 105105 - researchlab_1 (valid:true)
   pos = (-11.85, -0.00, -347.55)
   ents = table: 5503D998
   old_accessible_tech_trees = table: 5503E190
   old_station_recipes = table: 0E69F698
   old_prototyper = nil
   prototyper_active = true
scripts/components/builder.lua:108 in (method) OnUpdate (Lua) <107-109>
   self =
      exclude_tags = table: 4F6DDBB0
      buffered_builds = table: 4F6DDB88
      recipes = table: 4F6DD7C8
      station_recipes = table: 5503ED20
      bonus_tech_level = 0
      accessible_tech_trees = function - ../mods/Bo energy/scripts/prefabs/researchlab_1.lua:157
      inst = 108359 - wilson (valid:true)
      _ = table: 4F6DD228
      current_prototyper = 105105 - researchlab_1 (valid:true)
scripts/update.lua:187 in () ? (Lua) <150-223>
   dt = 0.033333335071802
   tick = 229
   k = 108359
   v = 108359 - wilson (valid:true)
   cmp = table: 4F6DD0E8

[00:00:45]: [string "scripts/components/builder.lua"]:191: attempt to index field 'accessible_tech_trees' (a function value)
LUA ERROR stack traceback:
    scripts/components/builder.lua:191 in (method) EvaluateTechTrees (Lua) <135-243>
    scripts/components/builder.lua:108 in (method) OnUpdate (Lua) <107-109>
    scripts/update.lua:187 in () ? (Lua) <150-223>

I realy now don't know what to do... Need some help! myprefab.lua is here

require "prefabutil"

local function isgifting(inst)
    for k, v in pairs(inst.components.prototyper.doers) do
        if k.components.giftreceiver ~= nil and
            k.components.giftreceiver:HasGift() and
            k.components.giftreceiver.giftmachine == inst then
            return true
        end
    end
end

local function onhammered(inst, worker)
    if inst.components.burnable ~= nil and inst.components.burnable:IsBurning() then
        inst.components.burnable:Extinguish()
    end
    inst.components.lootdropper:DropLoot()
    local fx = SpawnPrefab("collapse_small")
    fx.Transform:SetPosition(inst.Transform:GetWorldPosition())
    fx:SetMaterial("wood")
    inst:Remove()
end

local function onhit(inst)
    if not inst:HasTag("burnt") and not inst.components.bo_powered:IsEmpty() then
        inst.AnimState:PlayAnimation("hit")
        if inst.components.prototyper.on then
            inst.AnimState:PushAnimation(isgifting(inst) and "proximity_gift_loop" or "proximity_loop", true)
        else
            inst.AnimState:PushAnimation("idle", false)
        end
    end
end

local function doonact(inst, soundprefix)
    if inst._activecount > 1 then
        inst._activecount = inst._activecount - 1
    else
        inst._activecount = 0
        inst.SoundEmitter:KillSound("sound")
    end
    inst.SoundEmitter:PlaySound("dontstarve/common/researchmachine_lvl1_ding")
end

local function onturnoff(inst)
    if inst._activetask == nil and not inst:HasTag("burnt") and not inst.components.bo_powered:IsEmpty() then
        inst.AnimState:PushAnimation("idle", false)
        inst.SoundEmitter:KillSound("idlesound")
        inst.SoundEmitter:KillSound("loop")
    end
end

local function onsave(inst, data)
    if inst:HasTag("burnt") or (inst.components.burnable ~= nil and inst.components.burnable:IsBurning()) then
        data.burnt = true
    end
end

local function onload(inst, data)
    if data ~= nil and data.burnt then
        inst.components.burnable.onburnt(inst)
    end
end


local assets =
{
    Asset("ANIM", "anim/researchlab.zip"),
}

local prefabs =
{
    "collapse_small",
}
   local function onturnon(inst)
        if inst._activetask == nil and not inst:HasTag("burnt") and not inst.components.bo_powered:IsEmpty() then
            if isgifting(inst) then
                if inst.AnimState:IsCurrentAnimation("proximity_gift_loop") or
                    inst.AnimState:IsCurrentAnimation("place") then
                    --NOTE: push again even if already playing, in case an idle was also pushed
                    inst.AnimState:PushAnimation("proximity_gift_loop", true)
                else
                    inst.AnimState:PlayAnimation("proximity_gift_loop", true)
                end
                if not inst.SoundEmitter:PlayingSound("loop") then
                    inst.SoundEmitter:KillSound("idlesound")
                    inst.SoundEmitter:PlaySound("dontstarve/common/research_machine_gift_active_LP", "loop")
                end
            else
                if inst.AnimState:IsCurrentAnimation("proximity_loop") or
                    inst.AnimState:IsCurrentAnimation("place") then
                    --NOTE: push again even if already playing, in case an idle was also pushed
                    inst.AnimState:PushAnimation("proximity_loop", true)
                else
                    inst.AnimState:PlayAnimation("proximity_loop", true)
                end
                if not inst.SoundEmitter:PlayingSound("idlesound") then
                    inst.SoundEmitter:KillSound("loop")
                    inst.SoundEmitter:PlaySound("dontstarve/common/researchmachine_lvl1_idle_LP", "idlesound")
                end
            end
        end
    end

    local function refreshonstate(inst)
        --V2C: if "burnt" tag, prototyper cmp should've been removed *see standardcomponents*
        if not inst:HasTag("burnt") and not inst.components.bo_powered:IsEmpty() and inst.components.prototyper.on then
            onturnon(inst)
        end
    end

    local function doneact(inst)
        inst._activetask = nil
        if not inst:HasTag("burnt") and not inst.components.bo_powered:IsEmpty() then
            if inst.components.prototyper.on then
                onturnon(inst)
            else
                onturnoff(inst)
            end
        end
    end

    local function onactivate(inst)
        if not inst:HasTag("burnt") and not inst.components.bo_powered:IsEmpty() then
            inst.AnimState:PlayAnimation("use")
            inst.AnimState:PushAnimation("idle", false)
            if not inst.SoundEmitter:PlayingSound("sound") then
                inst.SoundEmitter:PlaySound("dontstarve/common/researchmachine_lvl1_run", "sound")
            end
            inst._activecount = inst._activecount + 1
            inst:DoTaskInTime(1.5, doonact, "lvl1")
            if inst._activetask ~= nil then
                inst._activetask:Cancel()
            end
            inst._activetask = inst:DoTaskInTime(inst.AnimState:GetCurrentAnimationLength() + 2 * FRAMES, doneact)
        end
    end

    local function ongiftopened(inst)
        if not inst:HasTag("burnt") and not inst.components.bo_powered:IsEmpty() then
            inst.AnimState:PlayAnimation("gift")
            inst.AnimState:PushAnimation("idle", false)
            inst.SoundEmitter:PlaySound("dontstarve/common/researchmachine_science_gift_recieve")
            if inst._activetask ~= nil then
                inst._activetask:Cancel()
            end
            inst._activetask = inst:DoTaskInTime(inst.AnimState:GetCurrentAnimationLength() + 2 * FRAMES, doneact)
        end
    end

    local function onbuilt(inst)
        inst.AnimState:PlayAnimation("place")
        inst.AnimState:PushAnimation("idle", false)
        inst.SoundEmitter:PlaySound("dontstarve/common/researchmachine_lvl1_place")
    end
	
	local function changingtrees(inst)
	if inst.components.bo_powered and inst.components.bo_powered:IsEmpty() then
	changingtrees = TUNING.PROTOTYPER_TREES.CRITTERLAB
	else
	changingtrees = TUNING.PROTOTYPER_TREES.SCIENCEMACHINE
	end
	return changingtrees
	end
	
	

local function fn()
    local inst = CreateEntity()
    local lvl = 1

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddMiniMapEntity()
    inst.entity:AddSoundEmitter()
    inst.entity:AddNetwork()

    MakeObstaclePhysics(inst, .4)

    inst.MiniMapEntity:SetPriority(5)
    inst.MiniMapEntity:SetIcon("researchlab.png")

    inst.AnimState:SetBank("researchlab")
    inst.AnimState:SetBuild("researchlab")
    inst.AnimState:PlayAnimation("idle")

--	if inst.components.bo_powered and inst.components.bo_powered:IsEmpty() then 
 --   inst:RemoveTag("prototyper")
--	else
	inst:AddTag("prototyper")
	--end
	
    inst:AddTag("structure")

    MakeSnowCoveredPristine(inst)
    inst.entity:SetPristine()
	
	inst:AddTag("prototyper")
    inst:AddTag("giftmachine")
    inst:AddTag("structure")
    inst:AddTag("level"..lvl)

    MakeSnowCoveredPristine(inst)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end
	inst._activecount = 0
    inst._activetask = nil
	
	----------------------------------------------
	inst:AddComponent("bo_powered")
	inst.components.bo_powered.type = "output"
	inst.components.bo_powered.period = 1
	inst.components.bo_powered.maxpower = (60)
	inst.components.bo_powered:InitializeFuelLevel(TUNING.PIGTORCH_FUEL_MAX)
	inst.components.bo_powered:StartConsuming()
	--------------------------------------------
	inst:AddComponent("talker")
    inst.components.talker.fontsize = 21
    inst.components.talker.font = TALKINGFONT
    inst.components.talker.colour = Vector3(0.7, 0.85, 1, 1)
    inst.components.talker.offset = Vector3(0,-550,0)
    inst.components.talker.symbol = "swap_object"
	inst.components.bo_powered:StartTalking()
	
    inst:AddComponent("inspectable")
    inst:AddComponent("prototyper")
    inst.components.prototyper.onturnon = onturnon
    inst.components.prototyper.onturnoff = onturnoff
    inst.components.prototyper.trees = changingtrees
	inst.components.prototyper.onactivate = onactivate

    inst:ListenForEvent("onbuilt", onbuilt)

    inst:AddComponent("lootdropper")
    inst:AddComponent("workable")
    inst.components.workable:SetWorkAction(ACTIONS.HAMMER)
    inst.components.workable:SetWorkLeft(4)
    inst.components.workable:SetOnFinishCallback(onhammered)
    inst.components.workable:SetOnWorkCallback(onhit)
    MakeSnowCovered(inst)
	
	inst:AddComponent("wardrobe")
    inst.components.wardrobe:SetCanUseAction(false) --also means NO wardrobe tag!
    inst.components.wardrobe:SetCanBeShared(true)
    inst.components.wardrobe:SetRange(TUNING.RESEARCH_MACHINE_DIST + .1)

    MakeLargeBurnable(inst, nil, nil, true)
    MakeLargePropagator(inst)

    inst.OnSave = onsave 
    inst.OnLoad = onload

    inst:AddComponent("hauntable")
    inst.components.hauntable:SetHauntValue(TUNING.HAUNT_TINY)
	
	inst:ListenForEvent("ms_addgiftreceiver", refreshonstate)
    inst:ListenForEvent("ms_removegiftreceiver", refreshonstate)
    inst:ListenForEvent("ms_giftopened", ongiftopened)

    return inst
end

return Prefab("researchlab_1", fn, assets, prefabs),
    MakePlacer("common/researchlab_1placer", "researchlab_1", "researchlab_1", "idle")

Oh, and if someone'll help me, I'll give em some reward :)

Tuxedo Gloves

Green Sweater Vest

Knee Pants

Blue Sneakers 

  • Like 1
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...