Well-met Posted July 27, 2023 Share Posted July 27, 2023 hello I've made a custom action that allows a character to till farm ground without a hoe local NEWTILL = AddAction("NEWTILL", "Scratch", function(pt, doer) GLOBAL.TheWorld.Map:CollapseSoilAtPoint(pt.x, 0, pt.z) GLOBAL.SpawnPrefab("farm_soil").Transform:SetPosition(pt:Get()) if doer ~= nil then doer:PushEvent("tilling") end end) NEWTILL.priority = -1 AddComponentAction("SCENE", "", function(inst, doer, actions, right) if right and doer.replica.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HANDS) == nil then if GLOBAL.TheWorld.Map:CanTillSoilAtPoint(pt.x, 0, pt.z, false) then table.insert(actions, NEWTILL) end end end) AddStategraphActionHandler("wilson", GLOBAL.ActionHandler(NEWTILL, function(inst) return "doshortaction" end)) AddStategraphActionHandler("wilson_client", GLOBAL.ActionHandler(NEWTILL, function(inst) return "doshortaction" end)) For the most part it seems to work however I get a FindEntities crash along the way [string "scripts/components/map.lua"]:140: bad argument #2 to 'FindEntities' (number expected, got nil) So I went into map.lua to see what's wrong and I assume it's the pt.y part which I've tried to replace with many other things but the problem remains and I'm really out of ideas local FIND_SOIL_MUST_TAGS = { "soil" } function Map:CollapseSoilAtPoint(x, y, z) local till_spacing = GetFarmTillSpacing() for i, v in ipairs(TheSim:FindEntities(x, y, z, till_spacing, FIND_SOIL_MUST_TAGS)) do v:PushEvent(v:GetDistanceSqToPoint(x, y, z) < till_spacing * 0.5 and "collapsesoil" or "breaksoil") end end This is the referenced map.lua. please help ive been on this for days Link to comment https://forums.kleientertainment.com/forums/topic/149896-collapsesoilatpoint-issue/ Share on other sites More sharing options...
ClumsyPenny Posted July 27, 2023 Share Posted July 27, 2023 On your first line, for the action function, your arguments are "pt ,doer", but action functions only really have "act" as an argument. You can still get the action point by doing something like this: local pt = act:GetActionPoint() That's one fix. It looks like the component action function is also having a similar problem, but not only you're using "SCENE" as the type, which isn't meant for what you're doing (it's for interacting with an object in the world), but also your action isn't tied to a component, so it's weird to use component actions. Is this code meant to be applied to just your own modded character or every character in general? If it's the former, there would be an easy way to do it, you can look at characters like Wortox, Wilson or Wolfgang who have right click actions on the world (Soul Hop, various Gym/Dumbbell actions and Torch Toss respectively) if you need pointers. If it's the latter, it should still be doable, in some way. Either way, if you're still lost, I can look into it further and try to whip up some code if you want. 1 Link to comment https://forums.kleientertainment.com/forums/topic/149896-collapsesoilatpoint-issue/#findComment-1654836 Share on other sites More sharing options...
Well-met Posted July 28, 2023 Author Share Posted July 28, 2023 10 hours ago, ariadnesGambit said: On your first line, for the action function, your arguments are "pt ,doer", but action functions only really have "act" as an argument. You can still get the action point by doing something like this: local pt = act:GetActionPoint() That's one fix. It looks like the component action function is also having a similar problem, but not only you're using "SCENE" as the type, which isn't meant for what you're doing (it's for interacting with an object in the world), but also your action isn't tied to a component, so it's weird to use component actions. Is this code meant to be applied to just your own modded character or every character in general? If it's the former, there would be an easy way to do it, you can look at characters like Wortox, Wilson or Wolfgang who have right click actions on the world (Soul Hop, various Gym/Dumbbell actions and Torch Toss respectively) if you need pointers. If it's the latter, it should still be doable, in some way. Either way, if you're still lost, I can look into it further and try to whip up some code if you want. Thank you for the help This is only for one character, hooked to a GetPointSpecialActions. However I don't know what else to use than AddComponentAction for this Link to comment https://forums.kleientertainment.com/forums/topic/149896-collapsesoilatpoint-issue/#findComment-1655136 Share on other sites More sharing options...
ClumsyPenny Posted July 28, 2023 Share Posted July 28, 2023 5 hours ago, Well-met said: This is only for one character, hooked to a GetPointSpecialActions. However I don't know what else to use than AddComponentAction for this You don't need AddComponentAction if you're doing it through GetPointSpecialActions! The function already gives the player the action they need. 1 Link to comment https://forums.kleientertainment.com/forums/topic/149896-collapsesoilatpoint-issue/#findComment-1655212 Share on other sites More sharing options...
Well-met Posted July 28, 2023 Author Share Posted July 28, 2023 2 hours ago, ariadnesGambit said: You don't need AddComponentAction if you're doing it through GetPointSpecialActions! The function already gives the player the action they need. Lol you're right. the function now works perfectly, however my character keeps saying "I can't do that." even though it does work, which is strange 1 Link to comment https://forums.kleientertainment.com/forums/topic/149896-collapsesoilatpoint-issue/#findComment-1655251 Share on other sites More sharing options...
ClumsyPenny Posted July 28, 2023 Share Posted July 28, 2023 11 minutes ago, Well-met said: Lol you're right. the function now works perfectly, however my character keeps saying "I can't do that." even though it does work, which is strange Your action needs a "return true" at the end if all the checks passed. 1 Link to comment https://forums.kleientertainment.com/forums/topic/149896-collapsesoilatpoint-issue/#findComment-1655253 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