zbizu
Legendary OT User
A scroll which adds skills using player's stamina.
Can bring lots of profits to server owners when used with items like stamina doll.
13:46 You earned 540000 points on Axe Fighting. 360 minutes of stamina used.
actions.xml
skillscroll.lua
creaturescripts.xml
scrollwindow.lua
Can bring lots of profits to server owners when used with items like stamina doll.
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: