Page 1 of 1

meleeattack power change.

Posted: Tue Apr 07, 2015 6:32 pm
by Emera Nova
I'm attempting to see if I can edit an items attackpower in mid game, I'm guessing I need setAttackPower but I'm not sure what goes in front of it. Do I put in the items name somehwere in the script? and what does MeleeAttackComponent: mean as far as its trigger? I tried. Myitemsname.MeleeAttack:setAttackPower(32) and it says its attempting to index global 'myitemsname'

Re: meleeattack power change.

Posted: Wed Apr 08, 2015 5:36 am
by Eburt
Emera Nova wrote:Myitemsname.MeleeAttack:setAttackPower(32) and it says its attempting to index global 'myitemsname'
Under most circumstances, this should work just fine. The issue is that the script doesn't know what item you are referring to. Most common cause is probably that you forgot to define something as a local variable in the script. If you post the whole script I'm sure someone can help find the error.

As an aside, this thread was very helpful for me when I was starting to play around with more interesting weapon definitions.

Re: meleeattack power change.

Posted: Wed Apr 08, 2015 8:36 pm
by Emera Nova
The script I have in atm is

function increasepower()
if findEntity("dagger_1") ~= nil then
dagger_1.MeleeAttack:setAttackPower(32)
end
end

But now its just straight up breaking the game xD, so not sure why..

Re: meleeattack power change.

Posted: Thu Apr 09, 2015 6:48 pm
by Eburt
Try:

Code: Select all

function increasepower()
if findEntity("dagger_1") ~= nil then
dagger_1.meleeattack:setAttackPower(32)
end
end
This works for me. Using the correct capitalization is an easy thing to miss ("meleeattack" must all be lowercase when used like this).

Also, just note that this will not work if the party is holding the dagger, it is in a container, monster inventory, etc. This is because findEntity will return nil under those circumstances. There are several threads about how to deal with this if it's important to fix in your case.

Re: meleeattack power change.

Posted: Thu Apr 09, 2015 8:42 pm
by Emera Nova
That works just fine ^-^ As it is the party has to give up the weapon for a fight and gets it back at the end, so with this script I can boost its power slightly after the fight is over.