Quantcast
Channel: [Don't Starve Together] Suggestions and Feedback Latest Topics
Viewing all articles
Browse latest Browse all 8120

Add a check for Sanity on Grue's attack

$
0
0

It'd be nice if this code in grue.lua component gets changed from this current code code

Spoiler

function Grue:OnUpdate(dt)
    if self.nextHitTime ~= nil and self.nextHitTime > 0 then
        self.nextHitTime = self.nextHitTime - dt
    end

    if self.nextSoundTime ~= nil and self.nextSoundTime > 0 then
        self.nextSoundTime = self.nextSoundTime - dt

        if self.nextSoundTime <= 0 then
            if self.soundwarn ~= nil then
                self.inst.SoundEmitter:PlaySound(self.soundwarn)
            end
            self.inst:DoTaskInTime(self.warndelay, self.inst.PushEvent, "heargrue")
        end
    end

    if self.nextHitTime ~= nil and self.nextHitTime <= 0 then
        self.level = self.level + 1
        self.nextHitTime = 5 + math.random() * 6
        self.nextSoundTime = self.nextHitTime * (.4 + math.random() * .4)

        if self.soundattack ~= nil then
            self.inst.SoundEmitter:PlaySound(self.soundattack)
        end

        if self.level > (self.resistance or 0) then
            self.inst.components.combat:GetAttacked(nil, TUNING.GRUEDAMAGE, nil, "darkness")
			self.inst.components.sanity:DoDelta(-TUNING.SANITY_MEDLARGE)
            self.inst:PushEvent("attackedbygrue")
        else
            self.inst:PushEvent("resistedgrue")
        end
    end
end

to this

Spoiler

function Grue:OnUpdate(dt)
    if self.nextHitTime ~= nil and self.nextHitTime > 0 then
        self.nextHitTime = self.nextHitTime - dt
    end

    if self.nextSoundTime ~= nil and self.nextSoundTime > 0 then
        self.nextSoundTime = self.nextSoundTime - dt

        if self.nextSoundTime <= 0 then
            if self.soundwarn ~= nil then
                self.inst.SoundEmitter:PlaySound(self.soundwarn)
            end
            self.inst:DoTaskInTime(self.warndelay, self.inst.PushEvent, "heargrue")
        end
    end

    if self.nextHitTime ~= nil and self.nextHitTime <= 0 then
        self.level = self.level + 1
        self.nextHitTime = 5 + math.random() * 6
        self.nextSoundTime = self.nextHitTime * (.4 + math.random() * .4)

        if self.soundattack ~= nil then
            self.inst.SoundEmitter:PlaySound(self.soundattack)
        end

        if self.level > (self.resistance or 0) then
            self.inst.components.combat:GetAttacked(nil, TUNING.GRUEDAMAGE, nil, "darkness")
			if self.inst.components.sanity then
				self.inst.components.sanity:DoDelta(-TUNING.SANITY_MEDLARGE)
			end
            self.inst:PushEvent("attackedbygrue")
        else
            self.inst:PushEvent("resistedgrue")
        end
    end
end

Adding a check for if the entity being attacked has Sanity to remove Sanity, then if they don't have Sanity the game doesn't crash. I'm sure this would be extremely easy to add & it'd be good for any modders adding AI players (like me) which don't really need Sanity :).


Viewing all articles
Browse latest Browse all 8120

Trending Articles