• Congratulations to the OTLand February Mapping Competition Winner! The grand prize of Otland Premium goes to eiserne festung.
  • 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 TFS 1.3 Spell upgrade

Icaraii

Member
Joined
Jan 5, 2020
Messages
94
Reaction score
8
Hello guys,

Can someone make this script for me please?!

Player learn a spell at level 10, lets says player learn exori flam. At level 30, he can talk to a npc and upgrade the spell to exori flam hur or exevo gran mas flam for 5k (gold). When the player get the upgrade spell, he doesn't know exori flam anymore, only exori flam hur or exevo gran mas flam.

-> Script need to support several upgrades, for example:
exori flam can be upgraded to exori flam hur or exevo gran mas flam
exori frigo can be upgraded to exori frigo hur or exevo gran mas frigo
 

Chev

C++ /lua scripter
Joined
May 22, 2010
Messages
194
Solutions
1
Reaction score
11
Location
Poland
You can use this npc, just change "spellname" to spell's "name" (not words)

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 cfg = {
    [0] = {spellName = "spellname0"}, -- basic spell
    [1] = {spellName = "spellname1", level = 10, cost = 1000}, -- spell up 1
    [2] = {spellName = "spellname2", level = 50, cost = 5000}, -- spell up 2
  
    unlearnOldSpell = true, -- remove old spell?
  
    greetCallback = 'Welcome |PLAYERNAME|! Do you want to {upgrade} your '..cfg[0].spellName..' spell?' -- welcome message
}

npcHandler:setMessage(MESSAGE_GREET, cfg.greetCallback)

local function upgrade(cid, level)
    if getPlayerLevel(cid) < cfg[level].level then
        if doPlayerRemoveMoney(cid, cfg[level].cost) == true then
            playerLearnInstantSpell(cid, cfg[level].spellName) 
            selfSay('Ok, listen... [Your spell '..cfg[level-1].spellName..' advanced to '..cfg[level].spellName..']', cid)
          
            if cfg.unlearnOldSpell == true then
                doPlayerUnlearnInstantSpell(cid, cfg[level-1].spellName)
            end
        else
            selfSay('Poor guy... You think I upgrade it for free? Bring me 'cfg[level].cost' gold coins then I teach you how to use this spell better!', cid)
        end
    else
        selfSay('Doh, this upgrade required '..cfg[level].spellName..'level. Get some exp!', cid)
    end
end

function creatureSayCallback(cid, type, msg)

    if msgcontains(msg, 'upgrade') then

        if getPlayerLearnedInstantSpell(cid, cfg[2].spellName) == true then
            selfSay('You already have all upgrades.', cid)
        elseif getPlayerLearnedInstantSpell(cid, cfg[1].spellName) == true then
            selfSay('Do You want to upgrade your '..cfg[1].spellName.." to " ..cfg[2].spellName.." for "..cfg[2].cost.." gold coins?", cid)
            npcHandler.topic[cid] == 2
        elseif getPlayerLearnedInstantSpell(cid, cfg[0].spellName) == true then
            selfSay('Do You want to upgrade your '..cfg[0].spellName.." to " ..cfg[1].spellName.." for "..cfg[1].cost.." gold coins?", cid)
            npcHandler.topic[cid] == 1
        else
            selfSay('First learn '..cfg[0].spellName..' spell.', cid)
        end
    elseif msgcontains(msg, 'yes')  then
        if npcHandler.topic[cid] == 1 then
            upgrade(cid, 1)
        elseif npcHandler.topic[cid] == 2 then
            upgrade(cid, 2)
        end
        npcHandler.topic[cid] = 0 -- reset anyway
    elseif msgcontains(msg, 'no') and (npcHandler.topic[cid] == 1 or npcHandler.topic[cid] == 2) then
        selfSay('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end

    return true
end


npcHandler:addModule(FocusModule:new())
 
Last edited:
OP
I

Icaraii

Member
Joined
Jan 5, 2020
Messages
94
Reaction score
8
First of all, very nice script, very easy to understand and edit.

But I got a little problem:

[Warning - NpcScript::NpcScript] Can not load script: upgradespell1.lua
data/npc/scripts/upgradespell1.lua:34: ')' expected near 'cfg'

So I went and edit the line 34 to that (don't know if what I did is right):

Lua:
            selfSay('Poor guy... You think I upgrade it for free? Bring me '..cfg[level].cost..' gold coins then I teach you how to use this spell better!', cid)

and then, this problem appear:

[Warning - NpcScript::NpcScript] Can not load script: upgradespell1.lua
data/npc/scripts/upgradespell1.lua:49: '=' expected near '=='
 

SorketROrk

Member
Joined
Oct 14, 2020
Messages
36
Reaction score
7
Location
OTLand
First of all, very nice script, very easy to understand and edit.

But I got a little problem:



So I went and edit the line 34 to that (don't know if what I did is right):

Lua:
            selfSay('Poor guy... You think I upgrade it for free? Bring me '..cfg[level].cost..' gold coins then I teach you how to use this spell better!', cid)

and then, this problem appear:
Did you try to change "==" to "=" ? Apparently it is expecting that on line 49 if my understanding is correct.
 
OP
I

Icaraii

Member
Joined
Jan 5, 2020
Messages
94
Reaction score
8
Did you try to change "==" to "=" ? Apparently it is expecting that on line 49 if my understanding is correct.
I change == to = and got this error:

Lua Script Error: [Npc interface]
data/npc/scripts/upgradespell1.lua
data/npc/scripts/upgradespell1.lua:19: attempt to index global 'cfg' (a nil value)
stack traceback:
[C]: in function '__index'
data/npc/scripts/upgradespell1.lua:19: in main chunk
[C]: in function 'createNpc'
data/talkactions/scripts/place_npc.lua:11: in function <data/talkactions/scripts/place_npc.lua:1>
[Warning - NpcScript::NpcScript] Can not load script: upgradespell1.lua
 

Azakelis

Intermediate OT User
Joined
Feb 17, 2014
Messages
113
Solutions
9
Reaction score
146
Lua:
selfSay('Poor guy... You think I upgrade it for free? Bring me '..cfg[level].cost..' gold coins then I teach you how to use this spell better!', cid)
 
OP
I

Icaraii

Member
Joined
Jan 5, 2020
Messages
94
Reaction score
8
selfSay('Poor guy... You think I upgrade it for free? Bring me '..cfg[level].cost..' gold coins then I teach you how to use this spell better!', cid)
Thanks, but I solve this problem already, now the problem is:

[Warning - NpcScript::NpcScript] Can not load script: upgradespell1.lua
data/npc/scripts/upgradespell1.lua:49: '=' expected near '=='
If I change == to = and got this error:

Lua Script Error: [Npc interface]
data/npc/scripts/upgradespell1.lua
data/npc/scripts/upgradespell1.lua:19: attempt to index global 'cfg' (a nil value)
stack traceback:
[C]: in function '__index'
data/npc/scripts/upgradespell1.lua:19: in main chunk
[C]: in function 'createNpc'
data/talkactions/scripts/place_npc.lua:11: in function <data/talkactions/scripts/place_npc.lua:1>
[Warning - NpcScript::NpcScript] Can not load script: upgradespell1.lua
 
OP
I

Icaraii

Member
Joined
Jan 5, 2020
Messages
94
Reaction score
8
show me the script
Is the one Chev post it:

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 cfg = {
    [0] = {spellName = "spellname0"}, -- basic spell
    [1] = {spellName = "spellname1", level = 10, cost = 1000}, -- spell up 1
    [2] = {spellName = "spellname2", level = 50, cost = 5000}, -- spell up 2
 
    unlearnOldSpell = true, -- remove old spell?
 
    greetCallback = 'Welcome |PLAYERNAME|! Do you want to {upgrade} your '..cfg[0].spellName..' spell?' -- welcome message
}

npcHandler:setMessage(MESSAGE_GREET, cfg.greetCallback)

local function upgrade(cid, level)
    if getPlayerLevel(cid) < cfg[level].level then
        if doPlayerRemoveMoney(cid, cfg[level].cost) == true then
            playerLearnInstantSpell(cid, cfg[level].spellName)
            selfSay('Ok, listen... [Your spell '..cfg[level-1].spellName..' advanced to '..cfg[level].spellName..']', cid)
          
            if cfg.unlearnOldSpell == true then
                doPlayerUnlearnInstantSpell(cid, cfg[level-1].spellName)
            end
        else
            selfSay('Poor guy... You think I upgrade it for free? Bring me 'cfg[level].cost' gold coins then I teach you how to use this spell better!', cid)
        end
    else
        selfSay('Doh, this upgrade required '..cfg[level].spellName..'level. Get some exp!', cid)
    end
end

function creatureSayCallback(cid, type, msg)

    if msgcontains(msg, 'upgrade') then

        if getPlayerLearnedInstantSpell(cid, cfg[2].spellName) == true then
            selfSay('You already have all upgrades.', cid)
        elseif getPlayerLearnedInstantSpell(cid, cfg[1].spellName) == true then
            selfSay('Do You want to upgrade your '..cfg[1].spellName.." to " ..cfg[2].spellName.." for "..cfg[2].cost.." gold coins?", cid)
            npcHandler.topic[cid] == 2
        elseif getPlayerLearnedInstantSpell(cid, cfg[0].spellName) == true then
            selfSay('Do You want to upgrade your '..cfg[0].spellName.." to " ..cfg[1].spellName.." for "..cfg[1].cost.." gold coins?", cid)
            npcHandler.topic[cid] == 1
        else
            selfSay('First learn '..cfg[0].spellName..' spell.', cid)
        end
    elseif msgcontains(msg, 'yes')  then
        if npcHandler.topic[cid] == 1 then
            upgrade(cid, 1)
        elseif npcHandler.topic[cid] == 2 then
            upgrade(cid, 2)
        end
        npcHandler.topic[cid] = 0 -- reset anyway
    elseif msgcontains(msg, 'no') and (npcHandler.topic[cid] == 1 or npcHandler.topic[cid] == 2) then
        selfSay('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end

    return true
end


npcHandler:addModule(FocusModule:new())
 

SorketROrk

Member
Joined
Oct 14, 2020
Messages
36
Reaction score
7
Location
OTLand
Maybe there are other ways to achieve the result you're looking for.

Could be item on use to learn a spell ( your upgraded version of the spell ) and then make use of some function to Unlearn the spell 'Exori Flam'. This item could be bought from a NPC, if you wish so.

Also set lvl requirement to use the item like for lvl 30 like you asked for.

Just sharing my thoughts on this matter, you can always try to breakdown your issue to smaller ones and see if you get anywhere instead of solving a big problem 😃
 
OP
I

Icaraii

Member
Joined
Jan 5, 2020
Messages
94
Reaction score
8
Maybe there are other ways to achieve the result you're looking for.

Could be item on use to learn a spell ( your upgraded version of the spell ) and then make use of some function to Unlearn the spell 'Exori Flam'. This item could be bought from a NPC, if you wish so.

Also set lvl requirement to use the item like for lvl 30 like you asked for.

Just sharing my thoughts on this matter, you can always try to breakdown your issue to smaller ones and see if you get anywhere instead of solving a big problem 😃
That is actually a good idea, I could use papers to be the item that will teach a new upgrade and I could put it to be owned by doing quests, I will try it out
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
4,983
Solutions
286
Reaction score
3,103
Is the one Chev post it:

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 cfg = {
    [0] = {spellName = "spellname0"}, -- basic spell
    [1] = {spellName = "spellname1", level = 10, cost = 1000}, -- spell up 1
    [2] = {spellName = "spellname2", level = 50, cost = 5000}, -- spell up 2
 
    unlearnOldSpell = true -- remove old spell?
 
    greetCallback = 'Welcome |PLAYERNAME|! Do you want to {upgrade} your '..cfg[0].spellName..' spell?' -- welcome message
}

npcHandler:setMessage(MESSAGE_GREET, cfg.greetCallback)

local function upgrade(cid, level)
    if getPlayerLevel(cid) < cfg[level].level then
        if doPlayerRemoveMoney(cid, cfg[level].cost) == true then
            playerLearnInstantSpell(cid, cfg[level].spellName)
            selfSay('Ok, listen... [Your spell '..cfg[level-1].spellName..' advanced to '..cfg[level].spellName..']', cid)
          
            if cfg.unlearnOldSpell == true then
                doPlayerUnlearnInstantSpell(cid, cfg[level-1].spellName)
            end
        else
            selfSay('Poor guy... You think I upgrade it for free? Bring me 'cfg[level].cost' gold coins then I teach you how to use this spell better!', cid)
        end
    else
        selfSay('Doh, this upgrade required '..cfg[level].spellName..'level. Get some exp!', cid)
    end
end

function creatureSayCallback(cid, type, msg)

    if msgcontains(msg, 'upgrade') then

        if getPlayerLearnedInstantSpell(cid, cfg[2].spellName) == true then
            selfSay('You already have all upgrades.', cid)
        elseif getPlayerLearnedInstantSpell(cid, cfg[1].spellName) == true then
            selfSay('Do You want to upgrade your '..cfg[1].spellName.." to " ..cfg[2].spellName.." for "..cfg[2].cost.." gold coins?", cid)
            npcHandler.topic[cid] == 2
        elseif getPlayerLearnedInstantSpell(cid, cfg[0].spellName) == true then
            selfSay('Do You want to upgrade your '..cfg[0].spellName.." to " ..cfg[1].spellName.." for "..cfg[1].cost.." gold coins?", cid)
            npcHandler.topic[cid] == 1
        else
            selfSay('First learn '..cfg[0].spellName..' spell.', cid)
        end
    elseif msgcontains(msg, 'yes')  then
        if npcHandler.topic[cid] == 1 then
            upgrade(cid, 1)
        elseif npcHandler.topic[cid] == 2 then
            upgrade(cid, 2)
        end
        npcHandler.topic[cid] = 0 -- reset anyway
    elseif msgcontains(msg, 'no') and (npcHandler.topic[cid] == 1 or npcHandler.topic[cid] == 2) then
        selfSay('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end

    return true
end


npcHandler:addModule(FocusModule:new())
Lua can't call the same table it's being created from.
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 cfg = {
	[0] = {spellName = "spellname0"}, -- basic spell
	[1] = {spellName = "spellname1", level = 10, cost = 1000}, -- spell up 1
	[2] = {spellName = "spellname2", level = 50, cost = 5000}, -- spell up 2
	
	unlearnOldSpell = true, -- remove old spell?
}

local function upgrade(cid, level)
	if getPlayerLevel(cid) < cfg[level].level then
		if doPlayerRemoveMoney(cid, cfg[level].cost) == true then
			playerLearnInstantSpell(cid, cfg[level].spellName)
			selfSay('Ok, listen... [Your spell '..cfg[level-1].spellName..' advanced to '..cfg[level].spellName..']', cid)
		
			if cfg.unlearnOldSpell == true then
				doPlayerUnlearnInstantSpell(cid, cfg[level-1].spellName)
			end
		else
			selfSay('Poor guy... You think I upgrade it for free? Bring me 'cfg[level].cost' gold coins then I teach you how to use this spell better!', cid)
		end
	else
		selfSay('Doh, this upgrade required '..cfg[level].spellName..'level. Get some exp!', cid)
	end
end

function creatureSayCallback(cid, type, msg)
	if msgcontains(msg, 'upgrade') then
	
		if getPlayerLearnedInstantSpell(cid, cfg[2].spellName) == true then
			selfSay('You already have all upgrades.', cid)
		elseif getPlayerLearnedInstantSpell(cid, cfg[1].spellName) == true then
			selfSay('Do You want to upgrade your '..cfg[1].spellName.." to " ..cfg[2].spellName.." for "..cfg[2].cost.." gold coins?", cid)
			npcHandler.topic[cid] == 2
		elseif getPlayerLearnedInstantSpell(cid, cfg[0].spellName) == true then
			selfSay('Do You want to upgrade your '..cfg[0].spellName.." to " ..cfg[1].spellName.." for "..cfg[1].cost.." gold coins?", cid)
			npcHandler.topic[cid] == 1
		else
			selfSay('First learn '..cfg[0].spellName..' spell.', cid)
		end
	elseif msgcontains(msg, 'yes')  then
		if npcHandler.topic[cid] == 1 then
			upgrade(cid, 1)
		elseif npcHandler.topic[cid] == 2 then
			upgrade(cid, 2)
		end
		npcHandler.topic[cid] = 0 -- reset anyway
	elseif msgcontains(msg, 'no') and (npcHandler.topic[cid] == 1 or npcHandler.topic[cid] == 2) then
		selfSay('Ok then.', cid)
		npcHandler.topic[cid] = 0
	end
	
	return true
end

npcHandler:setMessage(MESSAGE_GREET, 'Welcome |PLAYERNAME|! Do you want to {upgrade} your '..cfg[0].spellName..' spell?')
npcHandler:addModule(FocusModule:new())
 
OP
I

Icaraii

Member
Joined
Jan 5, 2020
Messages
94
Reaction score
8
Lua can't call the same table it's being created from.
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 cfg = {
    [0] = {spellName = "spellname0"}, -- basic spell
    [1] = {spellName = "spellname1", level = 10, cost = 1000}, -- spell up 1
    [2] = {spellName = "spellname2", level = 50, cost = 5000}, -- spell up 2
   
    unlearnOldSpell = true, -- remove old spell?
}

local function upgrade(cid, level)
    if getPlayerLevel(cid) < cfg[level].level then
        if doPlayerRemoveMoney(cid, cfg[level].cost) == true then
            playerLearnInstantSpell(cid, cfg[level].spellName)
            selfSay('Ok, listen... [Your spell '..cfg[level-1].spellName..' advanced to '..cfg[level].spellName..']', cid)
       
            if cfg.unlearnOldSpell == true then
                doPlayerUnlearnInstantSpell(cid, cfg[level-1].spellName)
            end
        else
            selfSay('Poor guy... You think I upgrade it for free? Bring me 'cfg[level].cost' gold coins then I teach you how to use this spell better!', cid)
        end
    else
        selfSay('Doh, this upgrade required '..cfg[level].spellName..'level. Get some exp!', cid)
    end
end

function creatureSayCallback(cid, type, msg)
    if msgcontains(msg, 'upgrade') then
   
        if getPlayerLearnedInstantSpell(cid, cfg[2].spellName) == true then
            selfSay('You already have all upgrades.', cid)
        elseif getPlayerLearnedInstantSpell(cid, cfg[1].spellName) == true then
            selfSay('Do You want to upgrade your '..cfg[1].spellName.." to " ..cfg[2].spellName.." for "..cfg[2].cost.." gold coins?", cid)
            npcHandler.topic[cid] == 2
        elseif getPlayerLearnedInstantSpell(cid, cfg[0].spellName) == true then
            selfSay('Do You want to upgrade your '..cfg[0].spellName.." to " ..cfg[1].spellName.." for "..cfg[1].cost.." gold coins?", cid)
            npcHandler.topic[cid] == 1
        else
            selfSay('First learn '..cfg[0].spellName..' spell.', cid)
        end
    elseif msgcontains(msg, 'yes')  then
        if npcHandler.topic[cid] == 1 then
            upgrade(cid, 1)
        elseif npcHandler.topic[cid] == 2 then
            upgrade(cid, 2)
        end
        npcHandler.topic[cid] = 0 -- reset anyway
    elseif msgcontains(msg, 'no') and (npcHandler.topic[cid] == 1 or npcHandler.topic[cid] == 2) then
        selfSay('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end
   
    return true
end

npcHandler:setMessage(MESSAGE_GREET, 'Welcome |PLAYERNAME|! Do you want to {upgrade} your '..cfg[0].spellName..' spell?')
npcHandler:addModule(FocusModule:new())
I test it and this error appear:
[Warning - NpcScript::NpcScript] Can not load script: upgradespell1.lua
data/npc/scripts/upgradespell1.lua:18: unexpected symbol near '}'
Also, this script don't allow me to do several upgrade for different spells, I would have to create one npc for each spell.
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
4,983
Solutions
286
Reaction score
3,103
I test it and this error appear:
Fixed all of the errors.
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 cfg = {
	[0] = {spellName = "light"}, -- basic spell
	[1] = {spellName = "great light", level = 10, cost = 1000}, -- spell up 1
	[2] = {spellName = "ultimate light", level = 50, cost = 5000}, -- spell up 2
	
	unlearnOldSpell = true -- remove old spell?
}

local function upgrade(cid, level)
	if getPlayerLevel(cid) < cfg[level].level then
		if doPlayerRemoveMoney(cid, cfg[level].cost) == true then
			playerLearnInstantSpell(cid, cfg[level].spellName)
			selfSay('Ok, listen... [Your spell '..cfg[level-1].spellName..' advanced to '..cfg[level].spellName..']', cid)
		
			if cfg.unlearnOldSpell == true then
				doPlayerUnlearnInstantSpell(cid, cfg[level-1].spellName)
			end
		else
			selfSay('Poor guy... You think I upgrade it for free? Bring me ' .. cfg[level].cost .. ' gold coins then I teach you how to use this spell better!', cid)
		end
	else
		selfSay('Doh, this upgrade required '..cfg[level].spellName..'level. Get some exp!', cid)
	end
end

function creatureSayCallback(cid, type, msg)
	if msgcontains(msg, 'upgrade') then
		if getPlayerLearnedInstantSpell(cid, cfg[2].spellName) == true then
			selfSay('You already have all upgrades.', cid)
		elseif getPlayerLearnedInstantSpell(cid, cfg[1].spellName) == true then
			selfSay('Do You want to upgrade your '..cfg[1].spellName.." to " ..cfg[2].spellName.." for "..cfg[2].cost.." gold coins?", cid)
			npcHandler.topic[cid] = 2
		elseif getPlayerLearnedInstantSpell(cid, cfg[0].spellName) == true then
			selfSay('Do You want to upgrade your '..cfg[0].spellName.." to " ..cfg[1].spellName.." for "..cfg[1].cost.." gold coins?", cid)
			npcHandler.topic[cid] = 1
		else
			selfSay('First learn '..cfg[0].spellName..' spell.', cid)
		end
	elseif msgcontains(msg, 'yes')  then
		if npcHandler.topic[cid] == 1 then
			upgrade(cid, 1)
		elseif npcHandler.topic[cid] == 2 then
			upgrade(cid, 2)
		end
		npcHandler.topic[cid] = 0 -- reset anyway
	elseif msgcontains(msg, 'no') and (npcHandler.topic[cid] == 1 or npcHandler.topic[cid] == 2) then
		selfSay('Ok then.', cid)
		npcHandler.topic[cid] = 0
	end
	
	return true
end

npcHandler:setMessage(MESSAGE_GREET, 'Welcome |PLAYERNAME|! Do you want to {upgrade} your '..cfg[0].spellName..' spell?')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Also, this script don't allow me to do several upgrade for different spells, I would have to create one npc for each spell.
I'm not in the right headspace to create that right now.
withdrawal symptoms suck.
 
OP
I

Icaraii

Member
Joined
Jan 5, 2020
Messages
94
Reaction score
8
Fixed all of the errors.
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 cfg = {
    [0] = {spellName = "light"}, -- basic spell
    [1] = {spellName = "great light", level = 10, cost = 1000}, -- spell up 1
    [2] = {spellName = "ultimate light", level = 50, cost = 5000}, -- spell up 2
   
    unlearnOldSpell = true -- remove old spell?
}

local function upgrade(cid, level)
    if getPlayerLevel(cid) < cfg[level].level then
        if doPlayerRemoveMoney(cid, cfg[level].cost) == true then
            playerLearnInstantSpell(cid, cfg[level].spellName)
            selfSay('Ok, listen... [Your spell '..cfg[level-1].spellName..' advanced to '..cfg[level].spellName..']', cid)
       
            if cfg.unlearnOldSpell == true then
                doPlayerUnlearnInstantSpell(cid, cfg[level-1].spellName)
            end
        else
            selfSay('Poor guy... You think I upgrade it for free? Bring me ' .. cfg[level].cost .. ' gold coins then I teach you how to use this spell better!', cid)
        end
    else
        selfSay('Doh, this upgrade required '..cfg[level].spellName..'level. Get some exp!', cid)
    end
end

function creatureSayCallback(cid, type, msg)
    if msgcontains(msg, 'upgrade') then
        if getPlayerLearnedInstantSpell(cid, cfg[2].spellName) == true then
            selfSay('You already have all upgrades.', cid)
        elseif getPlayerLearnedInstantSpell(cid, cfg[1].spellName) == true then
            selfSay('Do You want to upgrade your '..cfg[1].spellName.." to " ..cfg[2].spellName.." for "..cfg[2].cost.." gold coins?", cid)
            npcHandler.topic[cid] = 2
        elseif getPlayerLearnedInstantSpell(cid, cfg[0].spellName) == true then
            selfSay('Do You want to upgrade your '..cfg[0].spellName.." to " ..cfg[1].spellName.." for "..cfg[1].cost.." gold coins?", cid)
            npcHandler.topic[cid] = 1
        else
            selfSay('First learn '..cfg[0].spellName..' spell.', cid)
        end
    elseif msgcontains(msg, 'yes')  then
        if npcHandler.topic[cid] == 1 then
            upgrade(cid, 1)
        elseif npcHandler.topic[cid] == 2 then
            upgrade(cid, 2)
        end
        npcHandler.topic[cid] = 0 -- reset anyway
    elseif msgcontains(msg, 'no') and (npcHandler.topic[cid] == 1 or npcHandler.topic[cid] == 2) then
        selfSay('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end
   
    return true
end

npcHandler:setMessage(MESSAGE_GREET, 'Welcome |PLAYERNAME|! Do you want to {upgrade} your '..cfg[0].spellName..' spell?')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

I'm not in the right headspace to create that right now.
withdrawal symptoms suck.
First of all I wish you get better soon.

Second of all, I'm having so much trouble with learn spell situation:
11:46 Adam: Welcome Character Teste! Do you want to upgrade your Lesser Death Strike spell?
11:46 Character Teste [105]: upgrade
11:46 Adam: First learn Lesser Death Strike spell.
I'm trying to find a script so I can make the character learn the first spell LOL
 
Top