Jump to content

Recommended Posts

Hello!

I feel like my mod is finally nearing completion,

however there are two things I am trying to figure out.

 

First I want a function to start when inspecting a certain creature in the sleeping state,

like a beefalo for example. Though I am not really sure how to go about it.

I did notice the inspectable.lua can detect the creature's state, however I am not really sure how to use it.

 

Second, I am wondering how to reference my character in code.

I know it's "inst" when writing in the character lua,

however I am not sure how to it in a weapon's lua.

 

Any info/help would be much appreciated!

@HungryBerryBush

 

For inspecting. There are multiple ways this can be accomplished. What would you like to do in the function? Is it character specific, or do you want to change something of prefab (like description)? Or make the prefab react in some way when inspected?

 

For player reference outside of the create function.

GetPlayer()

Note that this is a accessible as-is in prefab files, but in modmain it's a child of the GLOBAL variable.

 

For inspecting. There are multiple ways this can be accomplished. What would you like to do in the function? Is it character specific, or do you want to change something of prefab (like description)? Or make the prefab react in some way when inspected?

yeah, it would be a good idea for me to say what I want it to do.

 

When inspecting the monster while it's in the sleep state, I want to remove it and place a different prefab in it's place.

(like a statue, though for testing lets say it's a boulder.)

 

 

For player reference outside of the create function. ? 1 GetPlayer() Note that this is a accessible as-is in prefab files, but in modmain it's a child of the GLOBAL variable.
 

Ooooh, thanks a bunch!

@HungryBerryBush

ACTIONS = GLOBAL.ACTIONSlocal old_LOOKAT_fn = ACTIONS.LOOKAT.fnACTIONS.LOOKAT.fn = function(act)    old_LOOKAT_fn (act)    if act.target and act.target.prefab == "beefalo"        and act.target.components.sleeper:IsAsleep() then        -- ...    endend

Edit: Added code to check for sleeping state.

 

Edited by Blueberrys

Thanks!

That code you posted is working nicely, though I admit the part I am adding to it isn't going so well.

I been using the pinecone prefab as a guide, though I am still having trouble.

 

Do you happen to also know how to replace the beefalo with a boulder?

@HungryBerryBush

 

Try this.

-- Where inst refers to beefalo instance-- Spawn a new boulderlocal boulder = SpawnPrefab("rock1")-- use rock2 for gold-filled boulder-- Get position of beefalolocal pos = inst.Transform:GetWorldPosition()-- Remove beefalooinst:Remove()-- Set position of boulderboulder.Transform:SetPosition(pos)

If you're using this with the code I posted previously, replace "inst" with "act.target".

 

@Blueberrys

 

It appears SetPosition is not reading pos as a number value.

 

This is what the code thing looks like as of now.

local old_LOOKAT_fn = ACTIONS.LOOKAT.fnACTIONS.LOOKAT.fn = function(act)    old_LOOKAT_fn (act)     if act.target and act.target.prefab == "beefalo"        and act.target.components.sleeper:IsAsleep() then			--Where inst refers to beefalo instance 			-- Spawn a new boulder			local boulder = GLOBAL.SpawnPrefab("rock1")			-- use rock2 for gold-filled boulder			 			-- Get position of beefalo			local pos = act.target.Transform:GetWorldPosition()			  			-- Remove beefaloo			act.target:Remove()			 			-- Set position of boulder			boulder.Transform:SetPosition(pos)    endend

Other than replacing "inst" with "act.target",

I did add GLOBAL. right before SpawnPrefab due to the game crashing with out it. 

Edited by HungryBerryBush

@HungryBerryBush Whoops. I thought GetWorldPosition() returns an object of some sort. Too much Java, haha. It actually returns multiple variables.

 

Fixed.

local old_LOOKAT_fn = ACTIONS.LOOKAT.fnACTIONS.LOOKAT.fn = function(act)    old_LOOKAT_fn (act)      if act.target and act.target.prefab == "beefalo"        and act.target.components.sleeper:IsAsleep() then            -- Spawn a new boulder            local boulder = GLOBAL.SpawnPrefab("rock1")            -- use rock2 for gold-filled boulder                          -- Get position of beefalo            -- Set position of boulder            boulder.Transform:SetPosition(act.target.Transform:GetWorldPosition())                           -- Remove beefaloo            act.target:Remove()    endend
Edited by Blueberrys

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