• 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!

Learn spell by clicking on a book [Quest]

rilleman

New Member
Joined
Feb 14, 2010
Messages
269
Reaction score
0
I wonder if its possible to make a book/chest and when you click on it you will learn a spell?
 
Lua:
-- ver. 0.1
local c = {
	[1ItemId1] = "Spell name1",
	[2ItemId2] = "Spell name2"
}
function onUse(cid, item, fromPosition, itemEx, toPosition)

	local spell = c[item.id]
	if spell then
		if getPlayerLearnedInstantSpell(cid, spell) then
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You already know this spell.")
			doSendMagicEffect(fromPosition, CONST_ME_POFF)
		else
			doPlayerLearnInstantSpell(cid, spell)
		end
	else
		return false
	end

	return true
end

--[[ todo
- check vocation
- if premium
- remove item?
 ]]
something like this?
 
Lua:
-- ver. 0.1
local c = {
	[1ItemId1] = "Spell name1",
	[2ItemId2] = "Spell name2"
}
function onUse(cid, item, fromPosition, itemEx, toPosition)

	local spell = c[item.id]
	if spell then
		if getPlayerLearnedInstantSpell(cid, spell) then
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You already know this spell.")
			doSendMagicEffect(fromPosition, CONST_ME_POFF)
		else
			doPlayerLearnInstantSpell(cid, spell)
		end
	else
		return false
	end

	return true
end

--[[ todo
- check vocation
- if premium
- remove item?
 ]]
something like this?


error:
spellquest.lua:3: malformed number near "1ItemId1"
 
Heh,

95209a691a593b232722112a5fff265c.png
 
Im sorry, late night hehe.

Could you make it so when you click on the book/container you'll see an text "You have learn a new spell" or something? :)

anyway thanks alot! ive repped u!
 

Attachments

Last edited:
XML:
<action actionid="1234" event="script" value="spell.lua"/>

spell.lua
Lua:
local spellName = "SPELLNAMEHERE" -- replace spellnamehere with ur spell
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.actionid == 1234 then -- 1234 should be as same aid in actions.xml
		if not getPlayerLearnedInstantSpell(cid, spellName) then
			doPlayerLearnInstantSpell(cid, spellName)
                        doPlayerPopupFYI(cid, You just learnt a new spell)
		else
			doPlayerSendCancel(cid, "You cannot learn this spell twice.")
		end	
	end
	return true
end
 
XML:
<action actionid="1234" event="script" value="spell.lua"/>

spell.lua
Lua:
local spellName = "SPELLNAMEHERE" -- replace spellnamehere with ur spell
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.actionid == 1234 then -- 1234 should be as same aid in actions.xml
		if not getPlayerLearnedInstantSpell(cid, spellName) then
			doPlayerLearnInstantSpell(cid, spellName)
                        doPlayerPopupFYI(cid, You just learnt a new spell)
		else
			doPlayerSendCancel(cid, "You cannot learn this spell twice.")
		end	
	end
	return true
end

can I make custom action ids, so I can make the player learn different spells for the same item id but with different action ids?
 
Yes, you can do that. :p

- - - Edited - - -

Haven't tested this, but please give it a try.
Lua:
local t = {
    [5000] = {"Light Healing"},
    [5001] = {"Haste"},
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local v = t[item.actionid]
    if v then
        if getPlayerLearnedInstantSpell(cid, v[1]) then
            return doPlayerSendCancel(cid, "You already know this spell."), doSendMagicEffect(getThingPos(cid), CONST_ME_POFF), false
        end
        
        doPlayerLearnInstantSpell(cid, v[1])
        doSendMagicEffect(getThingPos(cid), CONST_ME_WRAPS)
        doCreatureSay(cid, "You just learnt a new spell!", TALKTYPE_ORANGE_1)
    end
    return true
end
 
Last edited:
Yes, you can do that. :p

- - - Edited - - -

Haven't tested this, but please give it a try.
Lua:
local t = {
    [5000] = {"Light Healing"},
    [5001] = {"Haste"},
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local v = t[item.actionid]
    if v then
        if getPlayerLearnedInstantSpell(cid, v[1]) then
            return doPlayerSendCancel(cid, "You already know this spell."), doSendMagicEffect(getThingPos(cid), CONST_ME_POFF), false
        end
        
        doPlayerLearnInstantSpell(cid, v[1])
        doSendMagicEffect(getThingPos(cid), CONST_ME_WRAPS)
        doCreatureSay(cid, "You just learnt a new spell!", TALKTYPE_ORANGE_1)
    end
    return true
end

but how do I make custom action ids for the item? I want to use the poem scroll as the item
 
Lua:
local item = doPlayerAddItem(cid,5952,1)
doSetItemActionId(item, 5000)

awesome. im gonna put the script here and test.

- - - Updated - - -

I tested and seems to work. thanks A LOT. but how do I make the message tell me what was the spell I learned?

doCreatureSay(cid, "You just learnt a new spell!", TALKTYPE_ORANGE_1)
 
another thing, besides adding custom action id, can I add a custom description for the same item? I know I have to use the command doItemSetAttribute(item, "description", ....) but how do I add the description for the same item I added the action id? I just put the doitemsetattribute after the dosetitemaction id? wont it create two items?
 
Still using Mystic Spirit?
Lua:
local item = doPlayerAddItem(cid,5952,1)
doSetItemActionId(item, 5000)
doSetItemSpecialDescription(item, "Your text here.")
It won't create 2 items because you have doPlayerAddItem(cid,5952,1) only 1x.
 
Still using Mystic Spirit?
Lua:
local item = doPlayerAddItem(cid,5952,1)
doSetItemActionId(item, 5000)
doSetItemSpecialDescription(item, "Your text here.")
It won't create 2 items because you have doPlayerAddItem(cid,5952,1) only 1x.
yes im using mystic spirit 2.1.4

i got a problem, the server isnt recognizing neither doSeItemSpecialDescription nor doItemSetAttribute
 
I just tested it on TFS 0.2.14 (Mystic Spirit) and it worked fine for me.
16:19 You see a poem scroll.
It weighs 1.20 oz.
Your text here.
ItemID: [5952], ActionID: [5000].

Do you get errors?
 
[04/08/2013 11:13:05] Lua Script Error: [Action Interface]
[04/08/2013 11:13:05] data/actions/scripts/test.lua:eek:nUse
[04/08/2013 11:13:05] data/actions/scripts/test.lua:4: attempt to call global 'doItemSetAttribute' (a nil value)
[04/08/2013 11:13:05] stack traceback:
[04/08/2013 11:13:05] [C]: in function 'doItemSetAttribute'
[04/08/2013 11:13:05] data/actions/scripts/test.lua:4: in function <data/actions/scripts/test.lua:1>

- - - Updated - - -

WOW, now its working!
 
Back
Top