T
Tibia Demon
Guest
I use last forgottenserver.
Script working but when I have promotion already it sends the cancel message and continue promoting me to second promotion.
I add many checks and kept trying for long but it only sends
player:sendCancelMessage("You are already promoted!")
but continues and promotes me to second promotion instead of returning false.
Solved.
I changed fromvoc to same as vocation id in vocations.xml but I wonder why it doesn't work when I have the correct fromvoc? like Epic master sorcerer fromvoc mastersorcerer so fromvoc = "5"?
Is it safe to keep it fromvoc same as vocation id?
I want to use the correct fromvoc because this is a promotion not a whole new custom vocation.
Any idea?
I noticed one thing after changing fromvoc when I try to use it I get this client message
You cannot use this object.
It is like it doesn't read the checks [level check, storage check, money check] its trying to make next promotion and then it fails [because it doesn't exist anymore] I changed fromvoc/vocid so instead of sending the [level check, storage check, money check] error message it just send this one
You cannot use this object.
Script working but when I have promotion already it sends the cancel message and continue promoting me to second promotion.
Lua:
-- Promotion script TFS 1.3 revScriptSys
-- place in data/scripts/talkaction/promotion.lua
local config = {
["premium"] = true,
["price"] = 20000,
["level"] = 100
}
local vocationsforfirstpromo = {
[1] = 5,
[2] = 6,
[3] = 7,
[4] = 8,
}
local TA_promotion = TalkAction("!buypromotion")
function TA_promotion.onSay(player)
-- Check if player need premium
if not player:isPremium() and config.premium then
player:sendCancelMessage("Sorry, you need to have a premium account.")
return false
end
-- Check if player is already promoted
local vocation = player:getVocation()
local vocID = player:getVocation():getId()
local vocationName = vocation:getName()
local promotion = vocation:getPromotion()
if (vocID > 4) or player:getStorageValue(PlayerStorageKeys.promotion) == 1 then
player:sendCancelMessage("You are already promoted!")
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:setStorageValue(PlayerStorageKeys.promotion, 1)
return false
end
if (vocID == 0) then
player:sendCancelMessage("No vocation cannot get a promotion.")
player:getPosition():sendMagicEffect(CONST_ME_POFF)
return false
end
-- Check if player is high enough level
if player:getLevel() < config.level then
player:sendCancelMessage("You can only be promoted once you have reached level " .. config.level .. ".")
return false
end
-- Check if player can afford promotion
if not player:removeTotalMoney(config.price) then
player:sendCancelMessage("You do not have enough money!")
return false
end
if vocationsforfirstpromo[vocID] ~= nil then
if table.contains({4, 3, 2, 1}, vocID) then
player:setVocation(Vocation(vocationsforfirstpromo[vocID]))
player:setStorageValue(PlayerStorageKeys.promotion, 1)
player:save()
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You have succesfully upgraded from "..vocationName.." to "..Vocation(vocationsforfirstpromo[vocID]):getName()..".")
player:sendTextMessage(MESSAGE_EVENT_ORANGE, "Congratulations! You are now promoted.")
player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your vocation cannot use this promotion.")
end
end
return false
end
TA_promotion:register()
player:sendCancelMessage("You are already promoted!")
but continues and promotes me to second promotion instead of returning false.
Post automatically merged:
Solved.
I changed fromvoc to same as vocation id in vocations.xml but I wonder why it doesn't work when I have the correct fromvoc? like Epic master sorcerer fromvoc mastersorcerer so fromvoc = "5"?
Is it safe to keep it fromvoc same as vocation id?
Post automatically merged:
I want to use the correct fromvoc because this is a promotion not a whole new custom vocation.
Any idea?
Post automatically merged:
I noticed one thing after changing fromvoc when I try to use it I get this client message
You cannot use this object.
It is like it doesn't read the checks [level check, storage check, money check] its trying to make next promotion and then it fails [because it doesn't exist anymore] I changed fromvoc/vocid so instead of sending the [level check, storage check, money check] error message it just send this one
You cannot use this object.
Last edited by a moderator: