meleeattack power change.

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

meleeattack power change.

Post 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'
Eburt
Posts: 69
Joined: Thu Feb 05, 2015 5:44 am

Re: meleeattack power change.

Post 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.
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: meleeattack power change.

Post 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..
Eburt
Posts: 69
Joined: Thu Feb 05, 2015 5:44 am

Re: meleeattack power change.

Post 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.
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: meleeattack power change.

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