Leo32
Getting back into it...
- Joined
- Sep 21, 2007
- Messages
- 987
- Solutions
- 14
- Reaction score
- 532
This was mainly put together due to:
Convert onAdvance spell notification script to TFS 1.3
good morning, someone could convert this script to tfs 1.3. thanks function onAdvance(cid, skill, oldLevel, newLevel) if skill == SKILL__LEVEL then local spells = {} for index = 0, getPlayerInstantSpellCount(cid) - 1 do local spell =...
otland.net
This only works if 'needlearn' for spells is set to off.
We have a 0.4 version, a 1.3 version.
Mays well edit it for 1.0-1.2 and release it too.
Ignore the spells being learned in my screenshots, I've been messing with vocations and spells for the past few weeks.
They're just examples showing the appropriate grammar and formatting depending on the number of spells learned.
creaturescripts.xml add:
XML:
<event type="advance" name="SpellNotifier" script="spellnotifier.lua"/>
creaturescripts\scripts\login.lua add:
Lua:
-- Events
player:registerEvent("SpellNotifier")
creaturescripts\scripts\spellnotifier.lua:
Lua:
function onAdvance(player, skill, oldLevel, newLevel)
if skill == SKILL_LEVEL then
function grammarstring(spelltable)
local s = ""
local commacounter = 0
local lastcomma = -1
-- Put commas between spells
for k,v in ipairs(spelltable) do
if k ~= 1 then
spelltable[k] = ", " .. v
end
commacounter = commacounter+1
lastcomma = k
end
-- Edit the values for grammar depending on the comma count
if commacounter > 1 then
spelltable[1] = "s " .. spelltable[1] -- plural, add s
spelltable[lastcomma] = spelltable[lastcomma]:gsub(", ", " and ") -- replace last comma with an 'and'
else
spelltable[1] = " " .. spelltable[1] -- only 1 result, just add a space
end
-- Put final values into a single string
for k,v in ipairs(spelltable) do
s = s .. v
end
return s
end
local count = getPlayerInstantSpellCount(player)
local spells = {}
for i = 0, count - 1 do
local spell = getPlayerInstantSpellInfo(player, i)
if spell.level > oldLevel and spell.level <= newLevel then
table.insert(spells, "'" .. spell.name .. "'")
end
end
if #spells > 0 then
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have learned the spell" .. grammarstring(spells) .. ".")
end
end
return true
end
Last edited: