Jump to content

Recommended Posts

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

  • Like 1
  • Thanks 1

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 by Dragolantis
text doubled fsfr

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

 

 

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'

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

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

 

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.

  • Thanks 1

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

 

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.

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?

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