Jump to content

Recommended Posts

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 }end
Check components/combat.lua to see how variedmodefn is used (search for variedmodefn). Edited by squeek

I'd also like to know if there's anyway i can check for durability, like,

if durability > 50 then

Do something

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

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

local isranged = self.projectile ~= nil -- this could probably be done a better way

Edited by Blazingice26

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 way

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 ~= nil
Edited by squeek

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 ~= nil

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

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 something

Edited by Blazingice26

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 something

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 }end
Edited by squeek

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

Worked 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 :grin:

ill make sure to credit you when/if i upload the mod ^_^

Edited by Blazingice26

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

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

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

if ownersanity > 100 then

weapon.damage = 51 else

if ownersanity > 50 then

weapon.damage = 60 else

if ownersanity < 50 then

68

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

if ownersanity > 100 then

weapon.damage = 51 else

if ownersanity > 50 then

weapon.damage = 60 else

if ownersanity < 50 then

68

Simply replace these two lines accourding to how you wish it to be

local sanitydamage = ownersanity * 0.5local newdamage = weapon.damage + sanitydamage

For example

local sanitydamage = 0if ownersanity > .5 then    sanitydamage = 100endlocal newdamage = weapon.damage + sanitydamage

 

Simply replace these two lines accourding to how you wish it to be

local sanitydamage = ownersanity * 0.5local newdamage = weapon.damage + sanitydamage

For example

local sanitydamage = 0if ownersanity > .5 then    sanitydamage = 100endlocal newdamage = weapon.damage + sanitydamage

Thanks, 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?

 

Simply replace these two lines accourding to how you wish it to be

local sanitydamage = ownersanity * 0.5local newdamage = weapon.damage + sanitydamage

For example

local sanitydamage = 0if ownersanity > .5 then    sanitydamage = 100endlocal newdamage = weapon.damage + sanitydamage

Is the .5 the actual sanity value, or is it the percentage?

Is the .5 the actual sanity value, or is it the percentage?

Neither, it's a fraction of maxsanity  : P

It'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

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