Jump to content

how do I reference a variable in an item or a stategraph


Recommended Posts

i'm currently working on a character mod (Bellatrix)

 

I have an item which when equipped triggers a state graph and a transformation animation now all i have to do is change a variable to finish it off but it keeps crashing i already tried using owner./inst./self.inst.

even though i kinda new it wouldn't work i still tried and failed so if anyone knows can give me a hand thanks here is the variables i needed to change and how i structured them

 

 

if(damage=true) then
       damage=false
end
 
if(daytime=true) then
      damage=true
end

 

Link to comment
Share on other sites

Please show the entire code.

 

A stategraph instance can be referenced to by inst.sg

 

EDIT: Wait hang on, isn't Bellatrix the really complicated bee queen character that entirely modifies bees without actually overriding anything in that relation?

Link to comment
Share on other sites

 

@muddykat Like this?

-- In player scriptplayer_inst.val = 1-- In modmainprint(GLOBAL.GetPlayer().val) -- prints 1-- Elsewhereprint(GetPlayer().val) -- prints 1

Kind of like that execpt i need that value to change from 1 to 0 and back and fourth

here is the exact code that im using for my item

 

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( "SOUND", "sound/sfx.fsb" ),
        Asset( "ANIM", "anim/beard.zip" ),
Asset( "ANIM", "anim/shadow_hands.zip" ),
 
Asset("ANIM", "anim/cloak.zip"),
    Asset("ATLAS", "images/inventoryimages/cloak.xml")
}
 
 
local function onequip(inst, owner) 
    owner.AnimState:OverrideSymbol("swap_body", "cloak", "swap_body")
           owner.components.talker:Say(GetString(owner.prefab, "ANNOUNCE_NIGHTMAREFORM"))
                    SpawnPrefab("statue_transition").Transform:SetPosition(inst:GetPosition():Get())
                    SpawnPrefab("statue_transition_2").Transform:SetPosition(inst:GetPosition():Get())  
    owner.SoundEmitter:PlaySound("dontstarve/charlie/warn")
    owner.SoundEmitter:PlaySound("dontstarve/common/throne/thronemagic", "nightmaresound")
owner.components.combat.damagemultiplier = 2.1
owner.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 2)
owner.components.health.maxhealth = 95
owner.components.hunger.max = 100
owner.components.locomotor.walkspeed = 4
owner.components.locomotor.runspeed = 5
owner.components.builder.magic_bonus = 2
owner.components.builder.science_bonus = 0
    owner.sg:GoToState("nightmareform")
owner:AddTag("nonclonable")
if(damage=true) then
       damage=false
end
end
 
local function onunequip(inst, owner) 
owner.AnimState:ClearOverrideSymbol("swap_body")
    SpawnPrefab("statue_transition").Transform:SetPosition(inst:GetPosition():Get())
    SpawnPrefab("statue_transition_2").Transform:SetPosition(inst:GetPosition():Get())
    owner.SoundEmitter:PlaySound("dontstarve/charlie/warn")
    owner.SoundEmitter:PlaySound("dontstarve/creatures/knight_nightmare/voice")
owner.talksoundoverride = "dontstarve/characters/bellatrix/talk_LP"
owner.components.combat.damagemultiplier = .9
owner.components.builder.magic_bonus = 1
owner.components.builder.science_bonus = 0
owner.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1.05)
    owner.sg:GoToState("normalform")
owner.SoundEmitter:KillSound("nightmaresound")
owner:RemoveTag("nonclonable")
if(daytime=true) then
      damage=true
end
end
 
local function fn(Sim)
local inst = CreateEntity()
    
inst.entity:AddTransform()
inst.entity:AddAnimState()
    MakeInventoryPhysics(inst)
    
    inst.AnimState:SetBank("armor_grass")
    inst.AnimState:SetBuild("cloak")
    inst.AnimState:PlayAnimation("anim")
    
    inst:AddComponent("inspectable")
    
    inst:AddTag("irreplaceable")
    
    inst:AddComponent("inventoryitem")
  inst.components.inventoryitem.atlasname = "images/inventoryimages/cloak.xml"
    
    inst:AddComponent("equippable")
    inst.components.equippable.equipslot = EQUIPSLOTS.BODY
    
    inst.components.equippable:SetOnEquip( onequip )
    inst.components.equippable:SetOnUnequip( onunequip )
    
    inst:AddComponent("insulator")
    inst.components.insulator.insulation = math.huge
    
    return inst
end
 
return Prefab( "common/inventory/cloak", fn, assets ) 

 

Link to comment
Share on other sites

@muddykat Ah.. well, I was just demonstrating how you can access variables associated with your character. The rest depends on your design, think of how you can use that to do what you want to do.

 

eg.

player_inst.damage = trueplayer_inst.damage = false-- ...if (GetPlayer().damage) then    -- ...end
Link to comment
Share on other sites

Your lack of brackets is awful...

 

Pardon stranger? I would say there's even an excess of brackets in the if statements found on this thread. If your statement was meant to be sarcastic, then I'm afraid that the sarcasm wasn't clear enough.

 

Generally speaking, it's a good idea to give reason for your statements.

Link to comment
Share on other sites

Your lack of brackets is awful...

lol its my first mod to ya know no one really has taught me how to adequately use brackets or indents or what ever you meant so if you know what your calling me on id be glad to take a lesson if not then would you kindly back off

Link to comment
Share on other sites

@muddykat My previous link defines what indents are. Here's quite a long article on indentation. I don't think you need to read all of it, just skim through and check out the examples. It's not using Lua either, so keep that in mind.

 

For Lua, indentation will look something like this:

local function something()   -- Indented lines   -- Indented linesendif some_bool then   -- Indented lines   -- Indented linesendfor k, v in pairs(some_table) do   -- Indented lines   -- Indented linesend

And nested statements:

local function something()   -- Indented lines   if some_bool then -- Indented if-statement      -- Double indented lines      -- Double indented lines   end -- Indented end, same spacing as the corresponding if-statement above   -- Indented linesend
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...