Search the Community
Showing results for tags 'code'.
-
Howdy, here I'm posting free points and spools links. Like this: https://accounts.klei.com/link/gimmepointsplz - free 850 points. https://accounts.klei.com/link/pinetreepioneers - free 450 spools. https://accounts.klei.com/link/gimmesomespool - free 450 spools.
- 318 replies
-
- 144
-
-
-
-
-
-
-
-
-
-
So, I've been trying to make a command that forces inst to teleport in spirals for a number seconds. But when I put it in consolecommands.lua, It crashes on starting Don't Starve Together. This is the current code. local angle = 0 local radius = 5 local function spiral_step(inst) local center = inst:GetPosition() local x = center.x + radius * math.cos(angle) local z = center.z + radius * math.sin(angle) inst.Transform:SetPosition(x, center.y, z) angle = angle + 0.1 radius = radius + 0.02 end function z_playerspiral(inst, time) inst.task = inst:DoPeriodicTask(0.1, function() spiral_step(inst) end) inst:DoTaskInTime(time or 10, function() inst.task:Cancel() end) end and for some reason it works in-game if you type it in console.
-
Howdy. I need your help with projectile that is facing the wrong direction. It's artillery shell and I need its tip to be directed to the target. I have tried using local function OnThrown(inst) inst.AnimState:SetOrientation(ANIM_ORIENTATION.OnGround) inst.AnimState:PlayAnimation("idle") end but it does not work. I have also looked into boomerang and blowdart and didn't find any clue. If someone approached the same problem in the past I will be grateful for your help.
-
Hi! I'm trying to make a mod that reduces the quantity of slots on a backpack, however I'm unable to accomplish it. I would appreciate some help in how to reduce the quantity of slots, the backpack interface changes, but it continues with the same quantity of slots. My modmain will go attached here. I would appreciate any help! modmain.lua
-
Hello again. sorry for all the questions..! this time Its not Giggabyte I need help with. I'm making a character for my friend, and she wants her character to have a small sanity boost when killing things. not just monsters but even passive creatures like bunnies and birds. I have googled solutions and came across: https://forums.kleientertainment.com/forums/topic/51989-gain-sanity-during-day-and-gain-sanity-on-kill/ https://forums.kleientertainment.com/forums/topic/67456-gain-sanity-from-killing-monsters-lose-sanity-from-attacking-people/ https://forums.kleientertainment.com/forums/topic/57033-character-gain-sanity-upon-kill-not-working/ though none of these worked. I have also copied the code directly from Wathgrithr's(?) .lua but Im not really sure exactly what bits did what I was wanting and/or what i didnt need to copy and I got lost. I thought about copying the code: inst:ListenForEvent("onattackother", function(inst, data) if data.target.prefab == "spider" then inst.components.sanity:DoDelta(TUNING.SANITY_TINY) end end) (from the third link) and just copying this for every creature in the game but that would take forever and would probably cause problems. Ive tried putting code in the masters_postinit spot, above that, under the line "local prefabs = FlattenTree(start_inv, true)" but nothing Im doing is working. I really just need to know what code I need and where I put it. any help is greatly appreciated! thank you in advance!!
-
So, I'm trying to make my character afraid of Pickaxes. Being that he himself is made of rock. I've found a thread that point's me in the right direction. But I'm wondering how do I check other player's inventories for Them holding a pick, and how do I check the ground for random dropped pickaxes, either from corpses or people not using chests. Thanks in advance
- 5 replies
-
- code
- charactermod
-
(and 1 more)
Tagged with:
-
problem with custom speed up code
AkaiNight posted a topic in [Don't Starve Together] Mods and Tools
here is the code i use local function SpeedUp(inst) if inst:HasTag("playerghost") then return end if TheWorld.state.isday then if inst.transformed and inst.components.hunger.current>=5 and inst.components.sanity.current>=5 and inst.level >= 41 then inst.components.hunger.current = inst.components.hunger.current - 5 inst.components.sanity:DoDelta(-5) inst.components.locomotor.walkspeed = 6 inst.components.locomotor.runspeed = 8 inst.components.sanity.night_drain_mult = 1.5 inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 3) inst.components.combat:SetAttackPeriod(0.5) inst.components.talker:Say("Ikuzoo! Nya~", 1, true) elseif inst.transformed and inst.components.hunger.current< 5 then inst.components.talker:Say("Well better eat something before run. Nya~", 1, true) elseif inst.transformed and inst.components.sanity.current< 5 then inst.components.talker:Say("Run? Do i know how to run? Nya~", 1, true) elseif inst.transformed and inst.level < 41 then inst.components.talker:Say("I must be lvl 3 for use this. Nya~", 1, true) end elseif TheWorld.state.isnight then if TheWorld.state.moonphase == "new" then if inst.transformed and inst.components.hunger.current>=5 and inst.components.sanity.current>=5 and inst.level >= 41 then inst.components.hunger.current = inst.components.hunger.current - 5 inst.components.sanity:DoDelta(-5) inst.components.locomotor.walkspeed = 8.5 inst.components.locomotor.runspeed = 12 inst.components.sanity.night_drain_mult = 3 inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 2) inst.components.combat:SetAttackPeriod(0.3) inst.components.talker:Say("Ikuzoo! Nya~", 1, true) elseif inst.transformed and inst.components.hunger.current< 5 then inst.components.talker:Say("Well better eat something before run. Nya~", 1, true) elseif inst.transformed and inst.components.sanity.current< 5 then inst.components.talker:Say("Run? Do i know how to run? Nya~", 1, true) elseif inst.transformed and inst.level < 41 then inst.components.talker:Say("I must be lvl 3 for use this. Nya~", 1, true) end end elseif TheWorld.state.moonphase == "full" then if inst.transformed and inst.components.hunger.current>=15 and inst.components.sanity.current>=15 and inst.level >= 41 then inst.components.hunger.current = inst.components.hunger.current - 10 inst.components.sanity:DoDelta(-10) inst.components.locomotor.walkspeed = 6.5 inst.components.locomotor.runspeed = 7.5 inst.components.sanity.night_drain_mult = 1.7 inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 4) inst.components.combat:SetAttackPeriod(0.5) inst.components.talker:Say("Ikuzoo! Nya~", 1, true) elseif inst.transformed and inst.components.hunger.current< 10 then inst.components.talker:Say("Well better eat something before run. Nya~", 1, true) elseif inst.transformed and inst.components.sanity.current< 10 then inst.components.talker:Say("Run? Do i know how to run? Nya~", 1, true) elseif inst.transformed and inst.level < 41 then inst.components.talker:Say("I must be lvl 3 for use this. Nya~", 1, true) end elseif TheWorld.state.isdusk then if TheWorld.state.moonphase == "new" then if inst.transformed and inst.components.hunger.current>=5 and inst.components.sanity.current>=5 and inst.level >= 41 then inst.components.hunger.current = inst.components.hunger.current - 5 inst.components.sanity:DoDelta(-5) inst.components.locomotor.walkspeed = 7.5 inst.components.locomotor.runspeed = 10 inst.components.sanity.night_drain_mult = 2.5 inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 2.5) inst.components.combat:SetAttackPeriod(0.35) inst.components.talker:Say("Ikuzoo! Nya~", 1, true) elseif inst.transformed and inst.components.hunger.current< 5 then inst.components.talker:Say("Well better eat something before run. Nya~", 1, true) elseif inst.transformed and inst.components.sanity.current< 5 then inst.components.talker:Say("Run? Do i know how to run? Nya~", 1, true) elseif inst.transformed and inst.level < 41 then inst.components.talker:Say("I must be lvl 3 for use this. Nya~", 1, true) end elseif TheWorld.state.moonphase == "full" then if inst.transformed and inst.components.hunger.current>=7 and inst.components.sanity.current>=7 and inst.level >= 41 then inst.components.hunger.current = inst.components.hunger.current - 7 inst.components.sanity:DoDelta(-7) inst.components.locomotor.walkspeed = 7 inst.components.locomotor.runspeed = 8 inst.components.sanity.night_drain_mult = 2 inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 3) inst.components.combat:SetAttackPeriod(0.4) inst.components.talker:Say("Ikuzoo! Nya~", 1, true) elseif inst.transformed and inst.components.hunger.current< 7 then inst.components.talker:Say("Well better eat something before run. Nya~", 1, true) elseif inst.transformed and inst.components.sanity.current< 7 then inst.components.talker:Say("Run? Do i know how to run? Nya~", 1, true) elseif inst.transformed and inst.level < 41 then inst.components.talker:Say("I must be lvl 3 for use this. Nya~", 1, true) end end end inst.transformed = not inst.transformed return true end here is the log i cant figure what is wrong (the code is in modmain.lua) client_log_2019-11-12-06-54-35.txt client_log.txt -
Duplicate lua network variable
RevelHalcyon posted a topic in [Don't Starve Together] Mods and Tools
Well now I've run into another fundamental issue I don't understand; replicas I believe I've gleaned from context from other threads I've been reading trying to solve this issue that replicas are essentially the client-side component of any object that needs to be referenced by said clients, but I don't understand what drives this or even if it's 100% correct. So recently I created a system by which Guano is renamed to a playfully ambiguous title in keeping with the game's sort of vague reference to natural bodily functions. I do this in my modmain.lua with the following code; AddPrefabPostInit("guano",function(inst) inst:AddComponent("named") end) and everything is well and good until I try to perform this in a world with caves. I'm assuming it's because I added the named component artificially with no supporting logic of when to replicate it? (I notice there's a named_replica.lua in the components folder) but I have no idea how to go about fixing this. The specific error log being -
In the two (well, one and a half) mods I've made so far, I was coding for functionality only ("just make it work.") I was on a deadline and I didn't know the environment (or Lua) very well, and I did get everything working, but the result was very messy code. I ended up with 1647 lines of code in my modmain file. Now I'm about to start working on a new mod, something bigger and possibly with other people too, so this style of work is not a good approach - and I don't like it either, coming from a background of coding with a strong emphasis on design, style and conventions. So what I'm looking for here is some advice from veteran Don't Starve script writers. What are some good practices and rules of thumb for coding in Lua for Don't Starve Together? Some design patterns would also be nice (for example, I always try to wrap an existing function with my extra code rather than replace it with a copy of the original that has my additions in it.) I know there's an option for importing modules which can help reduce the size of modmain and organize the code better, but I think that when I tried using it I had some trouble accessing the GLOBAL variable (my memory's kind of fuzzy on that part). Thanks in advance. =)
-
Hello! I've made a mod with a small light radius work properly, but for some reason it stops working after a while. The light comes back once the server is restarted, but still glitches off at random moments. Might not have to do with anything, but it was noticed to happen when I lose a lot of sanity or when someone lights up a torch right by me. I have linked my character lua to the thread, but here's a peek at the master_postinit, with the light radius part at the end: local master_postinit = function(inst) -- choose which sounds this character will play inst.soundsname = "wendy" -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used --inst.talker_path_override = "dontstarve_DLC001/characters/" -- Stats inst.components.health:SetMaxHealth(140) inst.components.hunger:SetMax(150) inst.components.sanity:SetMax(210) inst.Transform:SetScale(1.1, 1.1, 1.1) -- Speed multiplier inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.25) inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.25) -- Damage multiplier (optional) inst.components.combat.damagemultiplier = 1 -- Hunger rate (optional) inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE --Star Antlers light inst.Light:Enable(true) inst.Light:SetRadius(.3) inst.Light:SetFalloff(.4) inst.Light:SetIntensity(.65) inst.Light:SetColour(0/255, 255/255, 255/255) inst.OnLoad = onload inst.OnNewSpawn = onload end Thank you for reading! ~ bubblegum.lua
-
Hello everyone. I am wondering how to make an event when something goes in X or Y axis in the DST world. For example chain of explosions (SpawnPrefab code) going from left to right or up to down. I made this code earlier by myself (just coppied some codelines from books of Wickerbottom). Maybe someone knows what should I change to make it linear, because right now it spawns prefabs randomly within certain area. Oh, and I have got sub-question for this, as you see in .lua below character must eat item with this prefab to activate it, I have tried to make it triggered with "OnHit" and error occured (yes, I made throwable weapon with parts of this prefab). local Assets = { Asset("ANIM", "anim/barrage.zip"), Asset("ATLAS", "images/inventoryimages/barrage.xml"), Asset("IMAGE", "images/inventoryimages/barrage.tex") } local prefabs = { "explode", "shell" } local function barragecall(inst, target) local pt = target:GetPosition() local numtentacles = 50 target:StartThread(function() for k = 1, numtentacles do local theta = math.random() * 2 * PI local radius = math.random(3, 8) -- we have to special case this one because birds can't land on creep local result_offset = FindValidPositionByFan(theta, radius, 12, function(offset) local pos = pt + offset --NOTE: The first search includes invisible entities return #TheSim:FindEntities(pos.x, 0, pos.z, 1, nil, { "INLIMBO", "FX" }) <= 0 and TheWorld.Map:IsDeployPointClear(pos, nil, 1) end) if result_offset ~= nil then local x, z = pt.x + result_offset.x, pt.z + result_offset.z local tentacle = SpawnPrefab("explode") tentacle.Transform:SetPosition(x, 0, z) local tentacle = SpawnPrefab("shell") tentacle.Transform:SetPosition(x, 0, z) end Sleep(.5) end end) end local function fn(Sim) local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() inst.entity:AddSoundEmitter() MakeInventoryPhysics(inst) inst.AnimState:SetBank("barrage") inst.AnimState:SetBuild("barrage") inst.AnimState:PlayAnimation("idle", true) inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("sanityaura") inst.components.sanityaura.aura = -TUNING.SANITYAURA_MED inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/barrage.xml" --inst.components.inventoryitem:OnDropFn(barragecall) inst:AddComponent("inspectable") MakeHauntableLaunch(inst) inst:AddComponent("edible") inst.components.edible:SetOnEatenFn(barragecall) return inst end return Prefab( "common/inventory/barrage", fn, Assets)
-
Hi. I wonder why my custom sound doesn't work at all. If someone is willing to help I would be grateful. I don't know where I have made mistake, despite fact that I tried everything that I knew. I just want my weapon to work. help.zip
-
I've added some components to certain prefabs which are stackable. I'd like to make it so that when two stacks of these prefabs are combined, the properties of the extra component would be decided by a custom piece of code. At the moment, one item remains and its stack size increases, while the other disappears, which means the properties are decided by whichever item happens to remain. Usually I would want these properties to be reset to some minimum/maximum instead. Is it possible to do this? Thanks in advance. =)
-
I've added a Wander behavior to my creature, and it uses it, but instead of wandering around the given home position it keeps returning exactly to it every time. I.e. it's on a loop of "go to a random point at wander distance" --> "go back to home point". It would make a kind of star or asterisk shape if you drew the lines it traverses, where I'd expect something more like random lines between points on a circle whose center is the home location. I don't recall seeing creatures in the game doing this, so I'm guessing there's something wrong with what I'm doing, which is this: Wander(self.inst, function() return self.inst.components.knownlocations:GetLocation("anchor") end, MAX_WANDER_DIST) The "anchor" position is fixed while this behavior is active, and at the moment MAX_WANDER_DIST = 5, but I've tried adjusting it and no matter what value I chose, it would always move like that, just up to a different distance from the center. I saw the same kind of behavior when I used Leash instead - which, by the way, is different from Wander how, exactly? I'm not sure I get the difference. Any help would be appreciated. Thanks in advance.
-
So I have a lightning prefab file and when I am looking at the code I don't see (and don't understand too) how lightning deals damage. I am at very beginning of my modding journey so this might seem so simple for others. Please help me if you are able to.
-
I'm looking for someone who, unlike me, knows what they're doing with coding for don't starve together. I've tried looking into files and workshops but nothing seems to work out, if any one could help me with it I'd appreciate it! What I've been trying to code into my mod character is the ability to clone themselves, pretty much like Maxwell's perk, but not in shadow form, I've seen people in the workshop who have done this before so I know it must be possible. Here are some examples of what I mean: https://steamcommunity.com/sharedfiles/filedetails/?id=885818848& https://steamcommunity.com/sharedfiles/filedetails/?id=485694807& https://steamcommunity.com/sharedfiles/filedetails/?id=644104565& Any help is very much appreciated, thanks! I have managed to get what I wanted ^^
-
So I want to make a follower for my character kind of like how crash bandicoot has... They need to float just over the shoulder of the character, and I would like if they could be used as a Chester too... coding is not really my strong suit so I wonder if anyone would be able to help me code this in? I really only have 2 days but I've already drawn up and put my character in he just needs his little buddy. Bonus if you can also help me figure out how to make this person change his form when he loses all sanity :/ Thank you so much ahead of time to anyone who can help me out!
-
Hello, i'm trying to add my character a skill (freeze everything if take enough damage and i want to add some cooldown for this ability. so i don't have any idea about how to make. I hope you guys can help me. So thanks for help. Edit: The cooldown must be 1 day at autm and spring and 2 days for summer and 1/2 day for winter.
-
Hiya, I'm pretty noob when it comes to scripting my characters, it took a while to understand how to add in custom items. But there are still so much I need help, if anyone can help I'd appreciate it very much!! What I'm looking for is: The Ancient Cane FX. It'll pretty much be a mod with the ancient cane FX but without holding the actual cane. Damage bonus in dusk and night. I've tried digging into the workshop mod, Charlie is pretty much the example I want, though When I use her code, it doesn't work. This make it so the mod gets a bonus at dusk, and a bigger bonus at night. Neutral to an aggressive mob. mobs like a frog or a killer bee, to be neutral only to you. That's pretty much all, I appreciate any help and/or comments!! Not sure if it'll help but this is pretty much the source mod I got these ideas from, so I know they're possible, just don't know how to add them in the way I want: https://steamcommunity.com/sharedfiles/filedetails/?id=1203081846&searchtext=charlie
-
Well I'm trying to make my character only can eat fish, fishsticks, fishtacos and ice. Is it possible? And also i need a code for can't open chester and can't pick up chester bone i was using this but not works. local function OnPickup(inst) if data.prefab == "chester_eyebone" then local eyebone = data.prefab inst.components.sanity:DoDelta(-30) inst.components.inventory:DropItem(eyebone) inst.components.talker:Say("It's the cursed bone for us. Nya~") end end inst:ListenForEvent("onpickup", OnPickup) It won't give any errors but just not works also i need a code for gain sanity when snow raining and lose sanity when raining. Thanks for help. Also there is an error that when i take damage game crashes. But i didin't understand any simple thing here is alisha.lua and client_log also modmain.lua client_log.txt alishia.lua modmain.lua
-
local function sanitydelta(inst) if inst.components.sanity.current >= 100 then inst.components.combat.damagemultiplier = 1.5 elseif inst.components.sanity.current >= 50 then inst.components.combat.damagemultiplier = 2 elseif inst.components.sanity.current <= 50 then inst.components.combat.damagemultiplier = 4 end end This code, as almost every one who looks at it will know this already, increases the damage multiplier as sanity goes down, I want to tweak it so it not only increases the attack damage of a character but also increases the hunger rate of the character. I've got an Idea but not too sure if it'll work.