KainMorgen Posted July 4, 2016 Share Posted July 4, 2016 (edited) So, I'm trying to have a character refuse when ordered to cook a rabbit by the player. I don't just want to remove the option of cooking. I want something else being done than usual instead. I would also like to do this in regards of "murdering" and attacking rabbits, when this function does what is intended. So far, I can make the cooking action fail. No cooked morsel is given to the player. The character says the line which is stored in Actionfail,Cook,Generic though instead of the bunny-related message. Also, right now the bunny is not returned into the inventory. It is deleted from the game and I'm not sure how to return it. The code is located in modmain.lua old_cook_fn = GLOBAL.ACTIONS.COOK.fn function GLOBAL.ACTIONS.COOK.fn(act) print (act.doer) print (act.doer.prefab) if (act.doer ~= nil and act.doer.prefab == "jessica") then -- do either return false if the action should fail, or return old_cook_fn(act) if the target can be cooked local ingredient = act.doer.components.inventory:RemoveItem(act.invobject) print (ingredient.prefab) if ingredient.prefab == "rabbit" then --this part of the code is reached, tested with prints into the console act.doer.components.talker:Say("No, I'm not going to cook it.") --the above line doesnt appear (maybe its overwritten too fast?) and instead ACTIONFAIL,COOK,GENERIC is displayed. --neither of both lines appears in the client chatlog. --act.doer.components.talker:Say(GetString(act.doer, "ANNOUNCE_NOCOOKRABBIT")) --the above line crashes :( --regards GetString as undefined Global variable --there has been added an entry for ANNOUNCE_NOCOOKRABBIT in the character-specific speech files! --then either return rabbit to inventory or "cursor" or release it somewhere near the fire, because otherwise it just 'vanished'. --what would be the correct code for a return into the inventory or freeing the bunny without accidentally having it die in the fire? else return old_cook_fn(act) end else return old_cook_fn(act) end end Edited July 5, 2016 by KainMorgen Link to comment Share on other sites More sharing options...
Muche Posted July 4, 2016 Share Posted July 4, 2016 Try old_cook_fn = GLOBAL.ACTIONS.COOK.fn function GLOBAL.ACTIONS.COOK.fn(act) print (act.doer) print (act.doer.prefab) if (act.doer ~= nil and act.doer.prefab == "jessica") then -- do either return false if the action should fail, or return old_cook_fn(act) if the target can be cooked print (tostring(act.invobject)) if act.invobject ~= nil and act.invobject.prefab == "rabbit" then --this part of the code is reached, tested with prints into the console --act.doer.components.talker:Say("No, I'm not going to cook it.") --the above line doesnt appear (maybe its overwritten too fast?) and instead ACTIONFAIL,COOK,GENERIC is displayed. --neither of both lines appears in the client chatlog. --act.doer.components.talker:Say(GetString(act.doer, "ANNOUNCE_NOCOOKRABBIT")) --the above line crashes :( --regards GetString as undefined Global variable --there has been added an entry for ANNOUNCE_NOCOOKRABBIT in the character-specific speech files! --then either return rabbit to inventory or "cursor" or release it somewhere near the fire, because otherwise it just 'vanished'. --what would be the correct code for a return into the inventory or freeing the bunny without accidentally having it die in the fire? return false, "NOCOOKRABBIT" -- or whatever the string is identified as (ACTIONFAIL.COOK.NOCOOKRABBIT) else return old_cook_fn(act) end else return old_cook_fn(act) end end Link to comment Share on other sites More sharing options...
KainMorgen Posted July 4, 2016 Author Share Posted July 4, 2016 (edited) Thanks Muche. The code you provided keeps the rabbit in the cursor and the cooking does fail.Still, Actionfail.cook.generic is called instead of Actionfail.cook.nocookrabbit. The character says Willow's line "Ew, I can't cook this" instead of the rabbit specific line. (speech_jessica is based on willow's file)The above was caused by an incompatibility with another mod called "Rowing", which also creates a function that is called instead of the default action and then calls the action itself, but discards all additional arguments that were given to the first call. Thus the "NOCOOKRABBIT" argument for data was discarded by Rowing. speech_jessica is included in modmain.lua STRINGS.CHARACTERS.JESSICA = require "speech_jessica" speech_jessica has this entry in the Actionfail subsection: COOK = { GENERIC = "I can't cook this! Ew!", NOCOOKRABBIT = "I don't want to cook rabbits.", INUSE = "Someone else is cooking.", TOOFAR = "It's too far awaaaaay!", }, I see, that in actions.lua "return false, "TOOFAR"" is used just the way you suggested. Still it doesn't seem to accept this identifier when I try to cook a rabbit in a firepit. There is no warning or crash given, though. Jessica V3.rar Edited July 5, 2016 by KainMorgen 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