Sign in to follow this  
Yagenius

[HELP] Can someone help me with coding please?

Recommended Posts

Yagenius    2

In game it say :  attempt to index  "locomote" (a nil value)
 
(It happen , after I choose my Character.)
 
--------------------------------------------------------
 
  (Sorry for my dumb , I'm Just a beginner.)
 
--------------------------------------------------------
 
Here this is a code (stategraph , SGai.lua ) I use in game . (I try to understand the Code from " Wicked The Merm " )
 
 

 

 

local trace = function() end

local function DoFoleySounds(inst)

    for k,v in pairs(inst.components.inventory.equipslots) do
        if v.components.inventoryitem and v.components.inventoryitem.foleysound then
            inst.SoundEmitter:PlaySound(v.components.inventoryitem.foleysound)
        end
    end

if inst.prefab == "wx78" then
inst.SoundEmitter:PlaySound("dontstarve/movement/foley/wx78")
end

end

local actionhandlers =
{
ActionHandler(ACTIONS.CHOP,
function(inst)
if not inst.sg:HasStateTag("prechop") then
if inst.sg:HasStateTag("chopping") then
return "chop"
else
return "chop_start"
end
end
end),
ActionHandler(ACTIONS.MINE,
function(inst)
if not inst.sg:HasStateTag("premine") then
if inst.sg:HasStateTag("mining") then
return "mine"
else
return "mine_start"
end
end
end),
ActionHandler(ACTIONS.HAMMER,
function(inst)
if not inst.sg:HasStateTag("prehammer") then
if inst.sg:HasStateTag("hammering") then
return "hammer"
else
return "hammer_start"
end
end
end),
    ActionHandler(ACTIONS.TERRAFORM,
        function(inst)
            return "terraform"
        end),
    
    ActionHandler(ACTIONS.DIG,
function(inst)
if not inst.sg:HasStateTag("predig") then
if inst.sg:HasStateTag("digging") then
return "dig"
else
return "dig_start"
end
end
end),
ActionHandler(ACTIONS.NET,
function(inst)
if not inst.sg:HasStateTag("prenet") then
if inst.sg:HasStateTag("netting") then
return "bugnet"
else
return "bugnet_start"
end
end
end),
ActionHandler(ACTIONS.FISH, "fishing_pre"),

    ActionHandler(ACTIONS.FERTILIZE, "doshortaction"),
    ActionHandler(ACTIONS.TRAVEL, "doshortaction"),
ActionHandler(ACTIONS.LIGHT, "give"),
ActionHandler(ACTIONS.UNLOCK, "give"),
ActionHandler(ACTIONS.TURNOFF, "give"),
ActionHandler(ACTIONS.TURNON, "give"),
ActionHandler(ACTIONS.ADDFUEL, "doshortaction"),
ActionHandler(ACTIONS.REPAIR, "dolongaction"),

ActionHandler(ACTIONS.READ, "book"),

ActionHandler(ACTIONS.MAKEBALLOON, "makeballoon"),
ActionHandler(ACTIONS.DEPLOY, "doshortaction"),
ActionHandler(ACTIONS.STORE, "doshortaction"),
ActionHandler(ACTIONS.DROP, "doshortaction"),
ActionHandler(ACTIONS.MURDER, "dolongaction"),
    ActionHandler(ACTIONS.ACTIVATE,
function(inst, action)
if action.target.components.activatable then
if action.target.components.activatable.quickaction then
return "doshortaction"
else
return "dolongaction"
end
end
end),
ActionHandler(ACTIONS.PICK,
function(inst, action)
if action.target.components.pickable then
if action.target.components.pickable.quickpick then
return "doshortaction"
else
return "dolongaction"
end
end
end),

ActionHandler(ACTIONS.SLEEPIN,
        function(inst, action)
            if action.invobject then
if action.invobject.onuse then
action.invobject.onuse()
end
                return "bedroll"
            else
                return "doshortaction"
            end
        
        end),

ActionHandler(ACTIONS.TAKEITEM, "dolongaction" ),

ActionHandler(ACTIONS.BUILD, "dolongaction"),
ActionHandler(ACTIONS.SHAVE, "shave"),
ActionHandler(ACTIONS.COOK, "dolongaction"),
ActionHandler(ACTIONS.PICKUP, "doshortaction"),
ActionHandler(ACTIONS.CHECKTRAP, "doshortaction"),
ActionHandler(ACTIONS.RUMMAGE, "doshortaction"),
ActionHandler(ACTIONS.BAIT, "doshortaction"),
ActionHandler(ACTIONS.HEAL, "dolongaction"),
ActionHandler(ACTIONS.SEW, "dolongaction"),
ActionHandler(ACTIONS.TEACH, "dolongaction"),
ActionHandler(ACTIONS.RESETMINE, "dolongaction"),
ActionHandler(ACTIONS.EAT,
function(inst, action)
if inst.sg:HasStateTag("busy") then
return nil
end
local obj = action.target or action.invobject
if not (obj and obj.components.edible) then
return nil
end

if obj.components.edible.foodtype == "MEAT" then
return "eat"
else
return "quickeat"
end
end),
ActionHandler(ACTIONS.GIVE, "give"),
ActionHandler(ACTIONS.PLANT, "doshortaction"),
ActionHandler(ACTIONS.HARVEST, "dolongaction"),
ActionHandler(ACTIONS.PLAY, function(inst, action)
if action.invobject then
if action.invobject:HasTag("flute") then
return "play_flute"
elseif action.invobject:HasTag("horn") then
return "play_horn"
end
end
end),
ActionHandler(ACTIONS.JUMPIN, "jumpin"),
ActionHandler(ACTIONS.DRY, "doshortaction"),
ActionHandler(ACTIONS.CASTSPELL, "castspell"),
ActionHandler(ACTIONS.BLINK, "quicktele"),
ActionHandler(ACTIONS.COMBINESTACK, "doshortaction"),
}


local events=
{

EventHandler("locomote", function(inst)
local is_attacking = inst.sg:HasStateTag("attack")
local is_busy = inst.sg:HasStateTag("busy")
if is_attacking or is_busy then return end
local is_moving = inst.sg:HasStateTag("moving")
local is_running = inst.sg:HasStateTag("running")
local should_move = inst.components.locomotor:WantsToMoveForward()
local should_run = inst.components.locomotor:WantsToRun()

if is_moving and not should_move then
if is_running then
inst.sg:GoToState("run_stop")
else
inst.sg:GoToState("walk_stop")
end
elseif (not is_moving and should_move) or (is_moving and should_move and is_running ~= should_run) then
if should_run then
inst.sg:GoToState("run_start")
else
inst.sg:GoToState("walk_start")
end
end
end),

EventHandler("transform_weretiger", function(inst, data)
if inst.components.weretigerss then
TheCamera:SetDistance(14)
inst.sg:GoToState("weretiger")

end
end),

EventHandler("blocked", function(inst, data)
if not inst.components.health:IsDead() then
if inst.sg:HasStateTag("shell") then
inst.sg:GoToState("shell_hit")
end
end
end),

EventHandler("attacked", function(inst, data)
        if not inst.components.health:IsDead() then
            if data.attacker and data.attacker:HasTag("insect") then
local is_idle = inst.sg:HasStateTag("idle")
if not is_idle then
-- avoid stunlock when attacked by bees/mosquitos
-- don't go to full hit state, just play sounds

inst.SoundEmitter:PlaySound("dontstarve/wilson/hit")

if inst.prefab ~= "wes" then
local sound_name = inst.soundsname or inst.prefab
local sound_event = "dontstarve/characters/"..sound_name.."/hurt"
inst.SoundEmitter:PlaySound(inst.hurtsoundoverride or sound_event)
end
return
end
            end
if inst.sg:HasStateTag("shell") then
inst.sg:GoToState("shell_hit")
else
inst.sg:GoToState("hit")
end
        end
    end),

EventHandler("doattack", function(inst)
if not inst.components.health:IsDead() and not inst.sg:HasStateTag("attack") then
local weapon = inst.components.combat and inst.components.combat:GetWeapon()
if weapon and weapon:HasTag("blowdart") then
inst.sg:GoToState("blowdart")
elseif weapon and weapon:HasTag("thrown") then
inst.sg:GoToState("throw")
else
inst.sg:GoToState("attack")
end
end
end),

--[[EventHandler("dowhiff", function(inst)
if not inst.components.health:IsDead() then
local weapon = inst.components.combat and inst.components.combat:GetWeapon()
if weapon and weapon:HasTag("blowdart") then
inst.sg:GoToState("blowdart")
elseif weapon and weapon:HasTag("thrown") then
inst.sg:GoToState("throw")
else
inst.sg:GoToState("attack")
end
end
end),
--]]

EventHandler("equip", function(inst, data)
if inst.sg:HasStateTag("idle") then
            if data.eslot == EQUIPSLOTS.HANDS then
                inst.sg:GoToState("item_out")
            else
                inst.sg:GoToState("item_hat")
            end
end
end),

EventHandler("unequip", function(inst, data)

if inst.sg:HasStateTag("idle") then

            if data.eslot == EQUIPSLOTS.HANDS then
                inst.sg:GoToState("item_in")
            else
                inst.sg:GoToState("item_hat")
            end
end
end),

EventHandler("death", function(inst)
inst.components.playercontroller:Enable(false)
inst.sg:GoToState("death")

--inst.SoundEmitter:PlaySound("dontstarve/wilson/death")

        --local sound_name = inst.soundsname or inst.prefab
--if inst.prefab ~= "wes" then
        --    inst.SoundEmitter:PlaySound("dontstarve/characters/"..sound_name.."/death_voice")
        --end

end),

EventHandler("ontalk", function(inst, data)
if inst.sg:HasStateTag("idle") then
if inst.prefab == "wes" then
                inst.sg:GoToState("mime")
else
                inst.sg:GoToState("talk", data.noanim)
            end
end

end),
EventHandler("wakeup",
function(inst)
inst.sg:GoToState("wakeup")
end),
EventHandler("powerup",
function(inst)
if GetTick() > 0 then
inst.sg:GoToState("powerup")
end
end),
EventHandler("powerdown",
function(inst)
inst.sg:GoToState("powerdown")
end),

EventHandler("readytocatch",
        function(inst)
            inst.sg:GoToState("catch_pre")
        end),

EventHandler("toolbroke",
        function(inst, data)
            inst.sg:GoToState("toolbroke", data.tool)
        end),

EventHandler("torchranout",
function(inst, data)
if not inst.components.inventory:IsItemEquipped(data.torch) then
local sameTool = inst.components.inventory:FindItem(function(item)
return item.prefab == data.torch.prefab
end)
if sameTool then
inst.components.inventory:Equip(sameTool)
end
end
end),

EventHandler("armorbroke",
        function(inst, data)
            inst.sg:GoToState("armorbroke", data.armor)
        end),

EventHandler("fishingcancel",
        function(inst)
         if inst.sg:HasStateTag("fishing") then
             inst.sg:GoToState("fishing_pst")
            end
        end),
}



local statue_symbols =
{
"ww_head",
"ww_limb",
"ww_meathand",
"ww_shadow",
"ww_torso",
"frame",
"rope_joints",
"swap_grown"
}


local states=
{

State{
name = "wakeup",

onenter = function(inst)
inst.components.playercontroller:Enable(false)
inst.AnimState:PlayAnimation("wakeup")
inst.components.health:SetInvincible(true)
end,

onexit = function(inst)
inst.components.playercontroller:Enable(true)
inst.components.health:SetInvincible(false)
end,


events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("idle") end),
},

},

State{
name = "powerup",
tags = {"busy"},
onenter = function(inst)
inst.Physics:Stop()
inst.AnimState:PlayAnimation("powerup")
inst.components.health:SetInvincible(true)
end,

onexit = function(inst)
inst.components.health:SetInvincible(false)

end,

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("idle") end),
},
},
State{
name = "powerdown",
tags = {"busy"},
onenter = function(inst)
inst.Physics:Stop()
inst.AnimState:PlayAnimation("powerdown")
inst.components.health:SetInvincible(true)
end,

onexit = function(inst)
inst.components.health:SetInvincible(false)

end,

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("idle") end),
},
},


State{
name = "caveenter",

onenter = function(inst)
inst.components.playercontroller:Enable(false)
inst.AnimState:PlayAnimation("enter")
inst.components.health:SetInvincible(true)
end,

onexit = function(inst)
inst.components.playercontroller:Enable(true)
inst.components.health:SetInvincible(false)
end,

timeline=
{
TimeEvent(11*FRAMES, function(inst)
inst.SoundEmitter:PlaySound("dontstarve/movement/bodyfall_dirt")
end),
        },


events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("idle") end),
},

},

State{
name = "failadventure",

onenter = function(inst)
inst.components.playercontroller:Enable(false)
inst.AnimState:PlayAnimation("wakeup")
end,

onexit = function(inst)
inst.components.playercontroller:Enable(true)
inst.components.talker:Say(GetString(inst.prefab, "ANNOUNCE_ADVENTUREFAIL"))
end,


events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("idle") end),
},

},

State{
name = "rebirth",

onenter = function(inst)
inst.components.playercontroller:Enable(false)
inst.AnimState:PlayAnimation("rebirth")

inst.components.hunger:Pause()
for k,v in pairs(statue_symbols) do
inst.AnimState:OverrideSymbol(v, "wilsonstatue", v)
end
end,

timeline=
{
TimeEvent(16*FRAMES, function(inst)
inst.SoundEmitter:PlaySound("dontstarve/common/dropwood")
end),
TimeEvent(45*FRAMES, function(inst)
inst.SoundEmitter:PlaySound("dontstarve/common/dropwood")
end),
TimeEvent(92*FRAMES, function(inst)
inst.SoundEmitter:PlaySound("dontstarve/common/rebirth")
end),
},

onexit = function(inst)
inst.components.hunger:Resume()
for k,v in pairs(statue_symbols) do
inst.AnimState:ClearOverrideSymbol(v)
end

inst.components.playercontroller:Enable(true)
end,


events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("idle") end),
},

},

State{
name = "sleep",

onenter = function(inst)
inst.AnimState:PlayAnimation("sleep")
inst.components.playercontroller:Enable(false)
inst.components.health:SetInvincible(true)
end,

onexit=function(inst)
inst.components.health:SetInvincible(false)
inst.components.playercontroller:Enable(true)
end,

},

State{
name = "sleepin",

onenter = function(inst)
inst.AnimState:PlayAnimation("sleep")
inst.components.locomotor:Stop()
--inst.Controller:Enable(false)
--inst.AnimState:Hide()
inst:PerformBufferedAction()
end,

onexit= function(inst)
--inst.Controller:Enable(true)
--inst.AnimState:Show()
end,

},

State{
name = "death",
tags = {"busy"},

onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:Hide("swap_arm_carry")
inst.AnimState:PlayAnimation("death")
end,
},


State{ name = "chop_start",
tags = {"prechop", "chopping", "working"},
onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("chop_pre") -- inst.prefab == "ai" and "ai_chop_pre" or
end,

events=
{
EventHandler("unequip", function(inst) inst.sg:GoToState("idle") end ),
EventHandler("animover", function(inst) inst.sg:GoToState("chop") end),
},
},

State{
name = "chop",
tags = {"prechop", "chopping", "working"},
onenter = function(inst)
            inst.sg.statemem.action = inst:GetBufferedAction()
inst.AnimState:PlayAnimation("chop_loop") -- inst.prefab == "ai" and "ai_chop_loop" or
end,

timeline=
{
TimeEvent(2*FRAMES, function(inst)
if inst.prefab == "woodie" then
inst:PerformBufferedAction()
end
end),

TimeEvent(5*FRAMES, function(inst)
if inst.prefab == "woodie" then
inst.sg:RemoveStateTag("prechop")
end
end),

TimeEvent(10*FRAMES, function(inst)
if inst.prefab == "woodie" and
(TheInput:IsControlPressed(CONTROL_PRIMARY) or TheInput:IsControlPressed(CONTROL_ACTION) or TheInput:IsControlPressed(CONTROL_CONTROLLER_ACTION)) and
inst.sg.statemem.action and
inst.sg.statemem.action:IsValid() and
inst.sg.statemem.action.target and
inst.sg.statemem.action.target:IsActionValid(inst.sg.statemem.action.action) and
inst.sg.statemem.action.target.components.workable then
inst:ClearBufferedAction()
inst:PushBufferedAction(inst.sg.statemem.action)
end
end),


TimeEvent(5*FRAMES, function(inst)
if inst.prefab ~= "woodie" then
inst:PerformBufferedAction()
end
end),


TimeEvent(9*FRAMES, function(inst)
if inst.prefab ~= "woodie" then
inst.sg:RemoveStateTag("prechop")
end
end),

TimeEvent(14*FRAMES, function(inst)
if inst.prefab ~= "woodie" and
(TheInput:IsMouseDown(MOUSEBUTTON_LEFT) or TheInput:IsControlPressed(CONTROL_ACTION) or TheInput:IsControlPressed(CONTROL_CONTROLLER_ACTION)) and
inst.sg.statemem.action and
inst.sg.statemem.action:IsValid() and
inst.sg.statemem.action.target and
inst.sg.statemem.action.target:IsActionValid(inst.sg.statemem.action.action) and
inst.sg.statemem.action.target.components.workable then
inst:ClearBufferedAction()
inst:PushBufferedAction(inst.sg.statemem.action)
end
end),

TimeEvent(16*FRAMES, function(inst)
inst.sg:RemoveStateTag("chopping")
end),

},

events=
{
EventHandler("unequip", function(inst) inst.sg:GoToState("idle") end ),
EventHandler("animover", function(inst)
inst.AnimState:PlayAnimation("chop_pst")
inst.sg:GoToState("idle")
end ),

},
},


State{ name = "mine_start",
tags = {"premine", "working"},
onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("pickaxe_pre")
end,

events=
{
EventHandler("unequip", function(inst) inst.sg:GoToState("idle") end ),
EventHandler("animover", function(inst) inst.sg:GoToState("mine") end),
},
},

State{
name = "mine",
tags = {"premine", "mining", "working"},
onenter = function(inst)
            inst.sg.statemem.action = inst:GetBufferedAction()
inst.AnimState:PlayAnimation("pickaxe_loop")
end,

timeline=
{
TimeEvent(9*FRAMES, function(inst)
if inst.sg.statemem.action and inst.sg.statemem.action.target then
                    local fx = SpawnPrefab("mining_fx")
                    fx.Transform:SetPosition(inst.sg.statemem.action.target:GetPosition():Get())
                end
inst:PerformBufferedAction()
inst.sg:RemoveStateTag("premine")
inst.SoundEmitter:PlaySound("dontstarve/wilson/use_pick_rock")
end),

TimeEvent(14*FRAMES, function(inst)
                if (TheInput:IsControlPressed(CONTROL_PRIMARY) or
                 TheInput:IsControlPressed(CONTROL_ACTION) or TheInput:IsControlPressed(CONTROL_CONTROLLER_ACTION)) and
                    inst.sg.statemem.action and
                    inst.sg.statemem.action.target and
                    inst.sg.statemem.action.target:IsActionValid(inst.sg.statemem.action.action) and
                    inst.sg.statemem.action.target.components.workable then
                        inst:ClearBufferedAction()
                        inst:PushBufferedAction(inst.sg.statemem.action)
                end
end),

},

events=
{
EventHandler("unequip", function(inst) inst.sg:GoToState("idle") end ),
EventHandler("animover", function(inst)
inst.AnimState:PlayAnimation("pickaxe_pst")
inst.sg:GoToState("idle", true)
end ),

},
},


State{ name = "hammer_start",
tags = {"prehammer", "working"},
onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("pickaxe_pre")
end,

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("hammer") end),
},
},

State{
name = "hammer",
tags = {"prehammer", "hammering", "working"},
onenter = function(inst)
            inst.sg.statemem.action = inst:GetBufferedAction()
inst.AnimState:PlayAnimation("pickaxe_loop")
end,

timeline=
{
TimeEvent(9*FRAMES, function(inst)
inst:PerformBufferedAction()
inst.sg:RemoveStateTag("prehammer")
inst.SoundEmitter:PlaySound("dontstarve/wilson/hit")
end),

TimeEvent(14*FRAMES, function(inst)

                if (TheInput:IsControlPressed(CONTROL_SECONDARY) or
                 TheInput:IsControlPressed(CONTROL_ACTION) or TheInput:IsControlPressed(CONTROL_CONTROLLER_ALTACTION)) and
                    inst.sg.statemem.action and
                    inst.sg.statemem.action.target and
                    inst.sg.statemem.action.target:IsActionValid(inst.sg.statemem.action.action, true) and
                    inst.sg.statemem.action.target.components.workable then
                        inst:ClearBufferedAction()
                        inst:PushBufferedAction(inst.sg.statemem.action)
                end
end),

},

events=
{
EventHandler("unequip", function(inst) inst.sg:GoToState("idle") end ),
EventHandler("animover", function(inst)
inst.AnimState:PlayAnimation("pickaxe_pst")
inst.sg:GoToState("idle", true)
end ),
},
},

State{
name = "hide",
tags = {"idle", "hiding"},
onenter = function(inst)

inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("hide")
            inst.SoundEmitter:PlaySound("dontstarve/movement/foley/hidebush")
inst:AddTag("notarget")
end,

onexit = function(inst)
inst:RemoveTag("notarget")
end,

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("hide_idle") end),
},
},

State{
name = "hide_idle",
tags = {"idle", "hiding"},
onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("hide_idle", true)
inst:AddTag("notarget")
end,

onexit = function(inst)
inst:RemoveTag("notarget")
end,

},

State{
name = "shell_enter",
tags = {"idle", "hiding", "shell"},
onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("hideshell")

end,
timeline =
{
TimeEvent(6*FRAMES, function(inst)
inst.SoundEmitter:PlaySound("dontstarve/movement/foley/hideshell")
end),
},

onexit = function(inst)

end,

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("shell_idle") end),
},
},

State{
name = "shell_idle",
tags = {"idle", "hiding", "shell"},
onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("hideshell_idle", true)
end,

onexit = function(inst)
end,

},

State{
name = "shell_hit",
tags = {"busy", "hiding", "shell"},

onenter = function(inst)
inst:ClearBufferedAction()
inst.SoundEmitter:PlaySound("dontstarve/wilson/hit")
inst.AnimState:PlayAnimation("hitshell")
--local sound_name = inst.soundsname or inst.prefab
--local sound_event = "dontstarve/characters/"..sound_name.."/hurt"
--inst.SoundEmitter:PlaySound(sound_event)
inst.components.locomotor:Stop()
end,

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("shell_idle") end ),
},

timeline =
{
TimeEvent(3*FRAMES, function(inst)
inst.sg:RemoveStateTag("busy")
end),
},

},

    State{ name = "terraform",
        tags = {"busy"},
        
        onenter = function(inst)
            inst.components.locomotor:Stop()
            inst.AnimState:PlayAnimation("shovel_pre")
            inst.AnimState:PushAnimation("shovel_loop")
            inst.AnimState:PushAnimation("shovel_pst", false)
        end,
        
timeline=
{
TimeEvent(25*FRAMES, function(inst)
inst:PerformBufferedAction()
inst.sg:RemoveStateTag("busy")
inst.SoundEmitter:PlaySound("dontstarve/wilson/dig")
end),
        },

events=
{
EventHandler("animqueueover", function(inst) inst.sg:GoToState("idle") end),
},
    },
    
    State{ name = "dig_start",
tags = {"predig", "working"},
onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("shovel_pre")
end,

events=
{
EventHandler("unequip", function(inst) inst.sg:GoToState("idle") end ),
EventHandler("animover", function(inst) inst.sg:GoToState("dig") end),
},
},

State{
name = "dig",
tags = {"predig", "digging", "working"},
onenter = function(inst)
inst.AnimState:PlayAnimation("shovel_loop")
            inst.sg.statemem.action = inst:GetBufferedAction()
end,

timeline=
{
TimeEvent(15*FRAMES, function(inst)
--[[ if inst.sg.statemem.action and inst.sg.statemem.action.target then
                    local fx = SpawnPrefab("shovel_dirt")
                    fx.Transform:SetPosition( inst.sg.statemem.action.target.Transform:GetWorldPosition() )
                end
--]]
inst:PerformBufferedAction()
inst.sg:RemoveStateTag("predig")
inst.SoundEmitter:PlaySound("dontstarve/wilson/dig")

end),

TimeEvent(35*FRAMES, function(inst)
                if (TheInput:IsMouseDown(MOUSEBUTTON_RIGHT) or
                 TheInput:IsControlPressed(CONTROL_ACTION) or TheInput:IsControlPressed(CONTROL_CONTROLLER_ACTION)) and
                    inst.sg.statemem.action and
                    inst.sg.statemem.action.target and
                    inst.sg.statemem.action.target:IsActionValid(inst.sg.statemem.action.action, true) and
                    inst.sg.statemem.action.target.components.workable then
                        inst:ClearBufferedAction()
                        inst:PushBufferedAction(inst.sg.statemem.action)
                end
end),

},

events=
{
EventHandler("unequip", function(inst) inst.sg:GoToState("idle") end ),
EventHandler("animover", function(inst)
inst.AnimState:PlayAnimation("shovel_pst")
inst.sg:GoToState("idle", true)
end ),

},
},

State{ name = "bugnet_start",
tags = {"prenet", "working"},
onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("bugnet_pre")
end,

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("bugnet") end),
},
},

State{
name = "bugnet",
tags = {"prenet", "netting", "working"},
onenter = function(inst)
inst.AnimState:PlayAnimation("bugnet")
inst.SoundEmitter:PlaySound("dontstarve/wilson/use_bugnet")
end,

timeline=
{
TimeEvent(10*FRAMES, function(inst)
inst:PerformBufferedAction()
inst.sg:RemoveStateTag("prenet")
inst.SoundEmitter:PlaySound("dontstarve/wilson/dig")
end),
},

events=
{
EventHandler("animover", function(inst)
inst.sg:GoToState("idle", true)
end ),
},
},


State{ name = "fishing_pre",
tags = {"prefish", "fishing"},
onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("fishing_pre")
end,

timeline =
{
TimeEvent(13*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/common/fishingpole_cast") end),
TimeEvent(15*FRAMES, function(inst) inst:PerformBufferedAction() end),
},

events=
{
EventHandler("animover", function(inst)
inst.SoundEmitter:PlaySound("dontstarve/common/fishingpole_baitsplash")
inst.sg:GoToState("fishing")
end ),
},
},

State{
name = "fishing",
tags = {"fishing"},
onenter = function(inst, pushanim)
if pushanim then
if type(pushanim) == "string" then
inst.AnimState:PlayAnimation(pushanim)
end
inst.AnimState:PushAnimation("fishing_idle", true)
else
inst.AnimState:PlayAnimation("fishing_idle", true)
end
local equippedTool = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
if equippedTool and equippedTool.components.fishingrod then
equippedTool.components.fishingrod:WaitForFish()
end
end,

events=
{
EventHandler("fishingnibble", function(inst) inst.sg:GoToState("fishing_nibble") end ),
},
},

State{ name = "fishing_pst",
tags = {},
onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("fishing_pst")
end,

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("idle") end ),
},
},

State{
name = "fishing_nibble",
tags = {"fishing", "nibble"},
onenter = function(inst)
inst.AnimState:PlayAnimation("bite_light_pre")
inst.AnimState:PushAnimation("bite_light_loop", true)
inst.sg:SetTimeout(1 + math.random())
inst.SoundEmitter:PlaySound("dontstarve/common/fishingpole_fishinwater", "splash")
end,

onexit = function(inst)
inst.SoundEmitter:KillSound("splash")
end,

ontimeout = function(inst)
inst.sg:GoToState("fishing", "bite_light_pst")
end,

events =
{
EventHandler("fishingstrain", function(inst) inst.sg:GoToState("fishing_strain") end),
},
},

State{
name = "fishing_strain",
tags = {"fishing"},
onenter = function(inst)
inst.AnimState:PlayAnimation("bite_heavy_pre")
inst.AnimState:PushAnimation("bite_heavy_loop", true)
inst.SoundEmitter:PlaySound("dontstarve/common/fishingpole_fishinwater", "splash")
inst.SoundEmitter:PlaySound("dontstarve/common/fishingpole_strain", "strain")
end,

onexit = function(inst)
inst.SoundEmitter:KillSound("splash")
inst.SoundEmitter:KillSound("strain")
end,

events =
{
EventHandler("fishingcatch", function(inst, data)
inst.sg:GoToState("catchfish", data.build)
end),
EventHandler("fishingloserod", function(inst)
inst.sg:GoToState("loserod")
end),

},
},

State{
name = "catchfish",
tags = {"fishing", "catchfish", "busy"},
onenter = function(inst, build)
inst.AnimState:PlayAnimation("fish_catch")
print("Using ", build, " to swap out fish01")
inst.AnimState:OverrideSymbol("fish01", build, "fish01")

-- inst.AnimState:OverrideSymbol("fish_body", build, "fish_body")
-- inst.AnimState:OverrideSymbol("fish_eye", build, "fish_eye")
-- inst.AnimState:OverrideSymbol("fish_fin", build, "fish_fin")
-- inst.AnimState:OverrideSymbol("fish_head", build, "fish_head")
-- inst.AnimState:OverrideSymbol("fish_mouth", build, "fish_mouth")
-- inst.AnimState:OverrideSymbol("fish_tail", build, "fish_tail")
end,

onexit = function(inst)
inst.AnimState:ClearOverrideSymbol("fish01")
-- inst.AnimState:ClearOverrideSymbol("fish_body")
-- inst.AnimState:ClearOverrideSymbol("fish_eye")
-- inst.AnimState:ClearOverrideSymbol("fish_fin")
-- inst.AnimState:ClearOverrideSymbol("fish_head")
-- inst.AnimState:ClearOverrideSymbol("fish_mouth")
-- inst.AnimState:ClearOverrideSymbol("fish_tail")
end,

timeline=
{
TimeEvent(8*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/common/fishingpole_fishcaught") end),
TimeEvent(10*FRAMES, function(inst) inst.sg:RemoveStateTag("fishing") end),
TimeEvent(23*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/common/fishingpole_fishland") end),
TimeEvent(24*FRAMES, function(inst)
local equippedTool = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
if equippedTool and equippedTool.components.fishingrod then
equippedTool.components.fishingrod:Collect()
end
end),
},

events=
{
EventHandler("animover", function(inst)
inst.sg:GoToState("idle")
end ),
},
},

State{
name = "loserod",
tags = {"busy"},
onenter = function(inst)
local equippedTool = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
if equippedTool and equippedTool.components.fishingrod then
equippedTool.components.fishingrod:Release()
equippedTool:Remove()
end
inst.AnimState:PlayAnimation("fish_nocatch")
end,

timeline=
{
TimeEvent(4*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/common/fishingpole_lostrod") end),
},

events=
{
EventHandler("animover", function(inst)
inst.sg:GoToState("idle")
end ),
},
},


State{
name = "eat",
tags ={"busy"},
onenter = function(inst)
inst.components.locomotor:Stop()
local is_gear = inst:GetBufferedAction() and inst:GetBufferedAction().invobject and inst:GetBufferedAction().invobject.components.edible and inst:GetBufferedAction().invobject.components.edible.foodtype == "GEARS"

if not is_gear then
inst.SoundEmitter:PlaySound("dontstarve/wilson/eat", "eating")
end

inst.AnimState:PlayAnimation("eat")
inst.components.hunger:Pause()
end,

timeline=
{

TimeEvent(28*FRAMES, function(inst)
inst:PerformBufferedAction()
end),

TimeEvent(30*FRAMES, function(inst)
inst.sg:RemoveStateTag("busy")
end),

TimeEvent(70*FRAMES, function(inst)
     inst.SoundEmitter:KillSound("eating")
     end),

},
events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("idle") end),
},

onexit= function(inst)
inst.SoundEmitter:KillSound("eating")
inst.components.hunger:Resume()
end,
},

State{
name = "quickeat",
tags ={"busy"},
onenter = function(inst)
inst.components.locomotor:Stop()
local is_gear = inst:GetBufferedAction() and inst:GetBufferedAction().invobject and inst:GetBufferedAction().invobject.components.edible and inst:GetBufferedAction().invobject.components.edible.foodtype == "GEARS"
if not is_gear then
inst.SoundEmitter:PlaySound("dontstarve/wilson/eat", "eating")
end
inst.AnimState:PlayAnimation("quick_eat")
inst.components.hunger:Pause()
end,

timeline=
{
TimeEvent(12*FRAMES, function(inst)
inst:PerformBufferedAction()
inst.sg:RemoveStateTag("busy")
end),
},

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("idle") end),
},

onexit= function(inst)
inst.SoundEmitter:KillSound("eating")
inst.components.hunger:Resume()
end,
},


State{
name = "talk",
tags = {"idle", "talking"},

onenter = function(inst, noanim)
inst.components.locomotor:Stop()
if not noanim then
inst.AnimState:PlayAnimation("dial_loop", true)
end

if inst.talksoundoverride then
inst.SoundEmitter:PlaySound(inst.talksoundoverride, "talk")
else
local sound_name = inst.soundsname or inst.prefab
inst.SoundEmitter:PlaySound("dontstarve/characters/"..sound_name.."/talk_LP", "talk")
end

inst.sg:SetTimeout(.45) -- 1.5 + math.random()*.5
end,

ontimeout = function(inst)
inst.SoundEmitter:KillSound("talk")
inst.sg:GoToState("idle")
end,

onexit = function(inst)
inst.SoundEmitter:KillSound("talk")
end,

events=
{
EventHandler("donetalking", function(inst) inst.sg:GoToState("idle") end),
},
},

State{
name = "mime",
tags = {"idle", "talking"},

onenter = function(inst)
inst.components.locomotor:Stop()


for k = 1, math.random(2,3) do
                local aname = "mime" .. tostring(math.random(8))
                if k == 1 then
                    inst.AnimState:PlayAnimation(aname, false)
                else
                    inst.AnimState:PushAnimation(aname, false)
                end
end
end,

events=
{
EventHandler("animqueueover", function(inst) inst.sg:GoToState("idle") end),
},
},

State{
name = "doshortaction",
tags = {"doing", "busy"},

onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("pickup")
inst.sg:SetTimeout(6*FRAMES)
end,


timeline=
{
TimeEvent(4*FRAMES, function( inst )
inst.sg:RemoveStateTag("busy")
end),
TimeEvent(10*FRAMES, function( inst )
inst.sg:RemoveStateTag("doing")
inst.sg:AddStateTag("idle")
end),
},

ontimeout = function(inst)
inst:PerformBufferedAction()

end,

events=
{
EventHandler("animover", function(inst) if inst.AnimState:AnimDone() then inst.sg:GoToState("idle") end end ),
},
},


State{
name = "dolongaction",
tags = {"doing", "busy"},

timeline=
{
TimeEvent(4*FRAMES, function( inst )
inst.sg:RemoveStateTag("busy")
end),
},

onenter = function(inst, timeout)

inst.sg:SetTimeout(timeout or 1)
inst.components.locomotor:Stop()
inst.SoundEmitter:PlaySound("dontstarve/wilson/make_trap", "make")

inst.AnimState:PlayAnimation("build_pre")
inst.AnimState:PushAnimation("build_loop", true)
end,

ontimeout= function(inst)
inst.AnimState:PlayAnimation("build_pst")
inst.sg:GoToState("idle", false)
inst:PerformBufferedAction()
end,

onexit= function(inst)
inst.SoundEmitter:KillSound("make")
end,

},

State{
name = "makeballoon",
tags = {"doing"},

onenter = function(inst, timeout)

inst.sg:SetTimeout(timeout or 1)
inst.components.locomotor:Stop()
inst.SoundEmitter:PlaySound("dontstarve/common/balloon_make", "make")
inst.SoundEmitter:PlaySound("dontstarve/common/balloon_blowup")

inst.AnimState:PlayAnimation("build_pre")
inst.AnimState:PushAnimation("build_loop", true)
end,

ontimeout= function(inst)
inst.AnimState:PlayAnimation("build_pst")
inst.sg:GoToState("idle", false)
inst:PerformBufferedAction()

end,

onexit= function(inst)
inst.SoundEmitter:KillSound("make")
end,
},

State{
name = "shave",
tags = {"doing", "shaving"},

onenter = function(inst)
local timeout = 1
inst.sg:SetTimeout(timeout)
inst.components.locomotor:Stop()
inst.SoundEmitter:PlaySound("dontstarve/wilson/shave_LP", "shave")

inst.AnimState:PlayAnimation("build_pre")
inst.AnimState:PushAnimation("build_loop", true)
end,

ontimeout = function(inst)
inst:PerformBufferedAction()
inst.AnimState:PlayAnimation("build_pst")
inst.sg:GoToState("idle", false)
end,

onexit= function(inst)
inst.SoundEmitter:KillSound("shave")
end,

},



State{
name = "enter_onemanband",
tags = {"doing", "playing", "idle"},

onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("idle_onemanband1_pre")
inst.SoundEmitter:PlaySound("dontstarve/wilson/onemanband")
end,

onexit = function(inst)
end,

events =
{
EventHandler("animover", function(inst) inst.sg:GoToState("play_onemanband") end),
},
},

State{
name = "play_onemanband",
tags = {"doing", "playing", "idle"},

onenter = function(inst)

inst.components.locomotor:Stop()
--inst.AnimState:PlayAnimation("idle_onemanband1_pre")
inst.AnimState:PlayAnimation("idle_onemanband1_loop")
inst.SoundEmitter:PlaySound("dontstarve/wilson/onemanband")
end,

onexit = function(inst)
end,

events =
{
EventHandler("animover", function(inst)
if math.random() <= 0.15 then
inst.sg:GoToState("play_onemanband_stomp") -- go into stomp
else
inst.sg:GoToState("play_onemanband")-- loop state again
end
end),
},
},

State{
name = "play_onemanband_stomp",
tags = {"doing", "playing", "idle"},

onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("idle_onemanband1_pst")
inst.AnimState:PushAnimation("idle_onemanband2_pre")
inst.AnimState:PushAnimation("idle_onemanband2_loop")
inst.AnimState:PushAnimation("idle_onemanband2_pst", false)
inst.SoundEmitter:PlaySound("dontstarve/wilson/onemanband")
end,

onexit = function(inst)
end,

timeline=
{
TimeEvent(20*FRAMES, function( inst )
inst.SoundEmitter:PlaySound("dontstarve/wilson/onemanband")
end),

TimeEvent(25*FRAMES, function( inst )
inst.SoundEmitter:PlaySound("dontstarve/wilson/onemanband")
end),

TimeEvent(30*FRAMES, function( inst )
inst.SoundEmitter:PlaySound("dontstarve/wilson/onemanband")
end),

TimeEvent(35*FRAMES, function( inst )
inst.SoundEmitter:PlaySound("dontstarve/wilson/onemanband")
end),
},

events =
{
EventHandler("animqueueover", function(inst)
inst.sg:GoToState("idle")
end),
},
},

State{
name = "play_flute",
tags = {"doing", "playing"},

onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("flute")
inst.AnimState:OverrideSymbol("pan_flute01", "pan_flute", "pan_flute01")
inst.AnimState:Hide("ARM_carry")
inst.AnimState:Show("ARM_normal")
if inst.components.inventory.activeitem and inst.components.inventory.activeitem.components.instrument then
inst.components.inventory:ReturnActiveItem()
end
end,

onexit = function(inst)
inst.SoundEmitter:KillSound("flute")
if inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) then
inst.AnimState:Show("ARM_carry")
inst.AnimState:Hide("ARM_normal")
end
end,

timeline=
{
TimeEvent(30*FRAMES, function(inst)
inst.SoundEmitter:PlaySound("dontstarve/wilson/flute_LP", "flute")
inst:PerformBufferedAction()
end),
TimeEvent(85*FRAMES, function(inst)
inst.SoundEmitter:KillSound("flute")
end),
},

events=
{
EventHandler("animover", function(inst)
inst.sg:GoToState("idle")
end),
},
},

State{
name = "play_horn",
tags = {"doing", "playing"},

onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("horn")
inst.AnimState:OverrideSymbol("horn01", "horn", "horn01")
--inst.AnimState:Hide("ARM_carry")
inst.AnimState:Show("ARM_normal")
if inst.components.inventory.activeitem and inst.components.inventory.activeitem.components.instrument then
inst.components.inventory:ReturnActiveItem()
end
end,

onexit = function(inst)
if inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) then
inst.AnimState:Show("ARM_carry")
inst.AnimState:Hide("ARM_normal")
end
end,

timeline=
{
TimeEvent(21*FRAMES, function(inst)
inst.SoundEmitter:PlaySound("dontstarve/common/horn_beefalo")
inst:PerformBufferedAction()
end),
},

events=
{
EventHandler("animover", function(inst)
inst.sg:GoToState("idle")
end),
},
},

State{
name = "book",
tags = {"doing"},

onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("book")
inst.AnimState:OverrideSymbol("book_open", "player_actions_uniqueitem", "book_open")
inst.AnimState:OverrideSymbol("book_closed", "player_actions_uniqueitem", "book_closed")
inst.AnimState:OverrideSymbol("book_open_pages", "player_actions_uniqueitem", "book_open_pages")
--inst.AnimState:Hide("ARM_carry")
inst.AnimState:Show("ARM_normal")
if inst.components.inventory.activeitem and inst.components.inventory.activeitem.components.book then
inst.components.inventory:ReturnActiveItem()
end
inst.SoundEmitter:PlaySound("dontstarve/common/use_book")
end,

onexit = function(inst)
if inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) then
inst.AnimState:Show("ARM_carry")
inst.AnimState:Hide("ARM_normal")
end
if inst.sg.statemem.book_fx then
inst.sg.statemem.book_fx:Remove()
inst.sg.statemem.book_fx = nil
end
end,

timeline=
{
TimeEvent(0, function(inst)
local fxtoplay = "book_fx"
if inst.prefab == "waxwell" then
fxtoplay = "waxwell_book_fx"
end
local fx = SpawnPrefab(fxtoplay)
local pos = inst:GetPosition()
fx.Transform:SetRotation(inst.Transform:GetRotation())
fx.Transform:SetPosition( pos.x, pos.y - .2, pos.z )
inst.sg.statemem.book_fx = fx
end),

TimeEvent(58*FRAMES, function(inst)
inst.SoundEmitter:PlaySound("dontstarve/common/book_spell")
inst:PerformBufferedAction()
inst.sg.statemem.book_fx = nil
end),
},

events=
{
EventHandler("animover", function(inst)
inst.sg:GoToState("idle")
end),
},
},

State{
name = "blowdart",
tags = {"attack", "notalking", "abouttoattack"},

onenter = function(inst)
inst.sg.statemem.target = inst.components.combat.target
inst.components.combat:StartAttack()
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("dart")

if inst.components.combat.target then
if inst.components.combat.target and inst.components.combat.target:IsValid() then
inst:FacePoint(Point(inst.components.combat.target.Transform:GetWorldPosition()))
end
end
end,

timeline=
{
TimeEvent(8*FRAMES, function(inst)
inst.SoundEmitter:PlaySound("dontstarve/wilson/blowdart_shoot")
end),
TimeEvent(10*FRAMES, function(inst)
inst.sg:RemoveStateTag("abouttoattack")
inst.components.combat:DoAttack(inst.sg.statemem.target)
inst.SoundEmitter:PlaySound("dontstarve/wilson/blowdart_shoot")
end),
TimeEvent(20*FRAMES, function(inst) inst.sg:RemoveStateTag("attack") end),
},

events=
{
EventHandler("animover", function(inst)
inst.sg:GoToState("idle")
end),
},
},

State{
name = "throw",
tags = {"attack", "notalking", "abouttoattack"},

onenter = function(inst)
inst.sg.statemem.target = inst.components.combat.target
inst.components.combat:StartAttack()
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("throw")

if inst.components.combat.target then
if inst.components.combat.target and inst.components.combat.target:IsValid() then
inst:FacePoint(inst.components.combat.target.Transform:GetWorldPosition())
end
end

end,

timeline=
{
TimeEvent(7*FRAMES, function(inst) inst.components.combat:DoAttack(inst.sg.statemem.target) inst.sg:RemoveStateTag("abouttoattack") end),
TimeEvent(11*FRAMES, function(inst) inst.sg:RemoveStateTag("attack") end),
},

events=
{
EventHandler("animover", function(inst)
inst.sg:GoToState("idle")
end),
},
},

State{
name = "catch_pre",
tags = {"notalking", "readytocatch"},

onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("catch_pre")
inst:PerformBufferedAction()
inst.sg:SetTimeout(2)
end,

ontimeout= function(inst)
inst.sg:GoToState("idle")
end,

events=
{
EventHandler("catch", function(inst)
inst.sg:GoToState("catch")
end),
},
},

State{
name = "catch",
tags = {"busy", "notalking"},

onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("catch")
inst.SoundEmitter:PlaySound("dontstarve/wilson/boomerang_catch")
end,

events=
{
EventHandler("animover", function(inst)
inst.sg:GoToState("idle")
end),
},
},

State{
name = "shoot",
tags = {"attack", "notalking", "abouttoattack", "busy"},

onenter = function(inst)
inst.AnimState:PlayAnimation("shoot")
if inst.components.combat.target then
inst.components.combat:BattleCry()
if inst.components.combat.target and inst.components.combat.target:IsValid() then
inst:FacePoint(Point(inst.components.combat.target.Transform:GetWorldPosition()))
end
end
inst.sg.statemem.target = inst.components.combat.target
inst.components.combat:StartAttack()
inst.components.locomotor:Stop()
end,

timeline=
{
TimeEvent(17*FRAMES, function(inst)
inst.components.combat:DoAttack(inst.sg.statemem.target)
inst.sg:RemoveStateTag("abouttoattack")
end),
TimeEvent(20*FRAMES, function(inst)
inst.sg:RemoveStateTag("attack")
end),
},

events=
{
EventHandler("animover", function(inst)
inst.sg:GoToState("idle")
end ),
},
},

State{
name = "attack",
tags = {"attack", "notalking", "abouttoattack", "busy"},

onenter = function(inst)
            --print(debugstack())
inst.sg.statemem.target = inst.components.combat.target
inst.components.combat:StartAttack()
inst.components.locomotor:Stop()
local weapon = inst.components.combat:GetWeapon()
local otherequipped = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)

if (weapon and weapon:HasTag("gun")) or (otherequipped and otherequipped:HasTag("gun")) then
inst.sg:GoToState("shoot")
return
end

if weapon then
inst.AnimState:PlayAnimation("atk")
                if weapon:HasTag("icestaff") then
inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_icestaff")
                elseif weapon:HasTag("shadow") then
inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_nightsword")
elseif weapon:HasTag("firestaff") then
inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_firestaff")
else
inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_weapon")
end
elseif otherequipped and (otherequipped:HasTag("light") or otherequipped:HasTag("nopunch")) then
inst.AnimState:PlayAnimation("atk")
inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_weapon")
else
                inst.sg.statemem.slow = true
inst.AnimState:PlayAnimation("punch")
inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_whoosh")
end

if inst.components.combat.target then
inst.components.combat:BattleCry()
if inst.components.combat.target and inst.components.combat.target:IsValid() then
inst:FacePoint(Point(inst.components.combat.target.Transform:GetWorldPosition()))
end
end

end,

timeline=
{
TimeEvent(8*FRAMES, function(inst) inst.components.combat:DoAttack(inst.sg.statemem.target) inst.sg:RemoveStateTag("abouttoattack") end),
TimeEvent(12*FRAMES, function(inst)
                inst.sg:RemoveStateTag("busy")
            end),                
TimeEvent(13*FRAMES, function(inst)
                if not inst.sg.statemem.slow then
                    inst.sg:RemoveStateTag("attack")
                end
end),
TimeEvent(24*FRAMES, function(inst)
                if inst.sg.statemem.slow then
                    inst.sg:RemoveStateTag("attack")
                end
end),


},

events=
{
EventHandler("animover", function(inst)
inst.sg:GoToState("idle")
end ),
},
},



State{
name = "run_start",
tags = {"moving", "running", "canrotate"},

onenter = function(inst)
            inst.components.locomotor:RunForward()
inst.AnimState:PlayAnimation("run_pre")
inst.sg.mem.foosteps = 0
end,

onupdate = function(inst)
inst.components.locomotor:RunForward()
end,

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("run") end ),
},

timeline=
{

TimeEvent(4*FRAMES, function(inst)
PlayFootstep(inst)
DoFoleySounds(inst)
end),
},

},

State{

name = "run",
tags = {"moving", "running", "canrotate"},

onenter = function(inst)
inst.components.locomotor:RunForward()
inst.AnimState:PlayAnimation("run_loop")

end,

onupdate = function(inst)
inst.components.locomotor:RunForward()
end,

timeline=
{
TimeEvent(7*FRAMES, function(inst)
                inst.sg.mem.foosteps = inst.sg.mem.foosteps + 1
PlayFootstep(inst, inst.sg.mem.foosteps < 5 and 1 or .6)
DoFoleySounds(inst)
end),
TimeEvent(15*FRAMES, function(inst)
                inst.sg.mem.foosteps = inst.sg.mem.foosteps + 1
PlayFootstep(inst, inst.sg.mem.foosteps < 5 and 1 or .6)
DoFoleySounds(inst)
end),
},

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("run") end ),
},


},

State{

name = "run_stop",
tags = {"canrotate", "idle"},

onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("run_pst")
end,

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("idle") end ),
},

},


State{
name="item_hat",
tags = {"idle"},

onenter = function(inst)
inst.components.locomotor:StopMoving()
inst.AnimState:PlayAnimation("item_hat")
end,

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("idle") end ),
},
},
State{
name="item_in",
tags = {"idle"},

onenter = function(inst)
inst.components.locomotor:StopMoving()
inst.AnimState:PlayAnimation("item_in")
end,

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("idle") end ),
},
},
State{
name="item_out",
tags = {"idle"},

onenter = function(inst)
inst.components.locomotor:StopMoving()
inst.AnimState:PlayAnimation("item_out")
end,

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("idle") end ),
},
},


State{
name = "give",

onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("give")
end,

timeline =
{
TimeEvent(13*FRAMES, function(inst)
inst:PerformBufferedAction()
end),
},

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("idle") end ),
},
},

    State{
name = "bedroll",

        --tags = {"busy"},

onenter = function(inst)
inst.components.playercontroller:Enable(false)
inst.components.locomotor:Stop()
inst.components.health:SetInvincible(true)
            if GetClock():IsDay() then

local tosay = "ANNOUNCE_NODAYSLEEP"
if GetWorld():IsCave() then
tosay = "ANNOUNCE_NODAYSLEEP_CAVE"
end

                inst.sg:GoToState("idle")
                inst.components.talker:Say(GetString(inst.prefab, tosay))
                return
            end
        
    
            local danger = FindEntity(inst, 10, function(target) return target:HasTag("monster") or target.components.combat and target.components.combat.target == inst end)
local hounded = GetWorld().components.hounded

            if hounded and (hounded.warning or hounded.timetoattack <= 0) then
                danger = true
            end
            if danger then
                inst.sg:GoToState("idle")
                inst.components.talker:Say(GetString(inst.prefab, "ANNOUNCE_NODANGERSLEEP"))
                return
            end

            -- you can still sleep if your hunger will bottom out, but not absolutely
            if inst.components.hunger.current < TUNING.CALORIES_MED then
                inst.sg:GoToState("idle")
                inst.components.talker:Say(GetString(inst.prefab, "ANNOUNCE_NOHUNGERSLEEP"))
                return
            end

inst.AnimState:PlayAnimation("bedroll")

end,

onexit = function(inst)
inst.components.health:SetInvincible(false)
inst.components.playercontroller:Enable(true)
    inst.AnimState:ClearOverrideSymbol("bedroll")
end,


timeline=
{
TimeEvent(20*FRAMES, function(inst)
inst.SoundEmitter:PlaySound("dontstarve/wilson/use_bedroll")
end),
},

events=
{
EventHandler("animover", function(inst)
if GetClock():IsDay() then
local tosay = "ANNOUNCE_NODAYSLEEP"
if GetWorld():IsCave() then
tosay = "ANNOUNCE_NODAYSLEEP_CAVE"
end
inst.sg:GoToState("wakeup")
inst.components.talker:Say(GetString(inst.prefab, tosay))
return
elseif inst:GetBufferedAction() then
inst:PerformBufferedAction()
else
inst.sg:GoToState("wakeup")
end

end ),
},
},


State{
name = "hit",
tags = {"busy"},

onenter = function(inst)
inst.SoundEmitter:PlaySound("dontstarve/wilson/hit")
inst.AnimState:PlayAnimation("hit")
inst:ClearBufferedAction()

if inst.prefab ~= "wes" then
local sound_name = inst.soundsname or inst.prefab
             local sound_event = "dontstarve/characters/"..sound_name.."/hurt"
inst.SoundEmitter:PlaySound(inst.hurtsoundoverride or sound_event)
end
inst.components.locomotor:Stop()
end,

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("idle") end ),
},

timeline =
{
TimeEvent(3*FRAMES, function(inst)
inst.sg:RemoveStateTag("busy")
end),
},

},

State{
name = "toolbroke",
tags = {"busy"},
onenter = function(inst, tool)
inst.AnimState:PlayAnimation("hit")
inst.SoundEmitter:PlaySound("dontstarve/wilson/use_break")
inst.AnimState:Hide("ARM_carry")
inst.AnimState:Show("ARM_normal")
local brokentool = SpawnPrefab("brokentool")
brokentool.Transform:SetPosition(inst.Transform:GetWorldPosition() )
inst.sg.statemem.tool = tool
end,

onexit = function(inst)
         local sameTool = inst.components.inventory:FindItem(function(item)
         return item.prefab == inst.sg.statemem.tool.prefab
         end)
         if sameTool then
         inst.components.inventory:Equip(sameTool)
         end

if inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) then
inst.AnimState:Show("ARM_carry")
inst.AnimState:Hide("ARM_normal")
end

end,

events=
{
EventHandler("animover", function(inst)
inst.sg:GoToState("idle")
end ),
},
},

State{
name = "armorbroke",
tags = {"busy"},
onenter = function(inst, armor)
inst.AnimState:PlayAnimation("hit")
inst.SoundEmitter:PlaySound("dontstarve/wilson/use_armour_break")
inst.sg.statemem.armor = armor
end,

onexit = function(inst)
         local sameArmor = inst.components.inventory:FindItem(function(item)
         return item.prefab == inst.sg.statemem.armor.prefab
         end)
         if sameArmor then
         inst.components.inventory:Equip(sameArmor)
         end
end,

events=
{
EventHandler("animover", function(inst)
inst.sg:GoToState("idle")
end ),
},
},

    State{
name = "teleportato_teleport",
tags = {"busy"},
        onenter = function(inst)
inst.components.locomotor:StopMoving()
            inst.components.playercontroller:Enable(false)
            inst.components.health:SetInvincible(true)
            inst.AnimState:PlayAnimation("teleport")
            TheCamera:SetDistance(20)
            inst.HUD:Hide()
        end,

onexit = function(inst)
inst.HUD:Show()
inst.components.playercontroller:Enable(true)
inst.components.health:SetInvincible(false)
end,

        timeline = {
            TimeEvent(0, function(inst)
                inst.SoundEmitter:PlaySound("dontstarve/common/teleportato/teleportato_pulled")
            end),
            TimeEvent(82*FRAMES, function(inst)
                inst.SoundEmitter:PlaySound("dontstarve/common/teleportato/teleportato_under")
            end),
        },
    },

    State{
name = "amulet_rebirth",
tags = {"busy"},
onenter = function(inst)
            GetClock():MakeNextDay()
            inst.components.playercontroller:Enable(false)
inst.AnimState:PlayAnimation("amulet_rebirth")
TheCamera:SetDistance(14)
inst.HUD:Hide()
inst.AnimState:OverrideSymbol("FX", "player_amulet_resurrect", "FX")
end,

onexit= function(inst)
            inst.components.hunger:SetPercent(2/3)
            inst.components.health:Respawn(TUNING.RESURRECT_HEALTH)
    
     if inst.components.sanity then
                inst.components.sanity:SetPercent(.5)
            end
            
            local item = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)
            if item and item.prefab == "amulet" then
                item = inst.components.inventory:RemoveItem(item)
                if item then
                    item:Remove()
                    item.persists = false
                end
            end
            --SaveGameIndex:SaveCurrent()
            inst.HUD:Show()
            TheCamera:SetDefault()
            inst.components.playercontroller:Enable(true)
inst.AnimState:ClearOverrideSymbol("FX")
            
end,

        timeline =
{
TimeEvent(0*FRAMES, function(inst)
inst.stafflight = SpawnPrefab("staff_castinglight")
local pos = inst:GetPosition()
local colour = {150/255, 46/255, 46/255}
inst.stafflight.Transform:SetPosition(pos.x, pos.y, pos.z)
inst.stafflight.setupfn(inst.stafflight, colour, 1.7, 1)

end),

            TimeEvent(0, function(inst) inst.SoundEmitter:PlaySound("dontstarve/common/rebirth_amulet_raise") end),
            TimeEvent(60*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/common/rebirth_amulet_poof") end),

TimeEvent(80*FRAMES, function(inst)
                local pos = Vector3(inst.Transform:GetWorldPosition())
                local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, 10)
                for k,v in pairs(ents) do
                    if v ~= inst and v.components.sleeper then
                        v.components.sleeper:GoToSleep(20)
                    end
                end
                
                
end),
},

events=
{
EventHandler("animover", function(inst) inst.sg:GoToState("idle") end ),
},
},


State{
name = "jumpin",
tags = {"doing", "canrotate"},

onenter = function(inst)
inst.components.locomotor:Stop()
inst.AnimState:PlayAnimation("jump")

            inst:DoTaskInTime(4.7, function(inst) inst.SoundEmitter:PlaySound("dontstarve/movement/bodyfall_dirt", "bodyfall") end )
end,

        timeline =
{
            -- this is just hacked in here to make the sound play BEFORE the player hits the wormhole
            TimeEvent(19*FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/common/teleportworm/travel", "wormhole_travel") end),
        },

events=
{
EventHandler("animover", function(inst)
                inst:PerformBufferedAction()
                inst.sg:GoToState("idle")
            end ),
},
},

State{
name = "castspell",
tags = {"doing", "busy", "canrotate"},

onenter = function(inst)
inst.components.playercontroller:Enable(false)
inst.AnimState:PlayAnimation("staff")
local colourizefx = function(staff)
return staff.fxcolour or {1,1,1}
end
inst.components.locomotor:Stop()
--Spawn an effect on the player's location
inst.stafffx = SpawnPrefab("staffcastfx")

local pos = inst:GetPosition()
local staff = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
inst.stafffx.Transform:SetPosition(pos.x, pos.y, pos.z)
local colour = colourizefx(staff)

inst.stafffx.Transform:SetRotation(inst.Transform:GetRotation())
inst.stafffx.AnimState:SetMultColour(colour[1], colour[2], colour[3], 1)
end,

onexit = function(inst)
inst.components.playercontroller:Enable(true)
if inst.stafffx then
inst.stafffx:Remove()
end
end,

timeline =
{
TimeEvent(13*FRAMES, function(inst)
inst.SoundEmitter:PlaySound("dontstarve/wilson/use_gemstaff")
end),
TimeEvent(0*FRAMES, function(inst)
inst.stafflight = SpawnPrefab("staff_castinglight")
local staff = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
local pos = inst:GetPosition()
local colour = staff.fxcolour or {1,1,1}
inst.stafflight.Transform:SetPosition(pos.x, pos.y, pos.z)
inst.stafflight.setupfn(inst.stafflight, colour, 1.9, .33)

end),
TimeEvent(53*FRAMES, function(inst) inst:PerformBufferedAction() end),
},

events = {
EventHandler("animover", function(inst)
inst.sg:GoToState("idle")
end ),
},

},

State{
name = "weretiger",
tags = {"busy"},
onenter = function(inst)
            inst.components.weretigerss.doing_transform = true
inst.Physics:Stop()
inst.components.playercontroller:Enable(false)
inst.AnimState:PlayAnimation("transform_pre")
inst.components.health:SetInvincible(true)
end,

onexit = function(inst)
            if not inst.components.weretigerss:IsWeretiger() then
                inst.components.weretigerss.makeweretiger(inst)
            end
            inst.components.health:SetInvincible(false)
            inst.components.playercontroller:Enable(true)
            inst.components.weretigerss.doing_transform = false
end,

events =
{
EventHandler("animover", function(inst)
     inst.components.weretigerss.makeweretiger(inst)
inst.sg:GoToState("transform_pst")
end ),
}
},

State{
name = "quicktele",
tags = {"doing", "busy", "canrotate"},

onenter = function(inst)
inst.AnimState:PlayAnimation("atk")
inst.SoundEmitter:PlaySound("dontstarve/wilson/attack_weapon")
end,

timeline =
{
TimeEvent(8*FRAMES, function(inst) inst:PerformBufferedAction() end),
},

events = {
EventHandler("animover", function(inst)
inst.sg:GoToState("idle")
end ),
},
},

}


return StateGraph("ai", states, events, "idle", actionhandlers)

 
Please Help.
 
 
 
Thank you.

Share this post


Link to post
Share on other sites
DarkXero    2886

@Yagenius:

This stategraph is from single player. Not even from RoG, just the vanilla single player. There's bound to have a lot of unused functions that cause errors.

 

You could be nice enough to post the exact line where the log says there's an error, so you avoid me reading so much for absolutely nothing. I can only spot one extra state, the weretiger state.

  • Like 1

Share this post


Link to post
Share on other sites
Yagenius    2

@Yagenius:

This stategraph is from single player. Not even from RoG, just the vanilla single player. There's bound to have a lot of unused functions that cause errors.

 

You could be nice enough to post the exact line where the log says there's an error, so you avoid me reading so much for absolutely nothing. I can only spot one extra state, the weretiger state.

 

@DarkXero:

 

Thank you very much for reading it.

 

and sorry for disturbing you .

 

And This script can be turn into DST version?

 

(because I want to play with my friends.)

 

The latest script , I use Woodie is script     The game run nicely ... but when I wait to Full Moon Day , My game is crashing....

 

 

 

 

[ and this is my little kitty. ]

 

http://upic.me/show/56569218

 

Share this post


Link to post
Share on other sites
Yagenius    2

 @DarkXero

 

Ok , Here is the code I used.

 

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

require "stategraphs/SGweretiger"local Badge = require "widgets/badge"local easing = require "easing"local MakePlayerCharacter = require "prefabs/player_common"local start_inv = {	"fish",	"rabbit",	"fish",	"fish",	"carrot",}local assets ={    Asset( "ANIM", "anim/player_basic.zip" ),    Asset( "ANIM", "anim/player_idles_shiver.zip" ),    Asset( "ANIM", "anim/player_actions.zip" ),    Asset( "ANIM", "anim/player_actions_axe.zip" ),    Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),    Asset( "ANIM", "anim/player_actions_shovel.zip" ),    Asset( "ANIM", "anim/player_actions_blowdart.zip" ),    Asset( "ANIM", "anim/player_actions_eat.zip" ),    Asset( "ANIM", "anim/player_actions_item.zip" ),    Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),    Asset( "ANIM", "anim/player_actions_bugnet.zip" ),    Asset( "ANIM", "anim/player_actions_fishing.zip" ),    Asset( "ANIM", "anim/player_actions_boomerang.zip" ),    Asset( "ANIM", "anim/player_bush_hat.zip" ),    Asset( "ANIM", "anim/player_attacks.zip" ),    Asset( "ANIM", "anim/player_idles.zip" ),    Asset( "ANIM", "anim/player_rebirth.zip" ),    Asset( "ANIM", "anim/player_jump.zip" ),    Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),    Asset( "ANIM", "anim/player_teleport.zip" ),    Asset( "ANIM", "anim/wilson_fx.zip" ),    Asset( "ANIM", "anim/player_one_man_band.zip" ),    Asset( "ANIM", "anim/shadow_hands.zip" ),	  	Asset( "ANIM", "anim/player_woodie.zip"),	Asset( "ANIM", "anim/woodie.zip"),	Asset( "ANIM", "anim/player_wolfgang.zip"),	    Asset( "ANIM", "anim/aikawa.zip" ),	Asset( "ANIM", "anim/ghost_aikawa_build.zip" ),    Asset( "ANIM", "anim/tiger_meter.zip"),    Asset("ANIM", "anim/weretiger_build.zip"),	    Asset( "IMAGE", "images/colour_cubes/tiger_vision_cc.tex" ),	Asset( "IMAGE", "images/colour_cubes/tiger_vision_1_cc.tex" ),	Asset( "IMAGE", "images/colour_cubes/tiger_vision_2_cc.tex" ),	Asset( "IMAGE", "images/colour_cubes/tiger_vision_3_cc.tex" ),	Asset( "IMAGE", "images/colour_cubes/tiger_vision_4_cc.tex" ),	Asset( "IMAGE", "images/colour_cubes/tiger_vision_5_cc.tex" ),	Asset( "IMAGE", "images/colour_cubes/tiger_vision_6_cc.tex" ),	    Asset("ATLAS", "images/woodie.xml"),    Asset("IMAGE", "images/woodie.tex"),}local prefabs = {}local TIGER_DIET ={    FOODTYPE.MEAT,}-- WERETIGER FUNCTIONS --local function tigeractionstring(inst, action)    return "Chomp"endlocal function TigerActionButton(inst)	local action_target = FindEntity(inst, 6, function(guy) return (guy.components.edible and inst.components.eater:CanEat(guy)) or		 													 (guy.components.workable and inst.components.worker:CanDoAction(guy.components.workable.action)) end)		if not inst.sg:HasStateTag("busy") and action_target then		if (action_target.components.edible and inst.components.eater:CanEat(action_target)) then			return BufferedAction(inst, action_target, ACTIONS.EAT)		else			return BufferedAction(inst, action_target, action_target.components.workable.action)		end	endendlocal function LeftClickPicker(inst, target_ent, pos)    if inst.components.combat:CanTarget(target_ent) then        return inst.components.playeractionpicker:SortActionList({ACTIONS.ATTACK}, target_ent, nil)    end    if target_ent and target_ent.components.edible and inst.components.eater:CanEat(target_ent) then        return inst.components.playeractionpicker:SortActionList({ACTIONS.EAT}, target_ent, nil)    end    if target_ent and target_ent.components.workable and inst.components.worker:CanDoAction(target_ent.components.workable.action) then        return inst.components.playeractionpicker:SortActionList({target_ent.components.workable.action}, target_ent, nil)    endendlocal function RightClickPicker(inst, target_ent, pos)    return {}end-------------------- CHANGE BADGE --------------------local TigerBadge = Class(Badge, function(self, owner)    Badge._ctor(self, "tiger_meter", owner)end)---------------------- CHANGE TO MEAT ----------------------local function ontigerdeat(inst, data)    if data.food and data.food.components.edible.ismeat and inst.components.tigerness:IsTiger() then        if data.food.components.edible.hungervalue == TUNING.CALORIES_TINY then            inst.components.tigerness:DoDelta(1)        elseif data.food.components.edible.hungervalue == TUNING.CALORIES_SMALL then            inst.components.tigerness:DoDelta(3)        elseif data.food.components.edible.hungervalue == TUNING.CALORIES_MEDSMALL then            inst.components.tigerness:DoDelta(6)        elseif data.food.components.edible.hungervalue == TUNING.CALORIES_MED then            inst.components.tigerness:DoDelta(10)		else            inst.components.tigerness:DoDelta(15)		end    endendlocal function onaikawaeat(inst, food)     	if inst:HasTag("beaver") then 		return	end		-- 1 Delta is 1%	-- Tigerness 70    if food.name == 'Meaty Stew' or food.name == 'Monster Meat' then			inst.components.tigerness:DoDelta(70)	-- Tigerness 40    elseif food.name == 'Meat' or food.name == 'Monster Lasagna' then		inst.components.tigerness:DoDelta(40)	-- Tigerness 35    elseif food.name == 'Bacon and Eggs' or food.name == 'Turkey Dinner' then				inst.components.tigerness:DoDelta(35)			-- Tigerness 30    elseif food.name == 'Morsel' or food.name == 'Batilisk Wing' then		inst.components.tigerness:DoDelta(30)    -- Tigerness 20    elseif food.name == 'Frog Legs' or food.name == 'Fishsticks' then		inst.components.tigerness:DoDelta(20)    -- Tigerness 12    elseif food.name == 'Jerky' then		inst.components.tigerness:DoDelta(12)    -- Tigerness 10    elseif food.name == 'Cooked Meat' or food.name == 'Cooked Frog Legs' then		inst.components.tigerness:DoDelta(10)	-- Tigerness 8    elseif food.name == 'Fried Drumstick' or food.name == 'Small Jerky' then		inst.components.tigerness:DoDelta(7)	-- Tigerness 7    elseif food.name == 'Fried Drumstick' or food.name == 'Fish' then		inst.components.tigerness:DoDelta(7)	-- Tigerness 5    elseif food.name == 'Cooked Morsel' or food.name == 'Cooked Fish' then		inst.components.tigerness:DoDelta(5)	end		if inst.components.tigerness:GetPercent() > .8 then			inst.components.talker:Say(GetString("aikawa", "ANNOUNCE_TIGERNESS_HIGHEST"))		elseif inst.components.tigerness:GetPercent() > .65 then			inst.components.talker:Say(GetString("aikawa", "ANNOUNCE_TIGERNESS_HIGHER"))				elseif inst.components.tigerness:GetPercent() > .5 then			inst.components.talker:Say(GetString("aikawa", "ANNOUNCE_TIGERNESS_AVERAGE"))				elseif inst.components.tigerness:GetPercent() > .3 then			inst.components.talker:Say(GetString("aikawa", "ANNOUNCE_TIGERNESS_LOW"))		elseif inst.components.tigerness:GetPercent() > .2 then			inst.components.talker:Say(GetString("aikawa", "ANNOUNCE_TIGERNESS_LOWER"))				elseif inst.components.tigerness:GetPercent() > .1 then			inst.components.talker:Say(GetString("aikawa", "ANNOUNCE_TIGERNESS_LOWEST"))			end	    print ('tigerness', inst.components.tigerness:GetPercent())    endlocal function tigerhurt(inst, delta)    if delta < 0 then        inst.sg:PushEvent("attacked")        inst.components.tigerness:DoDelta(delta*.25)        TheFrontEnd:GetSound():PlaySound("dontstarve/HUD/health_down")        inst.HUD.controls.tigerbadge:PulseRed()        if inst.HUD.bloodover then            inst.HUD.bloodover:Flash()        end    endendlocal function OnIsFullmoon(inst, isfullmoon)    if isfullmoon then        if inst.components.tigerness:GetPercent() > .25 then            inst.components.tigerness:SetPercent(.25)        end        inst.components.tigerness:SetTimeEffectMultiplier(TUNING.BEAVER_FULLMOON_DRAIN_MULTIPLIER*0.2)    else        inst.components.tigerness:SetTimeEffectMultiplier(1)    endendlocal function ontigernesschange(inst)    if inst.sg:HasStateTag("nomorph") or        inst.sg:HasStateTag("silentmorph") or        inst:HasTag("playerghost") or        inst.components.health:IsDead() or        not inst.entity:IsVisible() then        return    end    if inst.istigermode:value() then        if inst.components.tigerness:GetPercent() > TUNING.WOODIE_TRANSFORM_TO_HUMAN then            inst:PushEvent("transform_person")        end    elseif inst.components.tigerness:GetPercent() <= TUNING.WOODIE_TRANSFORM_TO_BEAVER then        inst:PushEvent("transform_weretiger")    endendlocal function onnewstate(inst)    if inst._wasnomorph ~= (inst.sg:HasStateTag("nomorph") or inst.sg:HasStateTag("silentmorph")) then        inst._wasnomorph = not inst._wasnomorph        if not inst._wasnomorph then            ontigernesschange(inst)        end    endendlocal function TransformTiger(inst, istiger)    if istiger then        onbecametiger(inst)    else        onbecamehuman(inst)    endendlocal function SetHUDState(inst)    if inst.HUD then        if inst.components.tigerness:IsTiger() and not inst.HUD.controls.tigerbadge then            inst.HUD.controls.tigerbadge = GetPlayer().HUD.controls.sidepanel:AddChild(TigerBadge(inst))            inst.HUD.controls.tigerbadge:SetPosition(0,-100,0)            inst.HUD.controls.tigerbadge:SetPercent(1)                        inst.HUD.controls.tigerbadge.inst:ListenForEvent("tigernessdelta", function(_, data)                 inst.HUD.controls.tigerbadge:SetPercent(inst.components.tigerness:GetPercent(), inst.components.tigerness.max)                if not data.overtime then                    if data.newpercent > data.oldpercent then                        inst.HUD.controls.tigerbadge:PulseGreen()                        TheFrontEnd:GetSound():PlaySound("dontstarve/HUD/health_up")                    elseif data.newpercent < data.oldpercent then                        TheFrontEnd:GetSound():PlaySound("dontstarve/HUD/health_down")                        inst.HUD.controls.tigerbadge:PulseRed()                    end                end            end, inst)      end	  endendlocal function SetGhostMode(inst, isghost)    if isghost then        SetTigerMode(inst, false)        inst._SetTigerMode(inst, true)    else        inst._SetGhostMode(inst, false)        SetTigerMode(inst, inst.istigermode:value())    endendlocal function OnTigerModeDirty(inst)    if inst.HUD ~= nil and not inst:HasTag("playerghost") then        SetTigerMode(inst, inst.istigermode:value())    endendlocal function OnPlayerDeactivated(inst)    inst:RemoveEventCallback("onremove", OnPlayerDeactivated)    if not TheWorld.ismastersim then        inst:RemoveEventCallback("istigermodedirty", OnTigerModeDirty)endendlocal function OnPlayerActivated(inst)    if inst.HUD.tigerOL == nil then            inst.HUD.tigerOL = inst.HUD.under_root:AddChild(Image(resolvefilepath "images/woodie.xml", "beaver_vision_OL.tex"))            inst.HUD.tigerOL:SetVRegPoint(ANCHOR_MIDDLE)            inst.HUD.tigerOL:SetHRegPoint(ANCHOR_MIDDLE)            inst.HUD.tigerOL:SetVAnchor(ANCHOR_MIDDLE)            inst.HUD.tigerOL:SetHAnchor(ANCHOR_MIDDLE)            inst.HUD.tigerOL:SetScaleMode(SCALEMODE_FILLSCREEN)            inst.HUD.tigerOL:SetClickable(false)    end    inst:ListenForEvent("onremove", OnPlayerDeactivated)    if not TheWorld.ismastersim then        inst:ListenForEvent("istigermodedirty", OnTigerModeDirty)    end    OnTigerModeDirty(inst)endlocal function SetTigerMode(inst, istiger)    if istiger then        inst.HUD.controls.status:SetTigerMode(true)        if inst.HUD.tigerOL ~= nil then            inst.HUD.tigerOL:Show()        end        if not TheWorld.ismastersim then            inst.CanExamine = CannotExamine            SetTigerActions(inst, true)            SetTigerVision(inst, true)            if inst.components.locomotor ~= nil then				inst.components.locomotor.walkspeed = 7                 inst.components.locomotor.runspeed = 8            end        end    else        inst.HUD.controls.status:SetTigerMode(false)        if inst.HUD.tigerOL ~= nil then            inst.HUD.tigerOL:Hide()        end        if not TheWorld.ismastersim then            inst.CanExamine = inst.istigermode:value() and CannotExamine or nil            SetTigerActions(inst, false)            SetTigerVision(inst, false)            if inst.components.locomotor ~= nil then                	inst.components.locomotor.walkspeed = 9                    inst.components.locomotor.runspeed = 10            end        end    endendlocal function onbecamehuman(inst)    inst.Transform:SetScale(1, 1, 1, 1)        inst.tiger = false    inst.ActionStringOverride = nil    inst.AnimState:SetBank("wilson")    inst.AnimState:SetBuild("aikawa")    inst:RemoveTag("beaver")	    inst:RemoveComponent("worker")	inst.components.locomotor.walkspeed = 7 	inst.components.locomotor.runspeed = 8    inst.components.talker:StopIgnoringAll()	inst.components.eater:SetOmnivore()	inst.components.temperature.inherentinsulation = 0    inst.components.temperature.inherentsummerinsulation = 0    inst.components.moisture:SetInherentWaterproofness(0)	inst.components.pinnable.canbepinned = true    inst.components.talker:StopIgnoringAll("becametiger")    inst.components.catcher:SetEnabled(true)    inst.CanExamine = nil    if inst.components.playercontroller ~= nil then        inst.components.playercontroller:SetCanUseMap(true)    end        inst.components.playercontroller.actionbuttonoverride = nil    inst.components.playeractionpicker.leftclickoverride = nil    inst.components.playeractionpicker.rightclickoverride = nil    inst.components.eater:SetOmnivore()    inst.components.eater.strongstomach = false    inst.components.hunger:Resume()    inst.components.sanity.ignore = false    inst.components.health.redirect = nil	     inst.components.tigerness:StartTimeEffect(2, -0.185)    inst:RemoveEventCallback("oneatsomething", ontigereat)       inst.Light:Enable(false)    inst.components.dynamicmusic:Enable()    inst.SoundEmitter:KillSound("danger")    GetWorld().components.colourcubemanager:SetOverrideColourCube(nil)    inst:DoTaskInTime(0, function() SetHUDState(inst) end)endlocal function onbecametiger(inst)    inst.tiger = true	    inst.Transform:SetScale(1.6, 1.6, 1.6, 1.6)    inst.components.eater:SetCarnivore(true)    inst.ActionStringOverride = tigeractionstring        inst:AddTag("beaver")    inst.AnimState:SetBuild("weretiger_build")    inst.AnimState:SetBank("weretiger")    inst:SetStateGraph("SGweretiger")    inst.components.talker:IgnoreAll()	inst.components.locomotor.walkspeed = 6	inst.components.locomotor.runspeed = 7    inst.components.combat:SetDefaultDamage(TUNING.BEAVER_DAMAGE*2)	inst.components.health:SetAbsorptionAmount(TUNING.BEAVER_ABSORPTION*1.5)         inst.components.inventory:DropEverything()        inst.components.playercontroller.actionbuttonoverride = TigerActionButton    inst.components.playeractionpicker.leftclickoverride = LeftClickPicker    inst.components.playeractionpicker.rightclickoverride = RightClickPicker    --inst.components.eater:SetBeaver()    inst:AddComponent("worker")    inst.components.worker:SetAction(ACTIONS.DIG, 4)	--inst.components.worker:SetAction(ACTIONS.CHOP, 4)    --inst.components.worker:SetAction(ACTIONS.MINE, 4)    inst.components.worker:SetAction(ACTIONS.HAMMER, 4)    --inst:RemoveEventCallback("oneatsomething", onaieat)    inst:ListenForEvent("oneatsomething", ontigereat)    inst.components.sanity:SetPercent(1)    inst.components.health:SetPercent(1)    inst.components.hunger:SetPercent(1)    inst.components.hunger:Pause()    inst.components.sanity.ignore = true    inst.components.health.redirect = tigerhurt    inst.components.health.redirect_percent = .25    inst.components.eater.strongstomach = true    inst.components.eater.monsterimmune = true   	    inst.CanExamine = CannotExamine    if inst.components.playercontroller ~= nil then        inst.components.playercontroller:SetCanUseMap(false)    end    local dt = 3    local BEAVER_DRAIN_TIME = 120    inst.components.tigerness:StartTimeEffect(dt, (-100/BEAVER_DRAIN_TIME)*dt)    inst.Light:Enable(true)    inst.components.dynamicmusic:Disable()    inst.SoundEmitter:KillSound("eating")    inst.SoundEmitter:PlaySound("dontstarve/music/music_epicfight_winter", "danger")    --GetWorld().components.colourcubemanager:SetOverrideColourCube(resolvefilepath "images/colour_cubes/tiger_vision_3_cc.tex")    inst:DoTaskInTime(0, function() SetHUDState(inst) end)endlocal function onbecameghost(inst)    if inst.istigermode:value() then        inst.AnimState:SetBuild("ghost_aikawa_build")    endend----------------------------------------------------------------------------Re-enter idle state right after loading because--idle animations are determined by beaver state.local function onentityreplicated(inst)    if inst.sg ~= nil and inst:HasTag("beaver") then        inst.sg:GoToState("idle")    endendlocal function onpreload(inst, data)    if data ~= nil and data.istiger then        onbecametiger(inst)        inst.sg:GoToState("idle")    endendlocal function onload(inst)    if inst.istigermode:value() and not inst:HasTag("playerghost") then        inst.components.inventory:Close()    endendlocal function onsave(inst, data)    data.istiger = inst.istigermode:value() or nilendlocal function onsetskin(inst)    if inst.istigermode:value() and not inst:HasTag("playerghost") then        inst.AnimState:SetBuild("weretiger_build")    endend--------------------------------------------------------------------------local function oncollide(inst, other)    if other == GetPlayer() or not inst:HasTag("beaver") then     	return    end     inst:DoTaskInTime(2*FRAMES, function()               if other and other.components.workable and other.components.workable.workleft > 0 then                SpawnPrefab("collapse_small").Transform:SetPosition(other:GetPosition():Get())                other.components.workable:Destroy(inst)				TheCamera:Shake("SIDE", 0.5, 0.05, 0.1)            end    end)endlocal master_postinit = function(inst)inst.components.health:SetMaxHealth(250)	inst.components.hunger:SetMax(100)	inst.components.sanity:SetMax(100)	inst.components.sanity.night_drain_mult = 0	inst.components.sanity.neg_aura_mult = 0	inst.components.temperature.maxtemp = 40	inst.components.health.fire_damage_scale = 5		inst.MiniMapEntity:SetIcon( "aikawa.tex" )	-- Custom Sound	inst.soundsname = "willow"    inst.components.talker.colour = Vector3(255/255, 255/255, 255/255)	inst.MiniMapEntity:SetIcon( "aikawa.tex" )	-- Custom Sound	inst.soundsname = "willow"    inst.components.talker.colour = Vector3(255/255, 255/255, 255/255)	-- Stats			-- Damage multiplier (optional)    inst.components.combat.damagemultiplier = 1.8		-- Hunger rate (optional)	inst.components.hunger.hungerrate = 0.8 * TUNING.WILSON_HUNGER_RATEend-- WERETIGER FUNCTIONS END --local function common_postinit(inst)    inst:AddTag("woodcutter")    inst:AddTag("polite")    inst:AddTag("ghostwithhat")    --beaverness (from beaverness component) added to pristine state for optimization    inst:AddTag("tigerness")    inst.istigermode = net_bool(inst.GUID, "aikawa.istigermode", "istigermodedirty")    inst:ListenForEvent("playeractivated", OnPlayerActivated)    inst:ListenForEvent("playerdeactivated", OnPlayerDeactivated)    if inst.ghostenabled then        inst._SetGhostMode = inst.SetGhostMode        inst.SetGhostMode = SetGhostMode    end    if not TheWorld.ismastersim then        inst.OnEntityReplicated = onentityreplicated    endendlocal function master_postinit(inst)    inst:AddComponent("tigerness")    inst._wasnomorph = nil    inst.TransformTiger = TransformTiger    inst:ListenForEvent("ms_becameghost", onbecameghost)		inst.entity:AddLight()    inst.Light:Enable(false)    inst.Light:SetRadius(15)    inst.Light:SetFalloff(.5)    inst.Light:SetIntensity(.6)    inst.Light:SetColour(255/255,0/255,0/255)	-- WERETIGER --        inst:AddComponent("tigerness")        inst.components.tigerness.makeperson = onbecamehuman        inst.components.tigerness.maketiger = onbecametiger            inst.components.tigerness.onbecomeperson = function()            inst:PushEvent("transform_person")        end        inst.components.tigerness.onbecometiger = function()            inst:PushEvent("transform_weretiger")        end	onbecamehuman(inst)    inst.components.eater:SetOnEatFn(onaikawaeat)    	-- WERETIGER END --	inst.Physics:SetCollisionCallback(oncollide)	inst.OnSave = onsave    inst.OnLoad = onload    inst.OnPreLoad = onpreload    inst.OnSetSkin = onsetskinendreturn MakePlayerCharacter("aikawa", prefabs, assets, master_postinit, start_inv)

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

This is my another error. after I try to fix it.

 

  http://upic.me/show/56578030

Share this post


Link to post
Share on other sites
DarkXero    2886

@Yagenius:

return MakePlayerCharacter("aikawa", prefabs, assets, master_postinit, start_inv)

should be

return MakePlayerCharacter("aikawa", prefabs, assets, common_postinit, master_postinit, start_inv)

Share this post


Link to post
Share on other sites
DarkXero    2886

@Yagenius, because in that line, the playercontroller component is nil.

Fixed by checking before indexing.

	if inst.components.playercontroller ~= nil then		inst.components.playercontroller.actionbuttonoverride = nil		inst.components.playeractionpicker.leftclickoverride = nil		inst.components.playeractionpicker.rightclickoverride = nil	end

The attempt to index field (nil value) happens because of this.

You enter inst, a table.

You enter inst["components"], another table.

You enter inst["components"]["playeractionpicker"], which in this case the value is nil, not another table.

When you do nil.actionbuttonoverride, which is, nil["actionbuttonoverride"], the game crashes.

You can only index tables, not booleans, integers, or the nil value.

 

The method ? happens because of this.

You get the value inst["components"]["eater"]["SetOmnivore"].

Because the function wasn't declared in the component definition, that value is nil.

Then, when you add the (), it ends up like nil().

And you can only () methods.

Share this post


Link to post
Share on other sites
Yagenius    2

 Ok I try to understand it .

 

I have an another error it say : Variable is not declared.

error4.jpg

 

when i look at My Line .

local function OnTigerModeDirty(inst)    if inst.HUD ~= nil and not inst:HasTag("playerghost") then        SetTigerMode(inst, inst.istigermode:value())    endend

 

 

 

 

" inst.istigermode:value() " Mean this ?

 inst.istigermode = net_bool(inst.GUID, "aikawa.istigermode", "istigermodedirty")

or just " SetTigerMode " ?

local function SetTigerMode(inst, istiger)    if istiger then        inst.HUD.controls.status:SetTigerMode(true)        if inst.HUD.tigerOL ~= nil then            inst.HUD.tigerOL:Show()        end        if not TheWorld.ismastersim then            inst.CanExamine = CannotExamine            SetTigerActions(inst, true)            SetTigerVision(inst, true)            if inst.components.locomotor ~= nil then				inst.components.locomotor.walkspeed = 7                 inst.components.locomotor.runspeed = 8            end        end    else        inst.HUD.controls.status:SetTigerMode(false)        if inst.HUD.tigerOL ~= nil then            inst.HUD.tigerOL:Hide()        end        if not TheWorld.ismastersim then            inst.CanExamine = inst.istigermode:value() and CannotExamine or nil            SetTigerActions(inst, false)            SetTigerVision(inst, false)            if inst.components.locomotor ~= nil then                	inst.components.locomotor.walkspeed = 9                    inst.components.locomotor.runspeed = 10            end        end    endend

I'm not sure what i'm going to do. because I try to remove " inst.istigermode:value() " and " inst.istigermode = net_bool "

but the game say Unknown.

Edited by Yagenius

Share this post


Link to post
Share on other sites
DarkXero    2886

@Yagenius, SetTigerMode is defined UNDER the function that uses it.

Therefore, it's not defined.

Put SetTigerMode OVER OnTigerModeDirty.

 

inst.istigermode:value() does refer to inst.istigermode.

The value() method returns the value of the net_bool variable.

Share this post


Link to post
Share on other sites
Yagenius    2

@DarkXero

 

Ok , And here is another error. 

 

it's say in my components / tigerness .

 

here is my components : 

local Tigerness = Class(function(self, inst)   --V2C: Recommended to explicitly add tag to prefab pristine state    inst:AddTag("tigerness")    self.inst = inst	self.max = 100    self.current = 0    self.is_tiger = falseend)function Tigerness:IsTiger()    return self.is_tigerendfunction Tigerness:OnSave()        return     {	current = self.current,        is_tiger = self.is_tiger	}endfunction Tigerness:OnLoad(data)    if data then        if data.current then            self.current = data.current        end        if data.is_tiger then            self.is_tiger = data.is_tiger        end    end    if self.is_tiger then        if self.maketiger then            self.maketiger(self.inst)        end    else        if self.makeperson then            self.makeperson(self.inst)        end    endendlocal function OnTimeEffectTick(inst, self, delta, dt)    self:DoDelta(delta * self.time_effect_multiplier, true)    --Tigerness hitting 0 does starving damage    if self.current <= 0 then        inst.components.health:DoDelta(-inst.components.hunger.hurtrate * dt, false, "hunger")    endendfunction Tigerness:StartTimeEffect(dt, delta_b)    if self.task ~= nil then        self.task:Cancel()    end    self.task = self.inst:DoPeriodicTask(dt, OnTimeEffectTick, nil, self, delta_b, dt)endfunction Tigerness:StopTimeEffect()    if self.task ~= nil then        self.task:Cancel()        self.task = nil    endendfunction Tigerness:SetTimeEffectMultiplier(multiplier)    self.time_effect_multiplier = multiplier or 1endfunction Tigerness:DoDelta(delta, overtime)    local oldpercent = self.current/self.max    self.current = self.current + delta        if self.current < 0 then self.current = 0 end    if self.current > self.max then self.current = self.max end    self.inst:PushEvent("tigernessdelta", {oldpercent = oldpercent, newpercent = self.current/self.max, overtime = overtime})                if self.is_tiger then             if self.current > 50 then                GetWorld().components.colourcubemanager:SetOverrideColourCube(nil)            elseif self.current > 50 then                GetWorld().components.colourcubemanager:SetOverrideColourCube(resolvefilepath "images/colour_cubes/tiger_vision_5_cc.tex")            elseif self.current > 40 then                GetWorld().components.colourcubemanager:SetOverrideColourCube(resolvefilepath "images/colour_cubes/tiger_vision_4_cc.tex")            elseif self.current > 30 then                GetWorld().components.colourcubemanager:SetOverrideColourCube(resolvefilepath "images/colour_cubes/tiger_vision_3_cc.tex")            elseif self.current > 20 then                GetWorld().components.colourcubemanager:SetOverrideColourCube(resolvefilepath "images/colour_cubes/tiger_vision_2_cc.tex")            elseif self.current > 10 then                GetWorld().components.colourcubemanager:SetOverrideColourCube(resolvefilepath "images/colour_cubes/tiger_vision_1_cc.tex")            else                GetWorld().components.colourcubemanager:SetOverrideColourCube(resolvefilepath "images/colour_cubes/tiger_vision_cc.tex")            end        end    --if delta ~= 0 then        if self.is_tiger and self.current <= 0 then            self.is_tiger = false                        if self.onbecomeperson then                self.onbecomeperson(self.inst)                self.inst:PushEvent("tigerend")            end        elseif not self.is_tiger and self.current >= self.max then            self.is_tiger = true            if self.onbecometiger then                self.onbecometiger(self.inst)                self.inst:PushEvent("tigerstart")            end        end    --endendfunction Tigerness:GetPercent()    return self.current / self.maxendfunction Tigerness:GetDebugString()    return string.format("%2.2f / %2.2f", self.current, self.max)endfunction Tigerness:SetPercent(percent)    self.current = self.max*percent    self:DoDelta(0)endreturn Tigerness

error5.jpg

Share this post


Link to post
Share on other sites
DarkXero    2886

@Yagenius:

local Tigerness = Class(function(self, inst)   --V2C: Recommended to explicitly add tag to prefab pristine state    inst:AddTag("tigerness")    self.inst = inst    self.max = 100    self.current = 0    self.is_tiger = false	-- Add this	self.time_effect_multiplier = 1end)

Share this post


Link to post
Share on other sites
Yagenius    2

@DarkXero

Ok , The games is running nicely .

 

 

but my health is damage by something . (It getting lower and lower)

 

This is the current Code we use :

require "stategraphs/SGweretiger"local Badge = require "widgets/badge"local easing = require "easing"local MakePlayerCharacter = require "prefabs/player_common"local start_inv = {	"fish",	"rabbit",	"fish",	"fish",	"carrot",}local assets ={    Asset( "ANIM", "anim/player_basic.zip" ),    Asset( "ANIM", "anim/player_idles_shiver.zip" ),    Asset( "ANIM", "anim/player_actions.zip" ),    Asset( "ANIM", "anim/player_actions_axe.zip" ),    Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),    Asset( "ANIM", "anim/player_actions_shovel.zip" ),    Asset( "ANIM", "anim/player_actions_blowdart.zip" ),    Asset( "ANIM", "anim/player_actions_eat.zip" ),    Asset( "ANIM", "anim/player_actions_item.zip" ),    Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),    Asset( "ANIM", "anim/player_actions_bugnet.zip" ),    Asset( "ANIM", "anim/player_actions_fishing.zip" ),    Asset( "ANIM", "anim/player_actions_boomerang.zip" ),    Asset( "ANIM", "anim/player_bush_hat.zip" ),    Asset( "ANIM", "anim/player_attacks.zip" ),    Asset( "ANIM", "anim/player_idles.zip" ),    Asset( "ANIM", "anim/player_rebirth.zip" ),    Asset( "ANIM", "anim/player_jump.zip" ),    Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),    Asset( "ANIM", "anim/player_teleport.zip" ),    Asset( "ANIM", "anim/wilson_fx.zip" ),    Asset( "ANIM", "anim/player_one_man_band.zip" ),    Asset( "ANIM", "anim/shadow_hands.zip" ),	  	Asset( "ANIM", "anim/player_woodie.zip"),	Asset( "ANIM", "anim/woodie.zip"),	Asset( "ANIM", "anim/player_wolfgang.zip"),	    Asset( "ANIM", "anim/aikawa.zip" ),	Asset( "ANIM", "anim/ghost_aikawa_build.zip" ),    Asset( "ANIM", "anim/tiger_meter.zip"),    Asset("ANIM", "anim/weretiger_build.zip"),	    Asset( "IMAGE", "images/colour_cubes/tiger_vision_cc.tex" ),	Asset( "IMAGE", "images/colour_cubes/tiger_vision_1_cc.tex" ),	Asset( "IMAGE", "images/colour_cubes/tiger_vision_2_cc.tex" ),	Asset( "IMAGE", "images/colour_cubes/tiger_vision_3_cc.tex" ),	Asset( "IMAGE", "images/colour_cubes/tiger_vision_4_cc.tex" ),	Asset( "IMAGE", "images/colour_cubes/tiger_vision_5_cc.tex" ),	Asset( "IMAGE", "images/colour_cubes/tiger_vision_6_cc.tex" ),	    Asset("ATLAS", "images/woodie.xml"),    Asset("IMAGE", "images/woodie.tex"),}local prefabs = {}local TIGER_DIET ={    FOODTYPE.MEAT,}-- WERETIGER FUNCTIONS --local function tigeractionstring(inst, action)    return "chomp"endlocal function TigerActionButton(inst)	local action_target = FindEntity(inst, 6, function(guy) return (guy.components.edible and inst.components.eater:CanEat(guy)) or		 													 (guy.components.workable and inst.components.worker:CanDoAction(guy.components.workable.action)) end)		if not inst.sg:HasStateTag("busy") and action_target then		if (action_target.components.edible and inst.components.eater:CanEat(action_target)) then			return BufferedAction(inst, action_target, ACTIONS.EAT)		else			return BufferedAction(inst, action_target, action_target.components.workable.action)		end	endendlocal function LeftClickPicker(inst, target_ent, pos)    if inst.components.combat:CanTarget(target_ent) then        return inst.components.playeractionpicker:SortActionList({ACTIONS.ATTACK}, target_ent, nil)    end    if target_ent and target_ent.components.edible and inst.components.eater:CanEat(target_ent) then        return inst.components.playeractionpicker:SortActionList({ACTIONS.EAT}, target_ent, nil)    end    if target_ent and target_ent.components.workable and inst.components.worker:CanDoAction(target_ent.components.workable.action) then        return inst.components.playeractionpicker:SortActionList({target_ent.components.workable.action}, target_ent, nil)    endendlocal function RightClickPicker(inst, target_ent, pos)    return {}end-------------------- CHANGE BADGE --------------------local TigerBadge = Class(Badge, function(self, owner)    Badge._ctor(self, "tiger_meter", owner)end)---------------------- CHANGE TO MEAT ----------------------local function ontigereat(inst, data)    if data.food and data.food.components.edible.ismeat and inst.components.tigerness:IsTiger() then        if data.food.components.edible.hungervalue == TUNING.CALORIES_TINY then            inst.components.tigerness:DoDelta(1)        elseif data.food.components.edible.hungervalue == TUNING.CALORIES_SMALL then            inst.components.tigerness:DoDelta(3)        elseif data.food.components.edible.hungervalue == TUNING.CALORIES_MEDSMALL then            inst.components.tigerness:DoDelta(6)        elseif data.food.components.edible.hungervalue == TUNING.CALORIES_MED then            inst.components.tigerness:DoDelta(10)		else            inst.components.tigerness:DoDelta(15)		end    endendlocal function onaikawaeat(inst, food)     	if inst:HasTag("beaver") then 		return	end		-- 1 Delta is 1%	-- Tigerness 70    if food.name == 'Meaty Stew' or food.name == 'Monster Meat' then			inst.components.tigerness:DoDelta(70)	-- Tigerness 40    elseif food.name == 'Meat' or food.name == 'Monster Lasagna' or food.name == 'Koalefant Trunk' or food.name == 'Winter Koalefant Trunk' then		inst.components.tigerness:DoDelta(40)			-- Tigerness 35    elseif food.name == 'Bacon and Eggs' or food.name == 'Turkey Dinner' or food.name == 'Tallbird Egg' or food.name == 'Koalefant Trunk Steak' or food.name == 'Koalefant Trunk Steak' then		inst.components.tigerness:DoDelta(35)			-- Tigerness 30    elseif food.name == 'Morsel' or food.name == 'Batilisk Wing' or food.name == 'Leafy Meat' then		inst.components.tigerness:DoDelta(30)    -- Tigerness 20    elseif food.name == 'Frog Legs' or food.name == 'Fishsticks' or food.name == 'Cooked Leafy Meat' then		inst.components.tigerness:DoDelta(20)    -- Tigerness 12    elseif food.name == 'Jerky' or food.name == 'Egg' then		inst.components.tigerness:DoDelta(12)    -- Tigerness 10    elseif food.name == 'Cooked Meat' or food.name == 'Cooked Frog Legs' or food.name == 'Cooked Egg' then		inst.components.tigerness:DoDelta(10)	-- Tigerness 8    elseif food.name == 'Drumstick' or food.name == 'Small Jerky' then		inst.components.tigerness:DoDelta(7)	-- Tigerness 7    elseif food.name == 'Fried Drumstick' or food.name == 'Fish' then		inst.components.tigerness:DoDelta(7)	-- Tigerness 5    elseif food.name == 'Cooked Morsel' or food.name == 'Cooked Fish' then		inst.components.tigerness:DoDelta(5)	end		if inst.components.tigerness:GetPercent() > .8 then			inst.components.talker:Say(GetString("aikawa", "ANNOUNCE_TIGERNESS_HIGHEST"))		elseif inst.components.tigerness:GetPercent() > .65 then			inst.components.talker:Say(GetString("aikawa", "ANNOUNCE_TIGERNESS_HIGHER"))				elseif inst.components.tigerness:GetPercent() > .5 then			inst.components.talker:Say(GetString("aikawa", "ANNOUNCE_TIGERNESS_AVERAGE"))				elseif inst.components.tigerness:GetPercent() > .3 then			inst.components.talker:Say(GetString("aikawa", "ANNOUNCE_TIGERNESS_LOW"))		elseif inst.components.tigerness:GetPercent() > .2 then			inst.components.talker:Say(GetString("aikawa", "ANNOUNCE_TIGERNESS_LOWER"))				elseif inst.components.tigerness:GetPercent() > .1 then			inst.components.talker:Say(GetString("aikawa", "ANNOUNCE_TIGERNESS_LOWEST"))			end	    print ('tigerness', inst.components.tigerness:GetPercent())    end---------------------  SetTigerMode --------------------local function SetHUDState(inst)    if inst.HUD then        if inst.components.tigerness:IsTiger() and not inst.HUD.controls.tigerbadge then            inst.HUD.controls.tigerbadge = GetPlayer().HUD.controls.sidepanel:AddChild(TigerBadge(inst))            inst.HUD.controls.tigerbadge:SetPosition(0,-100,0)            inst.HUD.controls.tigerbadge:SetPercent(1)                        inst.HUD.controls.tigerbadge.inst:ListenForEvent("tigernessdelta", function(_, data)                 inst.HUD.controls.tigerbadge:SetPercent(inst.components.tigerness:GetPercent(), inst.components.tigerness.max)                if not data.overtime then                    if data.newpercent > data.oldpercent then                        inst.HUD.controls.tigerbadge:PulseGreen()                        TheFrontEnd:GetSound():PlaySound("dontstarve/HUD/health_up")                    elseif data.newpercent < data.oldpercent then                        TheFrontEnd:GetSound():PlaySound("dontstarve/HUD/health_down")                        inst.HUD.controls.tigerbadge:PulseRed()                    end                end            end, inst)            inst.HUD.controls.crafttabs:Hide()            inst.HUD.controls.inv:Hide()            inst.HUD.controls.status:Hide()            inst.HUD.controls.mapcontrols.minimapBtn:Hide()            inst.HUD.tigerOL = inst.HUD.under_root:AddChild(Image(resolvefilepath "images/woodie.xml", "beaver_vision_OL.tex"))            inst.HUD.tigerOL:SetVRegPoint(ANCHOR_MIDDLE)            inst.HUD.tigerOL:SetHRegPoint(ANCHOR_MIDDLE)            inst.HUD.tigerOL:SetVAnchor(ANCHOR_MIDDLE)            inst.HUD.tigerOL:SetHAnchor(ANCHOR_MIDDLE)            inst.HUD.tigerOL:SetScaleMode(SCALEMODE_FILLSCREEN)            inst.HUD.tigerOL:SetClickable(false)                elseif not inst.components.tigerness:IsTiger() and inst.HUD.controls.tigerbadge then            if inst.HUD.controls.tigerbadge then                inst.HUD.controls.tigerbadge:Kill()                inst.HUD.controls.tigerbadge = nil            end            if inst.HUD.tigerOL then                inst.HUD.tigerOL:Kill()                inst.HUD.tigerOL = nil            end            inst.HUD.controls.crafttabs:Show()            inst.HUD.controls.inv:Show()            inst.HUD.controls.status:Show()            inst.HUD.controls.mapcontrols.minimapBtn:Show()        end    endendlocal function tigerhurt(inst, delta)    if delta < 0 then        inst.sg:PushEvent("attacked")        inst.components.tigerness:DoDelta(delta*.25)        TheFrontEnd:GetSound():PlaySound("dontstarve/HUD/health_down")        inst.HUD.controls.tigerbadge:PulseRed()        if inst.HUD.bloodover then            inst.HUD.bloodover:Flash()        end    endendlocal function OnIsFullmoon(inst, isfullmoon)    if isfullmoon then        if inst.components.tigerness:GetPercent() > .25 then            inst.components.tigerness:SetPercent(.25)        end        inst.components.tigerness:SetTimeEffectMultiplier(TUNING.BEAVER_FULLMOON_DRAIN_MULTIPLIER*0.2)    else        inst.components.tigerness:SetTimeEffectMultiplier(1)    endendlocal function ontigernesschange(inst)    if inst.sg:HasStateTag("nomorph") or        inst.sg:HasStateTag("silentmorph") or        inst:HasTag("playerghost") or        inst.components.health:IsDead() or        not inst.entity:IsVisible() then        return    end    if inst.istigermode:value() then        if inst.components.tigerness:GetPercent() > TUNING.WOODIE_TRANSFORM_TO_HUMAN then            inst:PushEvent("transform_person")        end    elseif inst.components.tigerness:GetPercent() <= TUNING.WOODIE_TRANSFORM_TO_BEAVER then        inst:PushEvent("transform_weretiger")    endend--------------------------------------------------------------------------------------------------------------------------			local function onbecamehuman(inst)    inst.Transform:SetScale(1, 1, 1, 1)        inst.tiger = false    inst.ActionStringOverride = nil    inst.AnimState:SetBank("wilson")    inst.AnimState:SetBuild("aikawa")    inst:RemoveTag("beaver")	    inst:RemoveComponent("worker")	inst.components.locomotor.walkspeed = 7 	inst.components.locomotor.runspeed = 8    inst.components.talker:StopIgnoringAll()	inst.components.eater:SetDiet({ FOODGROUP.OMNI })	inst.components.temperature.inherentinsulation = 0    inst.components.temperature.inherentsummerinsulation = 0    inst.components.moisture:SetInherentWaterproofness(0)	inst.components.pinnable.canbepinned = true    inst.components.talker:StopIgnoringAll("becametiger")    inst.components.catcher:SetEnabled(true)    inst.CanExamine = nil    if inst.components.playercontroller ~= nil then        inst.components.playercontroller:SetCanUseMap(true)    inst.components.playercontroller.actionbuttonoverride = nil    inst.components.playeractionpicker.leftclickoverride = nil    inst.components.playeractionpicker.rightclickoverride = nil    end	    inst.components.eater.strongstomach = false    inst.components.hunger:Resume()    inst.components.sanity.ignore = false    inst.components.health.redirect = nil	     inst.components.tigerness:StartTimeEffect(2, -0.185)    inst:RemoveEventCallback("oneatsomething", ontigereat)       inst.Light:Enable(false)    inst.SoundEmitter:KillSound("danger")    inst:DoTaskInTime(0, function() SetHUDState(inst) end)endlocal function onbecametiger(inst)    inst.tiger = true	    inst.Transform:SetScale(1.6, 1.6, 1.6, 1.6)    inst.components.eater:SetDiet({ FOODGROUP.TIGERDIET } , { FOODTYPE.HORRIBLE })    inst.ActionStringOverride = tigeractionstring        inst:AddTag("beaver")    inst.AnimState:SetBuild("weretiger_build")    inst.AnimState:SetBank("weretiger")    inst:SetStateGraph("SGweretiger")    inst.components.talker:IgnoreAll()	inst.components.locomotor.walkspeed = 6	inst.components.locomotor.runspeed = 7    inst.components.combat:SetDefaultDamage(TUNING.BEAVER_DAMAGE*2)	inst.components.health:SetAbsorptionAmount(TUNING.BEAVER_ABSORPTION*1.5)         inst.components.inventory:DropEverything()        inst.components.playercontroller.actionbuttonoverride = TigerActionButton    inst.components.playeractionpicker.leftclickoverride = LeftClickPicker    inst.components.playeractionpicker.rightclickoverride = RightClickPicker    --inst.components.eater:SetBeaver()    inst:AddComponent("worker")    inst.components.worker:SetAction(ACTIONS.DIG, 4)	--inst.components.worker:SetAction(ACTIONS.CHOP, 4)    --inst.components.worker:SetAction(ACTIONS.MINE, 4)    inst.components.worker:SetAction(ACTIONS.HAMMER, 4)    --inst:RemoveEventCallback("oneatsomething", onaieat)    inst:ListenForEvent("oneatsomething", ontigereat)    inst.components.sanity:SetPercent(1)    inst.components.health:SetPercent(1)    inst.components.hunger:SetPercent(1)    inst.components.hunger:Pause()    inst.components.sanity.ignore = true    inst.components.health.redirect = tigerhurt    inst.components.health.redirect_percent = .25    inst.components.eater.strongstomach = true    inst.components.eater.monsterimmune = true   	    inst.CanExamine = CannotExamine    if inst.components.playercontroller ~= nil then        inst.components.playercontroller:SetCanUseMap(false)    end    local dt = 3    local BEAVER_DRAIN_TIME = 120    inst.components.tigerness:StartTimeEffect(dt, (-100/BEAVER_DRAIN_TIME)*dt)    inst.Light:Enable(true)    inst.components.dynamicmusic:Disable()    inst.SoundEmitter:KillSound("eating")    inst.SoundEmitter:PlaySound("dontstarve/music/music_epicfight_winter", "danger")    --GetWorld().components.colourcubemanager:SetOverrideColourCube(resolvefilepath "images/colour_cubes/tiger_vision_3_cc.tex")    inst:DoTaskInTime(0, function() SetHUDState(inst) end)endlocal function onload(inst)    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)    if not inst:HasTag("playerghost") then        onbecamehuman(inst)    endend----------------------------------------------------------------------------Re-enter idle state right after loading because--idle animations are determined by beaver state.local function onentityreplicated(inst)    if inst.sg ~= nil and inst:HasTag("beaver") then        inst.sg:GoToState("idle")    endendlocal function onpreload(inst, data)    if data ~= nil and data.istiger then        onbecametiger(inst)        inst.sg:GoToState("idle")    endendlocal function onload(inst)    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)    if not inst:HasTag("playerghost") then        onbecamehuman(inst)    endend--------------------------------------------------------------------------local function oncollide(inst, other)    if other == GetPlayer() or not inst:HasTag("beaver") then     	return    end     inst:DoTaskInTime(2*FRAMES, function()               if other and other.components.workable and other.components.workable.workleft > 0 then                SpawnPrefab("collapse_small").Transform:SetPosition(other:GetPosition():Get())                other.components.workable:Destroy(inst)				TheCamera:Shake("SIDE", 0.5, 0.05, 0.1)            end    end)endlocal master_postinit = function(inst)inst.components.health:SetMaxHealth(250)	inst.components.hunger:SetMax(100)	inst.components.sanity:SetMax(100)	inst.components.sanity.night_drain_mult = 0	inst.components.sanity.neg_aura_mult = 0	inst.components.temperature.maxtemp = 40	inst.components.health.fire_damage_scale = 5		inst.MiniMapEntity:SetIcon( "aikawa.tex" )	-- Custom Sound	inst.soundsname = "willow"    inst.components.talker.colour = Vector3(255/255, 255/255, 255/255)	inst.MiniMapEntity:SetIcon( "aikawa.tex" )	-- Stats			-- Damage multiplier (optional)    inst.components.combat.damagemultiplier = 1.8		-- Hunger rate (optional)	inst.components.hunger.hungerrate = 0.8 * TUNING.WILSON_HUNGER_RATEend-- WERETIGER FUNCTIONS END --local function common_postinit(inst)    inst:AddTag("woodcutter")    inst:AddTag("polite")    inst:AddTag("ghostwithhat")    --beaverness (from beaverness component) added to pristine state for optimization    inst:AddTag("tigerness")    if not TheWorld.ismastersim then        inst.OnEntityReplicated = onentityreplicated    endendlocal function master_postinit(inst)    inst:AddComponent("tigerness")    inst._wasnomorph = nil		inst.entity:AddLight()    inst.Light:Enable(false)    inst.Light:SetRadius(15)    inst.Light:SetFalloff(.5)    inst.Light:SetIntensity(.6)    inst.Light:SetColour(255/255,0/255,0/255)	-- WERETIGER --        inst:AddComponent("tigerness")        inst.components.tigerness.makeperson = onbecamehuman        inst.components.tigerness.maketiger = onbecametiger            inst.components.tigerness.onbecomeperson = function()            inst:PushEvent("transform_person")        end        inst.components.tigerness.onbecometiger = function()            inst:PushEvent("transform_weretiger")        end	onbecamehuman(inst)    inst.components.eater:SetOnEatFn(onaikawaeat)    	-- WERETIGER END --	inst.Physics:SetCollisionCallback(oncollide)    inst.OnLoad = onload    inst.OnPreLoad = onpreload	inst.OnNewSpawn = onloadendreturn MakePlayerCharacter("aikawa", prefabs, assets, common_postinit, master_postinit, start_inv)

Thank you For your help very much!!!

Edited by Yagenius

Share this post


Link to post
Share on other sites
DarkXero    2886

@Yagenius, here I'm not sure.

Try removing lines that say "SetStategraph".

 

The werebeaver in DST uses the SGwilson stategraph, so maybe it won't appear for the SGwerebeaver.

Share this post


Link to post
Share on other sites
DarkXero    2886

@Yagenius, I don't know.

It doesn't matter if you set it to that, all players are already set to SGwilson.

 

But the bank has to be "weretiger", and the build "weretiger_build".

Share this post


Link to post
Share on other sites
DarkXero    2886

@Yagenius, I can't tell.

It's the single player Woodie code with multiplayer stuff tacked on.

 

Woodie is much more complex now because he can die as a werebeaver, be a werebeaver ghost, and even has werebeaver emotes.

 

I suggest you make your weretiger form based on the template

http://steamcommunity.com/sharedfiles/filedetails/?id=361202313

and simply switch builds, from aikawa to weretiger builds, using the same player bank.

 

If you truly want a werebeaver with werebeaver bank and build, you will need to use krane

http://forums.kleientertainment.com/files/file/583-ktools-cross-platform-modding-tools-for-dont-starve/

to decompile werebeaver_basic (anim) with werebeaver_build (build) and go on with the spriter project generated.

  • Like 2

Share this post


Link to post
Share on other sites

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
Sign in to follow this