Jump to content

Recommended Posts

Hello, I need help with something!

So, I have a tool which I want it to be able to be used for shaving. So, I went through the razor.lua & all I saw was this

if not TheWorld.ismastersim then
return inst
end

inst:AddComponent("shaver")

so I added that to my tool & it can shave things on worlds with no caves on, but on worlds with caves on the character just goes up to for example a beefalo & then just does nothing! Not even the shave fail strings comes up! I don't know what i'm doing wrong, does anyone know how to fix this? Because I have no idea :(... I really would appreciate any help anyone can offer on what I can do to fix this :)!

Thanks for reading, have a great day :D!

Edited by SuperDavid

So, maybe anyone knows what makes the Razor so special that only it can shave things on caves world?

This's what my mod item does in a world with caves on

Spoiler

whynowork.gif

& this's what it does in a world with caves off

Spoiler

works.gif

I don't understand what's wrong because the razor only has shaver component & works fine...?

 

Edited by SuperDavid

Maybe it's related to the fact that in one case you aren't the host, and in the other, you are. Because as far as i know, when there are caves in a server, you aren't considered as the host. But you are the host if there aren't cave. So maybe there is a line lacking somewhere or needed in the client part of the code.

I tried adding, which obviously didn't work, haha..

inst:AddInherentAction(ACTIONS.SHAVE)

So, if anyone can help that would be great cause i'm clueless.. The only other place I see "shaver" referenced in DST files is "actions.lua" & "componentactions.lua" but those don't have anything that is specifically making that only the razor can shave...

And shaver.lua is literally just this, nothing saying only the razor can shave.. So, if anyone can help that would be great :D! I have no idea what to do anymore..

local Shaver = Class(function(self, inst)
    self.inst = inst
end)

--Registered actions in componentactions.lua

return Shaver
Edited by SuperDavid

Seems to be working for me. I tried hosting (both overworld-only and overworld+caves) and joining a dedicated (with caves, if that matters), all of them work. Only caveat is that you can't shave beefalos with your weapon equipped.

1 minute ago, alainmcd said:

Seems to be working for me. I tried hosting (both overworld-only and overworld+caves) and joining a dedicated (with caves, if that matters), all of them work. Only caveat is that you can't shave beefalos with your weapon equipped.

So, you tested & the shaver works on world with no caves but it doesn't work on world with caves? There is no way to make it work on world with caves?

It worked the same regardless of server setup. In all cases I could shave the beefalo by hovering the tool over them, but couldn't shave them when I had the weapon equipped. Maybe you already fixed it and were trying to shave them with your weapon equipped?

My guess is that shaving other entities with your tool equipped doesn't work because razors don't have that behaviour (you can't equip it), so you might have to rewrite the shaving action.

Edited by alainmcd
26 minutes ago, alainmcd said:

It worked the same regardless of server setup. In all cases I could shave the beefalo by hovering the tool over them, but couldn't shave them when I had the weapon equipped. Maybe you already fixed it and were trying to shave them with your weapon equipped?

My guess is that shaving other entities with your tool equipped doesn't work because razors don't have that behaviour (you can't equip it), so might have to rewrite the shaving action.

Oh, how do you shave without equipping the tool? Because whenever I right click on beefalo to shave them with the kunai unequipped it makes me automatically equip it & if I left click it makes me attack the beefalo :(?

 

26 minutes ago, alainmcd said:

so you might have to rewrite the shaving action

You mean in the componentactions.lua & actions.lua? Do I have to edit those directly or is there something like prefabpostinit?

Edited by SuperDavid

I just mouseover the beefalo with the weapon on the cursor and right-click. The weapon is auto-equipped, but the action is still performed without clicking anymore. If I want to shave another beefalo, I have to left-click the weapon again and hover over the next beefalo with the weapon. I'm in the beta, in case that makes a difference.

If I understand it correctly, to be able to right-click on a beefalo to shave it with your weapon equipped, you'd have to add an entry for shaving in COMPONENT_ACTIONS.EQUIPPED (so disregard my previous comment about rewriting the shaving action).

Edit: didn't see your edit, but I think I'm sorta answering to it. :D There's probably something similar to AddPrefabPostInit to register mod actions, I'll have a look.

Edited by alainmcd

There's

env.AddComponentAction = function(actiontype, component, fn)

in modutil.lua. I'm not sure how to use it, I tried adding this to your modmain.lua, but no luck.

local function KunaiEquippedAction(inst, doer, actions)
	if doer:HasTag("bearded") and
	  not (doer.replica.inventory:GetActiveItem() == inst and
	  doer.replica.rider ~= nil and
	  doer.replica.rider:IsRiding()) then
		table.insert(actions, ACTIONS.SHAVE)
    end
end

AddComponentAction("EQUIPPED", "shaver", KunaiEquippedAction)

At least it didn't crash. Not sure what else could work. :/

On 11/24/2016 at 6:02 PM, alainmcd said:

There's


env.AddComponentAction = function(actiontype, component, fn)

in modutil.lua. I'm not sure how to use it, I tried adding this to your modmain.lua, but no luck.


local function KunaiEquippedAction(inst, doer, actions)
	if doer:HasTag("bearded") and
	  not (doer.replica.inventory:GetActiveItem() == inst and
	  doer.replica.rider ~= nil and
	  doer.replica.rider:IsRiding()) then
		table.insert(actions, ACTIONS.SHAVE)
    end
end

AddComponentAction("EQUIPPED", "shaver", KunaiEquippedAction)

At least it didn't crash. Not sure what else could work. :/

@alainmcd Thanks so much for doing your best :D! I appreciate it a lot :D!

And maybe @DarkXero you know how to make alainmcd's code work :)? Thank you very much DarkXero :D!! It 100% works fine now!!

Edited by SuperDavid

This is actually caused by the extremely annoying movement prediction mechanics.

local PlayerController = GLOBAL.require("components/playercontroller")
local _DoActionAutoEquip = PlayerController.DoActionAutoEquip
function PlayerController:DoActionAutoEquip(buffaction, ...)
	if buffaction.invobject ~= nil and
		buffaction.invobject.replica.equippable ~= nil and
		buffaction.invobject.replica.equippable:EquipSlot() == GLOBAL.EQUIPSLOTS.HANDS and
		buffaction.action == GLOBAL.ACTIONS.SHAVE then
		return
	end
	return _DoActionAutoEquip(self, buffaction, ...)
end

Put this in modmain to allow your hand-equippable to shave with movement prediction enabled (Lag Compensation: Predictive).

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...