hall123 Posted March 16, 2025 Share Posted March 16, 2025 I'm working on a mod that involves two items: painmagnet and painmagnet_item. Their relationship is similar to eyeturret and eyeturret_item from Houndius Shootius. The issue I'm facing is that when I move painmagnet_item from my inventory with the mouse to build, the displayed text says Plant instead of Build. Additionally, the constructed object is much smaller than expected. The code repository for the mod is here https://github.com/yanghao5/painmagnet Here is the key code snippet . modmain.lua AddRecipe2("painmagnet_item", { Ingredient("nightmarefuel", 5) }, TECH.SCIENCE_ONE, { -- placer = "painmagnet_placer", atlas = "images/inventoryimages/inventoryicon.xml", image = "inventoryicon.tex" }, {"MAGIC"} ) scripts\prefabs.lua -- painmagnet_item ondeploy local function ondeploy(inst, pt, deployer) local structure = SpawnPrefab("painmagnet") if structure then structure.Transform:SetPosition(pt:Get()) inst:Remove() -- Remove the item after deployment end end -- painmagnet_item local function itemfn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) MakeInventoryFloatable(inst) -- inst:AddTag("structure") inst.AnimState:SetBank("painmagnet_item") inst.AnimState:SetBuild("painmagnet_item") inst.AnimState:PlayAnimation("idle") if not TheWorld.ismastersim then return inst end inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "inventoryicon" inst.components.inventoryitem.atlasname = "images/inventoryimages/inventoryicon.xml" inst:AddComponent("deployable") inst.components.deployable.ondeploy = ondeploy inst.components.deployable:SetDeployMode(DEPLOYMODE.ANYWHERE) return inst end -- painmagnet local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeObstaclePhysics(inst, 1) inst:AddTag("structure") inst.AnimState:SetBank("painmagnet") inst.AnimState:SetBuild("painmagnet") inst.AnimState:PlayAnimation("idle") if not TheWorld.ismastersim then return inst end inst:AddComponent("inspectable") inst:AddComponent("workable") inst.components.workable:SetWorkAction(ACTIONS.HAMMER) inst.components.workable:SetWorkLeft(4) -- Takes 4 hammer hits to destroy inst.components.workable.onfinish = function(inst, worker) inst:Remove() -- Simply remove for now; add loot later if desired end return inst end return Prefab("painmagnet_item", itemfn, itemassets), Prefab("painmagnet", fn, assets), MakePlacer("painmagnet_placer", "painmagnet", "painmagnet", "idle") I think the key is the ondeploy function. local function ondeploy(inst, pt, deployer) local structure = SpawnPrefab("painmagnet") if structure then structure.Transform:SetPosition(pt:Get()) inst:Remove() end end I searched the Portable mod and didn't find any useful examples. Does anyone know how to fix it? Or are there any related examples I can refer to? Link to comment https://forums.kleientertainment.com/forums/topic/164902-how-do-i-modify-building-type/ Share on other sites More sharing options...
oregu Posted March 16, 2025 Share Posted March 16, 2025 (edited) You can make your Recipe structures as well {"MAGIC", "STRUCTURES"} Any object with the deployable component has "Plant" as its Action string by default. in STRINGS.ACTIONS Spoiler TOGGLE_DEPLOY_MODE = { GENERIC = "Plant", GROUNDTILE = "Place Ground", WALL = "Build Wall", FENCE = "Build Fence", GATE = "Build Gate", TURRET = "Place", WATER = "Launch", PORTABLE = "Place", DEPLOY = "Deploy", DEPLOY_TOSS = "Toss", FERTILIZE_GROUND = "Fertilize Plot", }, If these magnets are similar to the turrets I highly recommend using "Place" instead because of multi-language and consistency. The way you do this is inst:AddTag"deploykititem". If you want to make it "Build" still, you can do something like (untested): Spoiler GLOBAL.STRINGS.ACTIONS.TOGGLE_DEPLOY_MODE.CONSTRUCTED_TURRET = "Build" DEPLOY_strfn_old = GLOBAL.ACTIONS.DEPLOY.strfn GLOBAL.ACTIONS.DEPLOY.strfn = function(act, ...) if act.invobject and act.invobject:HasTag"builtturret" then -- "builtturret" is a new tag return "CONSTRUCTED_TURRET" end return DEPLOY_strfn_old(act, ...) end To change size of an object, you can do something like: Spoiler local SCALE = x -- in units. for reference 4 = 1 pitchfork tile inst.AnimState:SetScale(SCALE, SCALE) But if I had to guess, generally the better practice is to upscale it in whatever program you're using to create the texture instead. Be sure to tweak the obstacle physics as well: Spoiler MakeObstaclePhysics(inst, radius, height) -- in units. for reference 4 = 1 pitchfork tile Edited March 16, 2025 by oregu 1 Link to comment https://forums.kleientertainment.com/forums/topic/164902-how-do-i-modify-building-type/#findComment-1807660 Share on other sites More sharing options...
hall123 Posted March 17, 2025 Author Share Posted March 17, 2025 @oregu Thank you very much! I’ve fixed these issues. This code is useful: {"MAGIC", "STRUCTURES"} inst:AddTag("deploykititem") But this code doesn’t work: MakeObstaclePhysics(inst, 1, 3) Then I realized the texture size might be too small. I reviewed other mods. I changed the texture size from 128x128 pixels to 512x512 pixels. Everything works fine now. Link to comment https://forums.kleientertainment.com/forums/topic/164902-how-do-i-modify-building-type/#findComment-1807712 Share on other sites More sharing options...
oregu Posted March 17, 2025 Share Posted March 17, 2025 (edited) 8 hours ago, hall123 said: @oregu Thank you very much! I’ve fixed these issues. This code is useful: {"MAGIC", "STRUCTURES"} inst:AddTag("deploykititem") But this code doesn’t work: MakeObstaclePhysics(inst, 1, 3) Then I realized the texture size might be too small. I reviewed other mods. I changed the texture size from 128x128 pixels to 512x512 pixels. Everything works fine now. MakeObstaclePhysics already exists in your code. I think you can only use MakeObstaclePhysics once, and then you have to modify the physics using other means. Edited March 17, 2025 by oregu 1 Link to comment https://forums.kleientertainment.com/forums/topic/164902-how-do-i-modify-building-type/#findComment-1807757 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