Rosten Posted December 11, 2013 Share Posted December 11, 2013 So, the title pretty much explains it all, i'd like to be able to check a weapons durability, then change a stat/somethingelse depending on that durability,e.gDurability < 50 thenreduce damage--------------------Not entirely sure how this kind of thing works, and if this is even the right way to do it, i assume it would be something like ------------------elseif inst.components.finiteuses:Uses < 66 thenreduce damageelseif inst.components.finiteuses:Uses < 33 thenreduce damageetc. etc.----------------Like i said, im not sure about this whole thing, but i'd like some suggestionsanyways, i REALLY need to sleep, ill be back on tommarow Link to comment https://forums.kleientertainment.com/forums/topic/30330-how-to-check-for-then-do-something-based-on-durability/ Share on other sites More sharing options...
Malacath Posted December 11, 2013 Share Posted December 11, 2013 Just don't use the ':' when checking for values. You only do that when calling a function with the first parameter being implicit 'self' Instead doinst.components.finiteuses.usesBut make sure that the variable is actually called 'uses' by taking a look into the component. Link to comment https://forums.kleientertainment.com/forums/topic/30330-how-to-check-for-then-do-something-based-on-durability/#findComment-387678 Share on other sites More sharing options...
NikMik Posted December 11, 2013 Share Posted December 11, 2013 (edited) Finiteuses uses "GetPercent" not "uses", I think. I looked in the component file and found "GetPercent". Try that? There was a spoon on my keyboard. I don't know why... Edited December 11, 2013 by Mr. Tiddles Link to comment https://forums.kleientertainment.com/forums/topic/30330-how-to-check-for-then-do-something-based-on-durability/#findComment-387687 Share on other sites More sharing options...
Rosten Posted December 11, 2013 Author Share Posted December 11, 2013 (edited) Well, using this and the code malacath gave me for my sleeping swords mod (which i need to finish anyways) since i figured it wouldn't be as easy as calling inst.components.weapon:SetDamage(0) and changing the 0, is it?, knowing my luck, it probably is :/, anyways here it isinst:AddComponent("weapon") inst.components.weapon:SetDamage(0) inst:AddComponent("finiteuses") inst.components.finiteuses:SetMaxUses(140) inst.components.finiteuses:SetUses(140) inst.components.weapon.damage = 0 inst.components.weapon.variedmodefn = function( weapon_prefab ) local weapon = inst.components.weapon local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or GetPlayer() local sanitydamage = elseif inst.components.finiteuses:GetPercent > 80 then30elseif inst.components.finiteuses:GetPercent < 80 then20elseif inst.components.finiteuses:GetPercent < 40 then10 local newdamage = weapon.damage + sanitydamage local isranged = weapon.projectile ~= nil local attackrange = weapon.attackrange or 0 local hitrange = weapon.hitrange or 0 return { damage=newdamage, ranged=isranged, attackrange=attackrange, hitrange=hitrange }endor does getpercent get the actual percentage of durability? in which case it would be 66,66,33 Edited December 11, 2013 by Blazingice26 Link to comment https://forums.kleientertainment.com/forums/topic/30330-how-to-check-for-then-do-something-based-on-durability/#findComment-387713 Share on other sites More sharing options...
NikMik Posted December 11, 2013 Share Posted December 11, 2013 Not sure.. Link to comment https://forums.kleientertainment.com/forums/topic/30330-how-to-check-for-then-do-something-based-on-durability/#findComment-387714 Share on other sites More sharing options...
Malacath Posted December 11, 2013 Share Posted December 11, 2013 Quite sure GetPercent functions consistently return fractions. So 0.f should be fine. Link to comment https://forums.kleientertainment.com/forums/topic/30330-how-to-check-for-then-do-something-based-on-durability/#findComment-387717 Share on other sites More sharing options...
Rosten Posted December 11, 2013 Author Share Posted December 11, 2013 (edited) Alright, now that this is presumably solved (i'll test the code in a minute) how would you use this to change what the swap, ground. and inventory imagelooks like? would it be something like elseif inst.components.finiteuses.GetPercent > 80 thennilelseif inst.components.finiteuses.GetPercent < 80 thenChange swap, ground, and inventory image to... say brokenitemoneelseif inst.components.finiteuses.GetPercent < 40 thenChange swap, ground, and inventory image to... say brokenitemtwoMy problem is, i don't know how to change the swap, ground and inventory image, and i don't know where i would put this bit of code Edited December 11, 2013 by Blazingice26 Link to comment https://forums.kleientertainment.com/forums/topic/30330-how-to-check-for-then-do-something-based-on-durability/#findComment-387863 Share on other sites More sharing options...
squeek Posted December 11, 2013 Share Posted December 11, 2013 (edited) In your item's fn:inst:ListenForEvent( "percentusedchange", function( inst, data ) if data.percent < 0.40 then inst.components.inventoryitem.atlasname = "images/inventoryitems/brokenitemtwo.xml" inst.AnimState:SetBank( "brokenitemtwo" ) inst.AnimState:SetBuild( "brokenitemtwo" ) -- unsure if this is how changing the swap should be done inst.components.inventoryitem.owner.AnimState:OverrideSymbol("swap_object", "swap_brokenitemtwo", "swap_brokenitemtwo") elseif data.percent < 0.80 then inst.components.inventoryitem.atlasname = "images/inventoryitems/brokenitemone.xml" inst.AnimState:SetBank( "brokenitemone" ) inst.AnimState:SetBuild( "brokenitemone" ) -- unsure if this is how changing the swap should be done inst.components.inventoryitem.owner.AnimState:OverrideSymbol("swap_object", "swap_brokenitemone", "swap_brokenitemone") endend ) Edited December 11, 2013 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/30330-how-to-check-for-then-do-something-based-on-durability/#findComment-387932 Share on other sites More sharing options...
Rosten Posted December 12, 2013 Author Share Posted December 12, 2013 (edited) I added inst.components.weapon.variedmodefn = function( weapon_prefab )local weapon = inst.components.weaponlocal owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or GetPlayer()local sanitydamage = elseif inst.components.finiteuses.GetPercent > .66 then120elseif inst.components.finiteuses.GetPercent < .66 then80elseif inst.components.finiteuses.GetPercent < .33 then40 local newdamage = weapon.damage + sanitydamage local isranged = weapon.projectile ~= nil local attackrange = weapon.attackrange or 0 local hitrange = weapon.hitrange or 0 return { damage=newdamage, ranged=isranged, attackrange=attackrange, hitrange=hitrange }endand got an error saying there was something wrong with inst.components.finiteuses.GetPercent < .33 then40, looking at what you put above, i imagine thats (what i put) wrong :/ Edited December 12, 2013 by Blazingice26 Link to comment https://forums.kleientertainment.com/forums/topic/30330-how-to-check-for-then-do-something-based-on-durability/#findComment-388036 Share on other sites More sharing options...
Malacath Posted December 12, 2013 Share Posted December 12, 2013 Again realted to what I said earlier. GetPercent is a function and you'll need to call it with implicit self so you have to do finiteuses:GetPercent() Link to comment https://forums.kleientertainment.com/forums/topic/30330-how-to-check-for-then-do-something-based-on-durability/#findComment-388151 Share on other sites More sharing options...
squeek Posted December 12, 2013 Share Posted December 12, 2013 (edited) I addedand got an error saying there was something wrong with inst.components.finiteuses.GetPercent < .33 then40, looking at what you put above, i imagine thats (what i put) wrong :/Fixed code: inst.components.weapon.variedmodefn = function( weapon_prefab ) local weapon = inst.components.weapon local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner or GetPlayer() -- 120 damage by default local sanitydamage = 120 if inst.components.finiteuses:GetPercent() < .33 then sanitydamage = 80 elseif inst.components.finiteuses:GetPercent() < .66 then sanitydamage = 40 end local newdamage = weapon.damage + sanitydamage local isranged = weapon.projectile ~= nil local attackrange = weapon.attackrange or 0 local hitrange = weapon.hitrange or 0 return { damage=newdamage, ranged=isranged, attackrange=attackrange, hitrange=hitrange }endBlazingice26, you should try to learn some fundamentals of programming (try this perhaps?). Learning the difference between functions and variables, how to set variables, how to call functions, how to define functions, how if statements work, etc will really help you out. Even just proper indentation would go a long way.Note: The if statements have to be in the order I put them in because .33 is below .66. If .66 was first, the if check would always succeed when GetPercent < .33 and the code would never actually get to the .33 check Edited December 12, 2013 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/30330-how-to-check-for-then-do-something-based-on-durability/#findComment-388155 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