meleeattack power change.
-
Emera Nova
- Posts: 146
- Joined: Wed Jun 11, 2014 1:31 am
meleeattack power change.
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.
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.Emera Nova wrote:Myitemsname.MeleeAttack:setAttackPower(32) and it says its attempting to index global 'myitemsname'
As an aside, this thread was very helpful for me when I was starting to play around with more interesting weapon definitions.
-
Emera Nova
- Posts: 146
- Joined: Wed Jun 11, 2014 1:31 am
Re: meleeattack power change.
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..
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.
Try:
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.
Code: Select all
function increasepower()
if findEntity("dagger_1") ~= nil then
dagger_1.meleeattack:setAttackPower(32)
end
end
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.
-
Emera Nova
- Posts: 146
- Joined: Wed Jun 11, 2014 1:31 am
Re: meleeattack power change.
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.