Jump to content

Complex first mod.


Recommended Posts

Hello, I'm brand-new to this, and figured I'd dive right in.  I think I've got the hang of navigating the files, and the scripting seems simple enough.  I just need to know the terms that link to the various game mechanics such as health, hunger, time of day, temperature, item names (for crafting), etc.

 

I'm wanting to make a custom character that:

  1. Starts with a custom sword item that deals more damage to certain types of enemy (specifically Shadow Creatures) and works normally against others.
  2. Has custom crafting recipes for more custom weapons/items (character exclusive), each with slightly different abilities
  3. Has no sanity drain from night-time. 
  4. Can "Level up" for more max health, damage, max hunger, defense (if possible) XP/level visible on HUD
  5. Certain recipes becoming unlocked based on Level, not science.

 

I know most of this is possible, I've seen it done (across multiple mods); but i have no clue how to do it, especially all in one mod.  After searching multiple forums, on multiple sites, and several (very old) guides, I've found very little to help in my endeavor.  I'd appreciate any help you can give.

Link to comment
Share on other sites

this will get you a functioning character to work with, you can build on top of it from there

 

as for some of your more specific needs, namely the first 3:

this will provide you with everything you need to know to implement those 3 perks. but you'll have to add the custom items separately, this particular post doesn't cover custom item creation.
you can set up your character to spawn with a 'test item' (idk, like, a drumstick or something, that you'll replace with the custom item once you make it), as well as provide your character with custom recipes for several other 'test items'.

 

as for the rest, idk how to help ya. but hopefully these two posts can get you a good foundation to work forward from.
also i'd recommend thinking smaller to be honest. if i were you i'd walk back the scope of your mod.

Link to comment
Share on other sites

That helped a lot, thanks!  Though there are a few things i still need to know.

 

  1. How to make / where to put variables (modmain or character file)
  2. How to change melee damage based on defending creature
  3. How to check which item is equipped
  4. How to make custom items
  5. How to "speak" outside of speech_character file (mainly to display custom text on command either with a button, or on an event trigger)

There's probably more I need to know, but a little bit at a time.  Again, any help is appreciated.

Link to comment
Share on other sites

You can start with this, as well.

It should help you get started with the right tools off the bat (like debugging). Also, please please do take the Lua Crash Course linked there. I don't know how much of a grasp you have on coding or component-based systems, but learning the basics of Lua and how to make and use lists and dictionaries and things like that, will be of huge advantage. Kind of like the difference between hammering a nail in with a small rock and actually going to find a hammer to do it properly :)

Link to comment
Share on other sites

That crash course answered many of my questions concerning basic Lua scripting, though there is still a lot i need to learn.  From what i can tell, i can implement the level system with an XP variable.  and whenever XP == LevelBorder (XP required to level up), run a LevelUp function that will increase stats.  Will this work?

In the character file:

-- Custom Stats
MaxHealth = 150
MaxHunger = 150
MaxSanity = 200

Defense = 0

Attack = 1

MovementSpeedWalk = 4
MovementSpeedRun = 6

-- Apply custom stats
inst.components.health:SetMaxHealth(MaxHealth)
inst.components.hunger:SetMax(MaxHunger)
inst.components.sanity:SetMax(MaxSanity)

inst.components.combat.damagemultiplier = Attack

inst.components.health.absorb = Defense

inst.components.locomotor.walkspeed = MovementSpeedWalk
inst.components.locomotor.runspeed = MovementSpeedRun


-- no sanity drain at night
inst.components.sanity.night_drain_mult = 0


-- Level stats
XP = 0
Level = 1
LevelBorder = 100
BorderIncrement = 10

function CheckLevel(inst) -- Level Up
	if XP == LevelBorder then
    	-- example increase, will vary depending on which stat is increased
    	Level = Level + 1
		MaxHealth = MaxHealth + 10
		
		-- increase LevelBorder
		LevelBorder = (LevelBorder + BorderIncrement) * 1.1
		XP = 0
    	
    	-- Change stats to match new values
		inst.components.health:SetMaxHealth(MaxHealth)
		inst.components.hunger:SetMax(MaxHunger)
		inst.components.sanity:SetMax(MaxSanity)

		inst.components.combat.damagemultiplier = Attack

		inst.components.health.absorb = Defense

		inst.components.locomotor.walkspeed = MovementSpeedWalk
   		inst.components.locomotor.runspeed = MovementSpeedRun
	end
end

inst:DoPeriodicTask( 0.0, function(inst)
        CheckLevel(inst)
end)

This was compiled from my current code and from what I've learned so far.

Things i need to know about the above code:

  1. Confirmation that it will work like that
  2. Improvements to make it work better
  3. How to increase XP anytime a kill is made
  4. A good way to determine which stats to increase and how often (it won't be the same every time)

 

Things I need to know in general:

  1. How to make a custom sword that deals more damage to Shadow Creatures, but works normally against everyone else.
  2. How to "speak" outside of the speech file, so i can display XP, LevelBorder, and Level on one command (possibly "L"); Attack, Defense, and Movement Speed on another (possibly "Y"); and do display a "Level Up" message upon leveling up, detailing what stats got increased
  3. How to make more swords like 1. but have slightly different stats like attack, and effective creature, and their recipes become unlocked after a certain level (and maybe science machine)

I know I'm probably doing too much with this mod, but I don't mind the challenge.  Once it's done, I'm going to love playing with it, and letting my friends enjoy it too.  Plus I can take this experience and apply it to more/different mods.

Link to comment
Share on other sites

I looked over that post, and it looks like it could work for me, but i have a couple questions:

Why is "math.min(inst.level, max_level, min_level)" being used?  Doesn't it always return min_level?

Why is there an experience limit?  Can it and the level cap be removed without breaking it?

 

After reading it through, you've confirmed I'm on the right track, though for the sake of learning how to do these things, I'd rather build my own level system from scratch instead of copying from someone else.

Here's another question though, some programming languages have "switch" statements that are similar to "if" statements but are used when there are a large number of possibilities that need to be covered.  Does Lua have something similar?  Also, what is a good way to determine which stats get increased?  I don't want them all to increase simultaneously, but certain stats increase at different times.  I'd like for there to be a reasonable pattern to the stat buffs too.

Link to comment
Share on other sites

11 hours ago, ShadowGamer3 said:

Why is "math.min(inst.level, max_level, min_level)" being used?  Doesn't it always return min_level?

Yeah, you're right. That part of the code isn't mine. Must have missed that bug when I rewrote the code the other person had written. I'd rather you looked at the simpler example I made in my first post on that thread.

11 hours ago, ShadowGamer3 said:

Why is there an experience limit?  Can it and the level cap be removed without breaking it?

I don't know. My examples do not require a max experience value. You can put in exactly what you want to calculate or retrieve the needed experience for each level, depending on how you count it up. But getting the base structure of your code right is half the battle. Then you just need to adjust the algorithm(s).

 

11 hours ago, ShadowGamer3 said:

Here's another question though, some programming languages have "switch" statements that are similar to "if" statements but are used when there are a large number of possibilities that need to be covered.  Does Lua have something similar?  Also, what is a good way to determine which stats get increased?  I don't want them all to increase simultaneously, but certain stats increase at different times.  I'd like for there to be a reasonable pattern to the stat buffs too.

Lua has no built-in switch statement, but you can get an implementation someone else has made.

Link to comment
Share on other sites

[00:01:04]: scripts/mods.lua(44,1) error calling LoadPrefabFile in mod workshop-2002690739 (Sora): 
...ps/common/dont_starve/data/scripts/mainfunctions.lua:81: Error loading file prefabs/sora
...on/dont_starve/data/../mods/workshop-2002690739/scripts/prefabs/sora.lua:212: unexpected symbol near 'then'
LUA ERROR stack traceback:
        =[C] in function 'assert'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(81,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(42,1)
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(303,1) in function 'RegisterPrefabs'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(129,1) in function 'LoadAssets'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1438,1) in function 'DoResetAction'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1453,1) in function 'complete_callback'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/upsell.lua(27,1) in function 'UpdateGamePurchasedState'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1458,1)
	...
        =[C] in function 'GetPersistentString'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/saveindex.lua(104,1) in function 'Load'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1475,1) in function 'callback'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/playerprofile.lua(741,1) in function 'Set'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/playerprofile.lua(621,1)
        =[C] in function 'GetPersistentString'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/playerprofile.lua(619,1) in function 'Load'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1474,1) in main chunk
        =[C] in function 'require'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(755,1)	

 

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