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

You can learn only 2 spells from 3

Koozaczek

New Member
Joined
Jul 19, 2008
Messages
53
Reaction score
0
Like in thread.
How i can make that?
I mean it should wourk that the npc have 3 spells to learn, but you can learn only 2 from 3, you can choose what spells you want to learn and this 1 left spell will be impossible to learn you pernament.

Please help, also sorry for my bad english.
 
tfs 0.3.6

and conversation:
Player: Hi
Npc: Hello dear Player, i can teach you some interesting spells, but remember you cant learn it all.
Player: Spells
Npc: I can teach you spells: exura, exura gran, exura vita, exura san, exana mort. But remember, you can choose only 2 spells to learn from my list, other spells will be pernament not available to you.
Npc: So what spells you choose?
Player: Exura san
Npc: You learned spell Exura San
Player: Exana Mort
Npc: You learned spell Exana Mort
Player: Exura
Npc: Sorry, you already learned 2 spells from me, dont come back anymore.

Sorry for my bad english.
Could you help me?
 
make an storage value connected to the npc
if npc will say i have teach you exura san, then set storage +1

If player want to learn second spell, change storage into +2 storage...
And if player want to learn 3 spell, then send false ;p
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)  npcHandler:onCreatureAppear(cid)  end
function onCreatureDisappear(cid)  npcHandler:onCreatureDisappear(cid)  end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg)  end
function onThink()  npcHandler:onThink()  end

local storage = 98534
local spells = {"Light Healing", "Intense Healing", "Ultimate Healing", "Divine Healing", "Wound Cleansing"}

local text = ""
for x = 1, #spells do
     local c = ", "
     if x == 1 then
         c = ""
     elseif x == #spells then
         c = " and "
     end
     text = text .. c
     text = text .. spells[x]
end

function creatureSayCallback(cid, type, msg)

     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

     if not npcHandler:isFocused(cid) then
         if msg == "hi" or msg == "hello" then
             if getPlayerStorageValue(cid, storage) == -1 then
                 selfSay("Hello dear "..getCreatureName(cid)..", I can teach you some interesting {spells}, but remember you can't learn it all.", cid)
                 talkState[talkUser] = 1
             else
                 selfSay("Hello, hope you're doing well with your new spells.", cid)
             end
             npcHandler:addFocus(cid)
         else
             return false
         end
     end

     if msgcontains(msg, "spells") and talkState[talkUser] == 1 then
         selfSay("I can teach you spells: "..text..". But remember, you can choose only 2 spells to learn from my list, other spells will be pernament not available to you.", cid)
         selfSay("So which spells do you choose?", cid)
         talkState[talkUser] = 2
     elseif msgcontains(msg, "bye") then
         selfSay("Bye.", cid)
         npcHandler:releaseFocus(cid)
     elseif talkState[talkUser] == 2 then
         if isInArray(spells, msg) then
             if getPlayerStorageValue(cid, storage) < 1 then
                 selfSay(getPlayerStorageValue(cid, storage) == -1 and "You have now learned the spell "..msg..", you can choose 1 more spell."  or "So "..msg.." will be your second spell, good luck with both spells.", cid)
                 doPlayerLearnInstantSpell(cid, msg)
                 setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) + 1)
             else
                 selfSay("Sorry, you already learned 2 spells from me.", cid)
                 talkState[talkUser] = 0
             end
         else
             selfSay(msg.." is not a spell you can learn from me, you can choose "..text..".", cid)
         end
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Thx you a lot, work great.

Also can you tell me where i should change to be possible choose for example 3 or more spells to learn?

# Edit
Also can you fix to not be able to learn 2 the same spells?
At the moment i can learn for example light healing double time.
 
Last edited:
You can use getPlayerLearnedInstantSpell(cid, msg) to see if a player already learned the spell.
Change here the amount.
Code:
if getPlayerStorageValue(cid, storage) < 1 then
< 1 means -1 or 0, first it's -1 and + 1 it will be 0. So with 3 spells you can do < 2, since then it will be -1, 0 and 1.
 
getPlayerLearnedInstantSpell(cid, msg) But where i should put this in code?
Could you put this to the script?
Sry for my posts but im rly noob in this thread but i rly need help with this to everything works fine.

Also thx i trying do 3 spells to learn and it work.
 
Back
Top