• 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 How make Spell Scroll and lever !!

foulla

Member
Joined
Jun 26, 2016
Messages
78
Solutions
1
Reaction score
6
Hello
Can anyone tell me how make spell Scroll and lever when use Scroll add this spell "exevo gran ico" level 100 only vocation 3 . 4
Tfs 0.4
 
Last edited:
Solution
data\actions\scripts add a script with the name you choose granico.lua then add this to it.
Lua:
local spell = "gran ico"
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if not getPlayerLearnedInstantSpell(cid, spell) then
        doPlayerLearnInstantSpell(cid, spell)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!")
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
        doRemoveItem(item.uid, 1)
    else
        doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
    end
    return true
end
and in data\actions\actions.xml add
XML:
<action itemid="5957" event="script" value="granico.lua"/>
...
Can you show the current lever script?

I don't feel like I've seen the lever script in the past comments.
Lua:
local spell = "gran ico"
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if not getPlayerLearnedInstantSpell(cid, spell) then
        doPlayerLearnInstantSpell(cid, spell)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!")
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    else
        doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
    end
    return true
end
Post automatically merged:

How do I add a price using this?

Lua:
doPlayerRemoveItem(cid, 8981, 1)
doPlayerRemoveItem(cid, 2157, 20)
 
Lua:
local spell = "gran ico"
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if not getPlayerLearnedInstantSpell(cid, spell) then
        doPlayerLearnInstantSpell(cid, spell)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!")
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    else
        doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
    end
    return true
end
Post automatically merged:

How do I add a price using this?

Lua:
doPlayerRemoveItem(cid, 8981, 1)
doPlayerRemoveItem(cid, 2157, 20)
Lua:
local spell = "gran ico"

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerLearnedInstantSpell(cid, spell) then
        doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
        return true
    end
    if getPlayerItemCount(cid, 8981) < 1 or getPlayerItemCount(cid, 2157) < 20 then
        doCreatureSay(cid, "This spell costs 1 itemname8981 and 20 itemname2157!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
        return true
    end
    doPlayerRemoveItem(cid, 8981, 1)
    doPlayerRemoveItem(cid, 2157, 20)
    doPlayerLearnInstantSpell(cid, spell)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!")
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    return true
end
 
Lua:
local spell = "gran ico"

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerLearnedInstantSpell(cid, spell) then
        doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
        return true
    end
    if getPlayerItemCount(cid, 8981) < 1 or getPlayerItemCount(cid, 2157) < 20 then
        doCreatureSay(cid, "This spell costs 1 itemname8981 and 20 itemname2157!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
        return true
    end
    doPlayerRemoveItem(cid, 8981, 1)
    doPlayerRemoveItem(cid, 2157, 20)
    doPlayerLearnInstantSpell(cid, spell)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!")
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    return true
end
Do not give any errors, but lever does not move and does not give anything or any message
And if I have this (8981, 1) (2157, 20)
 
Do not give any errors, but lever does not move and does not give anything or any message
And if I have this (8981, 1) (2157, 20)
I've added some prints.

Check console to find out what is happening, and report back.
(If you don't see anything in console, then the script has likely errored while starting up the server.)

Lua:
local spell = "gran ico"

function onUse(cid, item, fromPosition, itemEx, toPosition)
    print("onUse function started..")
    if getPlayerLearnedInstantSpell(cid, spell) then
        doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
        print("onUse function finished. Ending 1 -- spell already known")
        return true
    end
    if getPlayerItemCount(cid, 8981) < 1 or getPlayerItemCount(cid, 2157) < 20 then
        doCreatureSay(cid, "This spell costs 1 itemname8981 and 20 itemname2157!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
        print("onUse function finished. Ending 2 -- required items missing from player")
        return true
    end
    doPlayerRemoveItem(cid, 8981, 1)
    doPlayerRemoveItem(cid, 2157, 20)
    doPlayerLearnInstantSpell(cid, spell)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!")
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    print("onUse function finished. Ending 3 -- Spell has been successfully learned.")
    return true
end
 
I've added some prints.

Check console to find out what is happening, and report back.
(If you don't see anything in console, then the script has likely errored while starting up the server.)

Lua:
local spell = "gran ico"

function onUse(cid, item, fromPosition, itemEx, toPosition)
    print("onUse function started..")
    if getPlayerLearnedInstantSpell(cid, spell) then
        doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
        print("onUse function finished. Ending 1 -- spell already known")
        return true
    end
    if getPlayerItemCount(cid, 8981) < 1 or getPlayerItemCount(cid, 2157) < 20 then
        doCreatureSay(cid, "This spell costs 1 itemname8981 and 20 itemname2157!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
        print("onUse function finished. Ending 2 -- required items missing from player")
        return true
    end
    doPlayerRemoveItem(cid, 8981, 1)
    doPlayerRemoveItem(cid, 2157, 20)
    doPlayerLearnInstantSpell(cid, spell)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!")
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    print("onUse function finished. Ending 3 -- Spell has been successfully learned.")
    return true
end
Well it really works but it doesn't give any of these messages :)
Lua:
 doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
Lua:
 doCreatureSay(cid, "This spell costs 1 itemname8981 and 20 itemname2157!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
and how add only vocation id 4,8 can use it
 
Well it really works but it doesn't give any of these messages :)
Lua:
 doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
Lua:
 doCreatureSay(cid, "This spell costs 1 itemname8981 and 20 itemname2157!", TALKTYPE_ORANGE_1, nil, cid, getThingPos(cid))
and how add only vocation id 4,8 can use it
Lua:
local spell = "gran ico"
local vocations = {4, 8}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerLearnedInstantSpell(cid, spell) then
        doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1)
        return true
    end
    local voc = getPlayerVocation(cid)
    if not isInArray(vocations, voc) then
        local text = ""
        for i = 1, #vocations do
            if text ~= "" then
                if i + 1 == #vocations then
                    text = text .. " and "
                else
                    text = text .. ", "
                end
            end
            text = text .. getVocationInfo(vocations[i]).name .. "'s"
        end
        doCreatureSay(cid, "Only " .. text .. " can learn this spell.", TALKTYPE_ORANGE_1)
        return true
    end
    if getPlayerItemCount(cid, 8981) < 1 or getPlayerItemCount(cid, 2157) < 20 then
        doCreatureSay(cid, "This spell costs 1 itemname8981 and 20 itemname2157!", TALKTYPE_ORANGE_1)
        return true
    end
    doPlayerRemoveItem(cid, 8981, 1)
    doPlayerRemoveItem(cid, 2157, 20)
    doPlayerLearnInstantSpell(cid, spell)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!")
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    return true
end
 
Last edited:
Lua:
local spell = "gran ico"
local vocations = {4, 8}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerLearnedInstantSpell(cid, spell) then
        doCreatureSay(cid, "You already know this spell!", TALKTYPE_ORANGE_1)
        return true
    end
    local voc = getPlayerVocation(cid)
    if not isInArray(vocations, voc)
        local text = ""
        for i = 1, #vocations do
            if text ~= "" then
                if i + 1 == #vocations then
                    text = text .. " and "
                else
                    text = text .. ", "
                end
            end
            text = text .. getVocationInfo(vocations[i]).name .. "'s"
        end
        doCreatureSay(cid, "Only " .. text .. " can learn this spell.", TALKTYPE_ORANGE_1)
        return true
    end
    if getPlayerItemCount(cid, 8981) < 1 or getPlayerItemCount(cid, 2157) < 20 then
        doCreatureSay(cid, "This spell costs 1 itemname8981 and 20 itemname2157!", TALKTYPE_ORANGE_1)
        return true
    end
    doPlayerRemoveItem(cid, 8981, 1)
    doPlayerRemoveItem(cid, 2157, 20)
    doPlayerLearnInstantSpell(cid, spell)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have learned spell " .. spell .. "!")
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    return true
end
Error
Code:
[13:33:58.746] [Error - LuaInterface::loadFile] data/actions/scripts/shop/hot2.lua:11: 'then' expected near 'local'
[13:33:58.761] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/shop/hot2.lua)
[13:33:58.761] data/actions/scripts/shop/hot2.lua:11: 'then' expected near 'local'
 
Error
Code:
[13:33:58.746] [Error - LuaInterface::loadFile] data/actions/scripts/shop/hot2.lua:11: 'then' expected near 'local'
[13:33:58.761] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/shop/hot2.lua)
[13:33:58.761] data/actions/scripts/shop/hot2.lua:11: 'then' expected near 'local'
change
Lua:
if not isInArray(vocations, voc)
to
Lua:
if not isInArray(vocations, voc) then
 
Back
Top