Jump to content

Recommended Posts

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

Durability < 50 then

reduce 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 damage

etc. etc.

----------------

Like i said, im not sure about this whole thing, but i'd like some suggestions

anyways, i REALLY need to sleep, ill be back on tommarow

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 do

inst.components.finiteuses.uses

But make sure that the variable is actually called 'uses' by taking a look into the component.

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 by Mr. Tiddles

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 is

inst: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 }end

or does getpercent get the actual percentage of durability? in which case it would be 66,66,33

Edited by Blazingice26

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 brokenitemtwo

My 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 by Blazingice26

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 by squeek

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 }end

and got an error saying there was something wrong with  inst.components.finiteuses.GetPercent < .33 then

40, looking at what you put above, i imagine thats (what i put) wrong :/

Edited by Blazingice26

I added

and got an error saying there was something wrong with  inst.components.finiteuses.GetPercent < .33 then

40, 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 }end
Blazingice26, 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 by squeek

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...