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

C++ How to edit this script to see the vocation

willks123

New Member
Joined
Dec 31, 2012
Messages
65
Reaction score
2
How do I edit this script so that when the player level up, he earns Outfit according to his vocation? Example: EK = Warrior Outfit, Sorcerer = Wizard ...
No need to earn the Addon. Outfit Only

local tabela =
{

-- [level] = type = "item", id = ITEM_ID, id2 = QUANTIDADE, msg = "MENSAGEM"},
-- [level] = type = "addon", id = ID_ADDON_FEMALE, id2 = ID_ADDON_MALE, msg = "MENSAGEM"},
-- [level] = type = "mount", id = ID_MOUNT, id2 = 0, msg = "MENSAGEM"},

[20] = {type = "promote", id = 2160, id2 = 2, msg = "Parabens! Voce foi promovido e ganhou 2 Crystal Coins"},
[40] = {type = "addon", id = 136, id2 = 128, msg = "Voce ganhou o addon citizen full por alcancar o level 40!"},
[50] = {type = "item", id = 2160, id2 = 5, msg = "Voce ganhou 5 crystal coins por alcancar o level 50!"},
[60] = {type = "mount", id = 2, id2 = 0, msg = "Voce ganhou uma montaria!"},
[100] = {type = "item", id = 2160, id2 = 10, msg = "Voce ganhou 10 crystal coins por alcancar o level 100!"},
[150] = {type = "item", id = 2160, id2 = 15, msg = "Voce ganhou 15 crystal coins por alcancar o level 150!"},
[200] = {type = "item", id = 2160, id2 = 20, msg = "Voce ganhou 20 crystal coins por alcancar o level 200!"},
[250] = {type = "item", id = 2160, id2 = 25, msg = "Voce ganhou 25 crystal coins por alcancar o level 250!"},
[300] = {type = "item", id = 2160, id2 = 30, msg = "Voce ganhou 30 crystal coins por alcancar o level 300!"},

}

local storage = 15000
function onAdvance(player, skill, oldLevel, newLevel)
if (skill == 8) then
for level, _ in pairs(tabela) do
if player:getLevel() >= level and player:getStorageValue(storage) < level then

if tabela[level].type == "item" then
player:addItem(tabela[level].id, tabela[level].id2)

elseif tabela[level].type == "addon" then
player:addOutfitAddon(tabela[level].id, 3)
player:addOutfitAddon(tabela[level].id2, 3)

elseif tabela[level].type == "mount" then
player:addMount(tabela[level].id)

elseif tabela[level].type == "promote" then
local vocation = player:getVocation()
local promotion = vocation:getPromotion()
player:setVocation(promotion)
player:addItem(tabela[level].id, tabela[level].id2)
else
return false
end

player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, tabela[level].msg)
player:setStorageValue(storage, level)
end
end
end
player:save() -- salvando player
return true
end
 
How do I edit this script so that when the player level up, he earns Outfit according to his vocation? Example: EK = Warrior Outfit, Sorcerer = Wizard ...
No need to earn the Addon. Outfit Only

local tabela =
{

-- [level] = type = "item", id = ITEM_ID, id2 = QUANTIDADE, msg = "MENSAGEM"},
-- [level] = type = "addon", id = ID_ADDON_FEMALE, id2 = ID_ADDON_MALE, msg = "MENSAGEM"},
-- [level] = type = "mount", id = ID_MOUNT, id2 = 0, msg = "MENSAGEM"},

[20] = {type = "promote", id = 2160, id2 = 2, msg = "Parabens! Voce foi promovido e ganhou 2 Crystal Coins"},
[40] = {type = "addon", id = 136, id2 = 128, msg = "Voce ganhou o addon citizen full por alcancar o level 40!"},
[50] = {type = "item", id = 2160, id2 = 5, msg = "Voce ganhou 5 crystal coins por alcancar o level 50!"},
[60] = {type = "mount", id = 2, id2 = 0, msg = "Voce ganhou uma montaria!"},
[100] = {type = "item", id = 2160, id2 = 10, msg = "Voce ganhou 10 crystal coins por alcancar o level 100!"},
[150] = {type = "item", id = 2160, id2 = 15, msg = "Voce ganhou 15 crystal coins por alcancar o level 150!"},
[200] = {type = "item", id = 2160, id2 = 20, msg = "Voce ganhou 20 crystal coins por alcancar o level 200!"},
[250] = {type = "item", id = 2160, id2 = 25, msg = "Voce ganhou 25 crystal coins por alcancar o level 250!"},
[300] = {type = "item", id = 2160, id2 = 30, msg = "Voce ganhou 30 crystal coins por alcancar o level 300!"},

}

local storage = 15000
function onAdvance(player, skill, oldLevel, newLevel)
if (skill == 8) then
for level, _ in pairs(tabela) do
if player:getLevel() >= level and player:getStorageValue(storage) < level then

if tabela[level].type == "item" then
player:addItem(tabela[level].id, tabela[level].id2)

elseif tabela[level].type == "addon" then
player:addOutfitAddon(tabela[level].id, 3)
player:addOutfitAddon(tabela[level].id2, 3)

elseif tabela[level].type == "mount" then
player:addMount(tabela[level].id)

elseif tabela[level].type == "promote" then
local vocation = player:getVocation()
local promotion = vocation:getPromotion()
player:setVocation(promotion)
player:addItem(tabela[level].id, tabela[level].id2)
else
return false
end

player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, tabela[level].msg)
player:setStorageValue(storage, level)
end
end
end
player:save() -- salvando player
return true
end

Firstly, this is lua not c++, secondly you should tab your scripts or insert them through the coding button cause its kinda hard to read, and lastly you should include your server version in your post, all this will help you receive more help from others.

You should probably just rewrite your script from scratch using this one you have as a reference. But you would basically just do somethine like this(written in a couple minutes so its only for reference):

Lua:
local outfits = {
    [1, 5] = {20 = {sorcererOutfit1}, 50 = {sorcererOutfit2}, 100 = {sorcererOutfit3}},-- change these values to the lookType ID
    [2, 6] = {20 = {druidOutfit1}, 50 = {druidOutfit2}, 100 = {druidOutfit3}},
    [3, 7] = {20 = {pallyOutfit1}, 50 = {pallyOutfit2}, 100 = {pallyOutfit3}},
    [4, 8] = {20 = {sorcererOutfit1}, 50 = {sorcererOutfit2}, 100 = {sorcererOutfit3}}
}

function onAdvance(player, skill, oldLevel, newLevel)
    if (skill == 8) then
        for i = 1, #outfits do
            if isInArray(player:getVocation(), outfits[i]) then
                player:addOutfit(outfits[i].newLevel)
                Position(player:getPosition()):sendMagicEffect(CONST_ME_FIREWORK_BLUE)
            end
        end
    end
    return true
end
 
Firstly, this is lua not c++, secondly you should tab your scripts or insert them through the coding button cause its kinda hard to read, and lastly you should include your server version in your post, all this will help you receive more help from others.

You should probably just rewrite your script from scratch using this one you have as a reference. But you would basically just do somethine like this(written in a couple minutes so its only for reference):

Lua:
local outfits = {
    [1, 5] = {20 = {sorcererOutfit1}, 50 = {sorcererOutfit2}, 100 = {sorcererOutfit3}},-- change these values to the lookType ID
    [2, 6] = {20 = {druidOutfit1}, 50 = {druidOutfit2}, 100 = {druidOutfit3}},
    [3, 7] = {20 = {pallyOutfit1}, 50 = {pallyOutfit2}, 100 = {pallyOutfit3}},
    [4, 8] = {20 = {sorcererOutfit1}, 50 = {sorcererOutfit2}, 100 = {sorcererOutfit3}}
}

function onAdvance(player, skill, oldLevel, newLevel)
    if (skill == 8) then
        for i = 1, #outfits do
            if isInArray(player:getVocation(), outfits[i]) then
                player:addOutfit(outfits[i].newLevel)
                Position(player:getPosition()):sendMagicEffect(CONST_ME_FIREWORK_BLUE)
            end
        end
    end
    return true
end



This script is not mine, in fact I do not know how to create scripts yet ... Actually I just want to put in my server a system that the player gets lvl 20 he gains a promotion and 1 Outfit according to his vocation. When you reach level 50, get another Promotion and another Outfit according to your vocation. And when reaching level 100 another promotion and another Outfit according to vocation. The version of my server is TFE 1.2 Can you do this script? And I'm sorry for posting wrong.
 
This script is not mine, in fact I do not know how to create scripts yet ... Actually I just want to put in my server a system that the player gets lvl 20 he gains a promotion and 1 Outfit according to his vocation. When you reach level 50, get another Promotion and another Outfit according to your vocation. And when reaching level 100 another promotion and another Outfit according to vocation. The version of my server is TFE 1.2 Can you do this script? And I'm sorry for posting wrong.

You should post in requests board if you want someone to make you a script. But this is a good script to begin practicing, I think you should give it a shot and see what you can figure out.
 
Code:
local vocations = {
[1] = {level = 20, voc_new = 5, m_outit = 111, f_outfit = 111, storage = 31000},
[2] = {level = 20, voc_new = 6, m_outit = 111, f_outfit = 111, storage = 31001}
}

function onAdvance(player, skill, oldLevel, newLevel)
    if (skill == SKILL_LEVEL) then
     
        for i = 1, #vocations do
            VOC = vocations[player:getVocation():getId()]
            if VOC then
                if newLevel == VOC.level and player:getStorageValue(VOC.storage) == nil then
                    if player:getSex() == 0 then
                        player:addOutfit(VOC.f_outfit)
                        player:addOutfitAddon(VOC.f_outfit, 1)
                        player:addOutfitAddon(VOC.f_outfit, 2)
                    else
                        player:addOutfit(VOC.m_outfit)
                        player:addOutfitAddon(VOC.m_outfit, 1)
                        player:addOutfitAddon(VOC.m_outfit, 2)
                    end
                        player:setVocation(VOC.voc_new)
                end
            end
        end
    end
    return true
end
 
this should work maybe

Lua:
local vocations = {
    [1] = { -- sorc or master sorc
        level = 20,
        voc_new = 5,
        outfit = {
            [0] = 111,
            [1] = 222
            },
        storage = 31001
    },
    [2] = { -- druid or elder druid
        level = 20,
        voc_new = 5,
        outfit = {
            [0] = 111,
            [1] = 222
            },
        storage = 31002
    }
}
function onAdvance(player, skill, oldLevel, newLevel)
    if (skill == SKILL_LEVEL) then
        local vocation = vocations[player:getVocation():getBase():getId()]
        if vocation then
            if newLevel >= vocation.level and player:getStorageValue(vocation.storage) < 1 then
                local outfit = vocation.outfit[player:getSex()]
                if outfit then
                    player:addOutfit(outfit)
                    player:addOutfitAddon(outfit, 1)
                    player:addOutfitAddon(outfit, 2)
                end
                player:setVocation(vocation.voc_new) -- or promote? dont know just copied what ltutorial did
                player:setStoraveValue(vocation.storage, 1)
            end
        end
    end
    return true
end
 
this should work maybe

Lua:
local vocations = {
    [1] = { -- sorc or master sorc
        level = 20,
        voc_new = 5,
        outfit = {
            [0] = 111,
            [1] = 222
            },
        storage = 31001
    },
    [2] = { -- druid or elder druid
        level = 20,
        voc_new = 5,
        outfit = {
            [0] = 111,
            [1] = 222
            },
        storage = 31002
    }
}
function onAdvance(player, skill, oldLevel, newLevel)
    if (skill == SKILL_LEVEL) then
        local vocation = vocations[player:getVocation():getBase():getId()]
        if vocation then
            if newLevel >= vocation.level and player:getStorageValue(vocation.storage) < 1 then
                local outfit = vocation.outfit[player:getSex()]
                if outfit then
                    player:addOutfit(outfit)
                    player:addOutfitAddon(outfit, 1)
                    player:addOutfitAddon(outfit, 2)
                end
                player:setVocation(vocation.voc_new) -- or promote? dont know just copied what ltutorial did
                player:setStoraveValue(vocation.storage, 1)
            end
        end
    end
    return true
end
uhm i'm using in Creaturescript.xml
Lua:
<event type="advance" name="LevelUp" event="script" value="levelup.lua"/>
but don't work...


Char increases the level. But it does not gain promotion and nothing happens.


Am I doing something wrong?
 
Register it in login.lua
I tried to register in two ways in Login.lua.
Lua:
registerCreatureEvent(cid,"LevelUp")


And so also
Lua:
player:registerEvent("LevelUp")


But anyway, I did the IN GAME test. And it did not work. Nothing happened, as if the script did not even exist.


Did I do something wrong?


I'll put Creaturescript.lua and Login.lua and can you see for me where I went wrong?

Login.lua
Code:
local function onMovementRemoveProtection(cid, oldPosition, time)
    local player = Player(cid)
    if not player then
        return true
    end

    local playerPosition = player:getPosition()
    if (playerPosition.x ~= oldPosition.x or playerPosition.y ~= oldPosition.y or playerPosition.z ~= oldPosition.z) or player:getTarget() then
        player:setStorageValue(Storage.combatProtectionStorage, 0)
        return true
    end

    addEvent(onMovementRemoveProtection, 1000, cid, oldPosition, time - 1)
end

function onLogin(player)
for i = 40000, 40012 do
            if player:getStorageValue(i) < 10 then
                player:setStorageValue(i, 10)
                player:setStorageValue(i + 1000, 0)
            end
        end
    local loginStr = "Welcome to " .. configManager.getString(configKeys.SERVER_NAME) .. "!"
    if player:getLastLoginSaved() <= 0 then
        loginStr = loginStr .. " Please choose your outfit."
        player:sendOutfitWindow()
    else
        if loginStr ~= "" then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
        end

        loginStr = string.format("Your last visit was on %s.", os.date("%a %b %d %X %Y", player:getLastLoginSaved()))
    end
    player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)

    local playerId = player:getId()

    -- Stamina
    nextUseStaminaTime[player.uid] = 0

    -- Promotion
    local vocation = player:getVocation()
    local promotion = vocation:getPromotion()
    if player:isPremium() or player:getLevel() <= 19 then
        local value = player:getStorageValue(STORAGEVALUE_PROMOTION)
        if not promotion and value ~= 1 then
            player:setStorageValue(STORAGEVALUE_PROMOTION, 1)
        elseif value == 1 then
            player:setVocation(promotion)
        end
    elseif not promotion then
        player:setVocation(vocation:getDemotion())
    end

    -- Rewards notice
    local rewards = #player:getRewardList()
    if rewards > 0 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You have %s %s in your reward chest.", rewards == 1 and 'one' or rewards, rewards > 1 and "rewards" or "reward"))
    end

    -- Update player id
    local stats = player:inBossFight()
    if stats then
        stats.playerId = player:getId()
    end

    -- Events
    player:registerEvent("PlayerDeath")
    player:registerEvent("DropLoot")
    player:registerEvent("BossParticipation")
    player:registerEvent("Teleport")
    player:registerEvent("smith_modal")
    player:registerEvent("smelt_modal")
    player:registerEvent("tan_modal")
    player:registerEvent("catacombw")
    registerCreatureEvent(cid, "dropStone")
    player:registerEvent("RewardChest")
    registerCreatureEvent(cid,"LevelUp")

    if player:getStorageValue(Storage.combatProtectionStorage) <= os.time() then
        player:setStorageValue(Storage.combatProtectionStorage, os.time() + 10)
        onMovementRemoveProtection(playerId, player:getPosition(), 10)
    end
    db.query('INSERT INTO `players_online` (`player_id`) VALUES (' .. playerId .. ')')
        return true
end

Creaturescript.lua
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<creaturescripts>
    <event type="login" name="PlayerLogin" script="login.lua" />
    <event type="logout" name="PlayerLogout" script="logout.lua" />
    <event type="login" name="OfflineTraining" script="offlinetraining.lua" />
    <event type="login" name="RegenerateStamina" script="regeneratestamina.lua" />
    <event type="death" name="PlayerDeath" script="playerdeath.lua" />
    <event type="death" name="DropLoot" script="droploot.lua" />
    <event type="extendedopcode" name="ExtendedOpcode" script="extendedopcode.lua" />

    <!-- Customs -->
    <event type="login" name="FirstItems" script="firstitems.lua" />
    <event type="advance" name="AdvanceSave" script="advance_save.lua" />
    <event type="death" name="BossDeath" script="boss.lua" />
    <event type="healthchange" name="BossParticipation" script="boss.lua" />
    <event type="think" name="BossThink" script="boss.lua" />
    <event type="modalWindow" name="Teleport" script="teleport.lua"/>
    <event type="modalwindow" name="smith_modal" script="smith.lua"/>
    <event type="modalwindow" name="smelt_modal" script="smelt.lua"/>
    <event type="modalwindow" name="tan_modal" script="tan.lua"/>
    <event type="modalwindow" name="catacombw" script="catacomb_window.lua"/>
    <event type="kill" name="dropStone" script="dropstone.lua"/>
    <event type="login" name="randomstats_register" script="randomstats.lua"/>
    <event type="kill" name="randomstats_loot" script="randomstats.lua"/>   
    <event type="login" name="SlotLogin" script="slot.lua"/>
    <event type="advance" name="LevelUp" event="script" value="levelup.lua"/>
   
        <!--<event type="advance" name="onadvance_reward" script="onadvance_reward.lua"/>
        <event type="login" name="onadv_register" script="onadvance_reward.lua"/>
        <event type="login" name="freebless" script="freeblesslowlevel.lua"/>
    -->
</creaturescripts>
 
do something like

Lua:
local vocations = {
    [1] = { -- sorc or master sorc
        level = 20,
        voc_new = 5,
        outfit = {
            [0] = 111,
            [1] = 222
            },
        storage = 31001
    },
    [2] = { -- druid or elder druid
        level = 20,
        voc_new = 5,
        outfit = {
            [0] = 111,
            [1] = 222
            },
        storage = 31002
    }
}
function onAdvance(player, skill, oldLevel, newLevel)
    if (skill == SKILL_LEVEL) then
        print("test 1")
        local vocation = vocations[player:getVocation():getBase():getId()]
        if vocation then
            print("test 2")
            if newLevel >= vocation.level and player:getStorageValue(vocation.storage) < 1 then
                local outfit = vocation.outfit[player:getSex()]
                if outfit then
                    print("test 3")
                    player:addOutfit(outfit)
                    player:addOutfitAddon(outfit, 1)
                    player:addOutfitAddon(outfit, 2)
                end
                player:setVocation(vocation.voc_new) -- or promote? dont know just copied what ltutorial did
                player:setStoraveValue(vocation.storage, 1)
            end
        end
    end
    return true
end
and show the console msgs
 
Back
Top