Skip to content

Instantly share code, notes, and snippets.

@Xaekai
Last active August 7, 2020 00:28
Show Gist options
  • Save Xaekai/29b4796d7f7ac753d98164f8f92acd8f to your computer and use it in GitHub Desktop.
Save Xaekai/29b4796d7f7ac753d98164f8f92acd8f to your computer and use it in GitHub Desktop.
Skill Rate Stages per Vocation and Offline Trainer Multiplier. Mod for TFS 0.x series.
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Skill Rates: Stages and Modes" version="2020.4.19" author="Lessaire" contact="https://otland.net/members/lessaire/" enabled="yes">
<credits>
This cleaned and refactored version is brought to you by Lessaire.
Original idea: Gesior
</credits>
<notes>
This revision attempts to register the creatureEvents in the buffered login script at the bottom.
If for whatever reason that doesn't work, you need to just move them to your regular login.lua.
</notes>
<description>
-------------------------------------------------------------------------------------------------
This mod lets you apply skill rates per skill, per vocation class,
and support for a rating multiplier for monks/offline training.
The only real caveat emptor here is that these rates are synergetic with the config.lua settings
That is, if you have skill rate x12 in global config,
and 12x in a skill stage, the effective rate the player gets is 144!
Remember this!
You may disable stage rating any skill just by commenting those lines out in CUSTOM_RATE_STAGES.
I expect most who want to use fishing skill stages will want to use the same ones for all vocs
so all you need to do is define them once in the "local SKILL_FISHING"
and uncomment the appropriate line in CUSTOM_RATE_STAGES
This uses the "isMage" type functions to determine what "vocation family" a character is.
-------------------------------------------------------------------------------------------------
</description>
<config name="skillStagesConfig"><![CDATA[
config = {
infoOnLogin = true,
infoOnAdvance = true,
loginColor = MESSAGE_STATUS_CONSOLE_ORANGE,
advanceColor = MESSAGE_STATUS_CONSOLE_BLUE,
monkStorage = 17000,
monkRating = 0.5,
}
SERVER_RATE_SR = getConfigValue('rateSkill')
SERVER_RATE_ML = getConfigValue('rateMagic')
local SKILL_FISHING = {{ 0, 5 },{ 60, 4 },{ 80, 3 },{ 100, 2 },{ 110, 1 }}
CUSTOM_RATE_STAGES = {
-- Skill Stages Rooker (None) --
ROOK = {
[SKILL_FIST] = {{ 0, 8 },{ 60, 5 },{ 80, 3 },{ 100, 2 }},
[SKILL_CLUB] = {{ 0, 8 },{ 60, 5 },{ 80, 2 },{ 100, 1 }},
[SKILL_SWORD] = {{ 0, 8 },{ 60, 5 },{ 80, 2 },{ 100, 1 }},
[SKILL_AXE] = {{ 0, 8 },{ 60, 5 },{ 80, 2 },{ 100, 1 }},
[SKILL_DISTANCE] = {{ 0, 8 },{ 60, 5 },{ 80, 2 },{ 100, 1 }},
[SKILL_SHIELD] = {{ 0, 9 },{ 60, 8 },{ 80, 7 },{ 100, 6 },{ 110, 3 }},
[SKILL__MAGLEVEL] = {{ 0, 10 },{ 6, 5 },{ 15, 7 },{ 80, 5 },{ 90, 2 },{ 99, 1 }},
--[SKILL_FISHING] = SKILL_FISHING
},
-- Skill Stages Mage --
MAGE = {
[SKILL_FIST] = {{ 0, 1.0 }},
[SKILL_CLUB] = {{ 0, 1.0 }},
[SKILL_SWORD] = {{ 0, 1.0 }},
[SKILL_AXE] = {{ 0, 1.0 }},
[SKILL_DISTANCE] = {{ 0, 1.0 }},
[SKILL_SHIELD] = {{ 0, 3.0 }},
[SKILL__MAGLEVEL] = {{ 0, 5.0 }},
--[SKILL_FISHING] = SKILL_FISHING
},
-- Skill Stages Paladin --
PALADIN = {
[SKILL_FIST] = {{ 0, 1.5 }},
[SKILL_CLUB] = {{ 0, 1.5 }},
[SKILL_SWORD] = {{ 0, 1.5 }},
[SKILL_AXE] = {{ 0, 1.5 }},
[SKILL_DISTANCE] = {{ 0, 5.0 }},
[SKILL_SHIELD] = {{ 0, 3.0 }},
[SKILL__MAGLEVEL] = {{ 0, 3.0 }},
--[SKILL_FISHING] = SKILL_FISHING
},
-- Skill Stages Knight --
KNIGHT = {
[SKILL_FIST] = {{ 0, 0.5 }},
[SKILL_CLUB] = {{ 0, 3.0 }},
[SKILL_SWORD] = {{ 0, 3.0 }},
[SKILL_AXE] = {{ 0, 3.0 }},
[SKILL_DISTANCE] = {{ 0, 0.6 }},
[SKILL_SHIELD] = {{ 0, 3.0 }},
[SKILL__MAGLEVEL] = {{ 0, 3.0 }},
--[SKILL_FISHING] = SKILL_FISHING
},
}
]]></config>
<lib name="skillStagesLib"><![CDATA[
local function getClass(cid)
if isMage(cid) then return 'MAGE' end
if isRanger(cid) then return 'PALADIN' end
if isWarrior(cid) then return 'KNIGHT' end
if isRooker(cid) then return 'ROOK' end
end
local function getPlayerSkillRatesText(cid)
local skillInfo = getPlayerRates(cid)
local packed = {
skillInfo[SKILL__MAGLEVEL] * SERVER_RATE_ML,
skillInfo[SKILL_FIST] * SERVER_RATE_SR,
skillInfo[SKILL_CLUB] * SERVER_RATE_SR,
skillInfo[SKILL_SWORD] * SERVER_RATE_SR,
skillInfo[SKILL_AXE] * SERVER_RATE_SR,
skillInfo[SKILL_DISTANCE] * SERVER_RATE_SR,
skillInfo[SKILL_SHIELD] * SERVER_RATE_SR,
skillInfo[SKILL_FISHING] * SERVER_RATE_SR
}
local message = string.format("YOUR RATES: [ Magic Level: %sx || Fist: %sx | Club: %sx | Sword: %sx | Axe: %sx | Distance: %s | Shielding: %sx | Fishing: %sx ]", unpack(packed))
return message
end
local function updatePlayerRates(cid, evented)
local oldRates = getPlayerRates(cid)
local training = 0 > getPlayerStorageValue(cid, config.monkStorage)
local function doRatings(class, training)
local classStages = CUSTOM_RATE_STAGES[class]
for skill, stages in pairs(classStages) do
local skillLevel = 0
if(skill >= 0 and skill <= 6) then
skillLevel = getPlayerSkillLevel(cid, skill)
else
-- if out of range, presume magic
skillLevel = getPlayerMagLevel(cid, true)
end
local skillRate = 1
-- gotta check cuz some are empty in the defaults like fishing
if(classStages[skill] ~= nil) then
for i, skillStage in pairs(stages) do
if(skillLevel >= skillStage[1]) then
skillRate = skillStage[2]
else
break
end
end
skillRate = skillRate * (training and config.monkRating or 1)
doPlayerSetRate(cid, skill, skillRate)
end
end
return getPlayerRates(cid)
end
if (type(evented) == "string") then
doPlayerSendTextMessage(cid, config.loginColor, evented)
end
return oldRates, doRatings(getClass(cid), training)
end
]]></lib>
<talkaction words="!skillstages" event="script"><![CDATA[
domodlib('skillStagesConfig')
domodlib('skillStagesLib')
function onSay(cid, words, param, channel)
doPlayerSendTextMessage(cid, config.loginColor, getPlayerSkillRatesText(cid))
return true
end
]]></talkaction>
<movevent type="StepIn" uniqueid="17001-17005" event="script"/><![CDATA[
domodlib('skillStagesConfig')
domodlib('skillStagesLib')
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
setPlayerStorageValue(cid, config.monkStorage, 1)
updatePlayerRates(cid, "Rates altered for offline training")
end
]]></movevent>
<movevent type="StepOut" uniqueid="17001-17005" event="script" /><![CDATA[
domodlib('skillStagesConfig')
domodlib('skillStagesLib')
function onStepOut(cid, item, position, lastPosition, fromPosition, toPosition, actor)
setPlayerStorageValue(cid, config.monkStorage, -1)
updatePlayerRates(cid, "Rates restored after offline training")
end
]]></movevent>
<event type="advance" name="skillStagesAdvance" event="script"><![CDATA[
domodlib('skillStagesConfig')
domodlib('skillStagesLib')
function onAdvance(cid, skill, oldLevel, newLevel)
local oldRates, newRates = updatePlayerRates(cid)
if(config.infoOnAdvance and newRates[skill] ~= oldRates[skill]) then
local configRate = 1
if(skill >= 0 and skill <= 6) then
configRate = SERVER_RATE_SR
else
configRate = SERVER_RATE_ML
end
local message = string.format("%s rate changed from %sx to %sx.",
SKILL_NAMES[skill], oldRates[skill] * configRate, newRates[skill] * configRate)
doPlayerSendTextMessage(cid, config.advanceColor, message)
doPlayerSendTextMessage(cid, config.advanceColor, getPlayerSkillRatesText(cid))
end
return true
end
]]></event>
<event type="login" name="skillStagesLogin" event="buffer"><![CDATA[
domodlib('skillStagesConfig')
domodlib('skillStagesLib')
-- maybe check tile player is standing on for monk storage
-- and update player storage in case any wierdness
updatePlayerRates(cid)
if(config.infoOnLogin) then
doPlayerSendTextMessage(cid, config.loginColor, getPlayerSkillRatesText(cid))
end
registerCreatureEvent(cid, "skillStagesAdvance")
_result = true
]]></event>
</mod>
@antonioaraujo664
Copy link

antonioaraujo664 commented Aug 7, 2020

it work on tfs 1.3?

Could you provide more installation details? please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment