• 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 Upgrade. HELP

Klank

Althea ¤ A New World Developer
Joined
Feb 21, 2008
Messages
1,093
Reaction score
659
Location
Norway
Hello.

I was thiking of a uniqe spell system on my ot. That players have to upgrade there spells to get them stronger. (0/5)

And at each level they would get 1 spell point.
But i wonder if anyone got a script for a npc that you can buy this upgrade for 1 spell point.

Also script for spell point each lvl.

This is just to get a harder start.

Thank you. :D
 
So, for every level they get 1 point, like a coin or something invisible? Then when they are for example lvl 20, they have 20 points and buy 20 upgrades for spells?
 
Yeah. but no coins. It will be invisible, and you get check your spell point status by !sp or !spellpoints. Yeah but i havnt figoure out if i want from lvl 8 or lvl 1. so lvl 20 = 12 points. It wont be a hard spell feature.
 
It's usefull to know, from lvl 1 I can just check for level, else I have to use storage. One more thing, the spells, they are have 1 upgrade or more and if more, how much?
 
I think i will go from lvl 8+. The start shall be a little hard. Anway, the upgrades should be (0/5) where 1 point is 10 %. So we lower the orginal spell dmg with 50%. so when the upgrades are 5/5 its 100 % dmg again. I suddently got an idea now about a book which shows how your status is on all ur spells and how many points you got. How does that sound?
 
Lets just start with the npc first, will take a few hours to make :p Btw with the idea I have in mind you do have to edit all the spells you want to be able to upgrade, won't be hard tho.
 
I have to say first of all, im not a scripter :p Im kinda new in all these mapping and scripting. Hmm, few hours? :s Do you wanna do that for free? xD I have a scripter dude which is with me starting this server. so he can do that spell part. But the npc dude is a problem for us.
 
Upgrader.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Upgrader" script="spellupgrade.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="140" head="95" body="113" legs="95" feet="113" addons="0"/>
	<parameters>
		<parameter key="message_greet" value="Hello |PLAYERNAME|. I can upgrade your spells, tell me the spell you want to upgrade, look in the {list} which spells you can upgrade or let me know if you need more {info}."/>
	</parameters>
</npc>

spellupgrade.lua
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 creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
 
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	local storage = 16002
 
local sorcspells = {
	["Flame Strike"] = {cost = 1, storage = 18001}, 	
	["Hells Core"] = {cost = 1, storage = 18002} 
}
local druidspells = {
	["Flame Strike"] = {cost = 1, storage = 18101}, 	
	["Eternal Winter"] = {cost = 1, storage = 18102} 
}
local pallyspells = {
	["Ethereal Spear"] = {cost = 1, storage = 18201}, 	
	["Divine Caldera"] = {cost = 1, storage = 18202} 
}
local knightspells = {
	["Berserk"] = {cost = 1, storage = 18301}, 	
	["Fierce Berserk"] = {cost = 1, storage = 18302} 
}
 
	if(getPlayerVocation(cid) == 1) or (getPlayerVocation(cid) == 5) then
		x = sorcspells[msg]
	end
	if(getPlayerVocation(cid) == 2) or (getPlayerVocation(cid) == 6) then
		x = druidspells[msg]
	end
	if(getPlayerVocation(cid) == 3) or (getPlayerVocation(cid) == 7) then
		x = pallyspells[msg]
	end
	if(getPlayerVocation(cid) == 4) or (getPlayerVocation(cid) == 8) then
		x = knightspells[msg]
	end
 
	if x then 
		if getPlayerStorageValue(cid, storage) >= x.cost then
			if getPlayerStorageValue(cid, x.storage) < 5 then
				if getPlayerStorageValue(cid, x.storage) == -1 then
					setPlayerStorageValue(cid, x.storage, 0)
				end
				setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - x.cost)
				setPlayerStorageValue(cid, x.storage, getPlayerStorageValue(cid, x.storage) + 1)
				selfSay('You have upgraded the spell '..msg..', the upgrade status of this spell is now: '..getPlayerStorageValue(cid, x.storage)..'. ', cid)
			else
				selfSay('You already upgraded this spell 5 times.', cid)
			end
		else
			selfSay('You don\'t have enough points to upgrade this spell.', cid)
		end
	end
 
	local info = (msgcontains(msg, 'info'))
	if info then
		selfSay('Each time you level up, you receive 1 point, with those points you can upgrade your spells. You have now '..getPlayerStorageValue(cid, storage)..' points. You can see the spells you can upgrade in the {list}.', cid)
	end
 
	local list = (msgcontains(msg, 'list'))
	if list then
		if(getPlayerVocation(cid) == 1) or (getPlayerVocation(cid) == 5) then
		text = 'Upgrade spells for Sorcerers\n'
			for i, x in pairs(sorcspells) do
				text = text .. "\n" .. i .. ""
			end
			doShowTextDialog(cid, 6120, "" .. text)
		end
		if(getPlayerVocation(cid) == 2) or (getPlayerVocation(cid) == 6) then
		text = 'Upgrade spells for Druids\n'
			for i, x in pairs(druidspells) do
				text = text .. "\n" .. i .. ""
			end
			doShowTextDialog(cid, 6120, "" .. text)
		end
		if(getPlayerVocation(cid) == 3) or (getPlayerVocation(cid) == 7) then
		text = 'Upgrade spells for Paladins\n'
			for i, x in pairs(pallyspells) do
				text = text .. "\n" .. i .. ""
			end
			doShowTextDialog(cid, 6120, "" .. text)
		end
		if(getPlayerVocation(cid) == 4) or (getPlayerVocation(cid) == 8) then
		text = 'Upgrade spells for Knights\n'
			for i, x in pairs(knightspells) do
				text = text .. "\n" .. i .. ""
			end
			doShowTextDialog(cid, 6120, "" .. text)
		end
	end
 
	if not x and not list and not info then
		selfSay('You can\'t upgrade this spell.', cid)
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

I did 2 spells as example for each vocation, for adding more spells, just copy and past 1 of the lines, don't forget to add a , at the end of every line except from the last one and change the storage.
The cost is for incase you want a spell upgrade to cost more points, if you want every spell to be 1 point, then just leave it all to 1.
It checks for vocations, so for god characters it won't work.
Add this to creaturescripts for getting points for each level, don't forget to also add the name to login.lua
Lua:
function onAdvance(cid, skill, oldlevel, newlevel)
local storage = 16002

    	if skill == SKILL_LEVEL then
		if getPlayerStorageValue(cid, storage) == -1 then
			setPlayerStorageValue(cid, storage, 0)
		end
		setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) + 1)
   	end
	return true
end

For the spell edit, look at the storage in the spell lines. Use that storage in the spells, just check for storage value 1, 2, 3, 4 and 5 and use 5 different stronger combats for each storagevalue check.
If you don't understand something or you have problems making it, let me know and I will show you an example.
 
Last edited:
Thanks a lot Limos. I will think i will test it out tomorrow, when i got my scripter and hoster online. So we can test it online x)

And if i get any problems ill PM you ;)

You already got a rep+

I just found a new name for server. "Althea" Seems cool? :p
 
Thank you Limos! It works perfectly :)

But can you help me make an example for the spell edits? I've never done it before :/
 
Last edited:
If you open a spell, you see it looks like this
Lua:
function onCastSpell(cid, var)
	return doCombat(cid, combat, var)
end

Here it does 1 combat, so now you have to make more combats.
Hells core example:
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
setAttackFormula(combat, COMBAT_FORMULA_LEVELMAGIC, 5, 5, 7, 14)

local area = createCombatArea(AREA_CROSS5X5)
setCombatArea(combat, area)
To make more combats you can copy and paste it, make it stronger and call it for example combat2, combat3, combat4 etc.
Example:
Lua:
local combat2 = createCombatObject()
setCombatParam(combat2, COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
setCombatParam(combat2, COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
setAttackFormula(combat2, COMBAT_FORMULA_LEVELMAGIC, 5, 5, 7, 14)

local area = createCombatArea(AREA_CROSS5X5)
setCombatArea(combat2, area)

Then check for the storage and do the stronger combats, for example like this:
Lua:
function onCastSpell(cid, var)
local storage = 18002

	if getPlayerStorageValue(cid, storage) == -1 then
		doCombat(cid, combat, var)
	elseif getPlayerStorageValue(cid, storage) == 1 then
		doCombat(cid, combat2, var)
	elseif getPlayerStorageValue(cid, storage) == 2 then
		doCombat(cid, combat3, var)
	elseif getPlayerStorageValue(cid, storage) == 3 then
		doCombat(cid, combat4, var)
	elseif getPlayerStorageValue(cid, storage) == 4 then
		doCombat(cid, combat5, var)
	else
		doCombat(cid, combat6, var)
	end
	return true
end

Btw, I edited the creaturescript and added some extra thing to the npc so if someone asks for info the npc also tells how much points someone has.
 
I have updated the NPC, now it also shows in the list the upgrade status of each spell, so you don't have to use the book. Ofc, if you want I can add it anyway.
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 creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
 
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	local storage = 16002


local sorcspells = {
	["Flame Strike"] = {cost = 1, storage = 18001}, 	
	["Hells Core"] = {cost = 1, storage = 18002} 
}
local druidspells = {
	["Flame Strike"] = {cost = 1, storage = 18101}, 	
	["Eternal Winter"] = {cost = 1, storage = 18102} 
}
local pallyspells = {
	["Ethereal Spear"] = {cost = 1, storage = 18201}, 	
	["Divine Caldera"] = {cost = 1, storage = 18202} 
}
local knightspells = {
	["Berserk"] = {cost = 1, storage = 18301}, 	
	["Fierce Berserk"] = {cost = 1, storage = 18302} 
}

	for v = 18000, 18400 do
		if getPlayerStorageValue(cid, v) == -1 then
			setPlayerStorageValue(cid, v, 0)
		end
	end

	if(getPlayerVocation(cid) == 1) or (getPlayerVocation(cid) == 5) then
		x = sorcspells[msg]
	end
	if(getPlayerVocation(cid) == 2) or (getPlayerVocation(cid) == 6) then
		x = druidspells[msg]
	end
	if(getPlayerVocation(cid) == 3) or (getPlayerVocation(cid) == 7) then
		x = pallyspells[msg]
	end
	if(getPlayerVocation(cid) == 4) or (getPlayerVocation(cid) == 8) then
		x = knightspells[msg]
	end

	if x then 
		if getPlayerStorageValue(cid, storage) >= x.cost then
			if getPlayerStorageValue(cid, x.storage) < 5 then
				setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - x.cost)
				setPlayerStorageValue(cid, x.storage, getPlayerStorageValue(cid, x.storage) + 1)
				selfSay('You have upgraded the spell '..msg..', the upgrade status of this spell is now: '..getPlayerStorageValue(cid, x.storage)..'. ', cid)
			else
				selfSay('You already upgraded this spell 5 times.', cid)
			end
		else
			selfSay('You don\'t have enough points to upgrade this spell.', cid)
		end
	end

	local info = (msgcontains(msg, 'info'))
	if info then
		selfSay('Each time you level up, you receive 1 point, with those points you can upgrade your spells. You have currently '..getPlayerStorageValue(cid, storage)..' points. You can see the spells you can upgrade in the {list}.', cid)
	end

	local list = (msgcontains(msg, 'list'))
	if list then
		if(getPlayerVocation(cid) == 1) or (getPlayerVocation(cid) == 5) then
		text = 'Upgrade spells for Sorcerers\n'
			for i, x in pairs(sorcspells) do
				text = text .. "\n" .. i .. " ["..getPlayerStorageValue(cid, x.storage).."]"
			end
			doShowTextDialog(cid, 6120, "" .. text)
		end
		if(getPlayerVocation(cid) == 2) or (getPlayerVocation(cid) == 6) then
		text = 'Upgrade spells for Druids\n'
			for i, x in pairs(druidspells) do
				text = text .. "\n" .. i .. " ["..getPlayerStorageValue(cid, x.storage).."]"
			end
			doShowTextDialog(cid, 6120, "" .. text)
		end
		if(getPlayerVocation(cid) == 3) or (getPlayerVocation(cid) == 7) then
		text = 'Upgrade spells for Paladins\n'
			for i, x in pairs(pallyspells) do
				text = text .. "\n" .. i .. " ["..getPlayerStorageValue(cid, x.storage).."]"
			end
			doShowTextDialog(cid, 6120, "" .. text)
		end
		if(getPlayerVocation(cid) == 4) or (getPlayerVocation(cid) == 8) then
		text = 'Upgrade spells for Knights\n'
			for i, x in pairs(knightspells) do
				text = text .. "\n" .. i .. " ["..getPlayerStorageValue(cid, x.storage).."]"
			end
			doShowTextDialog(cid, 6120, "" .. text)
		end
	end
	
	if not x and not list and not info then
		selfSay('You can\'t upgrade this spell.', cid)
	end
	return true
end
			


npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Everything works perfectly! Thank you so much Limos! I would give you more REP if I could but Otland won't let me :(

I got the spell to work but I'm trying to change the combat formula it used to be this:
Lua:
setCombatFormula(distanceCombat5, COMBAT_FORMULA_LEVELMAGIC, -0.4, 0, -0.5, 0)

But I'm trying to change it to something like this forumla:
Lua:
function onGetFormulaValues(cid, level, maglevel)
	local min = -(level * 1 + maglevel * 3) * 2.08
	local max = -(level * 1 + maglevel * 3) * 2.7
	return min, max
end

setCombatCallback(combat6, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
But I can't figure it out how to make it for each one :/ I tried to make it just for the last one to see if it'd work but this is how it ended up :/

[15/01/2013 19:55:52] Lua Script Error: [Spell Interface]
[15/01/2013 19:55:52] data/spells/scripts/attack/ice strike.lua:eek:nCastSpell
[15/01/2013 19:55:52] LuaScriptInterface::luaDoCombat(). Combat not found
[15/01/2013 19:55:52] stack traceback:
[15/01/2013 19:55:52] [C]: in function 'doCombat'
[15/01/2013 19:55:52] data/spells/scripts/attack/ice strike.lua:96: in function <data/spells/scripts/attack/ice strike.lua:81>

This is my script:
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -0.4, 0, -0.5, 0)

local distanceCombat = createCombatObject()
setCombatParam(distanceCombat, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(distanceCombat, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
setCombatParam(distanceCombat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SMALLICE)
setCombatFormula(distanceCombat, COMBAT_FORMULA_LEVELMAGIC, -0.4, 0, -0.5, 0)

local combat2 = createCombatObject()
setCombatParam(combat2, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(combat2, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
setCombatFormula(combat2, COMBAT_FORMULA_LEVELMAGIC, -0.4, 0, -0.5, 0)

local distanceCombat2 = createCombatObject()
setCombatParam(distanceCombat2, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(distanceCombat2, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
setCombatParam(distanceCombat2, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SMALLICE)
setCombatFormula(distanceCombat2, COMBAT_FORMULA_LEVELMAGIC, -0.4, 0, -0.5, 0)

local combat3 = createCombatObject()
setCombatParam(combat3, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(combat3, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
setCombatFormula(combat3, COMBAT_FORMULA_LEVELMAGIC, -0.4, 0, -0.5, 0)

local distanceCombat3 = createCombatObject()
setCombatParam(distanceCombat3, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(distanceCombat3, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
setCombatParam(distanceCombat3, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SMALLICE)
setCombatFormula(distanceCombat3, COMBAT_FORMULA_LEVELMAGIC, -0.4, 0, -0.5, 0)

local combat4 = createCombatObject()
setCombatParam(combat4, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(combat4, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
setCombatFormula(combat4, COMBAT_FORMULA_LEVELMAGIC, -0.4, 0, -0.5, 0)

local distanceCombat4 = createCombatObject()
setCombatParam(distanceCombat4, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(distanceCombat4, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
setCombatParam(distanceCombat4, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SMALLICE)
setCombatFormula(distanceCombat4, COMBAT_FORMULA_LEVELMAGIC, -0.4, 0, -0.5, 0)

local combat5 = createCombatObject()
setCombatParam(combat5, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(combat5, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
setCombatFormula(combat5, COMBAT_FORMULA_LEVELMAGIC, -0.4, 0, -0.5, 0)

local distanceCombat5 = createCombatObject()
setCombatParam(distanceCombat5, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(distanceCombat5, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
setCombatParam(distanceCombat5, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SMALLICE)
setCombatFormula(distanceCombat5, COMBAT_FORMULA_LEVELMAGIC, -0.4, 0, -0.5, 0)

local combat6 = createCombatObject()
setCombatParam(combat6, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(combat6, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)

local distanceCombat6 = createCombatObject()
setCombatParam(distanceCombat6, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(distanceCombat6, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
setCombatParam(distanceCombat6, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SMALLICE)

function onGetFormulaValues(cid, level, maglevel)
	local min = -(level * 1 + maglevel * 3) * 2.08
	local max = -(level * 1 + maglevel * 3) * 2.7
	return min, max
end

setCombatCallback(combat6, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onGetFormulaValues(cid, level, maglevel)
	local min = -(level * 1 + maglevel * 3) * 2.08
	local max = -(level * 1 + maglevel * 3) * 2.7
	return min, max
end

setCombatCallback(distancecombat6, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
local storage = 18101
 
	if(variantToNumber(var) ~= 0) then
	if getPlayerStorageValue(cid, storage) == -1 then
		doCombat(cid, distancecombat, var)
	elseif getPlayerStorageValue(cid, storage) == 1 then
		doCombat(cid, distancecombat2, var)
	elseif getPlayerStorageValue(cid, storage) == 2 then
		doCombat(cid, distancecombat3, var)
	elseif getPlayerStorageValue(cid, storage) == 3 then
		doCombat(cid, distancecombat4, var)
	elseif getPlayerStorageValue(cid, storage) == 4 then
		doCombat(cid, distancecombat5, var)
	elseif getPlayerStorageValue(cid, storage) == 5 then
		doCombat(cid, distancecombat6, var)		
	else
		doCombat(cid, distancecombat, var)
	end
end
	
	if getPlayerStorageValue(cid, storage) == -1 then
		doCombat(cid, combat, var)
	elseif getPlayerStorageValue(cid, storage) == 1 then
		doCombat(cid, combat2, var)
	elseif getPlayerStorageValue(cid, storage) == 2 then
		doCombat(cid, combat3, var)
	elseif getPlayerStorageValue(cid, storage) == 3 then
		doCombat(cid, combat4, var)
	elseif getPlayerStorageValue(cid, storage) == 4 then
		doCombat(cid, combat5, var)
	elseif getPlayerStorageValue(cid, storage) == 5 then
		doCombat(cid, combat6, var)		
	else
		doCombat(cid, combat, var)
	end
	return true
end

Sorry for bothering you though :/ I'm just kinda new and just want to learn more :p

Thanks though if you can help again! :D

Btw -- I haven't changed any of the forumlas for damage yet since I'm trying to get a new type of combat formula~ :p
 
Last edited:
Woot! It works! :D Thank you I never even thought about that :p

Well, here it is the finished spell for Frigo Strike:
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)

local distanceCombat = createCombatObject()
setCombatParam(distanceCombat, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(distanceCombat, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
setCombatParam(distanceCombat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SMALLICE)

local combat2 = createCombatObject()
setCombatParam(combat2, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(combat2, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)

local distanceCombat2 = createCombatObject()
setCombatParam(distanceCombat2, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(distanceCombat2, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
setCombatParam(distanceCombat2, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SMALLICE)

local combat3 = createCombatObject()
setCombatParam(combat3, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(combat3, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)

local distanceCombat3 = createCombatObject()
setCombatParam(distanceCombat3, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(distanceCombat3, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
setCombatParam(distanceCombat3, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SMALLICE)

local combat4 = createCombatObject()
setCombatParam(combat4, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(combat4, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)

local distanceCombat4 = createCombatObject()
setCombatParam(distanceCombat4, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(distanceCombat4, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
setCombatParam(distanceCombat4, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SMALLICE)

local combat5 = createCombatObject()
setCombatParam(combat5, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(combat5, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)

local distanceCombat5 = createCombatObject()
setCombatParam(distanceCombat5, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(distanceCombat5, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
setCombatParam(distanceCombat5, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SMALLICE)

local combat6 = createCombatObject()
setCombatParam(combat6, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(combat6, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)

local distanceCombat6 = createCombatObject()
setCombatParam(distanceCombat6, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
setCombatParam(distanceCombat6, COMBAT_PARAM_EFFECT, CONST_ME_ICEATTACK)
setCombatParam(distanceCombat6, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SMALLICE)

function onGetFormulaValues(cid, level, maglevel)
	local min = -(level * 1 + maglevel * 1) * 0.5
	local max = -(level * 1 + maglevel * 1.3) * 0.5
	return min, max
end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onGetFormulaValues(cid, level, maglevel)
	local min = -(level * 1 + maglevel * 1) * 0.6
	local max = -(level * 1 + maglevel * 1.3) * 0.6
	return min, max
end

setCombatCallback(combat2, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onGetFormulaValues(cid, level, maglevel)
	local min = -(level * 1 + maglevel * 1) * 0.7
	local max = -(level * 1 + maglevel * 1.3) * 0.7
	return min, max
end

setCombatCallback(combat3, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onGetFormulaValues(cid, level, maglevel)
	local min = -(level * 1 + maglevel * 1) * 0.8
	local max = -(level * 1 + maglevel * 1.3) * 0.8
	return min, max
end

setCombatCallback(combat4, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onGetFormulaValues(cid, level, maglevel)
	local min = -(level * 1 + maglevel * 1) * 0.9
	local max = -(level * 1 + maglevel * 1.3) * 0.9
	return min, max
end

setCombatCallback(combat5, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onGetFormulaValues(cid, level, maglevel)
	local min = -(level * 1 + maglevel * 1) * 1
	local max = -(level * 1 + maglevel * 1.3) * 1
	return min, max
end

setCombatCallback(combat6, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
local storage = 18101
 
	if(variantToNumber(var) ~= 0) then
	if getPlayerStorageValue(cid, storage) == -1 then
		doCombat(cid, distanceCombat, var)
	elseif getPlayerStorageValue(cid, storage) == 1 then
		doCombat(cid, distanceCombat2, var)
	elseif getPlayerStorageValue(cid, storage) == 2 then
		doCombat(cid, distanceCombat3, var)
	elseif getPlayerStorageValue(cid, storage) == 3 then
		doCombat(cid, distanceCombat4, var)
	elseif getPlayerStorageValue(cid, storage) == 4 then
		doCombat(cid, distanceCombat5, var)
	elseif getPlayerStorageValue(cid, storage) == 5 then
		doCombat(cid, distanceCombat6, var)		
	else
		doCombat(cid, distanceCombat, var)
	end
end
	
	if getPlayerStorageValue(cid, storage) == -1 then
		doCombat(cid, combat, var)
	elseif getPlayerStorageValue(cid, storage) == 1 then
		doCombat(cid, combat2, var)
	elseif getPlayerStorageValue(cid, storage) == 2 then
		doCombat(cid, combat3, var)
	elseif getPlayerStorageValue(cid, storage) == 3 then
		doCombat(cid, combat4, var)
	elseif getPlayerStorageValue(cid, storage) == 4 then
		doCombat(cid, combat5, var)
	elseif getPlayerStorageValue(cid, storage) == 5 then
		doCombat(cid, combat6, var)		
	else
		doCombat(cid, combat, var)
	end
	return true
end

Is there any tips for making it shorter? :p
 
Last edited:
You can also do it like this, will make it a bit shorter :p
Lua:
local t = {
	[1] = {type = combat2}, 
	[2] = {type = combat3}, 
	[3] = {type = combat4}, 
	[4] = {type = combat5}, 
	[5] = {type = combat6} 
} 

function onCastSpell(cid, var)
local storage = getPlayerStorageValue(cid, 18002)
 
	if t[storage] then
        	doCombat(cid, t[storage].type, var)
	else
        	doCombat(cid, combat, var)
	end
	return true
end

Oh btw, with the update I made on the npc, I set all spell storages to 0, so set -1 in the spell to 0 then if you want to check for that. If you do it like my example it's already correct. Here it does the first combat if the storage is not 1, 2, 3, 4 or 5.
Also forgot to add x.cost in the updated version to the part where it removes the storage. So change that incase you want some spells to cost more points to upgrade. I already edited my post from the updated NPC.
 
Last edited:
Back
Top