Jump to content

Modder's QoL Suggestion Thread


Recommended Posts

Heya! So since we have a QoL update coming in August. I think it wouldn't hurt to make a thread wheres Modders can make suggestions to add/change code in some bits of the game for reasons such as adding easier compatibility and what not. Possibly stuff such as making some parts of the games code more easily accessable to modders. Now i'll list what i'd like to be changed in the game's code.

And feel free to add your own suggestions on what Klei could do to make your modding experience easier and a better time!
 

Spoiler

Klei made it a bit tedious and difficult to create custom boats/platforms with custom radius's because of the way they made some of their functions.

 


local WALKABLE_PLATFORM_TAGS = {"walkableplatform"}

function Map:GetPlatformAtPoint(pos_x, pos_y, pos_z, extra_radius)
	if pos_z == nil then
		pos_z = pos_y
		pos_y = 0
	end
    local entities = TheSim:FindEntities(pos_x, pos_y, pos_z, TUNING.MAX_WALKABLE_PLATFORM_RADIUS + (extra_radius or 0), WALKABLE_PLATFORM_TAGS)
    for i, v in ipairs(entities) do
        return v 
    end
    return nil
end

Here in the "GetPlatformAtPoint" function, Klei does a search of 4 units around the coordinates given(The TUNING.MAX_WALKABLE_PLATFORM_RADIUS variable is equal to 4). Now this works alright in the game because boats are 4 units. However, in the case of custom platforms/boats added into the game by modders with custom radius, this does not work.

To make this function work with custom platforms with custom radius, I suggest Klei changes the function of the GetPlatformAtPoint function to this.
 


local WALKABLE_PLATFORM_TAGS = {"walkableplatform"}
function Map:GetPlatformAtPoint(pos_x, pos_y, pos_z, extra_radius)
	if pos_z == nil then
		pos_z = pos_y
		pos_y = 0
	end
	local entities = TheSim:FindEntities(pos_x, pos_y, pos_z, TUNING.MAX_WALKABLE_PLATFORM_RADIUS + (extra_radius or 0), WALKABLE_PLATFORM_TAGS)
	for i, v in ipairs(entities) do
		if  math.sqrt(v:GetDistanceSqToPoint(pos_x, 0, pos_z)) <= v.components.walkableplatform.platform_radius then
			return v 
        end
	end
	return nil --_GetPlatformAtPoint(GLOBAL.Map, pos_x, pos_y, pos_z, extra_radius) Ugh we have to replace the function...
end

With the extra check here added in the table loop, it'll make sure the distance to the custom platform/boat is equal to or under the radius of the platform. Modders will be able to add to the TUNING.MAX_WALKABLE_PLATFORM_RADIUS variable if there custom boats have a larger radius/platform with no consequence. That's the first thing i'd like to suggest.

As for the 2nd thing, is a quirk with the Crab King Claws
unknown.png

Here you can see the Claws are not properly on the custom boat/platform I added, and thats because....
 


local function ShouldClamp(inst)
    if inst:IsValid() and not inst.sg:HasStateTag("busy") then
        local x,y,z = inst.Transform:GetWorldPosition()
        local ents = TheSim:FindEntities(x,y,z, 4.5, BOAT_TAGS)
        if #ents > 0 then
            for i=#ents, 1, -1 do               
                if not ents[i]:IsValid() or ents[i].components.health:IsDead() then                    
                    table.remove(ents,i)
                end
            end
        end
        if #ents > 0 then
            inst:PushEvent("clamp",{target = ents[1]})
        end
    end 
    return nil
end

In the function where it checks whether or not the claw should clamp down, in brains/crabkingclawbrain.lua. The Claw checks if there is a boat in a 4.5 radius and if so, it clamps down. This works alright but it doesn't work for platforms/boats with custom radius's. I suggest that Klei changes the 4.5 number in the FindEntities call here, and change it to 
 


TUNING.MAX_WALKABLE_PLATFORM_RADIUS + 0.5

This still equals 4.5, but then modders would be able to add to the tuning variable as to add compatibility for their larger boats and platforms. And next, I suggest for an extra check to see if it's near a platform by checking if its distance to a platform is the same/close to the walkableplatform.platform_radius variable of a boat.

 

Edited by Hornete
  • Thanks 5
Link to comment
Share on other sites

Another thing is how if you want to implement custom mob/boss music you have to do some whacky voodoo, as explained below:

 

Spoiler

 

Using Fuelweaver as the example, his music is called via:


        ThePlayer:PushEvent("triggeredevent", { name = "stalker", level = level })

The  "name" data is is referring to a loooong list of songs -- which is a local variable in the dynamic music component. The dynamic component then checks the list for the name and its song. (Just for those who aren't aware. I probably explained it poorly)

 It would be wonderful if there was an "override" data or the likes that let us bypass the list so we could more easily add our own music. So the PushEvent would look more like this:


        ThePlayer:PushEvent("triggeredevent", { override = "dontstarve/music/custom_song"})

I imagine it would look something roughly like this in dynamic music (Note it's the exact same function with one minor change):


local function StartTriggeredDanger(player, data)
    local level = math.max(1, math.floor(data ~= nil and data.level or 1))
    if _triggeredlevel == level then
        _extendtime = math.max(_extendtime, GetTime() + (data.duration or 10))
    elseif _isenabled then
        StopBusy()
        StopDanger()
 --Just a quick check to see if there's an override down here oughta do the trick. 
        local music = data ~= nil and data.override ~= nil and data.override or TRIGGERED_DANGER_MUSIC[data.name ~= nil or "default"] or TRIGGERED_DANGER_MUSIC.default
        music = music[level] or music[1]
        if #music > 0 then
            _soundemitter:PlaySound(music, "danger")
        end
        _dangertask = inst:DoTaskInTime(data.duration or 10, StopDanger, true)
        _triggeredlevel = level
        _extendtime = 0
    end
end

I hope this was somewhat legible it's like 4am

 

 

btw Klei I will implement all of these suggestions for less than minimum wage plz hire me I lost my job to covid

Edited by Mr. Tiddles
  • Like 4
Link to comment
Share on other sites

i would like mod characters images able to show up in the world save area instead of a shadow wilson with a paper smiley face, like pls klei the images are even included in almost every mod :-(

image.png.ed17c194b50a6f91c30afebf84da3544.png

 

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