• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Spell Scroll Script (error) [OTX3] *solved*

X X X

Newb
Joined
Jul 26, 2015
Messages
146
Reaction score
13
Hey,

So what I'm going for is pretty simple, I want spells to be learned from using a scroll. I've searched around and obviously there are lots of different tutorials for this, but none are seeming to work with my distribution.

For something simple like "exura," I used the script from this thread https://otland.net/threads/use-scroll-learn-spell.71707/#post735701. Yes, I updated my actions.xml, made sure to change 'needlearn="1"' in spells.xml,

but I'm still getting the following error in my server console window:

Lua Script Error: [Action Interface]
data/actions/scripts/other/scroll.lua: onUse
data/actions/scripts/other/scroll.lua:4: attempt to call global 'doPlayerLearnInstantSpell' (a nil value)
stack traceback:
[C]: in function 'doPlayerLearnInstantSpell'
data/action/scripts/other/scroll.lua:4: in function <data/actions/scripts/other/scroll.lua:2>

I understand that there's something wrong with "doPlayerLearnInstantSpell," but I'm not sure what exactly is wrong.

Any ideas as to how to modify the script from the thread I linked to work for OTX3, or is there an example script out there that's already working?

thanks~
 
Solution
Perfect. Works awesome.
Hmmm I'm having trouble sending the message though...
Code:
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have learned the spell ' .. spellName() .. '.')
I'm getting an error, it can't callback to the spell name. What do I need to add?
because you're calling spellName as a function when it's just a string
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have learned the spell ".. spellName)
Do you have the sources for that distribution?
specifically "lua.cpp"?

for 0.3.7 we have these, to check and learn/unlearn spells.
Code:
getPlayerLearnedInstantSpell(cid, name)
getPlayerInstantSpellCount(cid)
getPlayerInstantSpellInfo(cid, index)
getInstantSpellInfo(cid, name)
doPlayerLearnInstantSpell(cid, name)
doPlayerUnlearnInstantSpell(cid, name)

Basically the problem is that this lua code is either non-existent or named differently in your distribution.
If you have the source, we can look through and find the appropriate code, or you can look through it. :p
 
iirc otx3 is based off of tfs 1.2+

Code:
local spellName = "exura"

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:hasLearnedSpell(spellName) then
        player:sendCancelMessage("You have already learned this spell.")
    else
        player:learnSpell(spellName)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    end
    return true
end
 
I do indeed have the source, I compiled it myself! However my file is called "luascript.cpp" and it's pretty big, idk which part I need to look at.

@Xeraphus, the script you made removed the error, but it still doesn't fully work. When I use the scroll, I get the blue shimmer effect, and if I try to use it a second time it says "You have already learned this spell," but I still can't cast it.

It still says "You must learn this spell first."
Any ideas?
Thanks!
 
Yep LOL that worked fine. I can't believe I didn't realize that, I already read someone else's post who made that same mistake xDD thanks man!
Another question if I may, can I add this line to remove the scroll?

Code:
item:remove(1)
 
Yep LOL that worked fine. I can't believe I didn't realize that, I already read someone else's post who made that same mistake xDD thanks man!
Another question if I may, can I add this line to remove the scroll?

Code:
item:remove(1)
yes you can
you can also inform the player that they learned the spell by textmessage
 
Perfect. Works awesome.
Hmmm I'm having trouble sending the message though...
Code:
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have learned the spell ' .. spellName() .. '.')
I'm getting an error, it can't callback to the spell name. What do I need to add?
 
Perfect. Works awesome.
Hmmm I'm having trouble sending the message though...
Code:
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have learned the spell ' .. spellName() .. '.')
I'm getting an error, it can't callback to the spell name. What do I need to add?
because you're calling spellName as a function when it's just a string
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have learned the spell ".. spellName)
 
Solution
Back
Top