Jump to content

Limiting cycle speed by time [modding] and API


Recommended Posts

While I was trying to figure out modding in dst, I realized that there is no clear, not outdated, auxiliary information, except for a few articles. In addition, many advise to look at the files of the game itself, but now, there are simply no uncompiled files that would store all the functions in themselves (I do not know if they were at all or I am doing something wrong).


At this stage I'm trying to make a smooth scale of the character by pressing a key using a loop, but this happens almost instantly. To my knowledge lua doesn't support any kind of timers or anything like that. After decompiling some dst files I found a mention of "SetDelayTime", but I have no idea if this function (if it's function) has anything to do with what I am trying to do.

Experienced modders, please provide answers to two main questions.

  1. in which files of the game you can find functions in a more or less expanded form
  2. how do I set a pause after one iteration in a loop when I try to scale in or out on a character.


My current code:

bigSize = 2
playerIsBig = False
local function MakeMeBig(player)
	for i=1, bigSize, 0.01 do
		player.Transform:SetScale(i,i,i)
    end
end

local function MakeMeSmall(player)
	for i=bigSize, 1, -0.01 do
		player.Transform:SetScale(i,i,i)
    end
end

AddModRPCHandler(modname, "MakeMeSmall", MakeMeSmall)
AddModRPCHandler(modname, "MakeMeBig", MakeMeBig)

local function SendChangeSizeRPC()
	if playerIsBig == true then
		SendModRPCToServer(MOD_RPC[modname]["MakeMeSmall"])
		playerIsBig = false
	else
		SendModRPCToServer(MOD_RPC[modname]["MakeMeBig"])
		playerIsBig = true
	end
end

GLOBAL.TheInput:AddKeyDownHandler(99, SendChangeSizeRPC) --c

 

Edited by Music Man
Link to comment
Share on other sites

The game files can be found in /Programs/SteamLibrary/common/Don't Starve Together/data/databundles/scripts.zip. Just extract those files and search through these to find the functions you want. You have a few files which contain some important functions that are used in a lot files, those are mostly in the main directory in scripts, for example mainfunctions.lua, entityscript.lua and so on... If you are looking for a specific function, just search in the folder for it or think of an ingame object that uses it perhaps and try to find it, at least that's my approach.

Fortunaly, the devs implement the functions DoTaskInTime and DoPeriodicTask, with these you can implement what you want.

local bigSize = 2  --better make them local to not clutter the game
local playerIsBig = False

local bigger = 1
local function MakeMeBig(player)
  	if bigger >= bigSize then --if we reach the wanted size, we stop the function and change bigger back to inital value
    		bigger = 1
    		return
  	end
  	bigger = bigger + 0.01
	player.Transform:SetScale(bigger,bigger,bigger)
  	player:DoTaskInTime(0,MakeMeBig) --by calling DoTaskInTime(0,fn), each frame the character will get 0.01 bigger. You can change the time to make it slower if you want
end

local smaller = bigSize
local function MakeMeSmall(player)
  	if smaller <= 1 then
    		smaller = bigSize
    		return
  	end
  	smaller = smaller - 0.01
	player.Transform:SetScale(smaller,smaller,smaller)
  	player:DoTaskInTime(0,MakeMeSmall)
end

Perhaps there is a better way to do it, but this is the only thing that comes to my mind.

Edited by Monti18
smaller and bigger are not always exactly equal, so small changes there
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Thanks. I actually found scripts where you wrote. I have now corrected my code by adding the DoTaskInTime function, but it gives the following error. I am very embarrassed to ask, but I still cannot fully figure out how to correctly work with variables in mods.

image.thumb.png.b6f0fc917f8480a9c5c7c8e19d4a0424.png

Below is the function itself for convenience.

image.thumb.png.b0be7d9cfdd7e905faaf5da3ec2a2a09.png

Oh, out of habit I confused ":" and "." :oops: Started with Lua just yesterday :mrgreen:

Link to comment
Share on other sites

Could you post the code you are using? As I just tested it and for me it worked as intended :D

It seems your DoTaskInTime is referring to the wrong entity, as it says in the log that self is a number value, but it should be an entity.

You will get a feeling for the variables after some time ;)

 

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