giabao1107 Posted July 9, 2023 Share Posted July 9, 2023 (edited) Hi guys, I made a mod which add 3 more book to WKBT's book collection. There was no problem with 2 previous book. But the third book, whick ability is summing meteor, has one. I can't read it while playing wickerbottom. Here is the lua file of that book. local assets = { Asset("ANIM", "anim/book_meteor.zip"), Asset("ANIM", "anim/swap_book_meteor.zip"), } local function SpawnMeteor(inst, target) local x, y, z = target.Transform:GetWorldPosition() local meteor = SpawnPrefab("shadowmeteor") meteor.Transform:SetPosition(x, y, z) end local function OnRead(inst, reader) if reader.components.sanity ~= nil then reader.components.sanity:DoDelta(-50) end local pt = inst:GetPosition() local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, 4, nil, nil, { "shadowmeteor" }) local count = 0 for i, ent in ipairs(ents) do ent:Remove() count = count + 1 end for i = 1, 16 - count do local pos = FindWalkableOffset(pt, math.random() * 2 * PI, math.random() * 4, 8, true, true) if pos ~= nil then local x, y, z = pt.x + pos.x, pt.y + pos.y, pt.z + pos.z local meteor = SpawnPrefab("shadowmeteor") meteor.Transform:SetPosition(x, y, z) end end end local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("book_meteor") inst.AnimState:SetBuild("book_meteor") inst.AnimState:PlayAnimation("book_meteor") inst:AddTag("book") inst:AddTag("bookcabinet_item") inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "book_meteor" inst.components.inventoryitem.atlasname = "images/images_meteor.xml" inst:AddComponent("finiteuses") inst.components.finiteuses:SetMaxUses(TUNING.USES_BOOK) inst.components.finiteuses:SetUses(TUNING.USES_BOOK) inst.components.finiteuses:SetOnFinished(inst.Remove) inst:AddComponent("fuel") inst.components.fuel.fuelvalue = TUNING.MED_FUEL MakeSmallBurnable(inst, TUNING.MED_BURNTIME) MakeSmallPropagator(inst) MakeHauntableLaunch(inst) return inst end return Prefab("book_meteor", fn, assets) Edited July 9, 2023 by giabao1107 Link to comment https://forums.kleientertainment.com/forums/topic/149231-wickerbottom-cant-read-my-mod-book/ Share on other sites More sharing options...
Haruhi Kawaii Posted July 10, 2023 Share Posted July 10, 2023 10 hours ago, giabao1107 said: Hi guys, I made a mod which add 3 more book to WKBT's book collection. There was no problem with 2 previous book. But the third book, whick ability is summing meteor, has one. I can't read it while playing wickerbottom. Here is the lua file of that book. local assets = { Asset("ANIM", "anim/book_meteor.zip"), Asset("ANIM", "anim/swap_book_meteor.zip"), } local function SpawnMeteor(inst, target) local x, y, z = target.Transform:GetWorldPosition() local meteor = SpawnPrefab("shadowmeteor") meteor.Transform:SetPosition(x, y, z) end local function OnRead(inst, reader) if reader.components.sanity ~= nil then reader.components.sanity:DoDelta(-50) end local pt = inst:GetPosition() local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, 4, nil, nil, { "shadowmeteor" }) local count = 0 for i, ent in ipairs(ents) do ent:Remove() count = count + 1 end for i = 1, 16 - count do local pos = FindWalkableOffset(pt, math.random() * 2 * PI, math.random() * 4, 8, true, true) if pos ~= nil then local x, y, z = pt.x + pos.x, pt.y + pos.y, pt.z + pos.z local meteor = SpawnPrefab("shadowmeteor") meteor.Transform:SetPosition(x, y, z) end end end local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("book_meteor") inst.AnimState:SetBuild("book_meteor") inst.AnimState:PlayAnimation("book_meteor") inst:AddTag("book") inst:AddTag("bookcabinet_item") inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "book_meteor" inst.components.inventoryitem.atlasname = "images/images_meteor.xml" inst:AddComponent("finiteuses") inst.components.finiteuses:SetMaxUses(TUNING.USES_BOOK) inst.components.finiteuses:SetUses(TUNING.USES_BOOK) inst.components.finiteuses:SetOnFinished(inst.Remove) inst:AddComponent("fuel") inst.components.fuel.fuelvalue = TUNING.MED_FUEL MakeSmallBurnable(inst, TUNING.MED_BURNTIME) MakeSmallPropagator(inst) MakeHauntableLaunch(inst) return inst end return Prefab("book_meteor", fn, assets) You forgot to add component book Spoiler inst:AddComponent("book") inst.components.book:SetOnRead(OnRead) Link to comment https://forums.kleientertainment.com/forums/topic/149231-wickerbottom-cant-read-my-mod-book/#findComment-1648397 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now