Jump to content

@Ipsquiggle How to make a slider?


itsLynx

Recommended Posts

I'm making an FOV slider for Don't Starve Together/ Don't Starve. How do I script the slider for configuration? I have the FOV set and when enabling the mod the FOV is great. It also says it may not be compatible for Don't Starve Together, can anyone help?

 

Thanks in advance.

 

Scripting

 

modinfo

name = "FOV Slider DST"description = "Slid the field of view to your liking."author = "Lynx"version = "1.0"forumthread = "none"api_version = 6icon_atlas = "modicon.xml"icon =priority = -5dst_compatible = truedont_starve_compatible = truereign_of_giants_compatible = trueconfiguration_options ={{name = "FOV Slider",label = "Field of View Slider",options = {{description = "35 (Default)", data = "default"},{description = "40", data = "FOV40"},{description = "50", data = "FOV45"},{description = "60", data = "FOV45"},{description = "70", data = "FOV45"},{description = "80", data = "FOV45"},{description = "90", data = "FOV45"},{description = "100", data = "FOV45"},},default = "default",},

modmain

 

local FOVdefault = (GetModConfigData("FOV")=="default")local FOV40 = (GetModConfigData("FOV")=="FOV40")local FOV50 = (GetModConfigData("FOV")=="FOV50")local FOV60 = (GetModConfigData("FOV")=="FOV60")local FOV70 = (GetModConfigData("FOV")=="FOV70")local FOV80 = (GetModConfigData("FOV")=="FOV80")local FOV90 = (GetModConfigData("FOV")=="FOV90")local FOV100 = (GetModConfigData("FOV")=="FOV100")local FollowCamera = GLOBAL.require("cameras/followcamera")local default = FollowCamera.SetDefaultFollowCamera.SetDefault = function (self)default(self)if FOVdefault thenself.fov = 35elseif FOV40 thenself.fov = 40elseif FOV45 thenself.fov = 50self.fov = 60elseif FOV40 thenself.fov = 70elseif FOV45 thenself.fov = 80self.fov = 90elseif FOV40 thenself.fov = 100endendlocal function addRevealer(inst)inst:AddComponent("revealer")if FOVdefault theninst.components.revealer.radius = 60elseif FOV40 theninst.components.revealer.radius = 66elseif FOV45 theninst.components.revealer.radius = 72endinst.components.revealer:StartUpdating()endfor k,prefabname in ipairs(CHARACTERLIST) doAddPrefabPostInit(prefabname, addRevealer)endif GLOBAL.MODCHARACTERLIST thenfor k,prefabname in ipairs(GLOBAL.MODCHARACTERLIST) doAddPrefabPostInit(prefabname, addRevealer)endend

followcamera

function FollowCamera:SetDefault()    self.targetpos = Vector3(0, 0, 0)    --self.currentpos = Vector3(0, 0, 0)    self.targetoffset = Vector3(0, 1.5, 0)    if self.headingtarget == nil then        self.headingtarget = 45    end    self.fov = 50    self.pangain = 4    self.headinggain = 20    self.distancegain = 1    self.zoomstep = 0    self.distancetarget = 30    self.mindist = 15    self.maxdist = 50 --40       self.mindistpitch = 30    self.maxdistpitch = 60--60     self.paused = false    self.shake = nil    self.controllable = true    self.cutscene = false    if TheWorld ~= nil and TheWorld:HasTag("cave") then        self.mindist = 15        self.maxdist = 35        self.mindistpitch = 25        self.maxdistpitch = 40        self.distancetarget = 25    end    if self.target ~= nil then        self:SetTarget(self.target)    endendfunction FollowCamera:GetRightVec()    local right = (self.headingtarget + 90) * DEGREES    return Vector3(math.cos(right), 0, math.sin(right))endfunction FollowCamera:GetDownVec()    local heading = self.headingtarget * DEGREES    return Vector3(math.cos(heading), 0, math.sin(heading))endfunction FollowCamera:SetPaused(val)self.paused = valendfunction FollowCamera:SetMinDistance(distance)    self.mindist = distanceendfunction FollowCamera:SetGains(pan, heading, distance)    self.distancegain = distance    self.pangain = pan    self.headinggain = headingendfunction FollowCamera:IsControllable()    return self.controllableendfunction FollowCamera:SetControllable(val)    self.controllable = valendfunction FollowCamera:CanControl()    return self.controllableendfunction FollowCamera:SetOffset(offset)    self.targetoffset.x, self.targetoffset.y, self.targetoffset.z = offset:Get()endfunction FollowCamera:GetDistance()    return self.distancetargetendfunction FollowCamera:SetDistance(dist)    self.distancetarget = distendfunction FollowCamera:Shake(type, duration, speed, scale)    if Profile:IsScreenShakeEnabled() then        self.shake = CameraShake(type, duration, speed, scale)    end    TheInputProxy:AddVibration(VIBRATION_CAMERA_SHAKE, duration, math.max(0, math.min(scale * .25, 1)), false)    endfunction FollowCamera:SetTarget(inst)    self.target = inst    if inst ~= nil then        self.targetpos.x, self.targetpos.y, self.targetpos.z = self.target.Transform:GetWorldPosition()    else        self.targetpos.x, self.targetpos.y, self.targetpos.z = 0, 0, 0    endendfunction FollowCamera:Apply()    --dir    local pitch = self.pitch * DEGREES    local heading = self.heading * DEGREES    local cos_pitch = math.cos(pitch)    local dx = -cos_pitch * math.cos(heading)    local dy = -math.sin(pitch)    local dz = -cos_pitch * math.sin(heading)    --pos    TheSim:SetCameraPos(        self.currentpos.x - dx * self.distance,        self.currentpos.y - dy * self.distance,        self.currentpos.z - dz * self.distance    )    TheSim:SetCameraDir(dx, dy, dz)    --right    local right = (self.heading + 90) * DEGREES    local rx = math.cos(right)    local ry = 0    local rz = math.sin(right)    --up    local ux = dy * rz - dz * ry    local uy = dz * rx - dx * rz    local uz = dx * ry - dy * rx    TheSim:SetCameraUp(ux, uy, uz)    TheSim:SetCameraFOV(self.fov)    --listen dist    local listendist = -.1 * self.distance    TheSim:SetListener(        dx * listendist + self.currentpos.x,        dy * listendist + self.currentpos.y,        dz * listendist + self.currentpos.z,        dx, dy, dz,        ux, uy, uz    )endlocal function lerp(lower, upper, t)    return t > 1 and upper        or (t < 0 and lower        or lower * (1 - t) + upper * t)endlocal function normalize(angle)    while angle > 360 do        angle = angle - 360    end    while angle < 0 do        angle = angle + 360    end    return angleendfunction FollowCamera:GetHeading()    return self.headingendfunction FollowCamera:GetHeadingTarget()    return self.headingtargetendfunction FollowCamera:SetHeadingTarget(r)    self.headingtarget = rendfunction FollowCamera:ZoomIn()    self.distancetarget = math.max(self.mindist, self.distancetarget - self.zoomstep)    self.time_since_zoom = 0endfunction FollowCamera:ZoomOut()    self.distancetarget = math.min(self.maxdist, self.distancetarget + self.zoomstep)    self.time_since_zoom = 0endfunction FollowCamera:Snap()    if self.target ~= nil then        local x, y, z = self.target.Transform:GetWorldPosition()        self.targetpos.x = x + self.targetoffset.x        self.targetpos.y = y + self.targetoffset.y        self.targetpos.z = z + self.targetoffset.z    else        self.targetpos.x, self.targetpos.y, self.targetpos.z = self.targetoffset:Get()    end    self.currentpos.x, self.currentpos.y, self.currentpos.z = self.targetpos:Get()    self.heading = self.headingtarget    self.distance = self.distancetarget    self.pitch = lerp(self.mindistpitch, self.maxdistpitch, (self.distance - self.mindist) / (self.maxdist - self.mindist))    self:Apply()endfunction FollowCamera:CutsceneMode(b)    self.cutscene = bendfunction FollowCamera:SetCustomLocation(loc)    self.targetpos.x, self.targetpos.y, self.targetpos.z  = loc:Get()endfunction FollowCamera:Update(dt)    if self.paused then        return    end    local pangain = dt * self.pangain    if self.cutscene then        self.currentpos.x = lerp(self.currentpos.x, self.targetpos.x + self.targetoffset.x, pangain)        self.currentpos.y = lerp(self.currentpos.y, self.targetpos.y + self.targetoffset.y, pangain)        self.currentpos.z = lerp(self.currentpos.z, self.targetpos.z + self.targetoffset.z, pangain)    else        if self.time_since_zoom ~= nil and not self.cutscene then            self.time_since_zoom = self.time_since_zoom + dt            if self.should_push_down and self.time_since_zoom > .25 then                self.distancetarget = self.distance - self.zoomstep            end        end        if self.target ~= nil then            local x, y, z = self.target.Transform:GetWorldPosition()            self.targetpos.x = x + self.targetoffset.x            self.targetpos.y = y + self.targetoffset.y            self.targetpos.z = z + self.targetoffset.z        else            self.targetpos.x, self.targetpos.y, self.targetpos.z = self.targetoffset:Get()        end        self.currentpos.x = lerp(self.currentpos.x, self.targetpos.x, pangain)        self.currentpos.y = lerp(self.currentpos.y, self.targetpos.y, pangain)        self.currentpos.z = lerp(self.currentpos.z, self.targetpos.z, pangain)    end    if self.shake ~= nil then        local shakeOffset = self.shake:Update(dt)        if shakeOffset ~= nil then            local rightOffset = self:GetRightVec() * shakeOffset.x            self.currentpos.x = self.currentpos.x + rightOffset.x            self.currentpos.y = self.currentpos.y + rightOffset.y + shakeOffset.y            self.currentpos.z = self.currentpos.z + rightOffset.z        else            self.shake = nil        end    end    self.heading = normalize(self.heading)    self.headingtarget = normalize(self.headingtarget)    local diffheading = math.abs(self.heading - self.headingtarget)    self.heading =        diffheading <= .01 and        self.headingtarget or        lerp(self.heading,            diffheading <= 180 and            self.headingtarget or            self.headingtarget + (self.heading > self.headingtarget and 360 or -360),            dt * self.headinggain)    self.distance =        math.abs(self.distance - self.distancetarget) > .01 and        lerp(self.distance, self.distancetarget, dt * self.distancegain) or        self.distancetarget        self.pitch = lerp(self.mindistpitch, self.maxdistpitch, (self.distance - self.mindist) / (self.maxdist - self.mindist))    self:onupdatefn(dt)    self:Apply()endfunction FollowCamera:SetOnUpdateFn(fn)    self.onupdatefn = fn or dummyfnendreturn FollowCamera
 
 
 
Link to comment
Share on other sites

this is bad

{description = "60", data = "FOV60"},

this is good

{description = "60", data = 60},

Also i should point out a bug that all your FOVXX strings are using the same number so there is no difference between any of the options.

 

 

In your modmain this is bad:

local FOV40 = (GetModConfigData("FOV")=="FOV40")local FOV50 = (GetModConfigData("FOV")=="FOV50")local FOV60 = (GetModConfigData("FOV")=="FOV60")local FOV70 = (GetModConfigData("FOV")=="FOV70")local FOV80 = (GetModConfigData("FOV")=="FOV80")local FOV90 = (GetModConfigData("FOV")=="FOV90")local FOV100 = (GetModConfigData("FOV")=="FOV100")if FOVdefault thenself.fov = 35elseif FOV40 thenself.fov = 40elseif FOV45 thenself.fov = 50self.fov = 60elseif FOV40 thenself.fov = 70elseif FOV45 thenself.fov = 80self.fov = 90elseif FOV40 thenself.fov = 100end

and this is good

local defaultFOV = 120 --this number is just for example. use whatever is actually appropriateself.fov = GetModConfigData("FOV") or defaultFOV
Link to comment
Share on other sites

 

this is bad

{description = "60", data = "FOV60"},

this is good

{description = "60", data = 60},

Also i should point out a bug that all your FOVXX strings are using the same number so there is no difference between any of the options.

 

 

In your modmain this is bad:

local FOV40 = (GetModConfigData("FOV")=="FOV40")local FOV50 = (GetModConfigData("FOV")=="FOV50")local FOV60 = (GetModConfigData("FOV")=="FOV60")local FOV70 = (GetModConfigData("FOV")=="FOV70")local FOV80 = (GetModConfigData("FOV")=="FOV80")local FOV90 = (GetModConfigData("FOV")=="FOV90")local FOV100 = (GetModConfigData("FOV")=="FOV100")if FOVdefault thenself.fov = 35elseif FOV40 thenself.fov = 40elseif FOV45 thenself.fov = 50self.fov = 60elseif FOV40 thenself.fov = 70elseif FOV45 thenself.fov = 80self.fov = 90elseif FOV40 thenself.fov = 100end

and this is good

local defaultFOV = 120 --this number is just for example. use whatever is actually appropriateself.fov = GetModConfigData("FOV") or defaultFOV

 

So like this?

local defaultFOV = (GetModConfigData("FOV")=="default")self.fov = (GetModConfigData("FOV")=="40")self.fov = (GetModConfigData("FOV")=="50")self.fov = (GetModConfigData("FOV")=="60")self.fov = (GetModConfigData("FOV")=="70")self.fov = (GetModConfigData("FOV")=="80")self.fov = (GetModConfigData("FOV")=="90")self.fov = (GetModConfigData("FOV")=="100")
Link to comment
Share on other sites

 

So like this?

local defaultFOV = (GetModConfigData("FOV")=="default")self.fov = (GetModConfigData("FOV")=="40")self.fov = (GetModConfigData("FOV")=="50")self.fov = (GetModConfigData("FOV")=="60")self.fov = (GetModConfigData("FOV")=="70")self.fov = (GetModConfigData("FOV")=="80")self.fov = (GetModConfigData("FOV")=="90")self.fov = (GetModConfigData("FOV")=="100")

No not like that.  Like what i actually wrote.  One line.  Get  _THE_  value that is saved in the option.   the value should never be  "80"  it should be  just 80 (or another number based on what is chosen in config).  A   number not  string.  

Link to comment
Share on other sites

No not like that.  Like what i actually wrote.  One line.  Get  _THE_  value that is saved in the option.   the value should never be  "80"  it should be  just 80 (or another number based on what is chosen in config).  A   number not  string.  

Okay, but why doesn't it say the author when I select the mod and it says it's not compatible.

Link to comment
Share on other sites

Configure has nothing to do with compatibility settings.

 

You need configure options table in your modinfo.lua for config options to be available.  Just look at any other mod that has config options. It should be bluntly obvious what you are doing wrong if you just look at functional code.

Link to comment
Share on other sites

@itsLynx,

 

In addition to what @seronis, has mentioned, you also need a closing bracket at the end of your config options. It's easier to see once you indent your code:

 

configuration_options =
{
    {
        name = "FOV Slider",
        label = "Field of View Slider",
        options = {
            {description = "35 (Default)", data = default},
            ...
        },
        default = default,
    },
} <-- missing

 

If it's still not working after that, please post an updated modinfo... hard to keep track of what you have/haven't done so far =)

Link to comment
Share on other sites

In the example above 'default' is not defined to any value so it will be nil in the options{} sub table and thusly also nil in the config_options{} table.

 

It looks like you copy/pasted a section out of a function that is designed to create the options{} sub table elements where it recieved a default value as an argument  (simplex's mods do this among others)

Link to comment
Share on other sites

Yeah, it was just a copy-paste with small edits (to redact his use of strings as values)... it was mainly to clarify closing out the table. I didn't want to get into it too much further without knowing what, if any, updates OP has already made.

 

PS - nice catch on the FOVXX strings, my eyes totally glazed over that. Repeatedly. Even after you mentioned it, haha.

Link to comment
Share on other sites

How to I made my own mod?

 

Definitely not like that.

 

May I redirect you here and there. Should questions arise, follow these steps:

  1. look for the answer using the search bar on this site
  2. look at similiar mods or game code
  3. ask your question in a topic in the mod forums, giving ideally all directly related information.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...