danielpa

  • Content Count

    17
  • Joined

  • Last visited

Community Reputation

4 Neutral

About danielpa

  • Rank
    Junior Member
...

Recent Profile Visitors

351 profile views
  1. I've noticed some or most of the mods use a list of prefabs when choosing to equip a weapon, axe, etc. This limits the mod to be updated every time new items are added to the games, and they wont work with other mods adding new equipments. So here I'll show you how I did it on my mod to make it work forever and with other mods (unless klei changes the api) Repo (in typescript, not lua) https://github.com/danielpza/dst-omnikey So you have an item/prefab on your inventory and you want to check if it is a weapon, a axe, etc, and how good it is, so you can pick the best. First step is to check the item for the appropriate components, for instance you should look for the `weapon` component when looking for a weapon. one trick I've seen in some mods is to create an instance of the prefab you want to inspect, look for the properties of the instance directly, and then remove the created instance. This is part of the code I used to get the values I needed: local copyPrefab, pick function copyPrefab(prefab) local isMasterSim = TheWorld.ismastersim TheWorld.ismastersim = true local copy = SpawnPrefab(prefab) local cache = { prefab = prefab, components = { waterproofer = pick(copy.components.waterproofer, {"effectiveness"}), insulator = pick(copy.components.insulator, {"insulation"}), eater = pick(copy.components.eater, {"preferseating"}), finiteuses = pick(copy.components.finiteuses, {"current", "total", "consumption"}), tool = pick(copy.components.tool, {"actions"}), weapon = pick(copy.components.weapon, {"damage"}), armor = pick(copy.components.armor, {"absorb_percent", "condition", "maxcondition"}), healer = pick(copy.components.healer, {"health"}), equippable = pick(copy.components.equippable, {"dapperness", "equipslot", "walkspeedmult"}), edible = pick(copy.components.edible, {"healthvalue", "hungervalue", "sanityvalue", "foodtype"}) } } copy:Remove() TheWorld.ismastersim = isMasterSim return cache end function pick(t, ks) if t == nil then return nil end local result = {} for ____, k in ipairs(ks) do result[k] = t[k] end return result end (if you see any weird code as the `____` in the pick function it's because this is code generated from typescript, source: https://github.com/danielpza/dst-omnikey/blob/master/src/scripts/omnikey/cache.ts) We have to trick the client into thinking we are the server `TheWorld.ismastersim = true`. You can improve this further by caching the results: local prefabCache = {} function getPrefabCopy(prefab) if prefabCache[prefab] == nil then prefabCache[prefab] = copyPrefab(prefab) end return prefabCache[prefab] end Then you can check if it's a weapon by checking the results: function valueAsWeapon(result) return ((result.components.weapon and result.components.weapon.damage) or 0) end To wrap things up, say you have two items(item1 and item2) and want to see which is a weapon and which is better: item1Value = valueAsWeapon(getPrefabCopy(item1.prefab)) item2Value = valueAsWeapon(getPrefabCopy(item2.prefab)) if item1Value > item2Value then bestItem = item1 end if item1Value < item2Value then bestItem = item2 end You'll get the best of the two in `bestItem`, if bestItem is nil, then none of them were weapons. You can check all of the code in typescript on github https://github.com/danielpza/dst-omnikey, and the generated lua code on steam by subscribing to the mod or compiling the source code Hope it helps
  2. I already do this, look at the end of the function. I use it in my mod to select the best tool for the job, I need not only the usage percent but also the armor reduction, weapon damage and others. I infer other values from the usage percent as well https://github.com/danielpza/dst-omnikey/blob/master/src/modmain.ts#L176-L185 The thing I did similar to Item Info is creating a prefab to cache it's components, I don't need/use/calculate other values like Item Info does
  3. This is my latest revision on the code: local prefabCache function getPrefabCopy(prefab) if prefabCache[prefab] == nil then local isMasterSim = GLOBAL.TheWorld.ismastersim GLOBAL.TheWorld.ismastersim = true local copy = GLOBAL.SpawnPrefab(prefab) local cache = {prefab = prefab, components = {}} if copy.components.finiteuses then local ____ = copy.components.finiteuses local current = ____.current local total = ____.total local consumption = ____.consumption cache.components.finiteuses = {current = current, total = total, consumption = consumption} end if copy.components.tool then local ____ = copy.components.tool local actions = ____.actions cache.components.tool = {actions = actions} end if copy.components.weapon then local ____ = copy.components.weapon local damage = ____.damage cache.components.weapon = {damage = damage} end if copy.components.armor then local ____ = copy.components.armor local absorb_percent = ____.absorb_percent local condition = ____.condition local maxcondition = ____.maxcondition cache.components.armor = {absorb_percent = absorb_percent, condition = condition, maxcondition = maxcondition} end if copy.components.healer then local ____ = copy.components.healer local health = ____.health cache.components.healer = {health = health} end if copy.components.edible then local ____ = copy.components.edible local healthvalue = ____.healthvalue local hungervalue = ____.hungervalue local sanityvalue = ____.sanityvalue local ismeat = ____.ismeat local foodtype = ____.foodtype cache.components.edible = {healthvalue = healthvalue, hungervalue = hungervalue, sanityvalue = sanityvalue, ismeat = ismeat, foodtype = foodtype} end copy:Remove() GLOBAL.TheWorld.ismastersim = isMasterSim prefabCache[prefab] = cache end return prefabCache[prefab] end
  4. Is there a way to make the created prefab "invisible", maybe move it very fay way in the world?
  5. How can I do this (get a component property) with RPC? do you have any examples of it besides https://forums.kleientertainment.com/forums/topic/47353-guide-getting-started-with-modding-dst-and-some-general-tips-for-ds-as-well/
  6. yes, you must remove the items, the original mods just cache the variables it needs and then destroys it.
  7. I found a workaround in other mod (Item Info), it doesn't seem the best way, but it works for me: local prefabCache function getPrefabCopy(prefab) if prefabCache[prefab] == nil then local isMasterSim = GLOBAL.TheWorld.ismastersim GLOBAL.TheWorld.ismastersim = true prefabCache[prefab] = GLOBAL.SpawnPrefab(prefab) GLOBAL.TheWorld.ismastersim = isMasterSim end return prefabCache[prefab] end -- then use getPrefabCopy("axe").components
  8. I've read the starting guides to modding and some explications for the replica and classifieds, but still haven't found a way to make it work: local healthvalue = item.components.edible && item.components.edible.healthvalue It worked when playing alone in my server, but if I'm playing multiplayer or in a game with caves it doesn't work.
  9. Version 0.4.0

    28 downloads

    OmniKey A Don't Starve Together Mod. Add keybindings to use with tools, weapons, armor and much more. Usage Keybindings can be changed in the configuration: Default Key Function G Equip best weapon by damage C Equip best armor V Equip best helmet 1 Equip best axe 2 Equip best pickaxe 3 Equip best shovel 4 Equip best scythe, requires scythes mod H Use best healing item J Eat food Also when unequiping the hand slot using the keybindings it automatically equips a cane if available Installing Download latest release from github
  10. This is my first mod, I'm not sure if it's supposed to be announced here, but here you go: EDIT: https://github.com/danielpza/dst-omnikey OmniKey A Don't Starve Together Mod. Add keybindings to use with tools, weapons, armor and much more. Usage Keybindings can be changed in the configuration: Default Key Function G Equip best weapon by damage C Equip best armor V Equip best helmet 1 Equip best axe 2 Equip best pickaxe 3 Equip best shovel H Use best healing item J Eat food Also when unequiping the hand slot using the keybindings it automatically equips a cane if available Installing Download latest release from github Made in typescript, transpiled to lua. Inspired by Fast Equipment.
  11. Anyway, here is a little improvement on the code, in case someone finds it useful function generateKeys(result, from, to) local s = string.byte(from, 1) local e = string.byte(to, 1) do local i = s while i <= e do local key = string.char(i) result[#result + 1] = {description = key, data = key} i = i + 1 end end end string = "" local keys = {} generateKeys(keys, "0", "9") generateKeys(keys, "a", "z")
  12. Like the selector don't starve provides for changing his keybindings, like attack, rotate etc...
  13. I see a lot of mods generate a list of keys when they want to add a keybinding like so: local FIRST_NUMBER = 48 local FIRST_LETTER = 65 for i = 1, 10 do local ch = string.char(FIRST_NUMBER + i - 1) keyslist[i] = {description = ch, data = ch} end for i = 11, 36 do local ch = string.char(FIRST_LETTER + i - 11) keyslist[i] = {description = ch, data = ch} end Is there a better way to assign a keybinding for your mod?