Jump to content

Crawling Horror and Terror Break


Recommended Posts

@kordhrufan, see this file.

"..\scripts\prefabs\shadowcreature.lua"

 

Specifically,

local data = {{name="crawlinghorror", build = "shadow_insanity1_basic", bank = "shadowcreature1", num = 1, speed = TUNING.CRAWLINGHORROR_SPEED, health=TUNING.CRAWLINGHORROR_HEALTH, damage=TUNING.CRAWLINGHORROR_DAMAGE, attackperiod = TUNING.CRAWLINGHORROR_ATTACK_PERIOD, sanityreward = TUNING.SANITY_MED},			  {name="terrorbeak", build = "shadow_insanity2_basic", bank = "shadowcreature2", num = 2, speed = TUNING.TERRORBEAK_SPEED, health=TUNING.TERRORBEAK_HEALTH, damage=TUNING.TERRORBEAK_DAMAGE, attackperiod = TUNING.TERRORBEAK_ATTACK_PERIOD, sanityreward = TUNING.SANITY_LARGE}}
Link to comment
Share on other sites

 

@kordhrufan, see this file.

"..\scripts\prefabs\shadowcreature.lua"

 

Specifically,

local data = {{name="crawlinghorror", build = "shadow_insanity1_basic", bank = "shadowcreature1", num = 1, speed = TUNING.CRAWLINGHORROR_SPEED, health=TUNING.CRAWLINGHORROR_HEALTH, damage=TUNING.CRAWLINGHORROR_DAMAGE, attackperiod = TUNING.CRAWLINGHORROR_ATTACK_PERIOD, sanityreward = TUNING.SANITY_MED},			  {name="terrorbeak", build = "shadow_insanity2_basic", bank = "shadowcreature2", num = 2, speed = TUNING.TERRORBEAK_SPEED, health=TUNING.TERRORBEAK_HEALTH, damage=TUNING.TERRORBEAK_DAMAGE, attackperiod = TUNING.TERRORBEAK_ATTACK_PERIOD, sanityreward = TUNING.SANITY_LARGE}}

Thanks man!  I don't know why they call it shadow creature 1 and 2

Link to comment
Share on other sites

 

@kordhrufan, see this file.

"..\scripts\prefabs\shadowcreature.lua"

 

Specifically,

local data = {{name="crawlinghorror", build = "shadow_insanity1_basic", bank = "shadowcreature1", num = 1, speed = TUNING.CRAWLINGHORROR_SPEED, health=TUNING.CRAWLINGHORROR_HEALTH, damage=TUNING.CRAWLINGHORROR_DAMAGE, attackperiod = TUNING.CRAWLINGHORROR_ATTACK_PERIOD, sanityreward = TUNING.SANITY_MED},			  {name="terrorbeak", build = "shadow_insanity2_basic", bank = "shadowcreature2", num = 2, speed = TUNING.TERRORBEAK_SPEED, health=TUNING.TERRORBEAK_HEALTH, damage=TUNING.TERRORBEAK_DAMAGE, attackperiod = TUNING.TERRORBEAK_ATTACK_PERIOD, sanityreward = TUNING.SANITY_LARGE}}

 

 

Now I'm having these issues... I don't know the reason...

log.txt

Link to comment
Share on other sites

@kordhrufan,

 

Your log:

...m/steamapps/common/dont_starve/data/scripts/util.lua:276: Could not find an asset matching anim/shadow_insanity2.zip in any of the search paths. 

I think you forgot the "_basic" part.

-- Path"anim/"..data.build..".zip"-- data.buildshadow_insanity1_basicshadow_insanity2_basic
Link to comment
Share on other sites

 

@kordhrufan,

 

Your log:

...m/steamapps/common/dont_starve/data/scripts/util.lua:276: Could not find an asset matching anim/shadow_insanity2.zip in any of the search paths. 

I think you forgot the "_basic" part.

-- Path"anim/"..data.build..".zip"-- data.buildshadow_insanity1_basicshadow_insanity2_basic

 

 

Besides that, I have another issue, why isn't entering in the IF sentence? 

 

 

 

local fn = function(inst)
 
-- choose which sounds this character will play
inst.soundsname = "wendy"
 
-- Minimap icon
inst.MiniMapEntity:SetIcon( "sari.tex" )
 
-- Stats
inst.components.health:SetMaxHealth(150)
inst.components.hunger:SetMax(120)
inst.components.sanity:SetMax(100)
inst.components.combat.damagemultiplier = (0.75)
inst.components.sanity.night_drain_mult = (0.5)
inst.components.sanity.neg_aura_mult = (0.5)
inst:AddComponent("SanityTsuki", personality(inst))
 
end
 
In the component folder
 
local function personality(inst)
  if inst.components.sanity:GetPercent() <= 0.5 then
   inst.components.combat.damagemultiplier = 1
   inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.5)
   inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 2)
   inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.5)
   inst.components.talker:Say("Happy mind !")
  else
   inst.components.combat.damagemultiplier = 0.75 
   inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1)
   inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1)
   inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1)
  end
 end

 

 

For some reason, when I'm entering in the character world, crashes....

 

scripts/frontend.lua(723,1) SCRIPT ERROR! Showing error screen
...amapps/common/dont_starve/data/scripts/gamelogic.lua:468: could not spawn player character
LUA ERROR stack traceback:
        =[C] in function 'assert'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(468,1) in function 'PopulateWorld'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(837,1) in function 'DoInitGame'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1018,1) in function 'cb'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/saveindex.lua(512,1)
        =[C] in function 'GetPersistentString'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/saveindex.lua(489,1) in function 'GetSaveData'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1020,1) in function 'DoLoadWorld'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1067,1) in function 'LoadSlot'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1133,1) in function 'DoResetAction'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1168,1) in function 'complete_callback'
...
        =[C] in function 'GetPersistentString'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/saveindex.lua(91,1) in function 'Load'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1189,1) in function 'callback'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/playerprofile.lua(574,1) in function 'Set'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/playerprofile.lua(458,1)
        =[C] in function 'GetPersistentString'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/playerprofile.lua(456,1) in function 'Load'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1188,1) in main chunk
        =[C] in function 'require'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(652,1)
scripts/modindex.lua(85,1) ModIndex: Load sequence finished successfully.
Link to comment
Share on other sites

@kordhrufan

Umm. Not sure what you're trying to accomplish here.

 

I don't think this "personality(inst)" part even passes anything. As far as I've seen, "AddComponent" only has one parameter.

inst:AddComponent("SanityTsuki", personality(inst))

Additionally, you can not call a local function from another file. You should add it as a child of your SanityTsuki component, like so:

function SanityTsuki:personality()

Then you can call it from your character.

inst:AddComponent("SanityTsuki")inst.components.SanityTsuki:personality()
Link to comment
Share on other sites

 

@kordhrufan

 

SanityTsuki should be a class, not a function.

 

Take a look at how other components are made (in "..\scripts\components\", see if you can replicate it. Hint:

local Component = Class(function(self, inst) ....

 

Components  returns something... I see.

 

I'm trying to build a sentence, that will activated when the sanity drops to 50%, and it will change the apperance of the character and stats... its necessary to return something?

 local SanityTsuki = Class(function(self,inst) self.inst = inst  end)    function SanityTsuki:personality()  if inst.components.sanity:GetPercent() <= 0.5 then   inst.components.combat.damagemultiplier = 1   inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.5)   inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 2)   inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.5)   inst.components.talker:Say("Happy mind !")  else   inst.components.combat.damagemultiplier = 0.75    inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1)   inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1)   inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1)  endendreturn SanityTsuki

...ds/Sariya Byakura/scripts/components/SanityTsuki.lua:6: variable 'inst' is not declared

 

 

 

Link to comment
Share on other sites

@kordhrufan, change inst to self.inst. There is no variable called inst being passed into the personality function.

Also, this function will have to be called periodically to keep checking the sanity level. It may not function as you want it to by calling it just once

 

I get it, thats the point of the function, I want to be called priodically, in order to do that, it need to "self.inst" in the function... its like a while, right?

 

Now it works!, but... how do I know the values change? I write "inst.components.talker:Say("Happy mind !")" to see the program entering in the "if", but my character isn't speaking... why?

 

if inst.components.sanity:GetPercent() <= 0.5 then

 

should enter when the sanity hits 50% and the character should say "happy mind" and do the other stuff

Link to comment
Share on other sites

I get it, thats the point of the function, I want to be called priodically, in order to do that, it need to "self.inst" in the function... its like a while, right?

No, those are two different issues.

 

"self.inst" is referring to the instance (wiki-p.) of your character associated with the SanityTsuki class (lua).

When you define the function (lua), "function SanityTsuki:personality()" using the colon syntax (stack o.f.) ( : ), it automatically takes in a variable named "self" as the first parameter (wiki-p.). Then when you call it using "SanityTsuki:personality()", it passes that instance of itself as the first parameter.

So inside the function, when you use "self", it's referring to that specific instance of its own class. "inst" is a child (lua) of "self" in this case (because it was defined earlier as such), so you can use "self.inst". Just using "inst" does not work because there is no variable available to the function (lua) called inst.

 

Your function currently only runs once, that's why your character never says anything (and the values don't change). You need that function to be called periodically, either by using an event listener, or inserting the call in a function that is already executed periodically (this is not exclusive, there are more ways too).

 

The sanity component does in fact push an event, "sanitydelta". You can set a listener for it.

local function sanity_event_listener(inst, data)    if data.newpercent <= 0.5 then        -- Transform or something..    endendself.inst:ListenForEvent("sanitydelta", sanity_event_listener)

This "self" should refer to your SanityTsuki component instance, so put it in that class (not in the personality function).

 

 

Please see at least 3 of the links provided, and read at least one-two paragraphs from any of them. They might seem like long boring text, but they're quite useful to know.

Link to comment
Share on other sites

No, those are two different issues.

 

"self.inst" is referring to the instance (wiki-p.) of your character associated with the SanityTsuki class (lua).

When you define the function (lua), "function SanityTsuki:personality()" using the colon syntax (stack o.f.) ( : ), it automatically takes in a variable named "self" as the first parameter (wiki-p.). Then when you call it using "SanityTsuki:personality()", it passes that instance of itself as the first parameter.

So inside the function, when you use "self", it's referring to that specific instance of its own class. "inst" is a child (lua) of "self" in this case (because it was defined earlier as such), so you can use "self.inst". Just using "inst" does not work because there is no variable available to the function (lua) called inst.

 

Your function currently only runs once, that's why your character never says anything (and the values don't change). You need that function to be called periodically, either by using an event listener, or inserting the call in a function that is already executed periodically (this is not exclusive, there are more ways too).

 

The sanity component does in fact push an event, "sanitydelta". You can set a listener for it.

local function sanity_event_listener(inst, data)    if data.newpercent <= 0.5 then        -- Transform or something..    endendself.inst:ListenForEvent("sanitydelta", sanity_event_listener)

This "self" should refer to your SanityTsuki component instance, so put it in that class (not in the personality function).

 

 

Please see at least 3 of the links provided, and read at least one-two paragraphs from any of them. They might seem like long boring text, but they're quite useful to know.

 

Ok, I read about that, is very similar to c++ pascal and java, I can asimilate more the syntax now, 

 

Self is the father, inst is the son, components is the child and what is going to do, SanityTsuki is the grandchild.

 

It should be like this, in the main character file(Sari)

 

local fn = function(inst)-- choose which sounds this character will playinst.soundsname = "wendy"-- Minimap iconinst.MiniMapEntity:SetIcon( "sari.tex" )-- Stats inst.components.health:SetMaxHealth(150)inst.components.hunger:SetMax(120)inst.components.sanity:SetMax(100)inst.components.combat.damagemultiplier = (0.75)inst.components.sanity.night_drain_mult = (0.5)inst.components.sanity.neg_aura_mult = (0.5)inst:AddComponent("SanityTsuki")--inst.components.SanityTsuki:personality()end

Like the example, I prefer to create a event_lisetener... should be like this?

 local SanityTsuki = Class(function(self,inst)   self.inst=inst  end)   function SanityTsuki:personality()endlocal function sanity_event_listener(inst, data)    if data.newpercent <= 0.5 then       self.inst.components.combat.damagemultiplier = 1       self.inst.components.locomotor.walkspeed =(TUNING.WILSON_WALK_SPEED * 2)       self.inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 2)       self.inst.components.locomotor.runspeed =(TUNING.WILSON_RUN_SPEED * 2)else       self.inst.components.combat.damagemultiplier = 0.75        self.inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1)       self.inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1)       self.inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1)    endend--self.inst:ListenForEvent("sanitydelta", sanity_event_listener)return SanityTsuki 

It doesn't crash... but it does when I write "self.inst:ListenForEvent("sanitydelta", sanity_event_listener)"

 

...ds/Sariya Byakura/scripts/components/SanityTsuki.lua:21: variable 'self' is not declared

I really want to learn so I'll be studying those links more!

 

Link to comment
Share on other sites

@kordhrufan

Try putting that line inside your class constructor. You'll have to move the event_listener function above it first, so the scope is valid.

-- local function sanity_event_listener herelocal SanityTsuki = Class(function(self,inst)    self.inst=inst    self.inst:ListenForEvent("sanitydelta", sanity_event_listener)end)

Edit: If you want to see an example on how an event listener is used, check out the armor component. It listens for the percentusedchange event.

"..\scripts\components\armor.lua"

 

Link to comment
Share on other sites

@kordhrufan

Try putting that line inside your class constructor. You'll have to move the event_listener function above it first, so the scope is valid.

-- local function sanity_event_listener herelocal SanityTsuki = Class(function(self,inst)    self.inst=inst    self.inst:ListenForEvent("sanitydelta", sanity_event_listener)end)

Edit: If you want to see an example on how an event listener is used, check out the armor component. It listens for the percentusedchange event.

"..\scripts\components\armor.lua"

 

Of course... silly me, now doesn't crash, it should be like this, based on the armor.lua.

local function sanity_event_listener(inst, data)    if self.inst.components.sanity:GetPercent() <= 0.5 then       self.inst.components.combat.damagemultiplier = 1       self.inst.components.locomotor.walkspeed =(TUNING.WILSON_WALK_SPEED * 2)       self.inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 2)       self.inst.components.locomotor.runspeed =(TUNING.WILSON_RUN_SPEED * 2)      else       self.inst.components.combat.damagemultiplier = 0.75        self.inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1)       self.inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1)       self.inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1)    endend local SanityTsuki = Class(function(self,inst)    self.inst=inst    self.inst:ListenForEvent("sanitydelta", sanity_event_listener)end)   function SanityTsuki:personality()  self.inst:PushEvent("sanitydelta")  end return SanityTsuki
...ds/Sariya Byakura/scripts/components/SanityTsuki.lua:2: variable 'self' is not declared
LUA ERROR stack traceback:

 

Link to comment
Share on other sites

@kordhrufan

-- local function sanity_event_listener herelocal function sanity_event_listener(inst, data)	if data.newpercent <= 0.5 then		inst.components.combat.damagemultiplier = 1		inst.components.locomotor.walkspeed =(TUNING.WILSON_WALK_SPEED * 2)		inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 2)		inst.components.locomotor.runspeed =(TUNING.WILSON_RUN_SPEED * 2)	else		inst.components.combat.damagemultiplier = 0.75		inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1)		inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1)		inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1)	endendlocal SanityTsuki = Class(function(self,inst)	self.inst=inst	-- Setting up an event listener to listen for the sanitydelta event	-- Which is already pushed by the sanity component.	self.inst:ListenForEvent("sanitydelta", sanity_event_listener)end)return SanityTsuki
Link to comment
Share on other sites

 

@kordhrufan

-- local function sanity_event_listener herelocal function sanity_event_listener(inst, data)	if data.newpercent <= 0.5 then		inst.components.combat.damagemultiplier = 1		inst.components.locomotor.walkspeed =(TUNING.WILSON_WALK_SPEED * 2)		inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 2)		inst.components.locomotor.runspeed =(TUNING.WILSON_RUN_SPEED * 2)	else		inst.components.combat.damagemultiplier = 0.75		inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1)		inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1)		inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1)	endendlocal SanityTsuki = Class(function(self,inst)	self.inst=inst	-- Setting up an event listener to listen for the sanitydelta event	-- Which is already pushed by the sanity component.	self.inst:ListenForEvent("sanitydelta", sanity_event_listener)end)return SanityTsuki

 

 

OHHHHHH I see!!! Now it works perfectly! geez man, sorry for don't realize it earlier... I'm very thankfully for your help, I guess I can go alone now in my mod character, again, thanks!

 

---------------------------------------------------------------------

Link to comment
Share on other sites

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.

×
  • Create New...