CrisChemical Posted January 17, 2023 Share Posted January 17, 2023 (edited) I've been trying to make an item for the mod that doesn't break when at 0% and i used this to try and make it happen Spoiler local function GetDamaged(self,damage_amount) if self.condition > damage_amount then inst.components.armor:SetCondition(self.condition - damage_amount) if self.ontakedamage ~= nil then self.ontakedamage(self.inst, damage_amount) end self.inst:PushEvent("armordamaged", damage_amount) else inst.components.armor:SetCondition(0) end end local function SetDurability(self,amount) if self.indestructible then return end self.condition = math.min(amount, self.maxcondition) self.inst:PushEvent("percentusedchange", { percent = inst.components.armor:GetPercent() }) if self.condition == 0 then self.absorb_percent = 0 else if self.oldabs then self.absorb_percent = self.oldabs else self.absorb_percent = 0.60 end end if self.inst.components.weapon and self.absorb_percent ~= 0 then inst.components.weapon:SetDamage(TUNING.HUNGERN_DAMAGE) elseif self.inst.components.weapon then inst.components.weapon:SetDamage(10) end end But the game crashes when i open a world, this is the error apparently: Spoiler [00:05:41]: [string "scripts/components/armor.lua"]:133: attempt to index local 'self' (a function value) LUA ERROR stack traceback: scripts/components/armor.lua:133 in (field) TakeDamage (Lua) <132-138> ../mods/Umbrella/scripts/prefabs/hungern.lua:151 in (field) fn (Lua) <82-157> scripts/mainfunctions.lua:336 in () ? (Lua) <325-371> =[C]:-1 in (method) SpawnPrefab (C) <-1--1> scripts/mainfunctions.lua:389 in (global) SpawnPrefab (Lua) <382-391> scripts/prefabs/player_common_extensions.lua:720 in (field) GivePlayerStartingItems (Lua) <714-741> scripts/prefabs/player_common.lua:1312 in (method) OnNewSpawn (Lua) <1311-1332> scripts/networking.lua:256 in () ? (Lua) <244-262> =[C]:-1 in (method) SendSpawnRequestToServer (C) <-1--1> scripts/mainfunctions.lua:1959 in (local) cb (Lua) <1938-1960> scripts/frontend.lua:635 in (method) DoFadingUpdate (Lua) <599-639> scripts/frontend.lua:703 in (method) Update (Lua) <657-854> scripts/update.lua:92 in () ? (Lua) <33-135> i don't know what happened and don't know how to fix it, i really need help, any ideas? Here's the whole item's script in case i forgot to add something in it to make it work Quote local Assets = { -- Animation files for the item (showing it on the ground and swap symbols for the players). Asset("ANIM", "anim/hungern.zip"), Asset("ANIM", "anim/hungern_ground.zip"), -- Inventory image and atlas file used for the item. Asset("ATLAS", "images/inventoryimages/hungern.xml"), Asset("IMAGE", "images/inventoryimages/hungern.tex"), } local function UpdateDamage(inst) if inst.components.armor and inst.components.weapon then local dmg = TUNING.HUNGERN_DAMAGE * inst.components.armor:GetPercent() dmg = Remap(dmg, 0, TUNING.HUNGERN_DAMAGE, .5*TUNING.HUNGERN_DAMAGE, TUNING.HUNGERN_DAMAGE) inst.components.weapon:SetDamage(dmg) end end -- Esta dando error, intenta cambiar los self por algun componente ya puesto local function GetDamaged(self,damage_amount) if self.condition > damage_amount then inst.components.armor:SetCondition(self.condition - damage_amount) if self.ontakedamage ~= nil then self.ontakedamage(self.inst, damage_amount) end self.inst:PushEvent("armordamaged", damage_amount) else inst.components.armor:SetCondition(0) end end local function SetDurability(self,amount) if self.indestructible then return end self.condition = math.min(amount, self.maxcondition) self.inst:PushEvent("percentusedchange", { percent = inst.components.armor:GetPercent() }) if self.condition == 0 then self.absorb_percent = 0 else if self.oldabs then self.absorb_percent = self.oldabs else self.absorb_percent = 0.60 end end if self.inst.components.weapon and self.absorb_percent ~= 0 then inst.components.weapon:SetDamage(TUNING.HUNGERN_DAMAGE) elseif self.inst.components.weapon then inst.components.weapon:SetDamage(10) end end local function OnEquip(inst, owner) -- This will override symbol "swap_body" of the equipping player with your custom build symbol. -- Here's what this function is overriding: -- owner.AnimState:OverrideSymbol(Player's_symbol, Your_build(*.zip_filename), Symbol_from_your_build(name_of_subfolder_with_art) owner.AnimState:OverrideSymbol("swap_object", "hungern", "swap_object") -- Players have 2 left arms - one of them is hidden when we are not holding an item and vice versa. -- Since we want to show an item on equip - hide ARM_normal and show ARM_carry. owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") owner:ListenForEvent("onattackother", inst._weaponused_callback) end local function OnUnequip(inst, owner) owner.AnimState:Hide("ARM_carry") owner.AnimState:Show("ARM_normal") end local function oneatfn(inst, food) local health = math.abs(food.components.edible:GetHealth(inst)) * inst.components.eater.healthabsorption local hunger = math.abs(food.components.edible:GetHunger(inst)) * inst.components.eater.hungerabsorption inst.components.armor:Repair(health + hunger) if not inst.inlimbo then inst.AnimState:PlayAnimation("eat") inst.AnimState:PushAnimation("idle", true) end end local function MainFunction() -- Functions which are performed both on Client and Server start here. local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() inst.entity:AddSoundEmitter() MakeInventoryPhysics(inst) -- Add minimap icon. Remember about its XML in modmain.lua! local minimap = inst.entity:AddMiniMapEntity() minimap:SetIcon("hungern.tex") --[[ ANIMSTATE ]]-- -- This is the name visible on the top of hierarchy in Spriter. inst.AnimState:SetBank("hungern_ground") -- This is the name of your compiled*.zip file. inst.AnimState:SetBuild("hungern_ground") -- This is the animation name while item is on the ground. inst.AnimState:PlayAnimation("anim") --[[ TAGS ]]-- inst:AddTag("hungern") inst:AddTag("handfed") inst:AddTag("fedbyall") inst:AddTag("eatsrawmeat") inst:AddTag("strongstomach") MakeInventoryFloatable(inst, "small", 0.05, {1.2, 0.75, 1.2}) inst.entity:SetPristine() if not TheWorld.ismastersim then -- If we're not the host - stop performing further functions. -- Only server functions below. return inst end inst._weaponused_callback = function(_, data) if data.weapon ~= nil and data.weapon == inst then inst.components.armor:TakeDamage(2) end end inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "hungern" inst.components.inventoryitem.atlasname = "images/inventoryimages/hungern.xml" inst:AddComponent("equippable") inst.components.equippable:SetOnEquip(OnEquip) inst.components.equippable:SetOnUnequip(OnUnequip) inst:AddComponent("eater") inst.components.eater:SetOnEatFn(oneatfn) inst.components.eater:SetAbsorptionModifiers(4.0, 1.75, 0) inst.components.eater:SetCanEatRawMeat(true) inst.components.eater:SetStrongStomach(true) inst.components.eater:SetCanEatHorrible(true) inst:AddComponent("weapon") inst.components.weapon:SetDamage(TUNING.HUNGERN_DAMAGE) inst.components.weapon:SetOnAttack(UpdateDamage) inst:AddComponent("armor") inst.components.armor:InitCondition(255, .6) inst.components.armor.TakeDamage(GetDamaged) inst.components.armor.SetCondition(SetDurability) MakeHauntableLaunch(inst) return inst end return Prefab("common/inventory/hungern", MainFunction, Assets) Edited January 17, 2023 by CrisChemical Link to comment https://forums.kleientertainment.com/forums/topic/145635-character-mod-crashes-while-attempting-to-index-a-local-self-value/ Share on other sites More sharing options...
Goregonzola Posted January 18, 2023 Share Posted January 18, 2023 Hey! I might be wrong on this, but I got to make my weapons unbreakable with a simple "finiteuses" component. This is how an unbreakable component looks in my script: inst:AddComponent("finiteuses") inst.components.finiteuses:SetMaxUses(TUNING.GRAFT_KNIGHT_USES) inst.components.finiteuses:SetUses(TUNING.GRAFT_KNIGHT_USES) and this is how a breakable looks like: inst:AddComponent("finiteuses") inst.components.finiteuses:SetMaxUses(TUNING.HAND_OF_WALENIA_MAX_USES) inst.components.finiteuses:SetUses(TUNING.HAND_OF_WALENIA_MAX_USES) inst.components.finiteuses:SetOnFinished(inst.Remove) -- This is the only difference I don't know if it clashes with something for you, I didn't read your whole weapon script, but it does the job with my items. I included the two scripts they're from. Hope this helps! Cheerio! hand_of_walenia.lua graft_knight.lua Link to comment https://forums.kleientertainment.com/forums/topic/145635-character-mod-crashes-while-attempting-to-index-a-local-self-value/#findComment-1618001 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