DevilXD Posted April 1, 2014 Share Posted April 1, 2014 (edited) I have a small question... I'm making a mod with magical sword, which has the "finiteuses" component, but it will be unbreakable... Normally, after finiteuses reaching 0, tool breaks... But my sword has this function:local function Discharge(inst) inst.IsCharged = false inst:RemoveComponent("finiteuses") inst.components.weapon:SetDamage(30) --inst:PushEvent("imagechange") endEverything works great, but removing "finiteuses" doesn't update "itemtile" widget, and leaves big "0%" on the sword image... Moving it to another slot causes "0%" to disappear, so it's iamge updating problem... I tried to solve this, by adding to "finiteuses" this function:local function FiniteUsesComponentPostInit(inst) function inst:OnRemoveFromEntity() --local itemtile = resolvefilepath("scripts/widgets/itemtile") local itemtile = require("widgets/itemtile") itemtile:PushEvent("imagechange") endendAddComponentPostInit("finiteuses", FiniteUsesComponentPostInit)...but the game crashes... Can someone help me? Edited April 1, 2014 by DevilXD Link to comment https://forums.kleientertainment.com/forums/topic/33846-widget-event/ Share on other sites More sharing options...
_Q_ Posted April 1, 2014 Share Posted April 1, 2014 Weapon is removed in on onfinished finction in your prefab file.You can just put discharged sword in the player invenotry after charges reach 0%you could search in other files it may be possible to equip that discharged sword rigth away. local item = SpawnPrefab("discharged sword") player.components.inventory:GiveItem(item) Link to comment https://forums.kleientertainment.com/forums/topic/33846-widget-event/#findComment-441513 Share on other sites More sharing options...
DevilXD Posted April 1, 2014 Author Share Posted April 1, 2014 I replaced:local function onfinished(inst) inst:Remove()endon:local function Discharge(inst) inst.IsCharged = false inst:RemoveComponent("finiteuses") inst.components.weapon:SetDamage(50) --inst:PushEvent("imagechange") end...and only issue is that sword image in inventory bar, which has a big "0%" leaved by removed "finiteuses" component...I just need a way to update image in the inventory... I tried to do this by pushing an "imagechange" event in "scripts/widgets/itemtile"...Maybe I am doing it the wrong way... How can I do this? Link to comment https://forums.kleientertainment.com/forums/topic/33846-widget-event/#findComment-441552 Share on other sites More sharing options...
_Q_ Posted April 1, 2014 Share Posted April 1, 2014 post the whole thing here I will fix it Link to comment https://forums.kleientertainment.com/forums/topic/33846-widget-event/#findComment-441573 Share on other sites More sharing options...
DevilXD Posted April 1, 2014 Author Share Posted April 1, 2014 (edited) Sword:local assets={ --Asset("SOUND", "sound/common.fsb"), Asset("ANIM", "anim/lightningsword.zip"), Asset("ANIM", "anim/swap_lightningsword.zip"), Asset("IMAGE", "images/lightningsword.tex"), Asset("ATLAS", "images/lightningsword.xml"), }--local function onfinished(inst)-- inst:Remove()--endlocal ShouldAdd = nillocal function Discharge(inst) --TO DO: Discharged Graphic inst.IsCharged = false inst:RemoveComponent("finiteuses") inst.Uses = nil inst.components.weapon:SetDamage(50) ShouldAdd = nil --inst.components.inventoryitem:ChangeImageName() --inst:PushEvent("imagechange") -- here should be image update fix endlocal function Calc(inst) if inst.IsCharged and not inst.components.finiteuses then inst:AddComponent("finiteuses") inst.components.finiteuses:SetMaxUses(1000) inst.components.finiteuses:SetUses(100) inst.components.finiteuses:SetOnFinished( Discharge ) if inst.Uses then inst.components.finiteuses:SetUses( inst.Uses ) end print("Initial charge") inst.components.weapon:SetDamage(100) if inst.Uses and inst.components.finiteuses then inst.Uses = inst.components.finiteuses:GetUses() end ShouldAdd = nil elseif inst.IsCharged and inst.components.finiteuses and ShouldAdd then if inst.components.finiteuses:GetUses() <= 900 then inst.components.finiteuses:Use(-100) else local uses = 1000 - inst.components.finiteuses:GetUses() inst.components.finiteuses:Use(-uses) end inst.Uses = inst.components.finiteuses:GetUses() ShouldAdd = nil print("Adnotial charge") inst.components.weapon:SetDamage(100) if inst.components.finiteuses:GetPercent() >= 1 then --inst.IsSuperCharged = true print("Super charge !") --TO DO: Super charged state end end --if inst.components.finiteuses then inst.components.finiteuses:SetOnFinished( Discharge ) end endlocal function Charge(inst) local pos = inst:GetPosition() --local light = SpawnPrefab("staffcastfx") --light.Transform:SetPosition(pos.x, pos.y, pos.z) local player = GetPlayer() inst.fxcolour = {223/255, 208/255, 69/255} if player then player.sg:GoToState("castspell") end inst.IsCharged = true --[[if not inst.components.finiteuses then inst.IsCharged = true inst:AddComponent("finiteuses") inst.components.finiteuses:SetMaxUses(1000) inst.components.finiteuses:SetUses(200) inst.components.finiteuses:SetOnFinished( Discharge ) print("Initial charge") inst.Uses = inst.components.finiteuses:GetUses() end]]-- --TO DO: Charged Graphic ShouldAdd = true Calc(inst) endlocal function OnSave(inst, data) if inst.components.finiteuses then data.Uses = inst.components.finiteuses:GetUses() end data.IsCharged = inst.IsCharged --data.IsSuperCharged = inst.IsSuperCharged return dataendlocal function OnLoad(inst, data) if data then if data.Uses then inst.Uses = data.Uses else inst.Uses = nil end inst.IsCharged = data.IsCharged --inst.IsSuperCharged = data.IsSuperCharged end Calc(inst) endlocal function onequip(inst, owner) owner.AnimState:OverrideSymbol("swap_object", "swap_lightningsword", "swap_nightmaresword") owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") endlocal function onunequip(inst, owner) owner.AnimState:Hide("ARM_carry") owner.AnimState:Show("ARM_normal") endlocal function fn(Sim) local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() local sound = inst.entity:AddSoundEmitter() MakeInventoryPhysics(inst) inst.AnimState:SetBank("nightmaresword") inst.AnimState:SetBuild("lightningsword") inst.AnimState:PlayAnimation("idle") --inst.AnimState:SetMultColour(1, 1, 1, 0.6) inst:AddTag("sharp") inst:AddComponent("weapon") --inst.components.weapon:SetOnAttack( OnAttack ) inst.components.weapon:SetDamage(50) inst.Uses = nil inst.IsCharged = false --inst.IsSuperCharged = false --inst:AddComponent("finiteuses") --inst.components.finiteuses:SetMaxUses(1000) --inst.components.finiteuses:SetUses(0) --inst.components.finiteuses:SetOnFinished( Discharge ) Calc(inst) inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "lightningsword" inst.components.inventoryitem.atlasname = "images/lightningsword.xml" --inst.components.inventoryitem:GetImage() --inst.components.inventoryitem:GetAtlas() inst:AddComponent("equippable") inst.components.equippable:SetOnEquip( onequip ) inst.components.equippable:SetOnUnequip( onunequip ) inst:ListenForEvent("lightningstrike", Charge) -- event pushed from modified seasonmanager component inst.OnSave = OnSave inst.OnLoad = OnLoad return instendreturn Prefab( "common/inventory/lightningsword", fn, assets) It should not be nessesary, beacause better is to add OnRemoveFromEntity() function to "finiteuses" component, that updates image after removing it, right ? By the way, is there any possible way to access a widget file from prefab ? Edited April 1, 2014 by DevilXD Link to comment https://forums.kleientertainment.com/forums/topic/33846-widget-event/#findComment-441623 Share on other sites More sharing options...
_Q_ Posted April 1, 2014 Share Posted April 1, 2014 I was thinking about making 2 prefab files:-normal discharged sword (this one is eternnal so no finite uses component)-charged sword with finiteuses component and just changing the prefab on ligtning strike to charged swordafter all charges run out just give the player discharged sword again will try to code that on something Link to comment https://forums.kleientertainment.com/forums/topic/33846-widget-event/#findComment-441641 Share on other sites More sharing options...
DevilXD Posted April 2, 2014 Author Share Posted April 2, 2014 Ahh, I see... So simply I should split it in 2 prefab files, one with discharged and one with normal state... That solves my future problem with making "Super charged" state - simply add third prefab file... Am I right? Link to comment https://forums.kleientertainment.com/forums/topic/33846-widget-event/#findComment-442062 Share on other sites More sharing options...
_Q_ Posted April 2, 2014 Share Posted April 2, 2014 Ahh, I see... So simply I should split it in 2 prefab files, one with discharged and one with normal state... That solves my future problem with making "Super charged" state - simply add third prefab file... Am I right?Maybe there is a way of updating that image, but I can't find it, tried few times with different things and nothing worked, so making them 2 prefabs is the only idea I have atm, but it can cause some problems.Maybe someone else will know how to update that image after component is gone. Link to comment https://forums.kleientertainment.com/forums/topic/33846-widget-event/#findComment-442071 Share on other sites More sharing options...
DevilXD Posted April 2, 2014 Author Share Posted April 2, 2014 There is a way to change image of the item in inventory, ex. chester eye bone (two images, with open and closed eye...) It's something like: inst.components.inventoryitem:ChangeImageName("path/to/file") You can see, i was trying to use it (look in Discharge), but it didn't work...But it only changes/refreshes an image, not a "child" tile on that image, in my case - "0%"... Link to comment https://forums.kleientertainment.com/forums/topic/33846-widget-event/#findComment-442095 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now