local skill_levels_to_give = 1
local function addSkillTriesByPercent(cid, skillid, amount)
amount = math.floor(amount)
if amount < 1 then
return false
end
for i = 1, amount do
local cur_skill = getPlayerSkillLevel(cid, skillid)
local cur_skill_tries = getPlayerSkillTries(cid, skillid)
local skill_tries = getPlayerRequiredSkillTries(cid, skillId, cur_skill)
local skill_tries_next = getPlayerRequiredSkillTries(cid, skillId, cur_skill + 1)
local skill_tries_next_next = getPlayerRequiredSkillTries(cid, skillId, cur_skill + 2)
local current_percent = (cur_skill_tries - skill_tries) / ((skill_tries_next - skill_tries) / 100)
local next_skill_tries_to_percent = ((skill_tries_next_next - skill_tries_next) / 100) * current_percent
local cur_skill_tries_to_next_skill_tries = skill_tries_next - cur_skill_tries
local skill_tries_to_give = math.floor(cur_skill_tries_to_next_skill_tries + next_skill_tries_to_percent)
doPlayerAddSkillTry(cid, skillid, skill_tries_to_give)
end
return true
end
local function getPlayerWeaponType(cid)
local weapon = getPlayerWeapon(cid, true)
if weapon and weapon.uid > 0 then
return getItemWeaponType(weapon.uid)
end
return WEAPON_NONE
end
local function getPlayerSkillByWeaponType(weaponType)
local skill = WEAPON_NONE
if weaponType == WEAPON_SWORD then
skill = SKILL_SWORD
elseif weaponType == WEAPON_AXE then
skill = SKILL_AXE
elseif weaponType == WEAPON_CLUB then
skill = SKILL_CLUB
elseif weaponType == WEAPON_DISTANCE then
skill = SKILL_DISTANCE
end
return skill
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
local skill = getPlayerSkillByWeaponType(getPlayerWeaponType(cid))
if skill == WEAPON_NONE then
doPlayerSendCancel(cid, "You need to have a weapon equipped.")
return true
end
if addSkillTriesByPercent(cid, skill, skill_levels_to_give) == false then
doPlayerSendCancel(cid, "An error has occurred. Contact administrator. Error: Xikini-404") -- skill_levels_to_give needs to be a number higher then 0.
return true
end
doPlayerSendTextMessage(cid, TALKTYPE_BROADCAST, "CONGRATULATIONS! You gained ".. skill_levels_to_give .." SKILLS from the SKILL SCROLL!.")
doRemoveItem(item.uid, 1)
return true
end