Rosten Posted November 24, 2013 Share Posted November 24, 2013 So, what i'd like to know is, is there anyway to check for a players sanity, and then change the damage of a certain weapon according to however much sanity the player has left Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/ Share on other sites More sharing options...
Rosten Posted November 24, 2013 Author Share Posted November 24, 2013 (edited) Woahh... Triple post, How the heck did that happen!? O-oCould a mod like, delete 2 of these posts?Also, please make this one the one that stays up Edited November 24, 2013 by Blazingice26 Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-376904 Share on other sites More sharing options...
Rosten Posted November 24, 2013 Author Share Posted November 24, 2013 Something along the lines of (not code, just what i want it to do)D = S(.5) + 30D = DamageS = Sanity Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-376919 Share on other sites More sharing options...
Rosten Posted November 24, 2013 Author Share Posted November 24, 2013 Either no-one has any idea how to do this, or everyone's asleep.Probably the latter T_T Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-376922 Share on other sites More sharing options...
Rosten Posted November 24, 2013 Author Share Posted November 24, 2013 I'd also like to know if there's anyway i can check for durability, like,if durability > 50 thenDo something Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-376923 Share on other sites More sharing options...
squeek Posted November 24, 2013 Share Posted November 24, 2013 (edited) This is one possible method (untested code):In the weapon prefab's fn:-- this is the base damageinst.components.weapon.damage = 30-- variedmodefn is a special function that needs to return a table with the following structure: {damage = num, ranged = true/false, attackrange = num, hitrange = num}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 ownersanity = owner.components.sanity and owner.components.sanity.current or 0 local sanitydamage = ownersanity * 0.5 local newdamage = weapon.damage + sanitydamage local isranged = weapon.projectile ~= nil -- this could probably be done a better way return { damage=newdamage, ranged=isranged, attackrange=self.attackrange, hitrange=self.hitrange }endCheck components/combat.lua to see how variedmodefn is used (search for variedmodefn). Edited November 24, 2013 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-376924 Share on other sites More sharing options...
squeek Posted November 24, 2013 Share Posted November 24, 2013 (edited) I'd also like to know if there's anyway i can check for durability, like,if durability > 50 thenDo somethingThat depends on what you want to do. But to simply check for durability: -- inst is the weapon prefablocal durability = inst.components.finiteuses:GetPercent()if durability > 0.5 then -- do somethingend Edited November 24, 2013 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-376925 Share on other sites More sharing options...
Rosten Posted November 24, 2013 Author Share Posted November 24, 2013 (edited) This is one possible method (untested code):In the weapon prefab's fn:-- this is the base damageinst.components.weapon.damage = 30-- variedmodefn is a special function that needs to return a table with the following structure: {damage = num, ranged = true/false, attackrange = num, hitrange = num}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 ownersanity = owner.components.sanity and owner.components.sanity.current or 0 local sanitydamage = ownersanity * 0.5 local newdamage = weapon.damage + sanitydamage local isranged = self.projectile ~= nil -- this could probably be done a better way return { damage=newdamage, ranged=isranged, attackrange=self.attackrange, hitrange=self.hitrange }endCheck components/combat.lua to see how variedmodefn is used (search for variedmodefn). Whenever i put this code in, i get an error about "variable self is not defined" which i assume means, either A i should have replaced self with a number, or B the game doesn't like you using self as a varible, looking a bit more specifically, it says this line is whats causing the problemlocal isranged = self.projectile ~= nil -- this could probably be done a better way Edited November 24, 2013 by Blazingice26 Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-376927 Share on other sites More sharing options...
squeek Posted November 24, 2013 Share Posted November 24, 2013 (edited) Whenever i put this code in, i get an error about "variable self is not defined" which i assume means, either A i should have replaced self with a number, or B the game doesn't like you using self as a varible, looking a bit more specifically, it says this line is whats causing the problem local isranged = self.projectile ~= nil -- this could probably be done a better wayIt's actually C: the variable 'self' is not defined (sometimes the errors mean exactly what they say). Copy + paste is my eternal enemy. That line should be: local isranged = weapon.projectile ~= nil Edited November 24, 2013 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-376929 Share on other sites More sharing options...
Rosten Posted November 24, 2013 Author Share Posted November 24, 2013 (edited) It's actually C: the variable 'self' is not defined (sometimes the errors mean exactly what they say). Copy + paste is my eternal enemy.That line should be:local isranged = weapon.projectile ~= nilUsing this knowledge, i replace all the "self"s to "weapon"s so it looks like - 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 ownersanity = owner.components.sanity and owner.components.sanity.current or 0 local sanitydamage = ownersanity * 0.5 local newdamage = weapon.damage + sanitydamage local isranged = weapon.projectile ~= nil return { damage=newdamage, ranged=isranged, attackrange=weapon.attackrange, hitrange=weapon.hitrange }endSo, that issue seems to be sorted, now im getting a error from combat.lua saying :data/scripts/components/combat.lua(601,1) in function 'GetAttackRange'data/scripts/components/combat.lua(611,1) in function 'CalcAttackRangeSq'data/scripts/behaviours/chaseandattack.lua(79,1) in functiion 'Visit'data/scripts/behaviourtree.lua(623,1) in function 'Visit'data/scripts/behaviourtree.lua(558,1) in function 'Visit'data/scripts/behaviourtree.lua(22,1) in function 'Update'data/scripts/brain.lua(212,1) in function 'OnUpdate'data/scripts/brain.lua(135,1) in function 'Update' Edit - Both of these errors only occured when i tryed to attack something Edited November 24, 2013 by Blazingice26 Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-376931 Share on other sites More sharing options...
squeek Posted November 24, 2013 Share Posted November 24, 2013 (edited) So, that issue seems to be sorted, now im getting a error from combat.lua saying :data/scripts/components/combat.lua(601,1) in function 'GetAttackRange'data/scripts/components/combat.lua(611,1) in function 'CalcAttackRangeSq'data/scripts/behaviours/chaseandattack.lua(79,1) in functiion 'Visit'data/scripts/behaviourtree.lua(623,1) in function 'Visit'data/scripts/behaviourtree.lua(558,1) in function 'Visit'data/scripts/behaviourtree.lua(22,1) in function 'Update'data/scripts/brain.lua(212,1) in function 'OnUpdate'data/scripts/brain.lua(135,1) in function 'Update' Edit - Both of these errors only occured when i tryed to attack somethingYou seem to have left out the actual error part of the log (most likely the line right above the stuff you posted). But, it looks like the combat component doesn't do the same nil checks for the result of variedmodefn that it does normally.Try this: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 ownersanity = owner.components.sanity and owner.components.sanity.current or 0 local sanitydamage = ownersanity * 0.5 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 Edited November 24, 2013 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-376938 Share on other sites More sharing options...
Rosten Posted November 24, 2013 Author Share Posted November 24, 2013 (edited) You seem to have left out the actual error part of the log (most likely the line right above the stuff you posted). But, it looks like the combat component doesn't do the same nil checks for the result of variedmodefn that it does normally.Try this: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 ownersanity = owner.components.sanity and owner.components.sanity.current or 0 local sanitydamage = ownersanity * 0.5 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 }endWorked like a charm!... atleast i assume, considering it's taking considerably less hits to murder beefalo with this weapon.now I just have to fine-tune the variables and some other things!thanks for the help ill make sure to credit you when/if i upload the mod ^_^ Edited November 24, 2013 by Blazingice26 Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-376941 Share on other sites More sharing options...
Malacath Posted November 24, 2013 Share Posted November 24, 2013 (edited) I'm actually confused because I thought that the argument passed to the variedmodefn is the weapon-entity (called weapon_prefab here) which you do not even use in the end. Instead you're using inst which doesn't seem to be definde from the code I can see. EDIT: Nevermind, of course it's defined... I was just confused by the argument you passed and never used. Sorry... disregard this post ^^ Edited November 24, 2013 by Malacath Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-376943 Share on other sites More sharing options...
squeek Posted November 24, 2013 Share Posted November 24, 2013 (edited) I'm actually confused because I thought that the argument passed to the variedmodefn is the weapon-entity (called weapon_prefab here) which you do not even use in the end. Instead you're using inst which doesn't seem to be definde from the code I can see. EDIT: Nevermind, of cours it's defined... I was just confused by the argument you passed and never used. Sorry... disregard this post ^^Yeah, I included the parameter as an attempt to make it clear what the parameter would be if it needed to be used (for example, if the callback function was defined as a named local function instead of an anonymous function). The prefab being a weapon and the prefab having a weapon component has the potential to make things a bit weird/ambiguous. Edited November 24, 2013 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-376945 Share on other sites More sharing options...
Rosten Posted November 24, 2013 Author Share Posted November 24, 2013 Would i also be able to modify this a little bit for it to change weapon damage from sanity by static numbers? (for the shadowspike, the first bit was for the dreamy sword) e.gif ownersanity > 100 thenweapon.damage = 51 elseif ownersanity > 50 thenweapon.damage = 60 elseif ownersanity < 50 then68 Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-376952 Share on other sites More sharing options...
Malacath Posted November 24, 2013 Share Posted November 24, 2013 Would i also be able to modify this a little bit for it to change weapon damage from sanity by static numbers? (for the shadowspike, the first bit was for the dreamy sword) e.gif ownersanity > 100 thenweapon.damage = 51 elseif ownersanity > 50 thenweapon.damage = 60 elseif ownersanity < 50 then68Simply replace these two lines accourding to how you wish it to belocal sanitydamage = ownersanity * 0.5local newdamage = weapon.damage + sanitydamageFor examplelocal sanitydamage = 0if ownersanity > .5 then sanitydamage = 100endlocal newdamage = weapon.damage + sanitydamage Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-376971 Share on other sites More sharing options...
Rosten Posted November 24, 2013 Author Share Posted November 24, 2013 Simply replace these two lines accourding to how you wish it to belocal sanitydamage = ownersanity * 0.5local newdamage = weapon.damage + sanitydamageFor examplelocal sanitydamage = 0if ownersanity > .5 then sanitydamage = 100endlocal newdamage = weapon.damage + sanitydamageThanks, i'll make sure to put that into use while making the mod, funny how just changing 1 or 2 lines you can turn an item into the polar opposite of what it was eh? Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-376976 Share on other sites More sharing options...
Rosten Posted November 24, 2013 Author Share Posted November 24, 2013 Im gonna start working on this mod Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-377173 Share on other sites More sharing options...
Rosten Posted November 24, 2013 Author Share Posted November 24, 2013 Simply replace these two lines accourding to how you wish it to belocal sanitydamage = ownersanity * 0.5local newdamage = weapon.damage + sanitydamageFor examplelocal sanitydamage = 0if ownersanity > .5 then sanitydamage = 100endlocal newdamage = weapon.damage + sanitydamageIs the .5 the actual sanity value, or is it the percentage? Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-377304 Share on other sites More sharing options...
Malacath Posted November 24, 2013 Share Posted November 24, 2013 Is the .5 the actual sanity value, or is it the percentage?Neither, it's a fraction of maxsanity : P Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-377307 Share on other sites More sharing options...
squeek Posted November 24, 2013 Share Posted November 24, 2013 Is the .5 the actual sanity value, or is it the percentage?Neither, it's a fraction of maxsanity : PIt's actually the current sanity value. To get the percentage (current / max), use:local ownersanitypercent = owner.components.sanity and owner.components.sanity:GetPercent() or 0 Link to comment https://forums.kleientertainment.com/forums/topic/29948-changing-damage-by-sanity/#findComment-377354 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