Hoit Posted December 19, 2015 Share Posted December 19, 2015 Hi guys, I've been playing DST and I am interested in modding now. The mod I have in mind is a special type of terrain, that when placed, would only allow the character who placed it walking onto it (so therefore kind of claiming a land plot for themselves). Before I dive into technical details I just wanted to ask if it is possible to do that at all? As for multiplayer servers I thought it would be quite common claiming own land plots to set up camp or something, but with a quick look I could not find such mod - perhaps it isn't currently possible to create one? Thanks a lot! Link to comment Share on other sites More sharing options...
ZupaleX Posted December 19, 2015 Share Posted December 19, 2015 I would say it is Link to comment Share on other sites More sharing options...
Maris Posted December 19, 2015 Share Posted December 19, 2015 Very nice idea! I thought about territories with borders. But this idea is very good too. Link to comment Share on other sites More sharing options...
Hoit Posted December 20, 2015 Author Share Posted December 20, 2015 Thanks! I was thinking for a while what would be the best way to implement such concept of players' own lands, and I thought that if a special type of terrain could have same mechanics as walls (can't go through) for all players except who built it, it could bring together pvp and creative/survival mods in same world. On a similar note - do you think it is possible to turn on PVP only on a certain type of terrain? Thanks! Link to comment Share on other sites More sharing options...
ZupaleX Posted December 20, 2015 Share Posted December 20, 2015 Yes it is Link to comment Share on other sites More sharing options...
Hoit Posted December 20, 2015 Author Share Posted December 20, 2015 Awesome So I've decided to get started with this idea slowly, and need some technical help if possible I'm looking a terraformer.lua and walls.lua to see what functions to use. I can see the lines that I could potentially use to achieve what I wantwall.Physics:SetCollides(false)wall.Physics:Teleport(x, 0, z)wall.Physics:SetCollides(true)TheWorld.Pathfinder:AddWall(x, 0, z)inst.Physics:SetActive(true)inst._ispathfinding:set(true)etc... But the thing is, I don't know how, in my modmain.lua, add a listener, that would run a function whenever the turf is placed?So I've got this:local function ondeployturf(turf, pt, deployer)endlocal function TurfObstacle(inst)endAddPrefabPostInit("turf_woodfloor", TurfObstacle)So I can run TurfObstacle, but I need to run another function on deployment with access to the deployed object (like for example ondeployturf above, the idea from ondeploywall from walls.lua). There is SpawnTurf in the terraformer.lua, so I just need some help how to listen to that and access the element? Also, I am in progress of reading the guides and instructions on the forum, wanted to ask if there is any other documentation for the API? Like more technical, i.e. list of events, functions we can run and so on? I know the option of going through the game code, and that is what I am doing now, but even so can't so far find answers to some problems, that seem they should be easy. Thanks a lot guys for help! Link to comment Share on other sites More sharing options...
ZupaleX Posted December 20, 2015 Share Posted December 20, 2015 Well what is not clear yet is how you want your stuff to work. You want to place a specific turf which would check who's the "owner" of that turf and allow trespassing only for this "owner"? Link to comment Share on other sites More sharing options...
Hoit Posted December 20, 2015 Author Share Posted December 20, 2015 (edited) Well what is not clear yet is how you want your stuff to work. You want to place a specific turf which would check who's the "owner" of that turf and allow trespassing only for this "owner"? As the end-result yes, I want that. But I'm going baby steps now, so I just want to find out how do I make a turf act as a wall, more accurately at least how do I set up a listener for the event so I can do something once a turf has been put on the ground Edited December 20, 2015 by Hoit Link to comment Share on other sites More sharing options...
ZupaleX Posted December 20, 2015 Share Posted December 20, 2015 Well if you want to push the same kind of event than the wall when it's placed (adding a coordinate for the pathfinder to take into account it's blocked where you deployed your turf) then it's a simple copy/paste of what you have in the wall lua Link to comment Share on other sites More sharing options...
Hoit Posted December 20, 2015 Author Share Posted December 20, 2015 Well if you want to push the same kind of event than the wall when it's placed (adding a coordinate for the pathfinder to take into account it's blocked where you deployed your turf) then it's a simple copy/paste of what you have in the wall lua What I don't get is what do I put in my TurfObstacle function to run a function when turf is placed.In walls.lua it's called like thatinst:AddComponent("deployable")inst.components.deployable.ondeploy = ondeploywallinst.components.deployable:SetDeployMode(DEPLOYMODE.WALL)local function ondeploywall(inst, pt, deployer) --inst.SoundEmitter:PlaySound("dontstarve/creatures/spider/spider_egg_sack") local wall = SpawnPrefab("wall_"..data.name) if wall ~= nil then local x = math.floor(pt.x) + .5 local z = math.floor(pt.z) + .5 wall.Physics:SetCollides(false) wall.Physics:Teleport(x, 0, z) wall.Physics:SetCollides(true) inst.components.stackable:Get():Remove() -- etc...But in terraformer.lua I don't see any components being added and there is a functionlocal function SpawnTurf(turf, pt) if turf ~= nil then local loot = SpawnPrefab(turf) loot.Transform:SetPosition(pt:Get()) if loot.Physics ~= nil then local angle = math.random() * 2 * PI loot.Physics:SetVel(2 * math.cos(angle), 10, 2 * math.sin(angle)) end endendSo ideally I would need some function that would run once the turf is spawned and the function would have access to the turf itself (loot variable). Not sure how clearly I explained myself, but as new to modding I can't figure a way to "insert" some function where/when I need to Link to comment Share on other sites More sharing options...
ZupaleX Posted December 20, 2015 Share Posted December 20, 2015 From turfs.lualocal function make_turf(data) local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst:AddTag("groundtile") inst.AnimState:SetBank("turf") inst.AnimState:SetBuild("turf") inst.AnimState:PlayAnimation(data.anim) inst:AddTag("molebait") MakeDragonflyBait(inst, 3) inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("stackable") inst.components.stackable.maxsize = TUNING.STACK_SIZE_LARGEITEM inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.data = data inst:AddComponent("bait") inst:AddComponent("fuel") inst.components.fuel.fuelvalue = TUNING.MED_FUEL MakeMediumBurnable(inst, TUNING.MED_BURNTIME) MakeSmallPropagator(inst) MakeHauntableLaunchAndIgnite(inst) inst:AddComponent("deployable") --inst.components.deployable:SetDeployMode(DEPLOYMODE.ANYWHERE) inst.components.deployable.ondeploy = ondeploy if data.tile == "webbing" then inst.components.deployable:SetDeployMode(DEPLOYMODE.ANYWHERE) else inst.components.deployable:SetDeployMode(DEPLOYMODE.TURF) end inst.components.deployable:SetUseGridPlacer(true) --------------------- return inst end return Prefab("turf_"..data.name, fn, assets, prefabs)endYou see the inst:AddComponent("deployable") So the turfs have the component deployable, thus the ondeploy function is called when deploying them. I'm not sure what you want to get from the terraformer component. The turfs doesn't even have it. It's the pitchfork which has this component (this is what handles the picking up of turfs placed on the ground) Link to comment Share on other sites More sharing options...
Hoit Posted December 20, 2015 Author Share Posted December 20, 2015 (edited) Ah! That must be why I was so confused I'll dig into that, thanks a lot!If I assign new function to inst.components.deployable.ondeploy is it going to run both (original from turfs and my custom one), or will replace it and run only mine? If it's the second, should I copy over the function from turfs.lua and adjust it in my way or is there a better way to do that? Really appreciate your help ZupaleX Edited December 20, 2015 by Hoit Link to comment Share on other sites More sharing options...
ZupaleX Posted December 21, 2015 Share Posted December 21, 2015 No it replaces.Basically : ondeploy is a member of the class Deployable. A member can be anything, from a boolean, a number (integer or float), to a string or even entity and functions.So ondeploy is a member of Deployable of type functionWhen you writeinst.components.deployable.ondeploy = WhateverYou replace the current ondeploy member by Whatever (btw, you can replace a member of type function by an other type if you're not careful, which will then creates issues when the code runs). Link to comment 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