• 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

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
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
 
First of all I wish you get better soon.

Second of all, I'm having so much trouble with learn spell situation:

I'm trying to find a script so I can make the character learn the first spell LOL
untested 🤷‍♂️
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 spellCost = 500
local spellName = "lesser death strike"

function creatureSayCallback(cid, type, msg)
	if msgcontains(msg, spellName) then
		if getPlayerLearnedInstantSpell(cid, spellName) == true then
			selfSay("You have already learned this spell.", cid)
			return true
		end
		selfSay("Do you want to learn " .. spellName .. " for " .. spellCost .. " gold coins?", cid)
		npcHandler.topic[cid] = 1
		
	elseif npcHandler.topic[cid] == 1 then
		if not msgcontains(msg, "yes") then
			selfSay("Ok then.", cid)
			npcHandler.topic[cid] = 0
			return true
		end
		if player:getMoney() < spellCost then
			selfSay("You do not have enough money.", cid)
			npcHandler.topic[cid] = 0
			return true
		end
		player:removeMoney(spellCost)
		playerLearnInstantSpell(cid, spellName)
		selfSay("Congratulations! You have learned " .. spellName .. ".", cid)
		npcHandler.topic[cid] = 0
		
	end	
	return true
end

npcHandler:setMessage(MESSAGE_GREET, "Welcome |PLAYERNAME|! I literally only sell {spellName}.")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
untested 🤷‍♂️
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 spellCost = 500
local spellName = "lesser death strike"

function creatureSayCallback(cid, type, msg)
    if msgcontains(msg, spellName) then
        if getPlayerLearnedInstantSpell(cid, spellName) == true then
            selfSay("You have already learned this spell.", cid)
            return true
        end
        selfSay("Do you want to learn " .. spellName .. " for " .. spellCost .. " gold coins?", cid)
        npcHandler.topic[cid] = 1
      
    elseif npcHandler.topic[cid] == 1 then
        if not msgcontains(msg, "yes") then
            selfSay("Ok then.", cid)
            npcHandler.topic[cid] = 0
            return true
        end
        if player:getMoney() < spellCost then
            selfSay("You do not have enough money.", cid)
            npcHandler.topic[cid] = 0
            return true
        end
        player:removeMoney(spellCost)
        playerLearnInstantSpell(cid, spellName)
        selfSay("Congratulations! You have learned " .. spellName .. ".", cid)
        npcHandler.topic[cid] = 0
      
    end  
    return true
end

npcHandler:setMessage(MESSAGE_GREET, "Welcome |PLAYERNAME|! I literally only sell {spellName}.")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
The npc did not take my money when I was trying to learn the first spells

12:09 Testenpc: Welcome Character Teste! I literally only sell spellName.
12:09 Character Teste [105]: lesser death strike
12:09 Testenpc: Do you want to learn lesser death strike for 500 gold coins?
12:09 Character Teste [105]: yes
 
The npc did not take my money when I was trying to learn the first spells
ugh.

It's cuz it's missing the standard stuff.

change
Lua:
local function creatureSayCallback(cid, type, msg)
for
Lua:
local function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	end
	
	local player = Player(cid)
 
ugh.

It's cuz it's missing the standard stuff.

change
Lua:
local function creatureSayCallback(cid, type, msg)
for
Lua:
local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
  
    local player = Player(cid)
ok, this script works perfectly, but the upgrade spell did not work.

12:13 Adam: Welcome Character Teste! Do you want to upgrade your Lesser Death Strike spell?
12:13 Character Teste [105]: upgrade
12:13 Adam: Do You want to upgrade your Lesser Death Strike to Fire Explosive Spider for 1000 gold coins?
12:13 Character Teste [105]: yes
12:13 Adam: Doh, this upgrade required Fire Explosive Spiderlevel. Get some exp!
I'm testing it on a character lvl 105 and the lvl required to upgrade the spell is lvl 10:
[1] = {spellName = "Fire Explosive Spider", level = 10, cost = 1000}, -- spell up 1

I believe @Levi999x is trying to create the upgrade script by using itens, and that will be good for me, so lets see if he can make it.
 
ok, this script works perfectly, but the upgrade spell did not work.


I'm testing it on a character lvl 105 and the lvl required to upgrade the spell is lvl 10:


I believe @Levi999x is trying to create the upgrade script by using itens, and that will be good for me, so lets see if he can make it.
change
Lua:
if getPlayerLevel(cid) < cfg[level].level then
for
Lua:
if getPlayerLevel(cid) >= cfg[level].level then
 
show current script?
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 = "Lesser Death Strike"}, -- basic spell
    [1] = {spellName = "Fire Explosive Spider", level = 10, cost = 1000}, -- spell up 1
    [2] = {spellName = "Venomous Explosive Spider", 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, when I'm going to upgrade the spell for the second time, it says the name of the base spell, not the spell I current have:

12:22 Adam: Welcome Character Teste! Do you want to upgrade your Lesser Death Strike spell?
12:22 Character Teste [105]: upgrade
12:22 Adam: Do You want to upgrade your Lesser Death Strike to Fire Explosive Spider for 1000 gold coins?
12:22 Character Teste [105]: yes
12:22 Adam: Ok, listen... [Your spell Lesser Death Strike advanced to Fire Explosive Spider]
12:24 Character Teste [105]: hi
12:24 Character Teste [105]: bye
12:24 Adam: Good bye, Character Teste.
12:24 Character Teste [105]: hi
12:24 Adam: Welcome Character Teste! Do you want to upgrade your Lesser Death Strike spell? <-- here it should be Fire Explosive Spider -->
12:24 Character Teste [105]: upgrade
12:24 Adam: Do You want to upgrade your Fire Explosive Spider to Venomous Explosive Spider for 5000 gold coins?
 
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 = "Lesser Death Strike"}, -- basic spell
    [1] = {spellName = "Fire Explosive Spider", level = 10, cost = 1000}, -- spell up 1
    [2] = {spellName = "Venomous Explosive Spider", 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, when I'm going to upgrade the spell for the second time, it says the name of the base spell, not the spell I current have:
lmao. this is literally why I hate fixing/upgrading other people's scripts.
I should've just made this from scratch.

I don't think this script is even what you originally asked for in this thread.
But w/e.

Here's the fixes.
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 = "Lesser Death Strike"}, -- basic spell
	[1] = {spellName = "Fire Explosive Spider", level = 10, cost = 1000}, -- spell up 1
	[2] = {spellName = "Venomous Explosive Spider", level = 50, cost = 5000}, -- spell up 2
	
	unlearnOldSpell = true -- remove old spell?
}

local function upgrade(cid, level)
	local player = Player(cid)
	if player:getLevel() >= cfg[level].level then
		if player:removeMoney(cfg[level].cost) == true then
			player:learnSpell(cfg[level].spellName)
			selfSay('Ok, listen... [Your spell '..cfg[level-1].spellName..' advanced to '..cfg[level].spellName..']', cid)
			if cfg.unlearnOldSpell == true then
				player:forgetSpell(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

local function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	end
	
	local player = Player(cid)
	
	if msgcontains(msg, 'upgrade') then
		
		if player:hasLearnedSpell(cfg[2].spellName) then
			selfSay('You already have all upgrades.', cid)
		elseif player:hasLearnedSpell(cfg[1].spellName)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 player:hasLearnedSpell(cfg[0].spellName) 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} a spell?')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
lmao. this is literally why I hate fixing/upgrading other people's scripts.
I should've just made this from scratch.

I don't think this script is even what you originally asked for in this thread.
But w/e.

Here's the fixes.
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 = "Lesser Death Strike"}, -- basic spell
    [1] = {spellName = "Fire Explosive Spider", level = 10, cost = 1000}, -- spell up 1
    [2] = {spellName = "Venomous Explosive Spider", level = 50, cost = 5000}, -- spell up 2
  
    unlearnOldSpell = true -- remove old spell?
}

local function upgrade(cid, level)
    local player = Player(cid)
    if player:getLevel() >= cfg[level].level then
        if player:removeMoney(cfg[level].cost) == true then
            player:learnSpell(cfg[level].spellName)
            selfSay('Ok, listen... [Your spell '..cfg[level-1].spellName..' advanced to '..cfg[level].spellName..']', cid)
            if cfg.unlearnOldSpell == true then
                player:forgetSpell(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

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
  
    local player = Player(cid)
  
    if msgcontains(msg, 'upgrade') then
      
        if player:hasLearnedSpell(cfg[2].spellName) then
            selfSay('You already have all upgrades.', cid)
        elseif player:hasLearnedSpell(cfg[1].spellName)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 player:hasLearnedSpell(cfg[0].spellName) 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} a spell?')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
It wasn't what I asked, but it kinda do half of what I needed, so it's kinda okay.

The npc won't answer my "hi" message. No errors on TFS
 
It wasn't what I asked, but it kinda do half of what I needed, so it's kinda okay.

The npc won't answer my "hi" message. No errors on TFS
I copy paste failed.

add this at the very bottom of the script.
Lua:
npcHandler:addModule(FocusModule:new())
 
Back
Top