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

NPC learn spell only for specific storage.

adamox223

New Member
Joined
Oct 21, 2017
Messages
99
Reaction score
4
Hi, i need script npc learn spell, i try write script but dont work, i have only this, so can you help me? tfs 0.3.6
Code:
 if getPlayerStorageValue(cid, 9996) == 1 then
            selfSay("I can teach you: bla bla, bla bla, bla")
else
            selfSay('Sorry, i can only teach only specific people.')
        end

Code:
function spell(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
      return false
    end
    if getPlayerSkillLevel(cid, 6) >= 30 then
        if getPlayerLearnedInstantSpell(cid, "spell") == false then
            if getPlayerLevel(cid) >= 15 then
              doPlayerLearnInstantSpell(cid, "spell")
            else
              selfSay("You are not level 15.", cid)
            end
        else
          selfSay("You have already learned spell.", cid)
        end
    else
      selfSay("You need to be level 30 in Fishing.", cid)
    end
   return true
end
Code:
local node1 = keywordHandler:addKeyword({'spell'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Do you want to learn spell?"})
    node1:addChildKeyword({'yes'}, yes, {npcHandler = npcHandler, onlyFocus = true, reset = true})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Are you an alienated!", reset = true})
 
Solution
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
function greet(cid)   talkState[cid] = 0   return true end
 
function getNpcName()
     return getCreatureName(getNpcId())
end
 
function creatureSayCallback(cid, type, msg)
     if(not npcHandler:isFocused(cid)) then
         return false
     end
   
     local talkUser = NPCHANDLER_CONVBEHAVIOR ==...
Hi, i need script npc learn spell, i try write script but dont work, i have only this, so can you help me? tfs 0.3.6
Code:
 if getPlayerStorageValue(cid, 9996) == 1 then
            selfSay("I can teach you: bla bla, bla bla, bla")
else
            selfSay('Sorry, i can only teach only specific people.')
        end

Code:
function spell(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
      return false
    end
    if getPlayerSkillLevel(cid, 6) >= 30 then
        if getPlayerLearnedInstantSpell(cid, "spell") == false then
            if getPlayerLevel(cid) >= 15 then
              doPlayerLearnInstantSpell(cid, "spell")
            else
              selfSay("You are not level 15.", cid)
            end
        else
          selfSay("You have already learned spell.", cid)
        end
    else
      selfSay("You need to be level 30 in Fishing.", cid)
    end
   return true
end
Code:
local node1 = keywordHandler:addKeyword({'spell'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Do you want to learn spell?"})
    node1:addChildKeyword({'yes'}, yes, {npcHandler = npcHandler, onlyFocus = true, reset = true})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Are you an alienated!", reset = true})
Start with a base npc file

Then add your code.
Lua:
if msgcontains(msg, "spell") and talkState[talkUser] == 0 then
    if getPlayerStorageValue(cid, 9996) < 1 then
        selfSay("Sorry, I only teach specific people.", cid)
        return true
    end
    if getPlayerLevel(cid) < 15 or getPlayerSkillLevel(cid, 6) < 30 then
        selfSay("You need to be level 15 and have level 30 in fishing to learn spell.", cid)
        return true
    end
    if getPlayerLearnedInstantSpell(cid, "spell") == true then
        selfSay("You have already learned spell.", cid)
        return true
    end
    selfSay("Would you like to purchase spell?", cid)
    talkState[cid] = 1
elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
    doPlayerLearnInstantSpell(cid, "spell")
    selfSay("You now have the magic spell! Hehe! Use it well.", cid)
    talkState[cid] = 0
else
    selfSay("Hmm?", cid)
end
 
i lost this script, i dont know where is it, because topic is old, i need this now, and i want to create npc who can talk only with storage: 9996: 1
and only can learn spells to this storage, can you help me with this?
 
i lost this script, i dont know where is it, because topic is old, i need this now, and i want to create npc who can talk only with storage: 9996: 1
and only can learn spells to this storage, can you help me with this?
I already gave the full script above.
Just take and install the 'base npc', then insert the script from my post inside of it.
 
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
function greet(cid)   talkState[cid] = 0   return true end
  
function getNpcName()
     return getCreatureName(getNpcId())
end
  
function creatureSayCallback(cid, type, msg)
     if(not npcHandler:isFocused(cid)) then
         return false
     end
    
     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    
     if msgcontains(msg, "job") then
         selfSay("My job is to show the world how fashionable they can be!", cid)
      
     elseif msgcontains(msg, "name") then
         selfSay("My name is " .. getNpcName() .. ".", cid)
         
         
         
         if msgcontains(msg, "spell") and talkState[talkUser] == 0 then
    if getPlayerStorageValue(cid, 9996) < 1 then
        selfSay("Sorry, I only teach specific people.", cid)
        return true
    end
    if getPlayerLevel(cid) < 15 or getPlayerSkillLevel(cid, 6) < 30 then
        selfSay("You need to be level 15 and have level 30 in fishing to learn spell.", cid)
        return true
    end
    if getPlayerLearnedInstantSpell(cid, "spell") == true then
        selfSay("You have already learned spell.", cid)
        return true
    end
    selfSay("Would you like to purchase spell?", cid)
    talkState[cid] = 1
elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
    doPlayerLearnInstantSpell(cid, "spell")
    selfSay("You now have the magic spell! Hehe! Use it well.", cid)
    talkState[cid] = 0
else
    selfSay("Hmm?", cid)
     
         
        end 
         
         
         
         
         
         
         
    
     end
     return true  
end

npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


21:51 Raven [449]: hi
21:51 Suiton Teacher: Hello Raven.
21:51 Raven [449]: offer
21:51 Raven [449]: job
21:51 Suiton Teacher: My job is to show the world how fashionable they can be!
21:51 Raven [449]: spell


and didn't work, npc need to say: Sorry, I only teach specific people.
when we dont have storage or we can learn spell when we have :/
 
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
function greet(cid)   talkState[cid] = 0   return true end
 
function getNpcName()
     return getCreatureName(getNpcId())
end
 
function creatureSayCallback(cid, type, msg)
     if(not npcHandler:isFocused(cid)) then
         return false
     end
   
     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
   
     if msgcontains(msg, "job") then
         selfSay("My job is to show the world how fashionable they can be!", cid)
     
     elseif msgcontains(msg, "name") then
         selfSay("My name is " .. getNpcName() .. ".", cid)
        
        
        
         if msgcontains(msg, "spell") and talkState[talkUser] == 0 then
    if getPlayerStorageValue(cid, 9996) < 1 then
        selfSay("Sorry, I only teach specific people.", cid)
        return true
    end
    if getPlayerLevel(cid) < 15 or getPlayerSkillLevel(cid, 6) < 30 then
        selfSay("You need to be level 15 and have level 30 in fishing to learn spell.", cid)
        return true
    end
    if getPlayerLearnedInstantSpell(cid, "spell") == true then
        selfSay("You have already learned spell.", cid)
        return true
    end
    selfSay("Would you like to purchase spell?", cid)
    talkState[cid] = 1
elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
    doPlayerLearnInstantSpell(cid, "spell")
    selfSay("You now have the magic spell! Hehe! Use it well.", cid)
    talkState[cid] = 0
else
    selfSay("Hmm?", cid)
    
        
        end
        
        
        
        
        
        
        
   
     end
     return true 
end

npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


21:51 Raven [449]: hi
21:51 Suiton Teacher: Hello Raven.
21:51 Raven [449]: offer
21:51 Raven [449]: job
21:51 Suiton Teacher: My job is to show the world how fashionable they can be!
21:51 Raven [449]: spell


and didn't work, npc need to say: Sorry, I only teach specific people.
when we dont have storage or we can learn spell when we have :/
A quick and basic skill to learn is tabbing code.
It'll help you with problems like this in the future.
Basically you had the if statement for 'spell' inside of the elseif statement from 'name'.

Thanks for giving it the effort.
Below should work for you.
Lua:
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
function greet(cid)   talkState[cid] = 0   return true end

function getNpcName()
    return getCreatureName(getNpcId())
end

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    
    if msgcontains(msg, "job") then
        selfSay("My job is to show the world how fashionable they can be!", cid)
    
    elseif msgcontains(msg, "name") then
        selfSay("My name is " .. getNpcName() .. ".", cid)
        
    -- buy 'spell' block    
    elseif msgcontains(msg, "spell") and talkState[talkUser] == 0 then
        if getPlayerStorageValue(cid, 9996) < 1 then
            selfSay("Sorry, I only teach specific people.", cid)
            return true
        end
        if getPlayerLevel(cid) < 15 or getPlayerSkillLevel(cid, 6) < 30 then
            selfSay("You need to be level 15 and have level 30 in fishing to learn spell.", cid)
            return true
        end
        if getPlayerLearnedInstantSpell(cid, "spell") == true then
            selfSay("You have already learned spell.", cid)
            return true
        end
        selfSay("Would you like to purchase spell?", cid)
        talkState[cid] = 1
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
        doPlayerLearnInstantSpell(cid, "spell")
        selfSay("You now have the magic spell! Hehe! Use it well.", cid)
        talkState[cid] = 0
    else
        selfSay("Hmm?", cid)
    end
    return true  
end

npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
Back
Top