• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua onChangeOutfit function bugging mount.

Apollos

Dude who does stuff
Premium User
Joined
Apr 22, 2009
Messages
845
Solutions
123
Reaction score
690
Location
United States
This is on TFS 1.1. Got a vocation specific outfit colors script working through events/scripts/creature.lua with other parts in login and logout but this part I have a problem with when players change their outfit color on something that isn't allowed it won't accept the color but then it bugs the mount so you can't use it until you relog. Wondering if there is maybe a function that could totally cancel the function so it would set to the previous outfit choices(which is what i have in login and logout)?

Code:
function Creature:onChangeOutfit(outfit)
     local VOC_WATER = {9,10,11,12,25,26,27,28}
     local VOC_EARTH = {13,14,15,16,29,30,31,32}
     local VOC_AIR = {5,6,7,8,21,22,23,24}
     local VOC_FIRE = {1,2,3,4,17,18,19,20}
    local outp = {outfit.lookFeet, outfit.lookLegs, outfit.lookBody, outfit.lookHead, outfit.lookMount}
     if self == nil then
     return true
     end
    if self:isPlayer() then
         if isInArray(VOC_WATER, self:getVocation():getId()) then
             if outp[1] ~= 68 or outp[2] ~= 0 or outp[3] ~= 68 or outp[4] ~= outfit.lookHead or outp[5] ~= outfit.lookMount then
             return false
             end
         end
     end
    if self:isPlayer() then
         if isInArray(VOC_EARTH, self:getVocation():getId()) then
             if outp[1] ~= 119 or outp[2] ~= 59 or outp[3] ~= 119 or outp[4] ~= outfit.lookHead or outp[5] ~= outfit.lookMount then
             return false
             end
         end
     end
    if self:isPlayer() then
         if isInArray(VOC_AIR, self:getVocation():getId()) then
             if outp[1] ~= 79 or outp[2] ~= 77 or outp[3] ~= 77 or outp[4] ~= outfit.lookHead or outp[5] ~= outfit.lookMount then
             return false
             end
         end
     end
    if self:isPlayer() then
         if isInArray(VOC_FIRE, self:getVocation():getId()) then
             if outp[1] ~= 132 or outp[2] ~= 114 or outp[3] ~= 132 or outp[4] ~= outfit.lookHead or outp[5] ~= outfit.lookMount then
             return false
             end
         end
     end
     return true
end
 
Solution
try this one on for size buddy
LUA:
local elements = {
    --// Water
    {
        vocations = {9, 10, 11, 12, 25, 26, 27, 28},
        colors = {lookBody = 68, lookLegs = 0, lookFeet = 68}
    },
    --// Earth
    {
        vocations = {13, 14, 15, 16, 29, 30, 31, 32},
        colors = {lookBody = 119, lookLegs = 59, lookFeet = 119}
    },
    --// Air
    {
        vocations = {5, 6, 7, 8, 21, 22, 23, 24},
        colors = {lookBody = 79, lookLegs = 77, lookFeet = 79}
    },
    --// Fire
    {
        vocations = {1, 2, 3, 4, 17, 18, 19, 20},
        colors = {lookBody = 132, lookLegs = 114, lookFeet = 132}
    }
}

--// Used to avoid stack overflow (because onChangeOutfit will be called over and over again since we set a new outfit)...
LUA:
local oldOutfit = self:getOutfit()
if not ... then
    self:setOutfit(oldOutfit)
end

Not sure what you wanted in the if statment so you will have to replace the dots for that :p
 
That entire code is wrong.

LUA:
if outp[1] ~= 68 or outp[2] ~= 0 or outp[3] ~= 68 or outp[4] ~= outfit.lookHead or outp[5] ~= outfit.lookMount then

All of these outp values are nil (do not exist).
 
Tried it with if not and replacing all the ~= with == but got an error saying then expected near =.
So changed to:
Code:
function Creature:onChangeOutfit(outfit)
     local oldOutfit = self:getOutfit()
     local VOC_WATER = {9,10,11,12,25,26,27,28}
     local VOC_EARTH = {13,14,15,16,29,30,31,32}
     local VOC_AIR = {5,6,7,8,21,22,23,24}
     local VOC_FIRE = {1,2,3,4,17,18,19,20}
     local outp = {outfit.lookFeet, outfit.lookLegs, outfit.lookBody, outfit.lookHead, outfit.lookMount}
    if self == nil then
     return true
     end
    if self:isPlayer() then
         if isInArray(VOC_WATER, self:getVocation():getId()) then
             if outp[1] ~= 68 or outp[2] ~= 0 or outp[3] ~= 68 or outp[4] ~= outfit.lookHead or outp[5] ~= outfit.lookMount then
             self:setOutfit(oldOutfit)
             end
         end
     end

And its now just allowing the outfit change.
 
That entire code is wrong.

LUA:
if outp[1] ~= 68 or outp[2] ~= 0 or outp[3] ~= 68 or outp[4] ~= outfit.lookHead or outp[5] ~= outfit.lookMount then

All of these outp values are nil (do not exist).

Im surprised myself but it does work. If there's a better way to write it let me know. I'm really new to scripting, this is biggest script I've taken on so far.
 
The question is; what are you trying to do? Considering the nil values your code is basically just doing this:

LUA:
function Creature:onChangeOutfit(outfit)
    if not self:isPlayer() then
        return true
    end

     local VOC_WATER = {9,10,11,12,25,26,27,28}
     local VOC_EARTH = {13,14,15,16,29,30,31,32}
     local VOC_AIR = {5,6,7,8,21,22,23,24}
     local VOC_FIRE = {1,2,3,4,17,18,19,20}
     
     if isInArray(VOC_WATER, self:getVocation():getId()) then
         return false
     end
     if isInArray(VOC_EARTH, self:getVocation():getId()) then
         return false
     end
     if isInArray(VOC_AIR, self:getVocation():getId()) then
         return false
     end
     if isInArray(VOC_FIRE, self:getVocation():getId()) then
         return false
     end
     return true
end

Fixed some other unnecessary stuff though. Just tell me what you wanna achieve and I'll help you get there. Those isPlayer could be moved up and used once only (as I did). This one was completely unnecessary:
LUA:
     if self == nil then -- what????? cant happen
     return true
     end
 
I'm trying to have it so that depending on what vocation you will be assigned an outfit color besides head color for example water nation will have blue and while outfit and cant change the color only can change had color, mount, and outfit/addons. I have two other scripts in login and logout.lua that might help you better understand what I'm doing with this.

Login.lua and Logout.lua have the same functions, because before you could relog quickly and get the new outfit color.

Code:
function onLogin(player)
    local VOC_WATER = {9,10,11,12,25,26,27,28}
    local VOC_EARTH = {13,14,15,16,29,30,31,32}
    local VOC_AIR = {5,6,7,8,21,22,23,24}
    local VOC_FIRE = {1,2,3,4,17,18,19,20}
    local outfit = player:getOutfit()
    if isInArray(VOC_WATER, player:getVocation():getId()) then
        player:setOutfit({lookType = outfit.lookType, lookHead = outfit.lookHead, lookBody = 68, lookLegs = 0, lookFeet = 68, lookAddons = outfit.lookAddons, lookMount = outfit.lookMount})
        end   
    if isInArray(VOC_EARTH, player:getVocation():getId()) then
        player:setOutfit({lookType = outfit.lookType, lookHead = outfit.lookHead, lookBody = 119, lookLegs = 59, lookFeet = 119, lookAddons = outfit.lookAddons, lookMount = outfit.lookMount})
        end   
    if isInArray(VOC_AIR, player:getVocation():getId()) then
        player:setOutfit({lookType = outfit.lookType, lookHead = outfit.lookHead, lookBody = 79, lookLegs = 77, lookFeet = 77, lookAddons = outfit.lookAddons, lookMount = outfit.lookMount})
        end   
    if isInArray(VOC_FIRE, player:getVocation():getId()) then
        player:setOutfit({lookType = outfit.lookType, lookHead = outfit.lookHead, lookBody = 132, lookLegs = 114, lookFeet = 132, lookAddons = outfit.lookAddons, lookMount = outfit.lookMount})
        end
 
try this one on for size buddy
LUA:
local elements = {
    --// Water
    {
        vocations = {9, 10, 11, 12, 25, 26, 27, 28},
        colors = {lookBody = 68, lookLegs = 0, lookFeet = 68}
    },
    --// Earth
    {
        vocations = {13, 14, 15, 16, 29, 30, 31, 32},
        colors = {lookBody = 119, lookLegs = 59, lookFeet = 119}
    },
    --// Air
    {
        vocations = {5, 6, 7, 8, 21, 22, 23, 24},
        colors = {lookBody = 79, lookLegs = 77, lookFeet = 79}
    },
    --// Fire
    {
        vocations = {1, 2, 3, 4, 17, 18, 19, 20},
        colors = {lookBody = 132, lookLegs = 114, lookFeet = 132}
    }
}

--// Used to avoid stack overflow (because onChangeOutfit will be called over and over again since we set a new outfit)
local key = 77777

function Creature:onChangeOutfit(outfit)
    if self:isPlayer() then
        if self:getStorageValue(key) == -1 then
            local voc = self:getVocation():getId()
            for i = 1, #elements do
                local val = elements[i]
                if isInArray(val.vocations, voc) then
                    outfit.lookBody = val.colors.lookBody
                    outfit.lookLegs = val.colors.lookLegs
                    outfit.lookFeet = val.colors.lookFeet
                    self:setStorageValue(key, 1)
                    self:setOutfit(outfit)
                    return false
                end
            end
        else
            self:setStorageValue(key, -1)
        end
    end
    return true
end
 
Solution
try this one on for size buddy
LUA:
local elements = {
    --// Water
    {
        vocations = {9, 10, 11, 12, 25, 26, 27, 28},
        colors = {lookBody = 68, lookLegs = 0, lookFeet = 68}
    },
    --// Earth
    {
        vocations = {13, 14, 15, 16, 29, 30, 31, 32},
        colors = {lookBody = 119, lookLegs = 59, lookFeet = 119}
    },
    --// Air
    {
        vocations = {5, 6, 7, 8, 21, 22, 23, 24},
        colors = {lookBody = 79, lookLegs = 77, lookFeet = 79}
    },
    --// Fire
    {
        vocations = {1, 2, 3, 4, 17, 18, 19, 20},
        colors = {lookBody = 132, lookLegs = 114, lookFeet = 132}
    }
}

--// Used to avoid stack overflow (because onChangeOutfit will be called over and over again since we set a new outfit)
local key = 77777

function Creature:onChangeOutfit(outfit)
    if self:isPlayer() then
        if self:getStorageValue(key) == -1 then
            local voc = self:getVocation():getId()
            for i = 1, #elements do
                local val = elements[i]
                if isInArray(val.vocations, voc) then
                    outfit.lookBody = val.colors.lookBody
                    outfit.lookLegs = val.colors.lookLegs
                    outfit.lookFeet = val.colors.lookFeet
                    self:setStorageValue(key, 1)
                    self:setOutfit(outfit)
                    return false
                end
            end
        else
            self:setStorageValue(key, -1)
        end
    end
    return true
end

Worked like a charm man, thanks so much. Now i need to work on learning how the heck you did all this. lol
 
Back
Top