• 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!

Action [TFS 1.2] Skill scroll (uses stamina)

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,323
Solutions
26
Reaction score
2,694
Location
Poland
A scroll which adds skills using player's stamina.
Can bring lots of profits to server owners when used with items like stamina doll.

GDS6x1R.jpg


13:46 You earned 540000 points on Axe Fighting. 360 minutes of stamina used.

actions.xml
Code:
<action itemid="23672" script="skillscroll.lua" />

skillscroll.lua
Code:
local skills = {"Magic Level", "Fist Fighting", "Club Fighting", "Sword Fighting", "Axe Fighting", "Distance Fighting", "Shielding", "Fishing"}

function Player:sendSkillVoucherWindow()
	local modaltext = "Select skill you would like to improve:"
	local modal = ModalWindow(7092, "Use voucher", modaltext)

	for i = 1, #skills do
		modal:addChoice(i, skills[i])
	end
	
	modal:addButton(1, "Select")
	modal:setDefaultEnterButton(1)
	modal:addButton(2, "Cancel")
	modal:setDefaultEscapeButton(2)

	return modal:sendToPlayer(self)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
	player:sendSkillVoucherWindow()
	return true
end

creaturescripts.xml
Code:
	<event type="login" name="skillScrollLogin" script="scrollwindow.lua"/>
	<event type="modalwindow" name="skillScrollWindow" script="scrollwindow.lua"/>

scrollwindow.lua
Code:
local rate = configManager.getNumber(configKeys.RATE_SKILL)
local magic = configManager.getNumber(configKeys.RATE_MAGIC)
local skills = {"Magic Level", "Fist Fighting", "Club Fighting", "Sword Fighting", "Axe Fighting", "Distance Fighting", "Shielding", "Fishing"}

local staminaCost = 6 * 60
local voucherTries = math.floor((staminaCost * 1000) / 2)
local voucherId = 23672

function onModalWindow(player, modalWindowId, buttonId, choiceId)
	if modalWindowId ~= 7092 then
		return false
	end
	
	if buttonId ~= 1 then
		return false
	end
	
	local voucher = player:getItemById(voucherId, true)
	if not voucher then
		-- avoids using scroll without removing one
		player:sendTextMessage(MESSAGE_INFO_DESCR, "Put the scroll in your backpack first.")
		return false
	end
	
	if not skills[choiceId] then
		return false
	end
	
	local stamina = player:getStamina()
	if stamina < staminaCost then
		player:sendTextMessage(MESSAGE_INFO_DESCR, "You need at least " .. math.floor(staminaCost/60) .. " hours of stamina to do that.")
		return false
	end
	
	local gain = 0
	local maxskill = false
	
	if choiceId == 1 then
		-- database limit
		if player:getManaSpent() > 4294967295 then
			maxskill = true
		else
			gain = voucherTries * magic * 75
			player:addManaSpent(gain)
		end
	else
		-- beyond certain point player won't receive skill tries anymore
		-- probably something in sources
		gain = voucherTries * rate
		local tries = player:getSkillTries(choiceId - 2)
		player:addSkillTries(choiceId - 2, gain)
		if tries == player:getSkillTries(choiceId - 2) then
			maxskill = true
		end
	end
	
	if maxskill then
		player:sendTextMessage(MESSAGE_INFO_DESCR, "Final skill state reached. You cannot improve any further.")	
		return true
	end
	
	player:setStamina(stamina - staminaCost)
	player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
	player:sendTextMessage(MESSAGE_INFO_DESCR, "You earned " .. gain .. " points on " .. skills[choiceId] .. ". " .. staminaCost .. " minutes of stamina used.")
	voucher:remove(1)
	return true
end

function onLogin(player)
	player:registerEvent("skillScrollWindow")
	return true
end
 
Last edited:
im gonna give this a go right now! thanks!

Edit: this works amazingly! I think the exp rate is multiplied by whatever you have your multiplier set to on the server obviously, so keep that in mind people!
 
Last edited:
im gonna give this a go right now! thanks!

Edit: this works amazingly! I think the exp rate is multiplied by whatever you have your multiplier set to on the server obviously, so keep that in mind people!
of course they do. That's reason why they're declared in first two lines.
 
you have this script for only one skill?
edit this table
Code:
local skills = {"Magic Level", "Fist Fighting", "Club Fighting", "Sword Fighting", "Axe Fighting", "Distance Fighting", "Shielding", "Fishing"}
 
for a point of the skill selected example, 18:31 You advanced to sword fighting level 23. use item 18:31 You advanced to sword fighting level 24.

1 lvl skill
no have good English srry
 
look my edition :p
Code:
local skills = {"Magic Level", "Fist Fighting", "Club Fighting", "Sword Fighting", "Axe Fighting", "Distance Fighting", "Shielding", "Fishing"}

local staminaCost = 6 * 60
local voucherId = 13948

function onModalWindow(player, modalWindowId, buttonId, choiceId)
    if modalWindowId ~= 7092 then
        return false
    end
   
    if buttonId ~= 1 then
        return false
    end
   
    local voucher = player:getItemById(voucherId, true)
    if not voucher then
        -- avoids using scroll without removing one
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Put the scroll in your backpack first.")
        return false
    end
   
    if not skills[choiceId] then
        return false
    end
   
    local stamina = player:getStamina()
    if stamina < staminaCost then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You need at least " .. math.floor(staminaCost/60) .. " hours of stamina to do that.")
        return false
    end
   
   
    local maxskill = false
   
    if choiceId == 1 then
        -- database limit
        if player:getManaSpent() > 4294967295 then
            maxskill = true
        else
        player:addManaSpent(player:getVocation():getRequiredManaSpent(player:getBaseMagicLevel() + 1))
        end

    end
        if choiceId == 2 then
       
        player:addSkillTries(SKILL_FIST, player:getVocation():getRequiredSkillTries(SKILL_FIST, player:getSkillLevel(SKILL_FIST) + 1) - player:getSkillTries(SKILL_FIST))
        end
        if choiceId == 3 then
       
        player:addSkillTries(SKILL_CLUB, player:getVocation():getRequiredSkillTries(SKILL_CLUB, player:getSkillLevel(SKILL_CLUB) + 1) - player:getSkillTries(SKILL_CLUB))
        end
        if choiceId == 4 then
       
        player:addSkillTries(SKILL_SWORD, player:getVocation():getRequiredSkillTries(SKILL_SWORD, player:getSkillLevel(SKILL_SWORD) + 1) - player:getSkillTries(SKILL_SWORD))
        end

       if choiceId == 5 then

        player:addSkillTries(SKILL_AXE, player:getVocation():getRequiredSkillTries(SKILL_AXE, player:getSkillLevel(SKILL_AXE) + 1) - player:getSkillTries(SKILL_AXE))
        end

        if choiceId == 6 then

        player:addSkillTries(SKILL_DISTANCE, player:getVocation():getRequiredSkillTries(SKILL_DISTANCE, player:getSkillLevel(SKILL_DISTANCE) + 1) - player:getSkillTries(SKILL_DISTANCE))
        end

        if choiceId == 7 then
       
        player:addSkillTries(SKILL_SHIELD, player:getVocation():getRequiredSkillTries(SKILL_SHIELD, player:getSkillLevel(SKILL_SHIELD) + 1) - player:getSkillTries(SKILL_SHIELD))
        end
        if choiceId == 8 then
        player:addSkillTries(SKILL_FISHING, player:getVocation():getRequiredSkillTries(SKILL_FISHING, player:getSkillLevel(SKILL_FISHING) + 1) - player:getSkillTries(SKILL_FISHING))
        end
    if maxskill then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Final skill state reached. You cannot improve any further.")   
        return true
    end
   
    player:setStamina(stamina - staminaCost)
    player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You earned points on " .. skills[choiceId] .. ". " .. staminaCost .. " minutes of stamina used.")
    voucher:remove(1)
    return true
end

function onLogin(player)
    player:registerEvent("skillScrollWindow")
    return true
end
 
I know that my code is slow, thats why i was asking you for another one, but thanks for being a jerk, The world need more people like you xoxo
 
Haha, Zbizu! i love you posting working codes! ;)

Works great, thanks for release!
 
i have a problem ;/
[Warning - Event::checkScript] Can not load script: scripts/skillscroll.lua
data/actions/scripts/skillscroll.lua:3: '=' expected near 'function'
[Warning - Event::checkScript] Can not load script: scripts/scrollwindow.lua
data/creaturescripts/scripts/scrollwindow.lua:5: '=' expected near 'local'
[Warning - Event::checkScript] Can not load script: scripts/scrollwindow.lua
data/creaturescripts/scripts/scrollwindow.lua:5: '=' expected near 'local'
[Warning - Event::checkScript] Can not load script: scripts/scrollwindow.lua
data/creaturescripts/scripts/scrollwindow.lua:5: '=' expected near 'local'
[Warning - Event::checkScript] Can not load script: scripts/scrollwindow.lua
data/creaturescripts/scripts/scrollwindow.lua:5: '=' expected near 'local'
 
hi there im trying to use this on tfs 1.3 and when i select a skill it says "put the scroll in your backpack first" what can i do to fix this,

Edit: sorry figured it out i hadn't change the item id in script to new one :)
 
Last edited:
[Error - CreatureEvent::configureEvent] Invalid type for creature event: skillScrollWindow
[Warning - BaseEvents::loadFromXml] Failed to configure event

Does anyone know the reason?

Nostalrius based in tfs 1.2
 
Last edited:
Back
Top