-LukaS- Posted June 1, 2022 Share Posted June 1, 2022 In Lua you're able to return a bool (true or false) value by simply putting conditional statements in the return. In these examples it works like this. -- Spiders ShouldWake local function ShouldWake(inst) return -- Return "true" IF: not TheWorld.state.iscaveday -- It is NOT day (TheWorld.state.iscaveday = false) -- OR or BasicWakeCheck(inst) -- The BasicWakeCheck function returns "true" (assuming it's a function that returns a bool) -- OR or (inst:HasTag("spider_warrior") and FindTarget(inst, TUNING.SPIDER_WARRIOR_WAKE_RADIUS) ~= nil) -- This spider has the "spider_warrior" tag AND there is a target close by, SPIDER_WARRIOR_WAKE_RADIUS = 6 end -- Koalefants ShouldWakeUp local function ShouldWakeUp(inst) local x, y, z = inst.Transform:GetWorldPosition() -- Get "x", "y", "z" of the koalefant return -- return "true" IF DefaultWakeTest(inst) -- DefaultWakeTest returns "true" (assuming it's a function that return a bool) -- OR or IsAnyPlayerInRange(x, y, z, WAKE_TO_RUN_DISTANCE) -- IsAnyPlayerInRange returns SOMETHING (aka doesn't return "nil") end FindTarget and IsAnyPlayerInRange are functions that search for an entity in a specified range. These functions don't return true or false but rather an entity if there is one. Putting a function like that in a return would return true if that function doesn't return nil. Putting not before a function like that would instead return true if that function returns nil (doesn't return anything). 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1574277 Share on other sites More sharing options...
Dragolantis Posted June 1, 2022 Author Share Posted June 1, 2022 thanks for clearing it up! I want a sleep and waking function to be added to my mobs, and I wasn't quite sure how it operated. Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1574311 Share on other sites More sharing options...
Dragolantis Posted June 7, 2022 Author Share Posted June 7, 2022 (edited) I'm here taking a peek at the spiderbrain again. I'm getting much better at reading the code. I understand a lot of it, but there are two things I don't understand. agressive_follow and defensive_follow. I think they are tied to how spiders follow leaders (Which I'm guessing is the player after feeding). But I'm not sure. I might need some form of following node as I get into the leader's rallying attack, so I want to know what these mean. For the time being, I've also been using spider models and ANIM (I wouldn't willingly go into those files, hell I'm still having problems opening them), and I've tried to put the warrior spider skin on my miniboss esque thing, and it spawned invisible. With me about to test the warrior attack on both the mobs, I'm wondering if I need that model in order to properly play the anim Edited June 7, 2022 by Dragolantis text doubled fsfr Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1575791 Share on other sites More sharing options...
Dragolantis Posted June 8, 2022 Author Share Posted June 8, 2022 I've now run into another roadblock. While trying to test what I currently have, I got the error :134: 'end' expected (to close 'function' at line 57) near '<eof>' I don't have anything like eof in my code, and I have an end to the function. I don't understand why I am getting this error Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1575824 Share on other sites More sharing options...
-LukaS- Posted June 8, 2022 Share Posted June 8, 2022 (edited) <eof> is short for 'end-of-file'. You must have a function in your file that you forgot to put an 'end' at the end of it. The function in question starts at line 57. Edited June 8, 2022 by -t- 1 Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1575857 Share on other sites More sharing options...
Dragolantis Posted June 8, 2022 Author Share Posted June 8, 2022 ok, I'll have a look. Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1575871 Share on other sites More sharing options...
Dragolantis Posted June 8, 2022 Author Share Posted June 8, 2022 I've run into another problem. [00:01:49]: [string "scripts/entityscript.lua"]:65: module 'stategraphs/SGcustommob' not found: no field package.preload['stategraphs/SGcustommob'][string "../mods/workshop-2811951071/scripts/stategraphs/SGcustommob.lu..."]:98: '}' expected (to close '{' at line 30) near 'State' no file '../mods/workshop-2811951071\scripts\stategraphs/SGcustommob.lua' no file 'scripts\stategraphs/SGcustommob.lua' no file 'scriptlibs\stategraphs/SGcustommob.lua' Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1575967 Share on other sites More sharing options...
-LukaS- Posted June 9, 2022 Share Posted June 9, 2022 You're missing a } somewhere in your SGcustommob.lua to close a table that starts at line 30, near State. 1 Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1576022 Share on other sites More sharing options...
Dragolantis Posted June 9, 2022 Author Share Posted June 9, 2022 I checked it, with both regular notepad and notepad ++, and I'm not missing one anywhere as far as I can tell Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1576068 Share on other sites More sharing options...
Dragolantis Posted July 7, 2022 Author Share Posted July 7, 2022 hello again! I left on a vacay for summer, and I got back a couple days ago. I fixed the error, spoiler alert it was me being dumb, and now I have a new problem. After going through and fixing all my typos and other stupid screwups, I've noticed my mob doesn't attack me. My thought is it has something to do with the target functions. I have an edited findtarget function and a retarget function. local TARGET_MUST_TAGS = { "_combat", "character" } local TARGET_CANT_TAGS = { "INLIMBO" } local function FindTarget(inst, radius) if not inst.no_targeting then return FindEntity( inst, SpringCombatMod(radius), function(guy) return (not inst.bedazzled and (not guy:HasTag("monster") or guy:HasTag("player"))) and inst.components.combat:CanTarget(guy) end, TARGET_MUST_TAGS, TARGET_CANT_TAGS ) end end local function Retarget(inst) return FindTarget(inst, TUNING.SPIDER_WARRIOR_TARGET_DIST) end Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1582666 Share on other sites More sharing options...
-LukaS- Posted July 7, 2022 Share Posted July 7, 2022 Did you set the Retarget function in the combat component? inst.components.combat:SetRetargetFunction(period, Retarget) Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1582726 Share on other sites More sharing options...
Dragolantis Posted July 7, 2022 Author Share Posted July 7, 2022 (edited) yes i did local function Retarget(inst) return FindTarget(inst, TUNING.SPIDER_WARRIOR_TARGET_DIST) end Edited July 8, 2022 by Dragolantis Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1582727 Share on other sites More sharing options...
Dragolantis Posted July 12, 2022 Author Share Posted July 12, 2022 I'm not sure if you noticed my comment, but I replied with the part where I set the retarget function. unless I missed something else when setting up the retarget function it should be fully functional (pun may or may not have been intended). local function Retarget(inst) return FindTarget(inst, TUNING.SPIDER_WARRIOR_TARGET_DIST) end Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1583571 Share on other sites More sharing options...
-LukaS- Posted July 12, 2022 Share Posted July 12, 2022 I see you have the function declared but did you set it up in the combat component like this: inst.components.combat:SetRetargetFunction(period, Retarget) 1 Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1583594 Share on other sites More sharing options...
Dragolantis Posted July 14, 2022 Author Share Posted July 14, 2022 (edited) that probably did it then. I'll see to adding that EDIT: I checked my code to see if I did include it, and I have the retarget function. so whats wrong with it? Edited July 14, 2022 by Dragolantis Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1584007 Share on other sites More sharing options...
-LukaS- Posted July 14, 2022 Share Posted July 14, 2022 Maybe your mobs brain doesn't contain any combat behaviours like ChaseAndAttack? Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1584055 Share on other sites More sharing options...
Dragolantis Posted July 15, 2022 Author Share Posted July 15, 2022 require "behaviours/chaseandattack" require "behaviours/runaway" require "behaviours/wander" require "behaviours/panic" require "behaviours/attackwall" are all the behaviors present in my mobs code Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1584306 Share on other sites More sharing options...
-LukaS- Posted July 15, 2022 Share Posted July 15, 2022 Send your entire mob file + stategraph and brain files. I'll look through them and see if there's something wrong with them. If i can't find anything then I don't know if I can help you. 1 Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1584645 Share on other sites More sharing options...
Dragolantis Posted July 17, 2022 Author Share Posted July 17, 2022 just noticed your comment. Here you go. SGcustommob.luacustommobbrain.luacustommob.lua Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1585792 Share on other sites More sharing options...
-LukaS- Posted July 17, 2022 Share Posted July 17, 2022 Ah, now I see what's the problem. Your mob's stategraph doesn't have an EventHandler for attacking. EventHandler("doattack", function(inst) if not (inst.sg:HasStateTag("busy") or inst.components.health:IsDead()) then inst.sg:GoToState("attack") end end) It should look something like this. You need to put it in the events table. 1 Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1585839 Share on other sites More sharing options...
Dragolantis Posted July 17, 2022 Author Share Posted July 17, 2022 Ahhhhhh! I feel a bit stupid now. I could've sworn I brought all the states I needed from the spider lua. [00:01:06]: [string "../mods/workshop-2811951071/scripts/stategr..."]:116: variable 'SoundPath' is not declared Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1585927 Share on other sites More sharing options...
Dragolantis Posted July 18, 2022 Author Share Posted July 18, 2022 The soundpath in question is for the attack grunt Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1585938 Share on other sites More sharing options...
-LukaS- Posted July 18, 2022 Share Posted July 18, 2022 You copied the attack state from SGspider.lua. The SoundPath function that this state uses is local so you need to copy that function and paste it into your stategraph file. local function SoundPath(inst, event) local creature = "spider" if inst:HasTag("spider_healer") then return "webber1/creatures/spider_cannonfodder/" .. event elseif inst:HasTag("spider_moon") then return "turnoftides/creatures/together/spider_moon/" .. event elseif inst:HasTag("spider_warrior") then creature = "spiderwarrior" elseif inst:HasTag("spider_hider") or inst:HasTag("spider_spitter") then creature = "cavespider" else creature = "spider" end return "dontstarve/creatures/" .. creature .. "/" .. event end Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1586077 Share on other sites More sharing options...
Dragolantis Posted July 18, 2022 Author Share Posted July 18, 2022 alright, thanks! I should probably triple check my stuff next time I decide to copy paste code from another part of the game to make sure I get everything I need. turns out I didn't have everything I needed. The creature won't do it's leap attack no matter how far I am from it. Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1586098 Share on other sites More sharing options...
Dragolantis Posted July 18, 2022 Author Share Posted July 18, 2022 bc I don't think you caught my most recent problem bc the replied merged (sorry I just am stuck on this part) the creature won't do it's leap attack, it will maul me just fine, but no matter how far I get from it, it won't leap. It'll keep chasing or give up, but not leap. I feel like I'm missing a part of the code, so could you help me with this? Link to comment https://forums.kleientertainment.com/forums/topic/138910-creature-mod-tutorials/page/2/#findComment-1586262 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