Jump to content

I got two more questions, mainly regarding referencing.


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!

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@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
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...