Sign in to follow this  
Woodside235

[Scripting - Tools] only usable on certain creatures?

Recommended Posts

Woodside235    1

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?

Share this post


Link to post
Share on other sites
Zoshiru    1

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 by Zoshiru

Share this post


Link to post
Share on other sites
Kzisor    1061

@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.

Share this post


Link to post
Share on other sites
Woodside235    1

@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.

Share this post


Link to post
Share on other sites
Kzisor    1061

@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.

Share this post


Link to post
Share on other sites
Woodside235    1

@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 by Woodside235

Share this post


Link to post
Share on other sites
rezecib    3182

@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. 

Share this post


Link to post
Share on other sites

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
Sign in to follow this