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

!promotion 1.2

bybbzan

mapper
Joined
Aug 4, 2012
Messages
809
Solutions
2
Reaction score
136
Location
Sweden
Hello!

I'm trying to make a working !promotion talkaction script.
But i am so freakin bad at scripting, although i tried.

I'm not getting any errors in the console, it just takes money and says "You are already promoted!"

script
Code:
local cost = 20000
local level = 20

function onSay(cid, words, param, channel)
    if getPromotedVocation(5,6,7,8) then
        return doPlayerSendCancel(cid, 'You are already promoted.')
    end
 
    if getPlayerLevel(cid) < level then
        return doPlayerSendCancel(cid, 'You must be at least level 20 in order to be promoted.')
    end
 
    if doPlayerRemoveMoney(cid, cost) then
        vocation:getPromotion()
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Congratulations! You have just been promoted')
        doSendMagicEffect(getThingPos(cid), math.random(28,30))
        doPlayerSave(cid)
    else
        return doPlayerSendCancel(cid, 'You must need '..cost..' gps in order to be promoted.')
    end
    return true
end
 
Solution
you're using 1.2, stop using the legacy functions & cid as parameters
function onSay(player, words, param)
you can find the list of functions in my signature (interface functions)
scripting-wise you can find the list of functions here (there are a few missing)
[TFS 1.0 / 1.2] LUA Functions
LUA:
local cost = 20000
local level = 20

function onSay(player, words, param)
    if player:isPremium() then
        local promotion = player:getVocation():getPromotion()
        if player:getStorageValue(STORAGEVALUE_PROMOTION) == 1 then
            player:sendCancelMessage("You are already promoted!")
        elseif player:getLevel() < level then
            player:sendCancelMessage("You need atleast level to buy promotion.")
        elseif not...
Hello!

I'm trying to make a working !promotion talkaction script.
But i am so freakin bad at scripting, although i tried.

I'm not getting any errors in the console, it just takes money and says "You are already promoted!"

script
Code:
local cost = 20000
local level = 20

function onSay(cid, words, param, channel)
    if getPromotedVocation(5,6,7,8) then
        return doPlayerSendCancel(cid, 'You are already promoted.')
    end
 
    if getPlayerLevel(cid) < level then
        return doPlayerSendCancel(cid, 'You must be at least level 20 in order to be promoted.')
    end
 
    if doPlayerRemoveMoney(cid, cost) then
        vocation:getPromotion()
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Congratulations! You have just been promoted')
        doSendMagicEffect(getThingPos(cid), math.random(28,30))
        doPlayerSave(cid)
    else
        return doPlayerSendCancel(cid, 'You must need '..cost..' gps in order to be promoted.')
    end
    return true
end

LUA:
vocation:getPromotion()

Take a look here; forgottenserver/modules.lua at 33d074fe1cb28d7f094e0e6896ada65d9cd472a2 · otland/forgottenserver · GitHub

Avoid returning a function, can screw things up.
LUA:
doPlayerSendCancel(cid, 'You are already promoted.')
return true
 
LUA:
vocation:getPromotion()

Take a look here; forgottenserver/modules.lua at 33d074fe1cb28d7f094e0e6896ada65d9cd472a2 · otland/forgottenserver · GitHub

Avoid returning a function, can screw things up.
LUA:
doPlayerSendCancel(cid, 'You are already promoted.')
return true

Thanks for the support, i just came this far tho.. lol
I dont know what im suppose to do with these lines.
Code:
        if player:isPremium() or not parameters.premium then
            local promotion = player:getVocation():getPromotion()

Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/promotion.lua:onSay
data/talkactions/scripts/promotion.lua:6: attempt to index upvalue 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/talkactions/scripts/promotion.lua:6: in function <data/talkactions/scripts/promotion.lua:5>

Code:
local cost = 20000
local level = 20
local player = Player(cid)

function onSay(cid, words, param, channel)
        if player:isPremium() or not parameters.premium then
            local promotion = player:getVocation():getPromotion()
            if player:getStorageValue(STORAGEVALUE_PROMOTION) == 1 then
                doPlayerSendCancel("You are already promoted!", cid)
            elseif player:getLevel() < level then
                doPlayerSendCancel("You need atleast level to buy promotion.", cid)
            elseif not player:removeMoney(cost) then
                doPlayerSendCancel("You do not have enough money!", cid)
            else
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'You successfully bought promotion.')
                doSendMagicEffect(getThingPos(cid), math.random(28,30))               
                player:setVocation(promotion)
                player:setStorageValue(STORAGEVALUE_PROMOTION, 1)
                doPlayerSave(cid)
            end
        else
            doPlayerSendCancel("You need a premium account in order to get promoted.", cid)
        end
        return true
    end
 
you're using 1.2, stop using the legacy functions & cid as parameters
function onSay(player, words, param)
you can find the list of functions in my signature (interface functions)
scripting-wise you can find the list of functions here (there are a few missing)
[TFS 1.0 / 1.2] LUA Functions
LUA:
local cost = 20000
local level = 20

function onSay(player, words, param)
    if player:isPremium() then
        local promotion = player:getVocation():getPromotion()
        if player:getStorageValue(STORAGEVALUE_PROMOTION) == 1 then
            player:sendCancelMessage("You are already promoted!")
        elseif player:getLevel() < level then
            player:sendCancelMessage("You need atleast level to buy promotion.")
        elseif not player:removeMoney(cost) then
            player:sendCancelMessage("You do not have enough money!")
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'You successfully bought promotion.')
            player:getPosition():sendMagicEffect(math.random(28,30))              
            player:setVocation(promotion)
            player:setStorageValue(STORAGEVALUE_PROMOTION, 1)
            player:save()
        end
    else
        player:sendCancelMessage("You need a premium account in order to get promoted.")
    end
    return true
end
 
Last edited:
Solution
you're using 1.2, stop using the legacy functions & cid as parameters
function onSay(player, words, param)
you can find the list of functions in my signature (interface functions)
scripting-wise you can find the list of functions here (there are a few missing)
[TFS 1.0 / 1.2] LUA Functions
LUA:
local cost = 20000
local level = 20

function onSay(player, words, param)
    if player:isPremium() then
        local promotion = player:getVocation():getPromotion()
        if player:getStorageValue(STORAGEVALUE_PROMOTION) == 1 then
            player:sendCancelMessage("You are already promoted!")
        elseif player:getLevel() < level then
            player:sendCancelMessage("You need atleast level to buy promotion.")
        elseif not player:removeMoney(cost) then
            player:sendCancelMessage("You do not have enough money!")
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'You successfully bought promotion.')
            player:getPosition():sendMagicEffect(math.random(28,30))             
            player:setVocation(promotion)
            player:setStorageValue(STORAGEVALUE_PROMOTION, 1)
            player:save()
        end
    else
        player:sendCancelMessage("You need a premium account in order to get promoted.")
    end
    return true
end

Why create a variable "promotion" when it's only used once?
And IMO it's better to give ppl hints insted of the full code, that way they *hopefully* learn insted of getting spoon feed.

- Atleast till you get tired and just give them the code haha :p
 
Why create a variable "promotion" when it's only used once?
And IMO it's better to give ppl hints insted of the full code, that way they *hopefully* learn insted of getting spoon feed.

- Atleast till you get tired and just give them the code haha :p
i didn't, i just copied it from the guy's script and converted the older functions to the newer ones.
also, that variable is the exact same in the default NPC lib, so if you actually have a problem with it maybe update it and create a pr, but it's such a small thing to bother with to improve (maybe) nanoseconds of time to save a small amount of memory.
even then, creating a variable for that long piece of code would still be optimal imo, rather than having a gigantic one-liner.
it is better to give hints but i'm getting too tired of waiting around on here for people to understand what i'm trying to tell them, especially if i can tell they don't have much knowledge themselves (so i doubt they will understand the hints).
if the guy really wants to learn, i gave him the references he needs and he can teach himself by comparing what his code was with what i gave him and learning lua by reading PIL online, if not, it's whatever.
 
Why create a variable "promotion" when it's only used once?
And IMO it's better to give ppl hints insted of the full code, that way they *hopefully* learn insted of getting spoon feed.

- Atleast till you get tired and just give them the code haha :p
i didn't, i just copied it from the guy's script and converted the older functions to the newer ones.
also, that variable is the exact same in the default NPC lib, so if you actually have a problem with it maybe update it and create a pr, but it's such a small thing to bother with to improve (maybe) nanoseconds of time to save a small amount of memory.
even then, creating a variable for that long piece of code would still be optimal imo, rather than having a gigantic one-liner.
it is better to give hints but i'm getting too tired of waiting around on here for people to understand what i'm trying to tell them, especially if i can tell they don't have much knowledge themselves (so i doubt they will understand the hints).
if the guy really wants to learn, i gave him the references he needs and he can teach himself by comparing what his code was with what i gave him and learning lua by reading PIL online, if not, it's whatever.

Well i'm really thankful for the hints, advices and what not to improve my horrible scripting skills.
I think it's good to do what you do @WibbenZ in some cases, giving hints to people to figure it out themselves.
Sometimes however you can tell that a person is impatient and don't want to learn.
I just recently started using TFS 1.2 which has some new functions and looks different compared to the old days.
Thats why i mixed old & new functions, because i have no idea what i am doing. Thanks you @Static_ for sending those links.
I will definitely take a look and start learning for real.
 
Sometimes however you can tell that a person is impatient and don't want to learn.

Well in those cases I rarely help, if person A has an error ex missing a function and he learns that error, he won't ever need help with that again.
But person B gets feed everytime and will create 20 threads with pretty much the same issues because he never learned how to read error codes and easy bugs.

But I get @Static_ after a while you get tired and just give them the code.
 
Well in those cases I rarely help, if person A has an error ex missing a function and he learns that error, he won't ever need help with that again.
But person B gets feed everytime and will create 20 threads with pretty much the same issues because he never learned how to read error codes and easy bugs.

But I get @Static_ after a while you get tired and just give them the code.

Yes I agree. And since this is the support section, you expect to get help by those who got the knowledge like yourself.
Then it's up to them how they want to support, by giving hints or just present the correct written code. :)
 
Back
Top