Jump to content

Recommended Posts

[MENTION=55]Ipsquiggle[/MENTION]So I made a custom structure, you deploy it from inventory item like spider den or walls. Now custom placers don't behave like the rest of the game placers.Game placer shows the green image of the structure when it can be placed and changes to red if it can't be placed, custom placer shows green image, but instantly changes to drop item action when it can't be placed, instead of that red image, also spacing of the custom structures don't want to work for some reason and I can build walls from them.

	local function test_pillar(inst, pt)		return true	end
                inst:AddComponent("deployable")		inst.components.deployable.ondeploy = ondeploypillar		inst.components.deployable.test = test_pillar		inst.components.deployable.min_spacing = 3		inst.components.deployable.placer = data.name.."_placer"
MakePlacer("common/"..data.name.."_placer", "blocker_sanity", "blocker_sanity", "idle_active") 
Edited by _Q_
  • Developer

@Ipsquiggle

Could you tell me please how to detect ground/floor? like find entity around object but this is ground

I will try to make multiplayer mod data sync with detect ground and floor ^^

EntityScript:GetCurrentTileType() is probably what you're looking for (use it most places with inst:GetCurrentTileType()). This will get the tile under an entity, and also accounts for the "overhangs" around the edge of the map and between different tile types. :)

If you're looking for something a bit more general, try Map:GetTile() or Map:GetTileAtPoint(). (Search the scripts for examples of those.)

  • Developer

@Ipsquiggle

So I made a custom structure, you deploy it from inventory item like spider den or walls.

Now custom placers don't behave like the rest of the game placers.

Game placer shows the green image of the structure when it can be placed and changes to red if it can't be placed, custom placer shows green image, but instantly changes to drop item action when it can't be placed, instead of that red image, also spacing of the custom structures don't want to work for some reason and I can build walls from them.

This seems to be consistent. "Deployables" are inventory items like the wall, spider sack, etc. These don't show the red outline when you can't place them, they just drop like inventory items. This is because their placer is handled automatically in the background, you're not actually "placing" it but "deploying" it.

Buildings on the other hand (like the birdcage) are created directly from the Recipes tab as placers (using MakePlacer) which do have the red image.

Snapping should still work though; look at the MakePlacer call for walls:

MakePlacer("common/wall_"..data.name.."_placer", "wall", "wall_"..data.name, "half", false, false, true) 
That final 'true' should turn on snapping for that object.

Would you be able to create or link me to a thread which tells me the basics of creating a mod for dont starve

Read this, but don't do it: http://forums.kleientertainment.com/showthread.php?10817-Creating-a-Mod-using-the-Mod-SystemThen read this: http://forums.kleientertainment.com/showthread.php?23184-Updating-your-mod-for-quot-Powers-quot-releaseAlso, just look at how other mods work, as well as the samples in the mods folder. There's no one place to find a tutorial, and that's because the mod system is still being worked on. Bigfoot's post is a great starting point but some of the things are out of date. Ipsquiggle's follow-up is where you'll find most of the big changes that came in the more recent updates. But really the best way to learn is to take one of the sample mods and start making changes to it.
  • Developer
Hey, sorry, it doesn't look like there's any file attached to that.You can also just attach the file directly to your post here for testing. :)

EntityScript:GetCurrentTileType() is probably what you're looking for (use it most places with inst:GetCurrentTileType()). This will get the tile under an entity, and also accounts for the "overhangs" around the edge of the map and between different tile types. :)If you're looking for something a bit more general, try Map:GetTile() or Map:GetTileAtPoint(). (Search the scripts for examples of those.)

Thankyou, How I can search area?; like find entity at position and enter range for find entity around position.

Thankyou, How I can search area?; like find entity at position and enter range for find entity around position.

The basic one is TheSim:FindEntities(x, y, z, radius, tags). Tags is an optional list (array) of tags, you don't need to provide it.For example
local pt = GetPlayer():GetPosition()local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, 32, {'player'})
should return a list (array) of all players within a 32 "meter" radius around the main player.For other functions that search for entities (based on TheSim:FindEntities()) check simutil.lua.

The basic one is TheSim:FindEntities(x, y, z, radius, tags). Tags is an optional list (array) of tags, you don't need to provide it.For example

local pt = GetPlayer():GetPosition()local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, 32, {'player'})
should return a list (array) of all players within a 32 "meter" radius around the main player.For other functions that search for entities (based on TheSim:FindEntities()) check simutil.lua.
OH!! Great!! Thankyou All thing in the simutil.lua. I mean full support Multiplayer!!

Hej [MENTION=55]Ipsquiggle[/MENTION]I have a short, probably stupid question about the DoPeriodicTask function.When I use it like

inst:DoPeriodicTask(0, MyTask)
what does it do? Will it do my task every frame or something else? And if it actually does my task every frame (which is how it looks like when testing) will it be a big problem for the performance?
  • Developer

Hej @Ipsquiggle

I have a short, probably stupid question about the DoPeriodicTask function.

When I use it like

inst:DoPeriodicTask(0, MyTask)
what does it do? Will it do my task every frame or something else? And if it actually does my task every frame (which is how it looks like when testing) will it be a big problem for the performance?
You are correct, it will do it every 0 seconds, but no more than once a frame, i.e. every frame. This kind of approach can be okay if it's just on one or a small number of entities, but if it's on a lot of things (say, flowers) it will be terrible. ;)

The preferred way to do this is with events and timers; either respoding to events with inst:ListenForEvent or inst:DoTaskInTime, so that your code is running only when it specifically needs to. This is, for example, how we manage to get every evergreen in the world to grow, or spider dens to behave.

If what you're working on really does need to run every frame, then making an updating component is probably the right approach:

Put your logic in a component, in function <componentname>:OnUpdate(dt), then call inst:StartUpdatingComponet(component) to make it run.

This is preferable because OnUpdate() only runs while the entity owning the component is awake (so no offscreen processing) and only for components for which you explicitly call StartUpdatingComponent (so you can have this happen only when certain conditions are met, for example).

Check out components/childspawner.lua for a working example of this.

[MENTION=55]Ipsquiggle[/MENTION]I want make grass and other pickables to get empty for winter. Right now I used something like that in grass prefab:

inst:ListenForEvent("seasonChange", function() makeemptyfn(inst) end, GetWorld() )
It makes them look empty but you can still pick grass from them.How to make them empty so you can't pick anything?

[....]

Check out components/childspawner.lua for a working example of this.

Good to know thanks ^^ In my case it's only one entity, ever. But then again it's an equippable item that should only do the Task while being equipped or on the ground. What I'd need is to be able to change the entity which as the component i.e. decrease it's durability. None of the OnUpdate functions I found used inst and thus I don't know if there's a way to reference the entity in the OnUpdate function.

I can't seem to get it to work with any inventoryitem to be precise, might jsut need some more trial and error ^^

Anyways, have a nice weekend everyone at Klei ; )

[MENTION=55]Ipsquiggle[/MENTION]

I want make grass and other pickables to get empty for winter.

Right now I used something like that in grass prefab:

inst:ListenForEvent("seasonChange", function() makeemptyfn(inst) end, GetWorld() )
It makes them look empty but you can still pick grass from them.

How to make them empty so you can't pick anything?

How about removing the pickable component? That's what happens when you pick the grass, so I guess it should work this way as well. Edited by Malacath

[MENTION=55]Ipsquiggle[/MENTION]

I want make grass and other pickables to get empty for winter.

Right now I used something like that in grass prefab:

inst:ListenForEvent("seasonChange", function() makeemptyfn(inst) end, GetWorld() )
It makes them look empty but you can still pick grass from them.

How to make them empty so you can't pick anything?

inst:ListenForEvent("seasonChange", function(world, data)	if not inst:IsValid() or inst:IsInLimbo() or not inst.components.pickable then return end	if data.season == SEASONS.WINTER then		inst.components.pickable:Pause()		inst.components.pickable:MakeEmpty()	else		inst.components.pickable:Resume()	endend, GetWorld() )
You should also apply this logic as a postinit, otherwise it will only be applied when the season changes.

---edit---

Oh yes, if you're doing this in the mod environment you'll have to import SEASONS first (or say GLOBAL.SEASONS). I'm quite sure you're already aware of that, but since bugs coming from that are very annoying I feel I should say it anyway.

---edit 2---

When applying the logic as a postinit, you should set it up as a callback with zero delay through inst:DoTaskInTIme(), since you want it to run after the OnLoad method from the pickable component. For example, assuming you called the seasonChange callback above do_pickable_seasonal_logic:

inst:DoTaskInTime(0, function(inst)	do_pickable_seasonal_logic( GetWorld(), {season = GetSeasonManager():GetSeason()} )end)
---edit 3---

You'd have, of course, to define a do_pickable_seasonal_logic() for every pickable inst, since there's no way to pass the inst as a parameter (so that it has to be an upvalue).

---edit 4---

Well, since I've already gone into so much detail, I might as well give a sample of how the whole thing would look as a postinit, taking the grass case as an example:

SEASONS = GLOBAL.SEASONSGetWorld = GLOBAL.GetWorldGetSeasonManager = GLOBAL.GetSeasonManagerAddPrefabPostInit("grass", function(inst)	local function do_pickable_seasonal_logic(world, data)		if not inst:IsValid() or inst:IsInLimbo() or not inst.components.pickable then return end		if data.season == SEASONS.WINTER then			inst.components.pickable:Pause()			inst.components.pickable:MakeEmpty()		else			inst.components.pickable:Resume()		end	end		inst:ListenForEvent("seasonChange", do_pickable_seasonal_logic, GetWorld())		inst:DoTaskInTime(0, function() do_pickable_seasonal_logic( GetWorld(), {season = GetSeasonManager():GetSeason()} ) end)end)
Edited by simplex

[MENTION=44092]simplex[/MENTION]Thank You.

You're welcome. Just don't forget to apply this logic on a per prefab basis, since there are pickables for which it wouldn't make sense. A tallbird nest is pickable, for example, and that's how the egg appears.
  • Developer

When applying the logic as a postinit, you should set it up as a callback with zero delay through inst:DoTaskInTIme(), since you want it to run after the OnLoad method from the pickable component. For example, assuming you called the seasonChange callback above do_pickable_seasonal_logic:

inst:DoTaskInTime(0, function(inst)    do_pickable_seasonal_logic( GetWorld(), {season = GetSeasonManager():GetSeason()} )end)
If your intention is to further modify the object after it's savedata has been loaded, could you not do something like this in AddPrefabPostInit:
local oldonload = inst.OnLoadinst.OnLoad = function(inst, data)    if oldonload then        oldonload(inst, data)    end    do_pickable_seasonal_logic( etc... )end
A similar style could be used with a components instead of a prefabs. If you are dependent on other entities being loaded, OnLoadPostPass happens after all OnLoad and could be appended similarly.
  • Developer

Good to know thanks ^^ In my case it's only one entity, ever. But then again it's an equippable item that should only do the Task while being equipped or on the ground. What I'd need is to be able to change the entity which as the component i.e. decrease it's durability. None of the OnUpdate functions I found used inst and thus I don't know if there's a way to reference the entity in the OnUpdate function.

I can't seem to get it to work with any inventoryitem to be precise, might jsut need some more trial and error ^^

Every component should be able to access self.inst to get the entity it's installed on; and other components with self.inst.components.finiteuses, and so on.

If it's in a function you're setting from the Prefab (i.e. inst.components.finiteuses:SetOnFinished( myfunction ) ), most of those provide the inst as a parameter...

In short, there should be a way, if it's not clear just ask and we'll figure it out. :)

If your intention is to further modify the object after it's savedata has been loaded, could you not do something like this in AddPrefabPostInit:

local oldonload = inst.OnLoadinst.OnLoad = function(inst, data)    if oldonload then        oldonload(inst, data)    end    do_pickable_seasonal_logic( etc... )end
A similar style could be used with a components instead of a prefabs. If you are dependent on other entities being loaded, OnLoadPostPass happens after all OnLoad and could be appended similarly.
Hmm, yes, that would also do it. Both approaches would work, but this may be considered cleaner (even if the whole "patching" is somewhat ugly). I'm just biased towards using a timed callback with zero delay because that's the way the game almost always does it (probably because it ensures all possible forms of initialization, not just the loading of savedata, have already been done, or maybe it's because it ensures the entity is awake when the callback runs). I also have a complete aversion to touching anything that requires direct indexing instead of being accessible through a getter (although that's completely unfounded in the case of EntityScript.OnLoad).But here's some trivia: the only use the game makes of OnLoadPostPass is in prefabs/walrus_camp.lua! In particular, the component version of OnLoadPostPass isn't used anywhere!---edit---I have to concede the whole technique of using a callback with 0 delay is kinda hackish, since it relies on the fact that all entities are awake on the first tick. Edited by simplex
  • Developer

how do you put a mod into don't starve in the first place, I already downloaded them but I don't know ware to put them?

In the game installation folder, there is a folder called 'mods', extract the mods to there and then enable them from in-game.The location of this folder will depend on your OS and what version of the game you're running. If you give some more details there I can help further. :)

I've been having some trouble with the player's stategraph file (SGwilson). In my co-op mod, I need to create a new player prefab for the second player. Unfortunately the second player can behave oddly at times, particularly when chopping down trees or mining rocks. The second player takes a swing, and then the action resets. So rather than the action being quick and continuous, its slow and stilted.I have previously been able to fix this problem by copying SGwilson, renaming it, and setting the SG of the second player's prefab to the copied SG file. However with the continued development of mod at some point this temp fix broke and I am no longer able to replicate the fix.Does anyone have any suggestions?EDIT: Oops. I overwrote my tweaked stategraph file. That would explain the problem :p

Edited by chromiumboy

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
×
  • Create New...