Jump to content

Adding Light to hand-slot item (weapon)


Foxrai

Recommended Posts

I want to make shining hand item - weapon kind.

My base was lightbulb at first, and then "torch" but there came an little issue... I tried following codes:

local assets={    Asset("ANIM", "anim/orbstaff.zip"),    Asset("ANIM", "anim/swap_orbstaff.zip"),      Asset("ATLAS", "images/inventoryimages/orbstaff.xml"),    Asset("IMAGE", "images/inventoryimages/orbstaff.tex"),} local prefabs ={    "torchfire",}     local function fn()      local function OnEquip(inst, owner)        owner.AnimState:OverrideSymbol("swap_object", "swap_orbstaff", "swap_orbstaff")        owner.AnimState:Show("ARM_carry")        owner.AnimState:Hide("ARM_normal")                 inst.fire = SpawnPrefab( "torchfire" )        --inst.fire.Transform:SetScale(.125,.125,.125)        local follower = inst.fire.entity:AddFollower()        follower:FollowSymbol( owner.GUID, "swap_object", 0, -110, 1 )        end      local function OnUnequip(inst, owner)        inst.fire:Remove()        inst.fire = nil             owner.AnimState:Hide("ARM_carry")        owner.AnimState:Show("ARM_normal")    end         local inst = CreateEntity()    local trans = inst.entity:AddTransform()    local anim = inst.entity:AddAnimState()    local sound = inst.entity:AddSoundEmitter()    MakeInventoryPhysics(inst)          anim:SetBank("orbstaff")    anim:SetBuild("orbstaff")    anim:PlayAnimation("idle")         inst:AddComponent("inspectable")         inst:AddTag("sharp")     inst:AddComponent("weapon")    inst.components.weapon:SetDamage(48)         inst:AddComponent("characterspecific")    inst.components.characterspecific:SetOwner("wayrra")         inst:AddComponent("inventoryitem")    inst.components.inventoryitem.imagename = "orbstaff"    inst.components.inventoryitem.atlasname = "images/inventoryimages/orbstaff.xml"          inst:AddComponent("equippable")    inst.components.equippable:SetOnEquip( OnEquip )    inst.components.equippable:SetOnUnequip( OnUnequip )      return instendreturn  Prefab("common/inventory/orbstaff", fn, assets)

I also tried the lightbulb one but didn't work at all..

local light = inst.entity:AddLight()light:SetFalloff(0.7)light:SetIntensity(.5)light:SetRadius(1)light:SetColour(230/255, 230/255, 100/255)light:Enable(true)

After using torchfire the item does shine when Equipped and stops when not equipped but you know how the torch/willow lighter looks - it has FIRE ANIMATION (yellow sparks, flames thing following the torch stick)

 

Is there anyway to remove showing of flames and leaving only LIGHT?

 

I tried commenting out some lines but effects where like:

NO LIGHT AT ALL 

or

LIGHT + FLAMES visible -.-

 

Guess I'm lost :/

Link to comment
Share on other sites

Did you try removing all the following bits?

local prefabs ={    "torchfire",}
 inst.fire = SpawnPrefab( "torchfire" )        --inst.fire.Transform:SetScale(.125,.125,.125)        local follower = inst.fire.entity:AddFollower()        follower:FollowSymbol( owner.GUID, "swap_object", 0, -110, 1 )
        inst.fire:Remove()        inst.fire = nil
Link to comment
Share on other sites

I want to make shining hand item - weapon kind.

My base was lightbulb at first, and then "torch" but there came an little issue... I tried following codes:

local assets={    Asset("ANIM", "anim/orbstaff.zip"),    Asset("ANIM", "anim/swap_orbstaff.zip"),      Asset("ATLAS", "images/inventoryimages/orbstaff.xml"),    Asset("IMAGE", "images/inventoryimages/orbstaff.tex"),} local prefabs ={    "torchfire",}     local function fn()      local function OnEquip(inst, owner)        owner.AnimState:OverrideSymbol("swap_object", "swap_orbstaff", "swap_orbstaff")        owner.AnimState:Show("ARM_carry")        owner.AnimState:Hide("ARM_normal")                 inst.fire = SpawnPrefab( "torchfire" )        --inst.fire.Transform:SetScale(.125,.125,.125)        local follower = inst.fire.entity:AddFollower()        follower:FollowSymbol( owner.GUID, "swap_object", 0, -110, 1 )        end      local function OnUnequip(inst, owner)        inst.fire:Remove()        inst.fire = nil             owner.AnimState:Hide("ARM_carry")        owner.AnimState:Show("ARM_normal")    end         local inst = CreateEntity()    local trans = inst.entity:AddTransform()    local anim = inst.entity:AddAnimState()    local sound = inst.entity:AddSoundEmitter()    MakeInventoryPhysics(inst)          anim:SetBank("orbstaff")    anim:SetBuild("orbstaff")    anim:PlayAnimation("idle")         inst:AddComponent("inspectable")         inst:AddTag("sharp")     inst:AddComponent("weapon")    inst.components.weapon:SetDamage(48)         inst:AddComponent("characterspecific")    inst.components.characterspecific:SetOwner("wayrra")         inst:AddComponent("inventoryitem")    inst.components.inventoryitem.imagename = "orbstaff"    inst.components.inventoryitem.atlasname = "images/inventoryimages/orbstaff.xml"          inst:AddComponent("equippable")    inst.components.equippable:SetOnEquip( OnEquip )    inst.components.equippable:SetOnUnequip( OnUnequip )      return instendreturn  Prefab("common/inventory/orbstaff", fn, assets)

I also tried the lightbulb one but didn't work at all..

local light = inst.entity:AddLight()light:SetFalloff(0.7)light:SetIntensity(.5)light:SetRadius(1)light:SetColour(230/255, 230/255, 100/255)light:Enable(true)

After using torchfire the item does shine when Equipped and stops when not equipped but you know how the torch/willow lighter looks - it has FIRE ANIMATION (yellow sparks, flames thing following the torch stick)

 

Is there anyway to remove showing of flames and leaving only LIGHT?

 

I tried commenting out some lines but effects where like:

NO LIGHT AT ALL 

or

LIGHT + FLAMES visible -.-

 

Guess I'm lost :/

On an unrelated note, your missing the following code in your example.

 

inst.entity:AddNetwork()

if not TheWorld.ismastersim then

return inst

end

 

Don't forget to add that code if your making it for Don't Starve Together. :)

Link to comment
Share on other sites

 

I can't help you with the coding, but why not reference the lantern or morning star?  Both are equipped in the weapon slot and emit light.

 

related to weapon - let's say a spear for now. Shining spear. for now.

 

Did you try removing all the following bits?
 

 

Yes I did.. When I remove any of them It will just stop emitting the flames... but ALSO it stops giving any light aura.. I thought using lightbulbs code will be handy here but it doesn't work either... 

 

On an unrelated note, your missing the following code in your example.

 

Hehe ye thank you for pointing it out. YET it's Don't Starve + ROG version ;) 

 

Link to comment
Share on other sites

Yes I did.. When I remove any of them It will just stop emitting the flames... but ALSO it stops giving any light aura.. I thought using lightbulbs code will be handy here but it doesn't work either...

Sorry, I didn't realize the last snipped with the light code wasn't in your prefab. You obviously need to put something like that in your prefab, since the torchfire can't give light anymore. Follow this explaination.

Link to comment
Share on other sites

Use the Morning Star code and remove the durability and wetness modifier if that's what you are looking for.  It is a weapon that emits light. 

 

I ll check it out :) Didn't think of that.

 

Sorry, I didn't realize the last snipped with the light code wasn't in your prefab. You obviously need to put something like that in your prefab, since the torchfire can't give light anymore. Follow this explaination.

 

Reading what you linked here - nice piece of information! Least for modding-noobs like myself o.o

Thank you ^^ 

Link to comment
Share on other sites

Use the Morning Star code and remove the durability and wetness modifier if that's what you are looking for.  It is a weapon that emits light. 

 

what is the name for that? -.- I can't seem to find anything looking at least similar in DS lua files.. Guess it's inside of something like all staffs are in one file... looking for :p

Link to comment
Share on other sites

what is the name for that? -.- I can't seem to find anything looking at least similar in DS lua files.. "lantern" lua either. That's why I didn't use lantern... 

 

lantern file = mininglantern.lua (prefab itself is still called lantern though)

the morning star is called nightstick (I think, idk what that is, I'm a RoG noob), but it's a lot more complicated than just "making light".

Link to comment
Share on other sites

lantern file = mininglantern.lua (prefab itself is still called lantern though)

the morning star is called nightstick (I think, idk what that is, I'm a RoG noob), but it's a lot more complicated than just "making light".

 

ye i just realized. + I don't want any ROG specified code parts... It has to be compatible with DS, ROG and DST so... working on  "making" light :p

Link to comment
Share on other sites

local function OnEquip(inst, owner)    owner.AnimState:OverrideSymbol("swap_object", "swap_orbstaff", "swap_orbstaff")    owner.AnimState:Show("ARM_carry")    owner.AnimState:Hide("ARM_normal")end

Well this is how you declared OnEquip. Its a function. Line 89 sets the equip handler to your local OnEquip function. Line 90 'states' that it is setting the unequip handler to a local function named OnUnequip but you dont have that function in your code.

 

1. write the function to do what you want it to do

2. remove line 89 if you dont actually need any special handling

 

Whichever solution works for you, use.

 

Link to comment
Share on other sites

 

local function OnEquip(inst, owner)    owner.AnimState:OverrideSymbol("swap_object", "swap_orbstaff", "swap_orbstaff")    owner.AnimState:Show("ARM_carry")    owner.AnimState:Hide("ARM_normal")end

Well this is how you declared OnEquip. Its a function. Line 89 sets the equip handler to your local OnEquip function. Line 90 'states' that it is setting the unequip handler to a local function named OnUnequip but you dont have that function in your code.

 

1. write the function to do what you want it to do

2. remove line 89 if you dont actually need any special handling

 

Whichever solution works for you, use.

 

 

Ye i just noticed my own stupid error -.- Fixed  :-)

Link to comment
Share on other sites

, but it's a lot more complicated than just "making light".

 

Complicated or not.. Still it works and doesnt work at once.. why?

 

When Item is dropped on the ground - it shines! (lights on!)  well it has square shape but still its light...

When item is in hand - no light -.-

 

Is that some functions order or thing ? :/

local assets={    Asset("ANIM", "anim/orbstaff.zip"),    Asset("ANIM", "anim/swap_orbstaff.zip"),      Asset("ATLAS", "images/inventoryimages/orbstaff.xml"),    Asset("IMAGE", "images/inventoryimages/orbstaff.tex"),} local prefabs ={    "torchfire",	"ice_projectile",	"staffcastfx",}    --ICE Staff functionslocal function onattack_blue(inst, attacker, target)    if attacker and attacker.components.sanity then        attacker.components.sanity:DoDelta(-TUNING.SANITY_SUPERTINY)    end        if target.components.freezable then        target.components.freezable:AddColdness(1)        target.components.freezable:SpawnShatterFX()    end    if target.components.sleeper and target.components.sleeper:IsAsleep() then        target.components.sleeper:WakeUp()    end    if target.components.burnable and target.components.burnable:IsBurning() then        target.components.burnable:Extinguish()    end    if target.components.combat then        target.components.combat:SuggestTarget(attacker)        if target.sg and not target.sg:HasStateTag("frozen") and target.sg.sg.states.hit then            target.sg:GoToState("hit")        end    endend  --Bell Staff functions basics + shinelocal function OnEquip(inst, owner)    owner.AnimState:OverrideSymbol("swap_object", "swap_orbstaff", "swap_orbstaff")    owner.AnimState:Show("ARM_carry")    owner.AnimState:Hide("ARM_normal")end--light parameterslocal function fn(inst)    inst.Light:SetIntensity(0.4)    inst.Light:SetRadius(1)    inst.Light:SetFalloff(0.9)endlocal function OnUnequip(inst, owner)    owner.AnimState:Hide("ARM_carry")    owner.AnimState:Show("ARM_normal")end		local function fn(Sim)    local inst = CreateEntity()    local trans = inst.entity:AddTransform()    local anim = inst.entity:AddAnimState()    local sound = inst.entity:AddSoundEmitter()    MakeInventoryPhysics(inst)		--light	inst.entity:AddLight()	inst.Light:SetColour(180/255, 195/255, 150/255)          anim:SetBank("orbstaff")    anim:SetBuild("orbstaff")    anim:PlayAnimation("idle")         inst:AddComponent("inspectable")	   -- lines 66-72 - ice staff weapon based with increased range      inst:AddTag("icestaff")     inst:AddComponent("weapon")    inst.components.weapon:SetDamage(0)    inst.components.weapon:SetRange(7, 11)    inst.components.weapon:SetOnAttack(onattack_blue)    inst.components.weapon:SetProjectile("ice_projectile")         inst:AddComponent("characterspecific")    inst.components.characterspecific:SetOwner("wayrra")         inst:AddComponent("inventoryitem")    inst.components.inventoryitem.imagename = "orbstaff"    inst.components.inventoryitem.atlasname = "images/inventoryimages/orbstaff.xml"          inst:AddComponent("equippable")    inst.components.equippable:SetOnEquip( OnEquip )    inst.components.equippable:SetOnUnequip( OnUnequip )      return instendreturn  Prefab("common/inventory/orbstaff", fn, assets) 
Link to comment
Share on other sites

Complicated or not.. Still it works and doesnt work at once.. why?

 

When Item is dropped on the ground - it shines! (lights on!)  well it has square shape but still its light...

When item is in hand - no light -.-

 

Is that some functions order or thing ? :/

 

EDIT: de cod, de horor

 

Good morning!

 

The light when dropped is square because you never define anything about it. All those things are in the former "fn" which never gets called but gets overwritten by the latter. Try to move those lines (without the function) under the part adding light.

 

For when equipped, the base heat rock always glows, even in chests.

inst.Light:SetDisableOnSceneRemoval(false)

You could also try to enable light on equipping, or if nothing else works, add light to the player (I genuinely dissuade you from doing it like that, since the player also gets light from caves torchberries)

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