Grymlahv Posted June 30, 2020 Share Posted June 30, 2020 (edited) Is it possible to assign the mine action to empty hands? Looking at the Zinnia mod I know you can move it to a new tool. But what about no tool? local function DoToolWork(act, workaction) if act.target.components.workable ~= nil and act.target.components.workable:CanBeWorked() and act.target.components.workable:GetWorkAction() == workaction then act.target.components.workable:WorkedBy( act.doer, ( ( act.invobject ~= nil and act.invobject.components.tool ~= nil and act.invobject.components.tool:GetEffectiveness(workaction) ) or ( act.doer ~= nil and act.doer.components.worker ~= nil and act.doer.components.worker:GetEffectiveness(workaction) ) or 1 ) * ( act.doer.components.workmultiplier ~= nil and act.doer.components.workmultiplier:GetMultiplier(workaction) or 1 ) ) return true end return false This seems to be the check for the right tool in your hand, I'm just not sure how to bypass it. Edited June 30, 2020 by Grymlahv Link to comment Share on other sites More sharing options...
Grymlahv Posted June 30, 2020 Author Share Posted June 30, 2020 local Worker = Class(function(self, inst) self.inst = inst self.actions = {} end) function Worker:GetEffectiveness(action) return self.actions[action] or 0 end function Worker:SetAction(action, effectiveness) self.actions[action] = effectiveness or 1 end function Worker:CanDoAction(action) return self.actions[action] ~= nil end return Worker The previous script mentioned the worker component, this is that Link to comment Share on other sites More sharing options...
Thomas Die Posted July 1, 2020 Share Posted July 1, 2020 maybe alter the fn for the component and action for mining and change it so that you can do it if your unarmed also look into the beaver code another option is to create a new component to use the mine option Link to comment Share on other sites More sharing options...
Grymlahv Posted July 1, 2020 Author Share Posted July 1, 2020 I've done some work by using this thread's advice My modmain is here https://pastebin.com/KiULw2gS and refuses to run. I've tried running it through repl.it, and it seems to have no errors, but immediately crashes with no error code. All of my changes are at the end. Link to comment Share on other sites More sharing options...
Thomas Die Posted July 2, 2020 Share Posted July 2, 2020 well that poste was made in 2015 so there must be some code that would've been changed, i can only recommend looking at woodie code 1 Link to comment Share on other sites More sharing options...
Grymlahv Posted July 8, 2020 Author Share Posted July 8, 2020 I do believe you were right to look in the woodie prefab, but I am now running into a little snag. Using what I believe to be the code snippets needed, every time I try to test it, it spawns me in random places (including the middle of the ocean) and then crashes the server. Here is my prefab with to verify my code, Spoiler local MakePlayerCharacter = require "prefabs/player_common" local assets = { Asset("SCRIPT", "scripts/prefabs/player_common.lua"), } -- Your character's stats TUNING.WARDEN_HEALTH = 300 TUNING.WARDEN_HUNGER = 100 TUNING.WARDEN_SANITY = 50 -- Custom starting inventory TUNING.GAMEMODE_STARTING_ITEMS.DEFAULT.WARDEN = { "flint", "flint", "rocks", "rocks", } local start_inv = {} for k, v in pairs(TUNING.GAMEMODE_STARTING_ITEMS) do start_inv[string.lower(k)] = v.WARDEN end local prefabs = FlattenTree(start_inv, true) -- When the character is revived from human local function onbecamehuman(inst) print("debug") -- Set speed when not a ghost (optional) inst.components.locomotor:SetExternalSpeedMultiplier(inst, "warden_speed_mod", .75) -- Mine the World SetWereActions(inst) SetWereWorker(inst) end local function onbecameghost(inst) -- Remove speed modifier when becoming a ghost inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "warden_speed_mod") end -- When loading or spawning the character local function onload(inst) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) inst:ListenForEvent("ms_becameghost", onbecameghost) if inst:HasTag("playerghost") then onbecameghost(inst) else onbecamehuman(inst) end end --Mine the World local WARDEN_LMB_ACTIONS = { "MINE", } local function GetWardenAction(inst, target) for i, v in ipairs(WARDEN_LMB_ACTIONS) do if target:HasTag(v.."_workable") then return not target:HasTag("sign") and ACTIONS[v] or nil end end end local function WardenLeftClickPicker(inst, target) if target ~= nil and target ~= inst then for i, v in ipairs(WARDEN_LMB_ACTIONS) do if target:HasTag(v.."_workable") then return not target:HasTag("sign") and inst.components.playeractionpicker:SortActionList({ ACTIONS[v] }, target, nil) or nil end end end end local function SetWereWorker(inst, mode) inst:RemoveEventCallback("working", onworked) if inst.components.worker == nil then inst:AddComponent("worker") inst.components.worker:SetAction(ACTIONS.MINE, 2) inst.components.worker:SetAction(ACTIONS.HAMMER, 1) OnWorking(inst) end end local function SetWereActions(inst) print("start function") inst.ActionStringOverride = WardenActionString if inst.components.playercontroller ~= nil then print ("inside") inst.components.playercontroller.actionbuttonoverride = WardenActionButton end if inst.components.playeractionpicker ~= nil then inst.components.playeractionpicker.leftclickoverride = WardenLeftClickPicker inst.components.playeractionpicker.rightclickoverride = WardenRightClickPicker inst.components.playeractionpicker.pointspecialactionsfn = nil end end -- This initializes for both the server and client. Tags can be added here. local common_postinit = function(inst) -- Minimap icon inst.MiniMapEntity:SetIcon( "warden.tex" ) end -- This initializes for the server only. Components are added here. local master_postinit = function(inst) -- Set starting inventory inst.starting_inventory = start_inv[TheNet:GetServerGameMode()] or start_inv.default -- choose which sounds this character will play inst.soundsname = "willow" -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used --inst.talker_path_override = "dontstarve_DLC001/characters/" -- Stats inst.components.health:SetMaxHealth(TUNING.WARDEN_HEALTH) inst.components.hunger:SetMax(TUNING.WARDEN_HUNGER) inst.components.sanity:SetMax(TUNING.WARDEN_SANITY) -- Damage multiplier (optional) inst.components.combat.damagemultiplier = 1 -- Hunger rate (optional) inst.components.hunger.hungerrate = .75 * TUNING.WILSON_HUNGER_RATE -- Sanity rate (optional) inst.components.sanity.rate_modifier = 0.75 -- Diet of Rocks inst.components.eater:SetDiet({ FOODTYPE.ELEMENTAL }, { FOODTYPE.ELEMENTAL }) -- Temperature Invulnerability inst.components.temperature.overheattemp = 69 inst.components.temperature.inherentsummerinsulation = 50 inst.components.temperature.inherentinsulation = 50 inst.OnLoad = onload inst.OnNewSpawn = onload end return MakePlayerCharacter("warden", prefabs, assets, common_postinit, master_postinit, prefabs) Link to comment Share on other sites More sharing options...
Grymlahv Posted July 9, 2020 Author Share Posted July 9, 2020 Looking into Woodie's code to see how he werebeaver and weremoose can break boulders without a tool, has lead me to miles of text. and i can't seem to replicate it, however looking at his axe Lucy gave me another idea on how to do this. Spoiler --Mine the World local function onworked(inst, data) if data.target ~= nil and data.target.components.workable ~= nil and data.target.components.workable.action == ACTIONS.MINE then local equipitem = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) if equipitem == nil and inst.components.worker:WorkerActions = nil then inst:AddComponent("worker") end end end local function SetWorker(inst) if components.worker == nil then inst:AddComponent("worker") inst.components.worker:SetAction(ACTIONS.MINE, 2) end end Is it possible to set your unequipped hands to do a worker variable? My server keeps crashing before I can even choose my character. What am I doing wrong and how can I fix this? Any help would be appreciated. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now