Jump to content

Help for creating a custom pet


Recommended Posts

Hello world !,

First, sorry for my english, i'm french :-)

 

Today I have a problem with my mod.

The mod include a dragonfly pet. For this mod, i have used the files of the game modified by me.(dragonfly.lua, SGdragonfly.lua and Abigailbrain.lua)

 

But since i have implemented the brain, i have a problem : attempt to index local creature (nil value)

 

I used the Cheerio's creature guide

 

Here is my crash.png and my lua files

 

Prefab :

local assets =
{
Asset("ANIM", "anim/dragonfly_build.zip"),
Asset("ANIM", "anim/dragonfly_fire_build.zip"),
Asset("ANIM", "anim/dragonfly_basic.zip"),
Asset("ANIM", "anim/dragonfly_actions.zip"),
Asset("SOUND", "sound/dragonfly.fsb")
}

local prefabs =
{
"lavaspit",
"armordragonfly",
"firesplash_fx",
"tauntfire_fx",
"attackfire_fx",
"vomitfire_fx",
"firering_fx",
}

local loot = {"meat", "meat", "meat", "meat", "meat", "meat", "meat", "minotaurhorn", "armordragonfly"}


--[NEW] This function creates a new entity based on a prefab.
local function init_prefab()

--[NEW] First we create an entity.
local inst = CreateEntity()
--[NEW] Then we add a transform component se we can place this entity in the world.
local trans = inst.entity:AddTransform()
--[NEW] Then we add an animation component which allows us to animate our entity.
local anim = inst.entity:AddAnimState()
--[NEW] The bank name is the name of the Spriter file.
anim:SetBank("dragonfly")
--[NEW] The build name is the name of the animation folder in spriter.
anim:SetBuild("dragonfly_build")
local shadow = inst.entity:AddDynamicShadow()
shadow:SetSize(6, 3.5)
--[NEW] Here we start playing the 'idle' animation and tell it to loop.
anim:PlayAnimation("idle", true )

inst:AddTag("epic")
inst:AddTag("dragonfly")
inst:AddTag("scarytoprey")
inst:AddTag("largecreature")
inst:AddTag("notraptrigger")
inst:AddTag("flying")

inst.Transform:SetFourFaced()

inst:AddComponent("health")
inst.components.health:SetMaxHealth(1500)
inst.components.health.fire_damage_scale = 0

inst:AddComponent("combat")
inst.components.combat:SetDefaultDamage(TUNING.DRAGONFLY_DAMAGE)
inst.components.combat.playerdamagepercent = .5
inst.components.combat:SetRange(4)
inst.components.combat:SetAreaDamage(6, 0.8)
inst.components.combat.hiteffectsymbol = "dragonfly_body"
inst.components.combat:SetAttackPeriod(1.5)
inst.components.combat:SetRetargetFunction(3, RetargetFn)
inst.components.combat:SetKeepTargetFunction(KeepTargetFn)
inst.components.combat.battlecryenabled = false
inst.components.combat:SetHurtSound("dontstarve_DLC001/creatures/dragonfly/hurt")
inst.flame_on = false
inst:ListenForEvent("killed", function(inst, data)
if inst.components.combat and data and data.victim == inst.components.combat.target then
inst.components.combat.target = nil
inst.last_kill_time = GetTime()
end
end)
inst:ListenForEvent("losttarget", function(inst)
SetFlameOn(inst, false)
end)
inst:ListenForEvent("giveuptarget", function(inst)
SetFlameOn(inst, false)
end)
inst:ListenForEvent("newcombattarget", function(inst, data)
if data.target ~= nil then
SetFlameOn(inst, true, true)
end
end)
inst.SetFlameOn = SetFlameOn

local light = inst.entity:AddLight()
inst.Light:Enable(false)
inst.Light:SetRadius(2)
inst.Light:SetFalloff(0.5)
inst.Light:SetIntensity(.75)
inst.Light:SetColour(235/255,121/255,12/255)

inst:AddComponent("lootdropper")
inst.components.lootdropper:SetLoot(loot)

--[NEW] We need to add a 'locomotor' component otherwise our creature can't walk around the world.
inst:AddComponent("locomotor")
--[NEW] Here we can tune how fast our creature runs forward.
inst.components.locomotor.runspeed = 7

--[NEW] We need to add a 'physics' component for our character to walk through the world. Lucky for us, this
-- this is made easy for us by the 'MakeCharacterPhysics' function. This function sets up physics,
-- collision tags, collision masks, friction etc. All we need to give it is a mass and a radius which
-- in this case we've set to 10 and 0.5.
MakeCharacterPhysics(inst, 500, 1.4)

inst:AddComponent("follower")
local player = GetPlayer()
if player and player.components.leader then
player.components.leader:AddFollower(inst)
end

--[NEW] Here we attach our stategraph to our prefab.
inst:SetStateGraph("SGdragonfly")

--[NEW] We need a reference to the brain we want to attach to our creature.
local brain = require "brains/natsudragonflybrain"

--[NEW] And then we attach the brain to our creature.
inst:SetBrain(brain)

--[NEW] Our creature needs a sound component to be able to play back sound.
inst.entity:AddSoundEmitter()

--[NEW] return our new entity so that it can be added to the world.
return inst
end

--[NEW] Here we register our new prefab so that it can be used in game.
return Prefab( "common/creatures/natsudragonfly", init_prefab, assets, nil)

 

Brain:

require "behaviours/follow"
require "behaviours/wander"


local NatsuDragonflyBrain = Class(Brain, function(self, inst)
Brain._ctor(self, inst)
end)

local MIN_FOLLOW = 4
local MAX_FOLLOW = 11
local MED_FOLLOW = 6
local MAX_WANDER_DIST = 10
local MAX_CHASE_TIME = 6


local function GetFaceTargetFn(inst)
return inst.components.follower.leader
end

local function KeepFaceTargetFn(inst, target)
return inst.components.follower.leader == target
end

function NatsuDragonflyBrain:OnStart()

local root = PriorityNode(
{
ChaseAndAttack(self.inst, MAX_CHASE_TIME),
Follow(self.inst, function() return self.inst.components.follower.leader end, MIN_FOLLOW, MED_FOLLOW, MAX_FOLLOW, true),
--FaceEntity(self.inst, GetFaceTargetFn, KeepFaceTargetFn),
Wander(self.inst, function() return Point(GetPlayer().Transform:GetWorldPosition()) end , MAX_WANDER_DIST)
}, .5)

self.bt = BT(self.inst, root)

end


return NatsuDragonflyBrain

 

 

Thanks for the help :-)

 

post-219833-0-93461200-1405687706_thumb.

 

Link to comment
Share on other sites

Thank you for the quick answer and sorry for the BBcode ^^

 

Here is my modmain.lua

 

--[NEW] This is how we tell the game we've created a new prefab.
PrefabFiles = {
--[NEW] This is the name of our prefab file in scripts/prefabs
"natsudragonfly",
}

--This function spawns the creature at the player's position.
function SpawnCreature(player)

--Get the player's current position.
local x, y, z = player.Transform:GetWorldPosition()

--[NEW] Spawn our new creature at the world origin.
local creature = GLOBAL.SpawnPrefab("natsudragonfly")

--Move the creature to the player's position.
creature.Transform:SetPosition( x, y, z )
end

--Tell the engine to run the function "SpawnCreature" as soon as the player spawns in the world.
AddSimPostInit(SpawnCreature)

 

 

 

Link to comment
Share on other sites

I don't think that is the issue in question, but "player" doesn't seem to be defined. It's probably supposed to be "GLOBAL.GetPlayer()", should an issue with it arise.

Other than that, I don't see an problem. I can't test stuff right now, if this post isn't updated when you read it, and you can't wait for others to answer, try removing "GLOBAL" from "GLOBAL.SpawnPrefab" and spelling ".Transform" as ".transform". I really don't think those things could be an issue, maybe the prefab gets loaded after modmain.

As said, I'll check that several hours later, if not tomorrow, unless you find a proper answer for your problem. Excuse me for any confusion and not doing more than that.

Link to comment
Share on other sites

@Mobbstar

Thank you very much for your answer, but it is not fixed. I can wait for other answers, so you are very nice if you can check this later. (when you want :-) )

Edit: I have deleted the spawn function, but i can't manually spawn the creature. (The prefabs was always activated in the modmain.lua)

 

@mynameisthis

Thank you but i couldn't do this work without the Cheerio's creature guide, and i have not finished yet :-)

Chester is irreplaceable, it will always be my favourite chest :grin:

Link to comment
Share on other sites

Edit: I have deleted the spawn function, but i can't manually spawn the creature. (The prefabs was always activated in the modmain.lua)

 

You can't spawn the prefab, huh? Are you using 'DebugSpawn("Prefab")' in the console? If so, does it give an error of any kind? Then the prefab doesn't work properly, and the spawn function is probably fine. I'll briefly read through your code before going to bed, maybe I spot something.

EDIT: I can't find a main function (nor called funtions) in your prefab file. Every prefab has a main function (usually called fn) that has all the "AddComponent" and "inst.component.x.y" in it, either directly or by other functions. The last line has the name of that main function, so the game runs it in order to create the entity as wanted.

Try comparing your prefabs structure to some other, simple things (for example homesign.lua = a normal, boring sign). Any function goes to a main function fn, and that main function goes to the line at the end, which actually makes the whole thing.

If you need more help than that, I'll have more time tomorrow.

Link to comment
Share on other sites

Yes, I used DebugSpawn.

When i use this command, all the console disappear and can't reappear using CTRL+L. And i cannot enter a new command

 

EDIT: In my prefab, there is "local function init_prefab()", instead of "local function fn(Sim)" in homesign.lua

I changed "local function init_prefab()" by "local function fn(Sim)" (also present in all other prefabs) in my own prefab but when i start my mod, the main screen with "play", "options"...  is freezing with no music :(

Yes please, i need more help tomorrow :-)

Link to comment
Share on other sites

Here's a (hopefully fixed) version. SetFlameOn() needs to be complemented, add the function just above the main function. I am honestly scared of testing it because I do not own the dlc. Would it be illegal? Probably.

Tell me wether it worked.

local assets ={Asset("ANIM", "anim/dragonfly_build.zip"),Asset("ANIM", "anim/dragonfly_fire_build.zip"),Asset("ANIM", "anim/dragonfly_basic.zip"),Asset("ANIM", "anim/dragonfly_actions.zip"),Asset("SOUND", "sound/dragonfly.fsb")}local prefabs ={"lavaspit","armordragonfly","firesplash_fx","tauntfire_fx","attackfire_fx","vomitfire_fx","firering_fx",}local loot = {"meat", "meat", "meat", "meat", "meat", "meat", "meat", "minotaurhorn", "armordragonfly"}--[NEW] This function creates a new entity based on a prefab.local function init_prefab() --that works the same as fn--[NEW] First we create an entity.local inst = CreateEntity()--[NEW] Then we add a transform component se we can place this entity in the world.local trans = inst.entity:AddTransform()--[NEW] Then we add an animation component which allows us to animate our entity.local anim = inst.entity:AddAnimState()--[NEW] The bank name is the name of the Spriter file.anim:SetBank("dragonfly")--[NEW] The build name is the name of the animation folder in spriter.anim:SetBuild("dragonfly_build")local shadow = inst.entity:AddDynamicShadow()shadow:SetSize(6, 3.5)--[NEW] Here we start playing the 'idle' animation and tell it to loop.anim:PlayAnimation("idle", true )inst:AddTag("epic") --I think this makes boss music play all the timeinst:AddTag("dragonfly")inst:AddTag("scarytoprey")inst:AddTag("largecreature")inst:AddTag("notraptrigger")inst:AddTag("flying")inst.Transform:SetFourFaced()inst:AddComponent("health")inst.components.health:SetMaxHealth(1500)inst.components.health.fire_damage_scale = 0inst:AddComponent("combat")inst.components.combat:SetDefaultDamage(TUNING.DRAGONFLY_DAMAGE)inst.components.combat.playerdamagepercent = .5inst.components.combat:SetRange(4)inst.components.combat:SetAreaDamage(6, 0.8)inst.components.combat.hiteffectsymbol = "dragonfly_body"inst.components.combat:SetAttackPeriod(1.5)inst.components.combat:SetRetargetFunction(3, RetargetFn)inst.components.combat:SetKeepTargetFunction(KeepTargetFn)inst.components.combat.battlecryenabled = falseinst.components.combat:SetHurtSound("dontstarve_DLC001/creatures/dragonfly/hurt")inst.flame_on = falseinst:ListenForEvent("killed", function(inst, data)if inst.components.combat and data and data.victim == inst.components.combat.target theninst.components.combat.target = nilinst.last_kill_time = GetTime()endend)inst:ListenForEvent("losttarget", function(inst)SetFlameOn(inst, false) --SetFlameOn isn't declared somewhereend)inst:ListenForEvent("giveuptarget", function(inst)SetFlameOn(inst, false)end)inst:ListenForEvent("newcombattarget", function(inst, data)if data.target ~= nil thenSetFlameOn(inst, true, true)endend)inst.SetFlameOn = SetFlameOnlocal light = inst.entity:AddLight()inst.Light:Enable(false)inst.Light:SetRadius(2)inst.Light:SetFalloff(0.5)inst.Light:SetIntensity(.75)inst.Light:SetColour(235/255,121/255,12/255)inst:AddComponent("lootdropper")inst.components.lootdropper:SetLoot(loot)--[NEW] We need to add a 'locomotor' component otherwise our creature can't walk around the world.inst:AddComponent("locomotor")--[NEW] Here we can tune how fast our creature runs forward.inst.components.locomotor.runspeed = 7--[NEW] We need to add a 'physics' component for our character to walk through the world. Lucky for us, this-- this is made easy for us by the 'MakeCharacterPhysics' function. This function sets up physics,-- collision tags, collision masks, friction etc. All we need to give it is a mass and a radius which-- in this case we've set to 10 and 0.5.MakeCharacterPhysics(inst, 500, 1.4)inst:AddComponent("follower")local player = GetPlayer()if player and player.components.leader thenplayer.components.leader:AddFollower(inst)end--[NEW] Here we attach our stategraph to our prefab.inst:SetStateGraph("SGdragonfly")--[NEW] We need a reference to the brain we want to attach to our creature.local brain = require "brains/natsudragonflybrain"--[NEW] And then we attach the brain to our creature.inst:SetBrain(brain)--[NEW] Our creature needs a sound component to be able to play back sound.inst.entity:AddSoundEmitter() --Maybe you should move this up. Maybe.--[NEW] return our new entity so that it can be added to the world.return instend--[NEW] Here we register our new prefab so that it can be used in game.return Prefab( "common/creatures/natsudragonfly", init_prefab, assets, nil) --what is that nil for?

You already had a main function. I just didn't see it :wilson_dorky:

Link to comment
Share on other sites

@Mobbstar

Okay i've read your issue :

 

"inst:AddTag("epic") --I think this makes boss music play all the time" I don't know but probably

 

"SetFlameOn(inst, false) --SetFlameOn isn't declared somewhere" Where and how i can declare this ? I'm a begginner in lua scripting ...

 

"return Prefab( "common/creatures/natsudragonfly", init_prefab, assets, nil) --what is that nil for?" I don't know, the nil was already present in the original file, what's a nil ?

 

 

 

I am honestly scared of testing it because I do not own the dlc. Would it be illegal? Probably.

 

Illegal ? I don't think  :wilson_laugh:

 

Link to comment
Share on other sites

"SetFlameOn(inst, false) --SetFlameOn isn't declared somewhere" Where and how i can declare this ?

It's probably in the original file. Sorry for not saying so. (it should start with "local function" and end with "end")

 

"return Prefab( "common/creatures/natsudragonfly", init_prefab, assets, nil) --what is that nil for?" I don't know, the nil was already present in the original file, what's a nil ?

 

It's for the prefabs table I think, which is odd, since the original file should have "prefabs" there instead of nil (which means undefined/no value, in any programming language).

 

Add the "local function SetFlameOn" and, if that doesn't help, try replacing the nil at the end with "prefabs" (again, I am confused about why it isn't already hooked up to something or integrated in any way)

Link to comment
Share on other sites

Add the "local function SetFlameOn" and, if that doesn't help, try replacing the nil at the end with "prefabs" (again, I am confused about why it isn't already hooked up to something or integrated in any way)

 

Yes, i have found the "SetFlameOn" :

local assets =

{

Asset("ANIM", "anim/dragonfly_build.zip"),

Asset("ANIM", "anim/dragonfly_fire_build.zip"),

Asset("ANIM", "anim/dragonfly_basic.zip"),

Asset("ANIM", "anim/dragonfly_actions.zip"),

Asset("SOUND", "sound/dragonfly.fsb")

}

local prefabs =

{

"lavaspit",

"armordragonfly",

"firesplash_fx",

"tauntfire_fx",

"attackfire_fx",

"vomitfire_fx",

"firering_fx",

}

local loot = {"meat", "meat", "meat", "meat", "meat", "meat", "meat", "minotaurhorn", "armordragonfly"}

local function SetFlameOn(inst, flameon, newtarget, freeze)

if flameon and not inst.flame_on then

inst.flame_on = true

if newtarget then

inst.sg:GoToState("taunt_pre")

end

elseif not flameon and inst.flame_on then

if freeze then

inst.flame_on = false

inst.Light:Enable(false)

inst.components.propagator:StopSpreading()

inst.AnimState:SetBuild("dragonfly_build")

inst.fire_build = false

elseif inst.components.combat and not inst.components.combat.target then

inst.sg:GoToState("flameoff")

end

end

end

--[NEW] This function creates a new entity based on a prefab.

local function init_prefab() --that works the same as fn

--[NEW] First we create an entity.

local inst = CreateEntity()

--[NEW] Then we add a transform component se we can place this entity in the world.

local trans = inst.entity:AddTransform()

--[NEW] Then we add an animation component which allows us to animate our entity.

local anim = inst.entity:AddAnimState()

--[NEW] The bank name is the name of the Spriter file.

anim:SetBank("dragonfly")

--[NEW] The build name is the name of the animation folder in spriter.

anim:SetBuild("dragonfly_build")

local shadow = inst.entity:AddDynamicShadow()

shadow:SetSize(6, 3.5)

--[NEW] Here we start playing the 'idle' animation and tell it to loop.

anim:PlayAnimation("idle", true )

--[NEW] Our creature needs a sound component to be able to play back sound.

inst.entity:AddSoundEmitter() --Maybe you should move this up. Maybe.

--inst:AddTag("epic") --I think this makes boss music play all the time

inst:AddTag("dragonfly")

inst:AddTag("scarytoprey")

inst:AddTag("largecreature")

inst:AddTag("notraptrigger")

inst:AddTag("flying")

inst.Transform:SetFourFaced()

inst:AddComponent("health")

inst.components.health:SetMaxHealth(1500)

inst.components.health.fire_damage_scale = 0

inst:AddComponent("combat")

inst.components.combat:SetDefaultDamage(TUNING.DRAGONFLY_DAMAGE)

inst.components.combat.playerdamagepercent = .5

inst.components.combat:SetRange(4)

inst.components.combat:SetAreaDamage(6, 0.8)

inst.components.combat.hiteffectsymbol = "dragonfly_body"

inst.components.combat:SetAttackPeriod(1.5)

inst.components.combat:SetRetargetFunction(3, RetargetFn)

inst.components.combat:SetKeepTargetFunction(KeepTargetFn)

inst.components.combat.battlecryenabled = false

inst.components.combat:SetHurtSound("dontstarve_DLC001/creatures/dragonfly/hurt")

inst.flame_on = false

inst:ListenForEvent("killed", function(inst, data)

if inst.components.combat and data and data.victim == inst.components.combat.target then

inst.components.combat.target = nil

inst.last_kill_time = GetTime()

end

end)

inst:ListenForEvent("losttarget", function(inst)

SetFlameOn(inst, false) --SetFlameOn isn't declared somewhere

end)

inst:ListenForEvent("giveuptarget", function(inst)

SetFlameOn(inst, false)

end)

inst:ListenForEvent("newcombattarget", function(inst, data)

if data.target ~= nil then

SetFlameOn(inst, true, true)

end

end)

inst.SetFlameOn = SetFlameOn

local light = inst.entity:AddLight()

inst.Light:Enable(false)

inst.Light:SetRadius(2)

inst.Light:SetFalloff(0.5)

inst.Light:SetIntensity(.75)

inst.Light:SetColour(235/255,121/255,12/255)

inst:AddComponent("lootdropper")

inst.components.lootdropper:SetLoot(loot)

--[NEW] We need to add a 'locomotor' component otherwise our creature can't walk around the world.

inst:AddComponent("locomotor")

--[NEW] Here we can tune how fast our creature runs forward.

inst.components.locomotor.runspeed = 7

--[NEW] We need to add a 'physics' component for our character to walk through the world. Lucky for us, this

-- this is made easy for us by the 'MakeCharacterPhysics' function. This function sets up physics,

-- collision tags, collision masks, friction etc. All we need to give it is a mass and a radius which

-- in this case we've set to 10 and 0.5.

MakeCharacterPhysics(inst, 500, 1.4)

inst:AddComponent("follower")

local player = GetPlayer()

if player and player.components.leader then

player.components.leader:AddFollower(inst)

end

--[NEW] Here we attach our stategraph to our prefab.

inst:SetStateGraph("SGdragonfly")

--[NEW] We need a reference to the brain we want to attach to our creature.

local brain = require "brains/natsudragonflybrain"

--[NEW] And then we attach the brain to our creature.

inst:SetBrain(brain)

--[NEW] return our new entity so that it can be added to the world.

return inst

end

--[NEW] Here we register our new prefab so that it can be used in game.

return Prefab( "common/creatures/natsudragonfly", init_prefab, assets, prefabs)

 

As you can see, I also have modified the nil by prefabs, but i still have the same error, so i tried to add these functions (Present in combat)

 

local function RetargetFn(inst)

if inst:GetTimeAlive() < 5 then return end

if inst.spit_interval and inst.last_target_spit_time and (GetTime() - inst.last_target_spit_time) > (inst.spit_interval * 1.5) then

return FindEntity(inst, 7*TARGET_DIST, function(guy)

return inst.components.combat:CanTarget(guy)

and not guy:HasTag("prey")

and not guy:HasTag("smallcreature")

end)

else

return FindEntity(inst, TARGET_DIST, function(guy)

return inst.components.combat:CanTarget(guy)

and not guy:HasTag("prey")

and not guy:HasTag("smallcreature")

end)

end

end

local function KeepTargetFn(inst, target)

return inst.components.combat:CanTarget(target)

end

 

But when i active the mod the menu keep freezing so i removed these lines ...

I'm sure the problems come from the combat component, but i can't see where exactly.

Thank you for the SetFlameOn, it solved one part of the crash but there are others parts ...

 

EDIT : I've found the issue, it works ! Thanks to you !

Can you read what i done ?

 

local assets =
{
Asset("ANIM", "anim/dragonfly_build.zip"),
Asset("ANIM", "anim/dragonfly_fire_build.zip"),
Asset("ANIM", "anim/dragonfly_basic.zip"),
Asset("ANIM", "anim/dragonfly_actions.zip"),
Asset("SOUND", "sound/dragonfly.fsb")
}
 
local prefabs =
{
"lavaspit",
"armordragonfly",
"firesplash_fx",
"tauntfire_fx",
"attackfire_fx",
"vomitfire_fx",
"firering_fx",
}
 
local loot = {"meat", "meat", "meat", "meat", "meat", "meat", "meat", "minotaurhorn", "armordragonfly"}
 
 local TARGET_DIST = 3
 
local function Retarget(inst)
 
    local newtarget = FindEntity(inst, 20, function(guy)
            return  guy.components.combat and 
                    inst.components.combat:CanTarget(guy) and
                    (guy.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == guy)
    end)
 
    return newtarget
end
 
 local function SetFlameOn(inst, flameon, newtarget, freeze)
    if flameon and not inst.flame_on then
        inst.flame_on = true
        if newtarget then
            inst.sg:GoToState("taunt_pre")
        end
    elseif not flameon and inst.flame_on then
        if freeze then
            inst.flame_on = false
            inst.Light:Enable(false)
            inst.AnimState:SetBuild("dragonfly_build")
            inst.fire_build = false
        elseif inst.components.combat and not inst.components.combat.target then
            inst.sg:GoToState("flameoff")
        end
    end
end
 
local function OnFreeze(inst)
    inst.SoundEmitter:KillSound("flying")
    inst:ClearBufferedAction()
    SetFlameOn(inst, false, nil, true)
end
 
local function OnUnfreeze(inst)
    inst.recently_frozen = true
    inst.components.locomotor.walkspeed = 4
    inst.SoundEmitter:PlaySound("dontstarve_DLC001/creatures/dragonfly/fly", "flying")
inst.components.combat:SetTarget(nil)
end
 
    inst:DoTaskInTime(5, function(inst) 
        inst.recently_frozen = false
        inst.components.locomotor.walkspeed = 9
        inst.spit_interval = math.random(20,30)
    end)
end
 
--[NEW] This function creates a new entity based on a prefab.
local function init_prefab() --that works the same as fn
 
--[NEW] First we create an entity.
local inst = CreateEntity()
--[NEW] Then we add a transform component se we can place this entity in the world.
local trans = inst.entity:AddTransform()
--[NEW] Then we add an animation component which allows us to animate our entity.
local anim = inst.entity:AddAnimState()
--[NEW] The bank name is the name of the Spriter file.
anim:SetBank("dragonfly")
--[NEW] The build name is the name of the animation folder in spriter.
anim:SetBuild("dragonfly_build")
local shadow = inst.entity:AddDynamicShadow()
shadow:SetSize(6, 3.5)
--[NEW] Here we start playing the 'idle' animation and tell it to loop.
anim:PlayAnimation("idle", true )
--[NEW] Our creature needs a sound component to be able to play back sound.
inst.entity:AddSoundEmitter() --Maybe you should move this up. Maybe.
 
--inst:AddTag("epic") --I think this makes boss music play all the time
inst:AddTag("dragonfly")
inst:AddTag("scarytoprey")
inst:AddTag("largecreature")
inst:AddTag("notraptrigger")
inst:AddTag("flying")
 
inst.Transform:SetFourFaced()
 
inst:AddComponent("health")
inst.components.health:SetMaxHealth(1500)
inst.components.health.fire_damage_scale = 0
 
inst:AddComponent("groundpounder")
    inst.components.groundpounder.numRings = 2
    inst.components.groundpounder.burner = false
    inst.components.groundpounder.groundpoundfx = "firesplash_fx"
    inst.components.groundpounder.groundpounddamagemult = .5
    inst.components.groundpounder.groundpoundringfx = "firering_fx"
 
inst:AddComponent("combat")
inst.components.combat:SetDefaultDamage(TUNING.DRAGONFLY_DAMAGE)
inst.components.combat.playerdamagepercent = 0
inst.components.combat:SetRange(4)
inst.components.combat:SetAreaDamage(6, 0.8)
inst.components.combat.hiteffectsymbol = "dragonfly_body"
inst.components.combat:SetAttackPeriod(1.5)
inst.components.combat:SetRetargetFunction(3, Retarget)
inst.components.combat.battlecryenabled = false
inst.components.combat:SetHurtSound("dontstarve_DLC001/creatures/dragonfly/hurt")
inst.flame_on = false
inst:ListenForEvent("killed", function(inst, data)
if inst.components.combat and data and data.victim == inst.components.combat.target then
inst.components.combat.target = nil
inst.last_kill_time = GetTime()
end
end)
inst:ListenForEvent("losttarget", function(inst)
SetFlameOn(inst, false) --SetFlameOn isn't declared somewhere
end)
inst:ListenForEvent("giveuptarget", function(inst)
SetFlameOn(inst, false)
end)
inst:ListenForEvent("newcombattarget", function(inst, data)
if data.target ~= nil then
SetFlameOn(inst, true, true)
end
end)
inst.SetFlameOn = SetFlameOn
 
local light = inst.entity:AddLight()
inst.Light:Enable(false)
inst.Light:SetRadius(2)
inst.Light:SetFalloff(0.5)
inst.Light:SetIntensity(.75)
inst.Light:SetColour(235/255,121/255,12/255)
 
inst:AddComponent("lootdropper")
inst.components.lootdropper:SetLoot(loot)
 
MakeHugeFreezableCharacter(inst, "dragonfly_body")
    inst.components.freezable.wearofftime = 1.5
    inst:ListenForEvent("freeze", OnFreeze)
    inst:ListenForEvent("unfreeze", OnUnfreeze)
 
--[NEW] We need to add a 'locomotor' component otherwise our creature can't walk around the world.
inst:AddComponent("locomotor")
--[NEW] Here we can tune how fast our creature runs forward.
inst.components.locomotor.walkspeed = 8
 
--[NEW] We need to add a 'physics' component for our character to walk through the world. Lucky for us, this
-- this is made easy for us by the 'MakeCharacterPhysics' function. This function sets up physics,
-- collision tags, collision masks, friction etc. All we need to give it is a mass and a radius which
-- in this case we've set to 10 and 0.5.
MakeCharacterPhysics(inst, 500, 1.4)
 
inst:AddComponent("follower")
local player = GetPlayer()
if player and player.components.leader then
player.components.leader:AddFollower(inst)
end
 
--[NEW] Here we attach our stategraph to our prefab.
inst:SetStateGraph("SGdragonfly")
 
--[NEW] We need a reference to the brain we want to attach to our creature.
local brain = require "brains/natsudragonflybrain"
 
--[NEW] And then we attach the brain to our creature.
inst:SetBrain(brain)
 
--[NEW] return our new entity so that it can be added to the world.
return inst
end
 
--[NEW] Here we register our new prefab so that it can be used in game.

return Prefab( "common/creatures/natsudragonfly", init_prefab, assets, prefabs) --what is that nil for?

 

Some bugs (no crashes) are persisting :

On Unfreeze, he didn't follow and stay,

When he fight, he enter in a "rage mode" (The mighty SetFlame ^^) but he never return to his normal mode

 

@Mobbstar hope you can help me  :wilson_smile:

Link to comment
Share on other sites

Some bugs (no crashes) are persisting :

On Unfreeze, he didn't follow and stay,

When he fight, he enter in a "rage mode" (The mighty SetFlame ^^) but he never return to his normal mode

 

@Mobbstar hope you can help me  :wilson_smile:

Did you make sure all the things he was fighting were gone? I seriously have little to no clue how the default dragonfly works, and as a consequence, how yours works (or doesn't :p). I am going to dig a little deeper if nobody else who has RoG comes to your aid *hostile sidestare* , but I just made a topic for "Questastic!" and I'm gonna make an update for "Pigspikes!" now.

Link to comment
Share on other sites

Thank you for your help, All is WORKING, i've solved all the things  :wilson_goodjob:

I've just one question, it is possible to script : When i give him ashes, his health is regen by 200 ?

 

PS: I love "Questastic" :D

 

Link to comment
Share on other sites

Thank you for your help, All is WORKING, i've solved all the things  :wilson_goodjob:

I've just one question, it is possible to script : When i give him ashes, his health is regen by 200 ?

 

PS: I love "Questastic" :grin:

 

Yay! You did it! That's the greatest joy, when stuff finally works!

 

P.S.: Glad to hear that! :loyal:

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