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

Spell TFS 1.2 Conjure Rune/Ammo Etc..

Codex NG

Recurrent Flamer
Joined
Jul 24, 2015
Messages
2,994
Solutions
12
Reaction score
1,657
So what this does is, it will allow you to basically conjure anything you specify, this is a spell not a talkaction.
Code:
function aOrAn(word)
    local vowels = {'a', 'e', 'i', 'o', 'u', 'x'}
    return isInArray(vowels, word:sub(1, 1):lower()) and 'an '..word or 'a '..word
end

local spells = {
    ["adori blank"] = { lvl = 20, mana = 50, conjureId = 2260, charges = 1},
    ["exevo con"] = { lvl = 13, mana = 100, conjureId = 2544, charges = 15},
}

local blank = {itemid = 2260, count = 1}

function onCastSpell(creature, var)
    if not creature:isPlayer() then
        return false
    end
    local words = var['string']
    if words then
        if spells[words] then
            if creature:getLevel() >= spells[words].lvl then
                if creature:getMana() >= spells[words].mana then
                    if creature:getItemCount(blank.itemid) >= blank.count then
                        creature:addItem(spells[words].conjureId, spells[words].charges)
                        creature:removeItem(blank.itemid, blank.count)
                    else
                        local name = ItemType(blank.itemid):getName()
                        creature:sendCancelMessage("You don't have enough ".. name.. "s, you need atleast "..blank.count ..' ' .. name .." to cast this spell.")
                    end
                else
                    creature:sendCancelMessage("You don't have enough mana, you need "..spells[words].mana .. " mana to create this item")
                end
            else
                creature:sendCancelMessage("You cannot conjure "..aOrAn(words)..", you need to be level "..spells[words].lvl..".")
            end
        else
            creature:sendCancelMessage("You cannot conjure "..aOrAn(words))
        end
    end
    return true
end

Code:
<instant spellid="175" name="test" words="conjure" params="1" aggressive="0" script="test.lua" />

If there is a space in the words, you have place a double quote in front of the words, just like you would with heal friend.
Example:
Code:
conjure "exevo con

@Zothion Version
Code:
local function aOrAn(word)
    local vowels = {'a', 'e', 'i', 'o', 'u', 'x'}
    return isInArray(vowels, word:sub(1, 1):lower()) and 'an '..word or 'a '..word
end

local spells = {
    ["blank"] = { mana = 20, conjureId = 2260, allowPz = 1, charges = 1},
    ["arrows"] = { lvl = 13, mana = 100, conjureId = 2544, allowPz = 1, soul = 1, charges = 15, vocations = {4,12}},
    ["sd"] = { lvl = 45, mana = 200, conjureId = 2268, allowPz = 0, soul = 10, charges = 3, reagents = {{2260, 1}}, vocations = {4, 12}},
}

local function gotReagents(player, word)
    if spells[word].reagents ~= nil then
        for i=1,#(spells[word].reagents),1 do
            if player:getItemCount((spells[word].reagents)[i][1]) < ((spells[word].reagents)[i][2]) then
                player:sendCancelMessage("You are missing "..(spells[word].reagents)[i][2].." "..getItemName((spells[word].reagents)[i][1]))
                return false
            end
        end
    end
    return true
end

local blank = 2260

function onCastSpell(creature, var)
    if not creature:isPlayer() then
        return false
    end
    local words = (var['string']):lower()
    if spells[words] then
            if (not spells[words].lvl) or (getPlayerLevel(creature) >= spells[words].lvl) then
                if (not spells[words].mana) or (creature:getMana() >= spells[words].mana) then
                    if (not spells[words].soul) or (creature:getSoul() >= spells[words].soul) then
                        if (not spells[words].vocations) or isInArray(spells[words].vocations, getPlayerVocation(creature)) then
                            if (spells[words].reagents == nil) or gotReagents(creature, words) then
                                local pz = getTilePzInfo(getCreaturePosition(creature))                     
                                if not pz or (pz == spells[words].allowPz) then                             
                                    if spells[words].reagents ~= nil then
                                        for i=1,#(spells[words].reagents),1 do
                                            creature:removeItem((spells[words].reagents)[i][1], (spells[words].reagents)[i][2])
                                        end
                                    end
                                    creature:addItem(spells[words].conjureId, spells[words].charges)
                                    creature:addMana(-((spells[words].mana) or 0))
                                    creature:addManaSpent((spells[words].mana) or 0)
                                    creature:addSoul(-((spells[words].soul) or 0))
                                    creature:say("conjure "..words, TALKTYPE_MONSTER_SAY)
                                    creature:sendTextMessage(creature, MESSAGE_STATUS_CONSOLE_BLUE, "You succesfully conjured "..spells[words].charges.." "..getItemName(spells[words].conjureId).."s.")
                                    doSendMagicEffect(getCreaturePosition(creature), CONST_ME_TELEPORT)
                                else
                                    creature:sendCancelMessage("You cannot conjure "..aOrAn(words).." inside a protection zone.")                             
                                end
                            else
                                return false
                            end
                        else
                            creature:sendCancelMessage("Your vocation cannot use that spell.")
                        end
                    else
                        creature:sendCancelMessage("You need "..spells[words].soul.." soul to cast that spell.")
                    end  
                else
                    creature:sendCancelMessage("You don't have enough mana, you need "..spells[words].mana .. " mana to create this item")
                end
            else
                creature:sendCancelMessage("You do not have enough level to conjure "..aOrAn(words)..".")
            end
    else
        creature:sendCancelMessage("You cannot conjure "..aOrAn(words))
    end
    return false
end
 
Last edited:
Nice one.

But you didn't specify what TFS this is. :(
 
Did you set up a function so it knows when to use an or a?
 
it looks good, certainly nicer than a talkaction, only thing is that you have to use
Code:
conjure "full name
to conjure something instead of just saying full name (which only seems possible with a talkaction unfortunately)
and since you define blank.count as its own variable instead of on a per conjuration spell basis spells such as ur exevo con in there will consume a blank rune
and it could use allowPz, soul and vocation conditions aswell (since all conjuration spells use them pretty much)
also as far as i can see it doesnt remove any mana / add mana spent either :(
 
Did you set up a function so it knows when to use an or a?
Code:
function aOrAn(word)
local vowels = {'a', 'e', 'i', 'o', 'u', 'x'}
return isInArray(vowels, word:sub(1, 1):lower()) and 'an '..word or 'a '..word
end
 
i changed the script around a bit so valid conjuration spells table now looks like
!conjures prints
Code:
17:03 --- Valid conjuration spells for you are ---
arrows --- which costs 100 mana, 1 soul and gives you 15 arrows.
sd --- which costs 200 mana, 10 soul, 1 blank rune and gives you 3 sudden death runes.
blank --- which costs 20 mana, 0 soul and gives you 1 blank rune.
and spells look like
Code:
spells = {
    ["blank"] = { conjureId = 2260, allowPz = 1, charges = 1},
    ["arrows"] = { lvl = 13, mana = 100, conjureId = 2544, allowPz = 1, soul = 1, charges = 15, vocations = {1,2,3,4,5,6,7,8}},
    ["sd"] = { lvl = 45, mana = 200, conjureId = 2268, soul = 10, charges = 3, reagents = {{2260, 1}}, vocations = {1,2,5,6}},
}
so runes only require
Code:
{conjureId, charges, [optional: mana, allowPz, lvl, soul, vocations, reagents]}
where almost all settings are optional, and you can add whatever reagents to cast that conjuration that you want.. eg reagents = {{2260, 1}, {2152, 100}} to make it cost 1 blank rune and 100 platinum coins to cast it..
however adding reagents like that, i chose to add an extra function that checks if you have all the required ingredients instead of adding a messy for loop to check all ingredients, i also added stuff like soul/pz checks, i also added :lower() for the var for convenience :p
Code:
local function aOrAn(word)
    local vowels = {'a', 'e', 'i', 'o', 'u', 'x'}
    return isInArray(vowels, word:sub(1, 1):lower()) and 'an '..word or 'a '..word
end

local function gotReagents(player, word)
    if spells[word].reagents ~= nil then 
        for i=1,#(spells[word].reagents),1 do
            if player:getItemCount((spells[word].reagents)[i][1]) < ((spells[word].reagents)[i][2]) then
                player:sendCancelMessage("You are missing "..(spells[word].reagents)[i][2].." "..getItemName((spells[word].reagents)[i][1]))
                return false
            end
        end
    end
    return true
end

local spells = {
    ["blank"] = { mana = 20, conjureId = 2260, allowPz = 1, charges = 1},
    ["arrows"] = { lvl = 13, mana = 100, conjureId = 2544, allowPz = 1, soul = 1, charges = 15, vocations = {1,2,3,4,5,6,7,8}},
    ["sd"] = { lvl = 45, mana = 200, conjureId = 2268, allowPz = 0, soul = 10, charges = 3, reagents = {{2260, 1}}, vocations = {1,2,5,6}},
}

local blank = 2260

function onCastSpell(creature, var)
    if not creature:isPlayer() then
        return false
    end
    local pz = getTilePzInfo(getCreaturePosition(creature))
    local words = (var['string']):lower()
    if spells[words] then
        if not pz or (pz == spells[words].allowPz) then
            if (not spells[words].lvl) or (getPlayerLevel(creature) >= spells[words].lvl) then
                if (not spells[words].mana) or (creature:getMana() >= spells[words].mana) then
                    if (not spells[words].soul) or (creature:getSoul() >= spells[words].soul) then
                        if (not spells[words].vocations) or isInArray(spells[words].vocations, getPlayerVocation(creature)) then
                            if (spells[words].reagents == nil) or gotReagents(creature, words) then
                                if spells[words].reagents ~= nil then
                                    for i=1,#(spells[words].reagents),1 do
                                        creature:removeItem((spells[words].reagents)[i][1], (spells[words].reagents)[i][2])
                                    end
                                end
                                creature:addItem(spells[words].conjureId, spells[words].charges)
                                creature:addMana(-((spells[words].mana) or 0))
                                creature:addManaSpent((spells[words].mana) or 0)
                                creature:addSoul(-((spells[words].soul) or 0))
                                creature:say("conjure "..words, TALKTYPE_MONSTER_SAY)
                                creature:sendTextMessage(creature, MESSAGE_STATUS_CONSOLE_BLUE, "You succesfully conjured "..spells[words].charges.." "..getItemName(spells[words].conjureId).."s.")
                                doSendMagicEffect(getCreaturePosition(creature), CONST_ME_TELEPORT)
                            else
                                return false
                            end
                        else
                            creature:sendCancelMessage("Your vocation cannot use that spell.")
                        end
                    else
                        creature:sendCancelMessage("You need "..spells[words].soul.." soul to cast that spell.")
                    end         
                else
                    creature:sendCancelMessage("You don't have enough mana, you need "..spells[words].mana .. " mana to create this item")
                end
            else
                creature:sendCancelMessage("You do not have enough level to conjure "..aOrAn(words)..".")
            end
        else
            creature:sendCancelMessage("You cannot conjure "..aOrAn(words).." inside a protection zone.")
        end
    else
        creature:sendCancelMessage("You cannot conjure "..aOrAn(words))
    end
    return false
end
 
Last edited:
it looks good, certainly nicer than a talkaction, only thing is that you have to use
Code:
conjure "full name
to conjure something instead of just saying full name (which only seems possible with a talkaction unfortunately)
and since you define blank.count as its own variable instead of on a per conjuration spell basis spells such as ur exevo con in there will consume a blank rune
and it could use allowPz, soul and vocation conditions aswell (since all conjuration spells use them pretty much)
also as far as i can see it doesnt remove any mana / add mana spent either :(
Yep its very bare bones, but thanks for upgrading it. :)
 
@Zothion I found an error in your script, its nothing major, just scope issue.
Also i was in the depo and it told me i could not conjure this rune while in the depo but when i went out i couldn't conjure it anyway it wasn't suited for my vocation.

Might seem trivial.
Code:
local function aOrAn(word)
    local vowels = {'a', 'e', 'i', 'o', 'u', 'x'}
    return isInArray(vowels, word:sub(1, 1):lower()) and 'an '..word or 'a '..word
end

local spells = {
    ["blank"] = { mana = 20, conjureId = 2260, allowPz = 1, charges = 1},
    ["arrows"] = { lvl = 13, mana = 100, conjureId = 2544, allowPz = 1, soul = 1, charges = 15, vocations = {4,12}},
    ["sd"] = { lvl = 45, mana = 200, conjureId = 2268, allowPz = 0, soul = 10, charges = 3, reagents = {{2260, 1}}, vocations = {4, 12}},
}

local function gotReagents(player, word)
    if spells[word].reagents ~= nil then
        for i=1,#(spells[word].reagents),1 do
            if player:getItemCount((spells[word].reagents)[i][1]) < ((spells[word].reagents)[i][2]) then
                player:sendCancelMessage("You are missing "..(spells[word].reagents)[i][2].." "..getItemName((spells[word].reagents)[i][1]))
                return false
            end
        end
    end
    return true
end



local blank = 2260

function onCastSpell(creature, var)
    if not creature:isPlayer() then
        return false
    end
    local pz = getTilePzInfo(getCreaturePosition(creature))
    local words = (var['string']):lower()
    if spells[words] then
        if not pz or (pz == spells[words].allowPz) then
            if (not spells[words].lvl) or (getPlayerLevel(creature) >= spells[words].lvl) then
                if (not spells[words].mana) or (creature:getMana() >= spells[words].mana) then
                    if (not spells[words].soul) or (creature:getSoul() >= spells[words].soul) then
                        if (not spells[words].vocations) or isInArray(spells[words].vocations, getPlayerVocation(creature)) then
                            if (spells[words].reagents == nil) or gotReagents(creature, words) then
                                if spells[words].reagents ~= nil then
                                    for i=1,#(spells[words].reagents),1 do
                                        creature:removeItem((spells[words].reagents)[i][1], (spells[words].reagents)[i][2])
                                    end
                                end
                                creature:addItem(spells[words].conjureId, spells[words].charges)
                                creature:addMana(-((spells[words].mana) or 0))
                                creature:addManaSpent((spells[words].mana) or 0)
                                creature:addSoul(-((spells[words].soul) or 0))
                                creature:say("conjure "..words, TALKTYPE_MONSTER_SAY)
                                creature:sendTextMessage(creature, MESSAGE_STATUS_CONSOLE_BLUE, "You succesfully conjured "..spells[words].charges.." "..getItemName(spells[words].conjureId).."s.")
                                doSendMagicEffect(getCreaturePosition(creature), CONST_ME_TELEPORT)
                            else
                                return false
                            end
                        else
                            creature:sendCancelMessage("Your vocation cannot use that spell.")
                        end
                    else
                        creature:sendCancelMessage("You need "..spells[words].soul.." soul to cast that spell.")
                    end     
                else
                    creature:sendCancelMessage("You don't have enough mana, you need "..spells[words].mana .. " mana to create this item")
                end
            else
                creature:sendCancelMessage("You do not have enough level to conjure "..aOrAn(words)..".")
            end
        else
            creature:sendCancelMessage("You cannot conjure "..aOrAn(words).." inside a protection zone.")
        end
    else
        creature:sendCancelMessage("You cannot conjure "..aOrAn(words))
    end
    return false
end
 
oops, letting gotReagents access spells table is probably a good idea :(

i have my own spells/gotReagents/aOrAn in global.lua due to using them in other places also, so i wouldve never noticed :p

incase anyone wants a talkaction so the player can see what conjure spells they can use:
talkactions.xml
Code:
<talkaction words="!conjures" script="conjures.lua"/>
and /scripts/conjures.lua
local exhaustTime = 1000

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, exhaustTime)

local function printReagents(t)
local str = ""
if t ~= nil then
for i=1,#t,1 do
str = str..", "..t[2].." "..getItemName(t[1])..""
if t[2] > 1 then
str = str.."s"
end
end
end
return str
end

function onSay(player, words)
if(getCreatureCondition(player, CONDITION_EXHAUST)) then
doPlayerSendDefaultCancel(player, RETURNVALUE_YOUAREEXHAUSTED)
return true
end

local conjure.."--- Valid conjuration spells for you are ---"
for pos,val in pairs(spells) do
if validVoc(getPlayerVocation(player), pos) then
conjure = conjure.."\n"..pos.." --- which costs "..(spells[pos].mana).." mana, "..(spells[pos].soul or 0).." soul"..(printReagents(spells[pos].reagents)).." and gives you "..(spells[pos].charges).." "..(getItemName(spells[pos].conjureId))..""
if spells[pos].charges > 1 then
conjure = conjure.."s."
else
conjure = conjure.."."
end
end
end
doPlayerSendTextMessage(player, MESSAGE_STATUS_CONSOLE_BLUE, conjure)
doAddCondition(player, exhaust)
return false
end
im sure i can improve the !conjures talkaction, but it works and rarely needs to be used to i cant be bothered... :rolleyes:


@Codex NG can just change the order of the checks so the pz check is last, ill fix it up
 
Code:
local function aOrAn(word)
    local vowels = {'a', 'e', 'i', 'o', 'u', 'x'}
    return isInArray(vowels, word:sub(1, 1):lower()) and 'an '..word or 'a '..word
end

local spells = {
    ["blank"] = { mana = 20, conjureId = 2260, allowPz = 1, charges = 1},
    ["arrows"] = { lvl = 13, mana = 100, conjureId = 2544, allowPz = 1, soul = 1, charges = 15, vocations = {4,12}},
    ["sd"] = { lvl = 45, mana = 200, conjureId = 2268, allowPz = 0, soul = 10, charges = 3, reagents = {{2260, 1}}, vocations = {4, 12}},
}

local function gotReagents(player, word)
    if spells[word].reagents ~= nil then
        for i=1,#(spells[word].reagents),1 do
            if player:getItemCount((spells[word].reagents)[i][1]) < ((spells[word].reagents)[i][2]) then
                player:sendCancelMessage("You are missing "..(spells[word].reagents)[i][2].." "..getItemName((spells[word].reagents)[i][1]))
                return false
            end
        end
    end
    return true
end

local blank = 2260

function onCastSpell(creature, var)
    if not creature:isPlayer() then
        return false
    end
    local words = (var['string']):lower()
    if spells[words] then
            if (not spells[words].lvl) or (getPlayerLevel(creature) >= spells[words].lvl) then
                if (not spells[words].mana) or (creature:getMana() >= spells[words].mana) then
                    if (not spells[words].soul) or (creature:getSoul() >= spells[words].soul) then
                        if (not spells[words].vocations) or isInArray(spells[words].vocations, getPlayerVocation(creature)) then
                            if (spells[words].reagents == nil) or gotReagents(creature, words) then
                                local pz = getTilePzInfo(getCreaturePosition(creature))                      
                                if not pz or (pz == spells[words].allowPz) then                              
                                    if spells[words].reagents ~= nil then
                                        for i=1,#(spells[words].reagents),1 do
                                            creature:removeItem((spells[words].reagents)[i][1], (spells[words].reagents)[i][2])
                                        end
                                    end
                                    creature:addItem(spells[words].conjureId, spells[words].charges)
                                    creature:addMana(-((spells[words].mana) or 0))
                                    creature:addManaSpent((spells[words].mana) or 0)
                                    creature:addSoul(-((spells[words].soul) or 0))
                                    creature:say("conjure "..words, TALKTYPE_MONSTER_SAY)
                                    creature:sendTextMessage(creature, MESSAGE_STATUS_CONSOLE_BLUE, "You succesfully conjured "..spells[words].charges.." "..getItemName(spells[words].conjureId).."s.")
                                    doSendMagicEffect(getCreaturePosition(creature), CONST_ME_TELEPORT)
                                else
                                    creature:sendCancelMessage("You cannot conjure "..aOrAn(words).." inside a protection zone.")                              
                                end
                            else
                                return false
                            end
                        else
                            creature:sendCancelMessage("Your vocation cannot use that spell.")
                        end
                    else
                        creature:sendCancelMessage("You need "..spells[words].soul.." soul to cast that spell.")
                    end   
                else
                    creature:sendCancelMessage("You don't have enough mana, you need "..spells[words].mana .. " mana to create this item")
                end
            else
                creature:sendCancelMessage("You do not have enough level to conjure "..aOrAn(words)..".")
            end
    else
        creature:sendCancelMessage("You cannot conjure "..aOrAn(words))
    end
    return false
end
now it should check pz after every other check so you dont get fooled ;)
 
Back
Top