Woodside235 Posted January 10, 2015 Share Posted January 10, 2015 How would I make it so a weapon can only be used on sleeping beefalo, and other players asleep or awake? Also, would there be a way to make it so it doesn't wake up the beefalo? Link to comment Share on other sites More sharing options...
Zoshiru Posted January 10, 2015 Share Posted January 10, 2015 (edited) Friend of Woodside here: We tried looking at the code for the Razor, since it seems to be exactly what we want in this tool, but the problem is it doesn't seem to HAVE any code. The chain of modules its scripts reference just ends in an ACTIONS.SHAVE. Edited January 10, 2015 by Zoshiru Link to comment Share on other sites More sharing options...
Kzisor Posted January 10, 2015 Share Posted January 10, 2015 @Woodside235, the following code is from actions.lua. ACTIONS.SHAVE.fn = function(act) if act.invobject and act.invobject.components.shaver then local shavee = act.target or act.doer if shavee and shavee.components.beard then return shavee.components.beard:Shave(act.doer, act.invobject) end end end This code points to the beard component. Check out the beefalo and see if they have a beard component on them, we know Wilson does. Link to comment Share on other sites More sharing options...
Woodside235 Posted January 11, 2015 Author Share Posted January 11, 2015 @Kzisor Doesn't really answer my question. I want to make a new equipable tool and I want the only valid targets to be sleeping beefalo and other players. I haven't found much useful code tracing the razor stuff. Link to comment Share on other sites More sharing options...
Kzisor Posted January 11, 2015 Share Posted January 11, 2015 @Woodside235, actually the code I posted did in fact answer your question. The way the razor works is it uses the Shave action, which is used depending upon whether the shavee has the beard component. From the beefalo.lua main function: inst:AddComponent("beard") -- assume the beefalo has already grown its hair inst.components.beard.bits = 3 inst.components.beard.daysgrowth = hair_growth_days + 1 inst.components.beard.onreset = OnResetBeard inst.components.beard.canshavetest = CanShaveTest inst.components.beard.prize = "beefalowool" inst.components.beard:AddCallback(0, OnShaved) inst.components.beard:AddCallback(hair_growth_days, OnHairGrowth) The CanShaveTest from the beefalo.lua is what determines if you are able to shave the beefalo during the day or only at night. I don't understand how the given solution didn't answer your question. Link to comment Share on other sites More sharing options...
Woodside235 Posted January 12, 2015 Author Share Posted January 12, 2015 @Kzisor Oh, okay. It's a bit more clear now, thanks. Link to comment Share on other sites More sharing options...
Woodside235 Posted January 12, 2015 Author Share Posted January 12, 2015 @Kzisor Wait, I get how to detect if the beefalo are sleeping, but how do I detect ANY player? The prefab variable could be anything. Link to comment Share on other sites More sharing options...
rezecib Posted January 12, 2015 Share Posted January 12, 2015 @Woodside235, :HasTag("player") Link to comment Share on other sites More sharing options...
Woodside235 Posted January 13, 2015 Author Share Posted January 13, 2015 (edited) @rezecib Thanks. New question: Is there also a way to make an item destroy itself if it's dropped, and have a player spawn with it if they're revived? EDIT: Nevermind, I changed my mind about how I want to handle this. Edited January 13, 2015 by Woodside235 Link to comment Share on other sites More sharing options...
rezecib Posted January 13, 2015 Share Posted January 13, 2015 @Woodside235, If I remember correctly, there is a... toground function, I think it's called, in the inventoryitem component. As for being revived, you'll want to listen for the ms_respawnedfromghost event, I think. 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