HungryBerryBush Posted February 22, 2015 Share Posted February 22, 2015 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 More sharing options...
Blueberrys Posted February 22, 2015 Share Posted February 22, 2015 @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 More sharing options...
HungryBerryBush Posted February 22, 2015 Author Share Posted February 22, 2015 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 More sharing options...
Blueberrys Posted February 22, 2015 Share Posted February 22, 2015 @HungryBerryBushACTIONS = 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 -- ... endendEdit: Added code to check for sleeping state. Link to comment Share on other sites More sharing options...
HungryBerryBush Posted February 23, 2015 Author Share Posted February 23, 2015 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? Link to comment Share on other sites More sharing options...
Blueberrys Posted February 23, 2015 Share Posted February 23, 2015 @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 More sharing options...
HungryBerryBush Posted February 23, 2015 Author Share Posted February 23, 2015 @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) endendOther 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 More sharing options...
Blueberrys Posted February 23, 2015 Share Posted February 23, 2015 @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 More sharing options...
HungryBerryBush Posted February 23, 2015 Author Share Posted February 23, 2015 Works perfectly!Thanks a bunch! Link to comment Share on other sites More sharing options...
Recommended Posts
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.