CreatureEvent [TFS 1.1] Skill Points, modalwindow

Mkalo

ボーカロイド
Joined
Jun 1, 2011
Messages
1,118
Best answers
54
Reaction score
899
Location
Japan
Ah, I see. Thank you.

adding this:
Code:
isInArray(skillForVoc[self:getBaseVocId()], choiceId)
to this "if" with "and" operator should fix that:
Code:
if not skills[choiceId] then
let me know if it fixes the issue
can't test it myself now (need to maintain all ot stuff again due to OS reinstall)
You have to use or and not like:
if not skills[choiceId] or not isInArray(skillForVoc[self:getBaseVocId()], choiceId) then

This fixes the issue.
 
OP
zbizu

zbizu

Excellent OT User
Joined
Nov 22, 2010
Messages
2,463
Best answers
1
Reaction score
1,373
Location
Poland
I'm still noob in this part, I'm trying to learn day long trying to do What you said but I could not, could you give me an example of how to do?

Code:
				local maxStor = skills[choiceId][5]
				local getStor = player:getStorageValue(maxStor)
				if getStor == -1 then
					player:setStorageValue(maxStor, 0)
				end

				if getStor < 100 then
					player:setStorageValue(maxStor, getStor + 1)
				else
					local textWindow = ModalWindow(TextModalId, "Information", "You already added 100 points on this skill. You cannot improve your " .. skills[choiceId][1] .. " anymore.")
					textWindow:addButton(1, "Ok")
					textWindow:setDefaultEnterButton(1)
					textWindow:setDefaultEscapeButton(1)
					textWindow:sendToPlayer(self)						
					return false
				end
@MatheusMkalo
I see, thanks again.
 

bonfim25

New Member
Joined
Jan 17, 2011
Messages
17
Best answers
0
Reaction score
1
Location
Brazil

Code:
                local maxStor = skills[choiceId][5]
                local getStor = player:getStorageValue(maxStor)
                if getStor == -1 then
                    player:setStorageValue(maxStor, 0)
                end

                if getStor < 100 then
                    player:setStorageValue(maxStor, getStor + 1)
                else
                    local textWindow = ModalWindow(TextModalId, "Information", "You already added 100 points on this skill. You cannot improve your " .. skills[choiceId][1] .. " anymore.")
                    textWindow:addButton(1, "Ok")
                    textWindow:setDefaultEnterButton(1)
                    textWindow:setDefaultEscapeButton(1)
                    textWindow:sendToPlayer(self)                       
                    return false
                end
@MatheusMkalo
I see, thanks again.
Thanks, but not yet worked.
I added and gave error player (a nil value) and I changed player to self:
Code:
local maxStor = skills[choiceId][5]
                local getStor = self:getStorageValue(maxStor)
                if getStor == -1 then
                    self:setStorageValue(maxStor, 0)
                end

                if getStor < 100 then
                    self:setStorageValue(maxStor, getStor + 1)
                else
                    local textWindow = ModalWindow(TextModalId, "Information", "You already added 100 points on this skill. You cannot improve your " .. skills[choiceId][1] .. " anymore.")
                    textWindow:addButton(1, "Ok")
                    textWindow:setDefaultEnterButton(1)
                    textWindow:setDefaultEscapeButton(1)
                    textWindow:sendToPlayer(self)                       
                    return false
                end
but does not add any more point and not from any error in the distro, simply does not happen nothing so closes the window to add points.
 

Starliks

New Member
Joined
Jan 6, 2013
Messages
9
Best answers
0
Reaction score
0
hi.
I'm getting error


resolved, I forgot to add the function in lib..
 
Last edited:

SlayingWorld

Intermediate OT User
Joined
Jan 23, 2014
Messages
122
Best answers
0
Reaction score
29
Location
USA
If anyone wants the fixed version for TFS 1.2 on the problem that only 1% skill was added instead of the whole level let me know so i can post the fixed lib.
 

SlayingWorld

Intermediate OT User
Joined
Jan 23, 2014
Messages
122
Best answers
0
Reaction score
29
Location
USA
Well F it ima upload it anyways, heres the lib i edited to make it work with the latest TFS 1.2

NOTE: I added some effects when you get skillpoints.


Code:
-- config
--promoted vocations included in function
local gainVoc = {
    [0] = {health = 20, mana = 20, magic = 1, skill = 1, cap = 50},
    [1] = {health = 20, mana = 20, magic = 1, skill = 1, cap = 50},
    [2] = {health = 20, mana = 20, magic = 1, skill = 1, cap = 50},
    [3] = {health = 20, mana = 20, magic = 1, skill = 1, cap = 50},
    [4] = {health = 20, mana = 20, magic = 1, skill = 1, cap = 50}
}

local skillStorage = 62490
local modalId = 4869
local TextModalId = 4870 -- so player may return to skill window
local skillPointsPerLevel = 2 -- points per level
local skillPointsAdvanceStorage = 62491 -- storage to avoid giving points twice for same level
local skillPointsTalkaction = "!skillpoints" -- so player knows command when he gets level up

local skills = {
-- name, get value, set value
    [1] = {'Health', function(player) return player:getMaxHealth() end, function(player) local gain = gainVoc[player:getBaseVocId()].health player:setMaxHealth(player:getMaxHealth() + gain) return gain end, 10},
    [2] = {'Mana', function(player) return player:getMaxMana() end, function(player) local gain = gainVoc[player:getBaseVocId()].mana player:setMaxMana(player:getMaxMana() + gain) return gain end, 10},
    [3] = {'Capacity', function(player) return player:getCapacity() / 100 end, function(player) local gain = gainVoc[player:getBaseVocId()].cap player:setCapacity(player:getCapacity() + (gain * 100)) return gain end, 10},
    [4] = {'Magic', function(player) return player:getBaseMagicLevel() end, function(player) local gain = gainVoc[player:getBaseVocId()].magic player:addSkillLevels(SKILL_MAGLEVEL, gain) return gain end, 10},
    [5] = {'Fist', function(player) return player:getSkillLevel(SKILL_FIST) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_FIST, gain) return gain end, 10},
    [6] = {'Club', function(player) return player:getSkillLevel(SKILL_CLUB) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_CLUB, gain) return gain end, 10},
    [7] = {'Sword', function(player) return player:getSkillLevel(SKILL_SWORD) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_SWORD, gain) return gain end, 10},
    [8] = {'Axe', function(player) return player:getSkillLevel(SKILL_AXE) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_AXE, gain) return gain end, 10},
    [9] = {'Distance', function(player) return player:getSkillLevel(SKILL_DISTANCE) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_DISTANCE, gain) return gain end, 10},
    [10] = {'Shielding', function(player) return player:getSkillLevel(SKILL_SHIELD) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_SHIELD, gain) return gain end, 10},
    [11] = {'Fishing', function(player) return player:getSkillLevel(SKILL_FISHING) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_FISHING, gain) return gain end, 10}
}

local skillForVoc = {
    [1] = {1, 2, 3, 4, 10, 11}, -- sorcerer
    [2] = {1, 2, 3, 4, 10, 11}, -- druid
    [3] = {1, 2, 3, 4, 9, 10, 11}, -- paladin
    [4] = {1, 2, 3, 5, 6, 7, 8, 10, 11}, -- knight
}

function Player:getBaseVocId()
    local basevoc = self:getVocation():getDemotion()
    if basevoc then
        return basevoc:getId()
    end
    return self:getVocation():getId()
end

function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

function Player:addSkillLevels(skill, count)
    count = math.max(1, count or 1)
   
    if isInArray({SKILL_FIST, SKILL_CLUB, SKILL_SWORD, SKILL_AXE, SKILL_DISTANCE, SKILL_SHIELD, SKILL_FISHING}, skill) then
        for i = 1, count do
            local xp = math.ceil(self:getVocation():getRequiredSkillTries(skill, self:getSkillLevel(skill) + 1) - self:getSkillTries(skill))
            self:addSkillTries(skill, xp)
        end
        return true
    end

    if skill == SKILL_MAGLEVEL then
        for i = 1, count do
            local xp = math.ceil(self:getVocation():getRequiredManaSpent(self:getBaseMagicLevel() + 1) - self:getManaSpent())
            self:addManaSpent(xp)
        end
        return true
    end

    if skill == SKILL_LEVEL then
        for i = 1, count do
            local lv = self:getLevel()
            local xp = getExpForLevel(lv + 1) - getExpForLevel(lv)
            self:addExperience(xp, false)
        end
        return true
    end
    return false
end

function Player:sendSkillPointsWindow()
    local pts = self:getStorageValue(skillStorage)
    if pts < 0 then
        self:setStorageValue(skillStorage, 0)
        pts = 0
    end

    local window = ModalWindow(modalId, "Character Mastery", "Available points: [" .. pts .. "]")
    window:addButton(1, "Assign")
    window:addButton(2, "Exit")

    for i = 1, #skills do
        if isInArray(skillForVoc[self:getBaseVocId()], i) then
            window:addChoice(i, skills[i][1] .. ": [" .. skills[i][2](self) .. "][cost: " .. skills[i][4] .. "]")
        end
    end
   
    window:setDefaultEnterButton(1)
    window:setDefaultEscapeButton(2)
    window:sendToPlayer(self)
    return true
end

function Player:skillWindowChoice(windowId, buttonId, choiceId)
    if windowId == modalId then
        if buttonId == 1 then
            if not skills[choiceId] then
                local textWindow = ModalWindow(TextModalId, "Error", "No skill selected.")
                textWindow:addButton(1, "Ok")
                textWindow:setDefaultEnterButton(1)
                textWindow:setDefaultEscapeButton(1)
                textWindow:sendToPlayer(self)
                return true
            end
            local pts = self:getStorageValue(skillStorage)
            if pts < 0 then
                self:setStorageValue(skillStorage, 0)
                pts = 0
            end
           
            if pts - skills[choiceId][4] >= 0 then
                local textWindow = ModalWindow(TextModalId, "Point assigned.", skills[choiceId][1] .. " +" .. skills[choiceId][3](self))
                textWindow:addButton(1, "Ok")
                textWindow:setDefaultEnterButton(1)
                textWindow:setDefaultEscapeButton(1)
                textWindow:sendToPlayer(self)
                self:setStorageValue(skillStorage, pts - skills[choiceId][4])
                return true
            end

            local textWindow = ModalWindow(TextModalId, "Error", "Not enough points")
            textWindow:addButton(1, "Ok")
            textWindow:setDefaultEnterButton(1)
            textWindow:setDefaultEscapeButton(1)
            textWindow:sendToPlayer(self)
            return true
        end
        return false
    end
   
    if not (windowId == TextModalId) then
        return false
    end
       
    self:sendSkillPointsWindow()
    return false
end

function Player:addSkillPoints(count)
    count = math.max(1, count or 1)
   
    local pts = self:getStorageValue(skillStorage)
    if pts < 0 then
        self:setStorageValue(skillStorage, 0)
        pts = 0
    end
   
    return self:setStorageValue(skillStorage, pts + count)
end

function Player:skillPointsAdvance(nlevel)
    if self:getStorageValue(skillPointsAdvanceStorage) < nlevel then
        self:addSkillPoints(skillPointsPerLevel * (nlevel - self:getStorageValue(skillPointsAdvanceStorage)))
        self:setStorageValue(skillPointsAdvanceStorage, nlevel)
        self:say('Skillpoints Added!', TALKTYPE_MONSTER_SAY, false, player)
        self:getPosition():sendMagicEffect(CONST_ME_FIREAREA)
        self:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "New skill points available. Type " .. skillPointsTalkaction .. " to open character mastery window.")
    end
    return true
end
 

God Mythera

Veteran OT User
Joined
Aug 11, 2012
Messages
2,043
Best answers
2
Reaction score
212
Location
United States
Well F it ima upload it anyways, heres the lib i edited to make it work with the latest TFS 1.2

NOTE: I added some effects when you get skillpoints.


Code:
-- config
--promoted vocations included in function
local gainVoc = {
    [0] = {health = 20, mana = 20, magic = 1, skill = 1, cap = 50},
    [1] = {health = 20, mana = 20, magic = 1, skill = 1, cap = 50},
    [2] = {health = 20, mana = 20, magic = 1, skill = 1, cap = 50},
    [3] = {health = 20, mana = 20, magic = 1, skill = 1, cap = 50},
    [4] = {health = 20, mana = 20, magic = 1, skill = 1, cap = 50}
}

local skillStorage = 62490
local modalId = 4869
local TextModalId = 4870 -- so player may return to skill window
local skillPointsPerLevel = 2 -- points per level
local skillPointsAdvanceStorage = 62491 -- storage to avoid giving points twice for same level
local skillPointsTalkaction = "!skillpoints" -- so player knows command when he gets level up

local skills = {
-- name, get value, set value
    [1] = {'Health', function(player) return player:getMaxHealth() end, function(player) local gain = gainVoc[player:getBaseVocId()].health player:setMaxHealth(player:getMaxHealth() + gain) return gain end, 10},
    [2] = {'Mana', function(player) return player:getMaxMana() end, function(player) local gain = gainVoc[player:getBaseVocId()].mana player:setMaxMana(player:getMaxMana() + gain) return gain end, 10},
    [3] = {'Capacity', function(player) return player:getCapacity() / 100 end, function(player) local gain = gainVoc[player:getBaseVocId()].cap player:setCapacity(player:getCapacity() + (gain * 100)) return gain end, 10},
    [4] = {'Magic', function(player) return player:getBaseMagicLevel() end, function(player) local gain = gainVoc[player:getBaseVocId()].magic player:addSkillLevels(SKILL_MAGLEVEL, gain) return gain end, 10},
    [5] = {'Fist', function(player) return player:getSkillLevel(SKILL_FIST) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_FIST, gain) return gain end, 10},
    [6] = {'Club', function(player) return player:getSkillLevel(SKILL_CLUB) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_CLUB, gain) return gain end, 10},
    [7] = {'Sword', function(player) return player:getSkillLevel(SKILL_SWORD) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_SWORD, gain) return gain end, 10},
    [8] = {'Axe', function(player) return player:getSkillLevel(SKILL_AXE) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_AXE, gain) return gain end, 10},
    [9] = {'Distance', function(player) return player:getSkillLevel(SKILL_DISTANCE) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_DISTANCE, gain) return gain end, 10},
    [10] = {'Shielding', function(player) return player:getSkillLevel(SKILL_SHIELD) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_SHIELD, gain) return gain end, 10},
    [11] = {'Fishing', function(player) return player:getSkillLevel(SKILL_FISHING) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_FISHING, gain) return gain end, 10}
}

local skillForVoc = {
    [1] = {1, 2, 3, 4, 10, 11}, -- sorcerer
    [2] = {1, 2, 3, 4, 10, 11}, -- druid
    [3] = {1, 2, 3, 4, 9, 10, 11}, -- paladin
    [4] = {1, 2, 3, 5, 6, 7, 8, 10, 11}, -- knight
}

function Player:getBaseVocId()
    local basevoc = self:getVocation():getDemotion()
    if basevoc then
        return basevoc:getId()
    end
    return self:getVocation():getId()
end

function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

function Player:addSkillLevels(skill, count)
    count = math.max(1, count or 1)
  
    if isInArray({SKILL_FIST, SKILL_CLUB, SKILL_SWORD, SKILL_AXE, SKILL_DISTANCE, SKILL_SHIELD, SKILL_FISHING}, skill) then
        for i = 1, count do
            local xp = math.ceil(self:getVocation():getRequiredSkillTries(skill, self:getSkillLevel(skill) + 1) - self:getSkillTries(skill))
            self:addSkillTries(skill, xp)
        end
        return true
    end

    if skill == SKILL_MAGLEVEL then
        for i = 1, count do
            local xp = math.ceil(self:getVocation():getRequiredManaSpent(self:getBaseMagicLevel() + 1) - self:getManaSpent())
            self:addManaSpent(xp)
        end
        return true
    end

    if skill == SKILL_LEVEL then
        for i = 1, count do
            local lv = self:getLevel()
            local xp = getExpForLevel(lv + 1) - getExpForLevel(lv)
            self:addExperience(xp, false)
        end
        return true
    end
    return false
end

function Player:sendSkillPointsWindow()
    local pts = self:getStorageValue(skillStorage)
    if pts < 0 then
        self:setStorageValue(skillStorage, 0)
        pts = 0
    end

    local window = ModalWindow(modalId, "Character Mastery", "Available points: [" .. pts .. "]")
    window:addButton(1, "Assign")
    window:addButton(2, "Exit")

    for i = 1, #skills do
        if isInArray(skillForVoc[self:getBaseVocId()], i) then
            window:addChoice(i, skills[i][1] .. ": [" .. skills[i][2](self) .. "][cost: " .. skills[i][4] .. "]")
        end
    end
  
    window:setDefaultEnterButton(1)
    window:setDefaultEscapeButton(2)
    window:sendToPlayer(self)
    return true
end

function Player:skillWindowChoice(windowId, buttonId, choiceId)
    if windowId == modalId then
        if buttonId == 1 then
            if not skills[choiceId] then
                local textWindow = ModalWindow(TextModalId, "Error", "No skill selected.")
                textWindow:addButton(1, "Ok")
                textWindow:setDefaultEnterButton(1)
                textWindow:setDefaultEscapeButton(1)
                textWindow:sendToPlayer(self)
                return true
            end
            local pts = self:getStorageValue(skillStorage)
            if pts < 0 then
                self:setStorageValue(skillStorage, 0)
                pts = 0
            end
          
            if pts - skills[choiceId][4] >= 0 then
                local textWindow = ModalWindow(TextModalId, "Point assigned.", skills[choiceId][1] .. " +" .. skills[choiceId][3](self))
                textWindow:addButton(1, "Ok")
                textWindow:setDefaultEnterButton(1)
                textWindow:setDefaultEscapeButton(1)
                textWindow:sendToPlayer(self)
                self:setStorageValue(skillStorage, pts - skills[choiceId][4])
                return true
            end

            local textWindow = ModalWindow(TextModalId, "Error", "Not enough points")
            textWindow:addButton(1, "Ok")
            textWindow:setDefaultEnterButton(1)
            textWindow:setDefaultEscapeButton(1)
            textWindow:sendToPlayer(self)
            return true
        end
        return false
    end
  
    if not (windowId == TextModalId) then
        return false
    end
      
    self:sendSkillPointsWindow()
    return false
end

function Player:addSkillPoints(count)
    count = math.max(1, count or 1)
  
    local pts = self:getStorageValue(skillStorage)
    if pts < 0 then
        self:setStorageValue(skillStorage, 0)
        pts = 0
    end
  
    return self:setStorageValue(skillStorage, pts + count)
end

function Player:skillPointsAdvance(nlevel)
    if self:getStorageValue(skillPointsAdvanceStorage) < nlevel then
        self:addSkillPoints(skillPointsPerLevel * (nlevel - self:getStorageValue(skillPointsAdvanceStorage)))
        self:setStorageValue(skillPointsAdvanceStorage, nlevel)
        self:say('Skillpoints Added!', TALKTYPE_MONSTER_SAY, false, player)
        self:getPosition():sendMagicEffect(CONST_ME_FIREAREA)
        self:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "New skill points available. Type " .. skillPointsTalkaction .. " to open character mastery window.")
    end
    return true
end
You sure it works with TFS 1.2? I have tested and with the other parts on the main post and it doesnt work. I get a level it says 0 i try to buy health or mana it closes window says nothing no error ;o
 

mezuf98

Member
Joined
Jul 4, 2016
Messages
36
Best answers
0
Reaction score
0
Guys, it has some way to reset the points ?
 

BloodGauntlet

Member
Joined
Jul 27, 2016
Messages
45
Best answers
0
Reaction score
16
Having some trouble, getting this when the server starts up. [TFS 1.1]

[Warning - Event::checkScript] Event onSay not found. scripts/sp.lua

Followed the directions exactly. Any help much appreciated.

EDIT: re went through the steps and it is working, apologies.
 
Last edited:

Brunner25

New Member
Joined
May 26, 2017
Messages
3
Best answers
0
Reaction score
0
I know this is an older thread and that it might not be possible, but is there a way of making this where it uses a leveling points system?

like 10/100/500 points at a time. I've been 'dabbling' with the script trying to get it to work on with my server. The reason behind the leveling points system is because I'm trying to make it where there's a reward system that gives out points as 1 of the many rewards.

Thank you for any and all help,
Brunner
 

Bogart

...has super panda powers
Joined
Jun 21, 2009
Messages
8,010
Best answers
27
Reaction score
532
Location
Panda Land!
I know this is an older thread and that it might not be possible, but is there a way of making this where it uses a leveling points system?

like 10/100/500 points at a time. I've been 'dabbling' with the script trying to get it to work on with my server. The reason behind the leveling points system is because I'm trying to make it where there's a reward system that gives out points as 1 of the many rewards.

Thank you for any and all help,
Brunner
I know this is an older thread and that it might not be possible, but is there a way of making this where it uses a leveling points system?

like 10/100/500 points at a time. I've been 'dabbling' with the script trying to get it to work on with my server. The reason behind the leveling points system is because I'm trying to make it where there's a reward system that gives out points as 1 of the many rewards.

Thank you for any and all help,
Brunner
Do you mean that instead of levels it uses another point system?
 

Kubakos

Intermediate OT User
Joined
Mar 3, 2010
Messages
744
Best answers
0
Reaction score
26
Well F it ima upload it anyways, heres the lib i edited to make it work with the latest TFS 1.2

NOTE: I added some effects when you get skillpoints.


Code:
-- config
--promoted vocations included in function
local gainVoc = {
    [0] = {health = 20, mana = 20, magic = 1, skill = 1, cap = 50},
    [1] = {health = 20, mana = 20, magic = 1, skill = 1, cap = 50},
    [2] = {health = 20, mana = 20, magic = 1, skill = 1, cap = 50},
    [3] = {health = 20, mana = 20, magic = 1, skill = 1, cap = 50},
    [4] = {health = 20, mana = 20, magic = 1, skill = 1, cap = 50}
}

local skillStorage = 62490
local modalId = 4869
local TextModalId = 4870 -- so player may return to skill window
local skillPointsPerLevel = 2 -- points per level
local skillPointsAdvanceStorage = 62491 -- storage to avoid giving points twice for same level
local skillPointsTalkaction = "!skillpoints" -- so player knows command when he gets level up

local skills = {
-- name, get value, set value
    [1] = {'Health', function(player) return player:getMaxHealth() end, function(player) local gain = gainVoc[player:getBaseVocId()].health player:setMaxHealth(player:getMaxHealth() + gain) return gain end, 10},
    [2] = {'Mana', function(player) return player:getMaxMana() end, function(player) local gain = gainVoc[player:getBaseVocId()].mana player:setMaxMana(player:getMaxMana() + gain) return gain end, 10},
    [3] = {'Capacity', function(player) return player:getCapacity() / 100 end, function(player) local gain = gainVoc[player:getBaseVocId()].cap player:setCapacity(player:getCapacity() + (gain * 100)) return gain end, 10},
    [4] = {'Magic', function(player) return player:getBaseMagicLevel() end, function(player) local gain = gainVoc[player:getBaseVocId()].magic player:addSkillLevels(SKILL_MAGLEVEL, gain) return gain end, 10},
    [5] = {'Fist', function(player) return player:getSkillLevel(SKILL_FIST) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_FIST, gain) return gain end, 10},
    [6] = {'Club', function(player) return player:getSkillLevel(SKILL_CLUB) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_CLUB, gain) return gain end, 10},
    [7] = {'Sword', function(player) return player:getSkillLevel(SKILL_SWORD) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_SWORD, gain) return gain end, 10},
    [8] = {'Axe', function(player) return player:getSkillLevel(SKILL_AXE) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_AXE, gain) return gain end, 10},
    [9] = {'Distance', function(player) return player:getSkillLevel(SKILL_DISTANCE) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_DISTANCE, gain) return gain end, 10},
    [10] = {'Shielding', function(player) return player:getSkillLevel(SKILL_SHIELD) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_SHIELD, gain) return gain end, 10},
    [11] = {'Fishing', function(player) return player:getSkillLevel(SKILL_FISHING) end, function(player) local gain = gainVoc[player:getBaseVocId()].skill player:addSkillLevels(SKILL_FISHING, gain) return gain end, 10}
}

local skillForVoc = {
    [1] = {1, 2, 3, 4, 10, 11}, -- sorcerer
    [2] = {1, 2, 3, 4, 10, 11}, -- druid
    [3] = {1, 2, 3, 4, 9, 10, 11}, -- paladin
    [4] = {1, 2, 3, 5, 6, 7, 8, 10, 11}, -- knight
}

function Player:getBaseVocId()
    local basevoc = self:getVocation():getDemotion()
    if basevoc then
        return basevoc:getId()
    end
    return self:getVocation():getId()
end

function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

function Player:addSkillLevels(skill, count)
    count = math.max(1, count or 1)
  
    if isInArray({SKILL_FIST, SKILL_CLUB, SKILL_SWORD, SKILL_AXE, SKILL_DISTANCE, SKILL_SHIELD, SKILL_FISHING}, skill) then
        for i = 1, count do
            local xp = math.ceil(self:getVocation():getRequiredSkillTries(skill, self:getSkillLevel(skill) + 1) - self:getSkillTries(skill))
            self:addSkillTries(skill, xp)
        end
        return true
    end

    if skill == SKILL_MAGLEVEL then
        for i = 1, count do
            local xp = math.ceil(self:getVocation():getRequiredManaSpent(self:getBaseMagicLevel() + 1) - self:getManaSpent())
            self:addManaSpent(xp)
        end
        return true
    end

    if skill == SKILL_LEVEL then
        for i = 1, count do
            local lv = self:getLevel()
            local xp = getExpForLevel(lv + 1) - getExpForLevel(lv)
            self:addExperience(xp, false)
        end
        return true
    end
    return false
end

function Player:sendSkillPointsWindow()
    local pts = self:getStorageValue(skillStorage)
    if pts < 0 then
        self:setStorageValue(skillStorage, 0)
        pts = 0
    end

    local window = ModalWindow(modalId, "Character Mastery", "Available points: [" .. pts .. "]")
    window:addButton(1, "Assign")
    window:addButton(2, "Exit")

    for i = 1, #skills do
        if isInArray(skillForVoc[self:getBaseVocId()], i) then
            window:addChoice(i, skills[i][1] .. ": [" .. skills[i][2](self) .. "][cost: " .. skills[i][4] .. "]")
        end
    end
  
    window:setDefaultEnterButton(1)
    window:setDefaultEscapeButton(2)
    window:sendToPlayer(self)
    return true
end

function Player:skillWindowChoice(windowId, buttonId, choiceId)
    if windowId == modalId then
        if buttonId == 1 then
            if not skills[choiceId] then
                local textWindow = ModalWindow(TextModalId, "Error", "No skill selected.")
                textWindow:addButton(1, "Ok")
                textWindow:setDefaultEnterButton(1)
                textWindow:setDefaultEscapeButton(1)
                textWindow:sendToPlayer(self)
                return true
            end
            local pts = self:getStorageValue(skillStorage)
            if pts < 0 then
                self:setStorageValue(skillStorage, 0)
                pts = 0
            end
          
            if pts - skills[choiceId][4] >= 0 then
                local textWindow = ModalWindow(TextModalId, "Point assigned.", skills[choiceId][1] .. " +" .. skills[choiceId][3](self))
                textWindow:addButton(1, "Ok")
                textWindow:setDefaultEnterButton(1)
                textWindow:setDefaultEscapeButton(1)
                textWindow:sendToPlayer(self)
                self:setStorageValue(skillStorage, pts - skills[choiceId][4])
                return true
            end

            local textWindow = ModalWindow(TextModalId, "Error", "Not enough points")
            textWindow:addButton(1, "Ok")
            textWindow:setDefaultEnterButton(1)
            textWindow:setDefaultEscapeButton(1)
            textWindow:sendToPlayer(self)
            return true
        end
        return false
    end
  
    if not (windowId == TextModalId) then
        return false
    end
      
    self:sendSkillPointsWindow()
    return false
end

function Player:addSkillPoints(count)
    count = math.max(1, count or 1)
  
    local pts = self:getStorageValue(skillStorage)
    if pts < 0 then
        self:setStorageValue(skillStorage, 0)
        pts = 0
    end
  
    return self:setStorageValue(skillStorage, pts + count)
end

function Player:skillPointsAdvance(nlevel)
    if self:getStorageValue(skillPointsAdvanceStorage) < nlevel then
        self:addSkillPoints(skillPointsPerLevel * (nlevel - self:getStorageValue(skillPointsAdvanceStorage)))
        self:setStorageValue(skillPointsAdvanceStorage, nlevel)
        self:say('Skillpoints Added!', TALKTYPE_MONSTER_SAY, false, player)
        self:getPosition():sendMagicEffect(CONST_ME_FIREAREA)
        self:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "New skill points available. Type " .. skillPointsTalkaction .. " to open character mastery window.")
    end
    return true
end
Unfortunatly there is a bug with this script:

when the player get many level advance in the same time he earn sick amount of skill points.

with 2 skill points / level advance in config, when I won 6 levels at the same time I earned 674 skill points, I should earn only 12.. :/
 

Kubakos

Intermediate OT User
Joined
Mar 3, 2010
Messages
744
Best answers
0
Reaction score
26
Edit: I understood why it's adding skill points like that: it's because the script take old level advances and complete them with skill points on new advance.
So if I set that new player start on level 8 on my server and if he reach level 9 he will have 18 skill points. Is there any way to disable that?
 

Brunner25

New Member
Joined
May 26, 2017
Messages
3
Best answers
0
Reaction score
0
Do you mean that instead of levels it uses another point system?
Sorry I meant that instead of using 10 points at a time they could use 10 points, 100 points or 500 points at a time. so they'd gain 2%, 20%, or 100% per skill level.

This way they don't have to keep using 10 points at a time,
like if a reward gave them 200 points,
they won't have to click on the skill to level 20 times verses using it twice for 100 points at a time.

Thanks for the reply.
 

hacuna

Well-Known Member
Joined
Sep 24, 2010
Messages
19
Best answers
0
Reaction score
0
Can you add a reset button? to reset the points and return to normal status? and does the player receive the points again? and another one I tested here, but the message does not appear pro player that he won the points, however the points are added normally.
 

Togu

Active Member
Joined
Jun 22, 2018
Messages
300
Best answers
1
Reaction score
141
Location
Brazil

Attachments

jededias

New Member
Joined
Jan 21, 2019
Messages
19
Best answers
0
Reaction score
3
[13/04/2019 12:06:08] [Error - TalkAction Interface]
[13/04/2019 12:06:08] data/lib/sp.lua
[13/04/2019 12:06:08] Description:
[13/04/2019 12:06:08] data/lib/sp.lua:40: attempt to index global 'Player' (a nil value)
[13/04/2019 12:06:08] [Warning - LuaScriptInterface::initState] Cannot load data/lib/

TFS 0.3.6 8.54
 
Top