forgottenserver icon indicating copy to clipboard operation
forgottenserver copied to clipboard

Repair "player:getInstantSpells()" to get "userdata spell" instead "comum table"

Open alysonjacomin opened this issue 2 months ago • 3 comments

Pull Request Prelude

  • [x] I have followed [proper The Forgotten Server code styling][code].
  • [x] I have read and understood the [contribution guidelines][cont] before making this PR.
  • [x] I am aware that this PR may be closed if the above-mentioned criteria are not fulfilled.

Changes Proposed

Rework LUA function "player:getInstantSpells()"

alysonjacomin avatar Oct 24 '25 15:10 alysonjacomin

Now it only remains for you to fix this in this same PR. https://github.com/otland/forgottenserver/blob/master/data/scripts/actions/others/spellbook.lua

Since we no longer have the fields available in a table, we must use the methods of the Spell metatable.

Or, if you prefer, you can add a custom __index metamethod to the metatable to simulate access to these fields. This would make it feel more retrocompatible with possible scripts that use these fields.

However, you must take into account that the spellbook.lua script also makes use of the __newindex metamethod, but userdata cannot have fields associated directly.

My complete recommendation would be to have an __index metamethod for retrocompatibility and also update the spellbook.lua script.

MillhioreBT avatar Oct 24 '25 16:10 MillhioreBT

Now it only remains for you to fix this in this same PR. https://github.com/otland/forgottenserver/blob/master/data/scripts/actions/others/spellbook.lua

I didn't understand what you meant by this PR ^

I added the compatibility function and reworked spellbook.lua

alysonjacomin avatar Oct 28 '25 01:10 alysonjacomin

@MillhioreBT Is there still something missing to change in the code?

alysonjacomin avatar Nov 14 '25 05:11 alysonjacomin