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

TFS 0.X script wont stop looping rainbow outfit

royalpala

Well-Known Member
Joined
Dec 31, 2019
Messages
85
Solutions
1
Reaction score
68
i made this to work with a storage onDeEquip function but it wont stop looping

does anyone knows where the problem is???


I used the script from @Darkhaos here ----->>> Raibow Outfit (https://otland.net/threads/raibow-outfit.35629/)
TFS 0.4


Lua:
local colors = {94, 81, 79, 88, 18, 11, 92, 128}

function changeOutfit(cid)

local randomHead = colors[math.random(#colors)]
local randomLegs = colors[math.random(#colors)]
local randomBody = colors[math.random(#colors)]
local randomFeet = colors[math.random(#colors)]

local outfit = getCreatureOutfit(cid)
local tmp = {}

    if isPlayer(cid) then
        tmp = outfit
        tmp.lookType = outfit.lookType
        tmp.lookHead = randomHead
        tmp.lookLegs = randomLegs
        tmp.lookBody = randomBody
        tmp.lookFeet = randomFeet
        tmp.lookAddons = outfit.lookAddons

        doCreatureChangeOutfit(cid, tmp)
        setPlayerStorageValue(cid,14000,-1)
        local event = addEvent(repeatChangeOutfit, 200, cid)
        return TRUE
    
    elseif getPlayerStorageValue (cid, 14000) == 1 then
        stopEvent(event)
        return TRUE
    end
end

function repeatChangeOutfit(cid)

local randomHead = colors[math.random(#colors)]
local randomLegs = colors[math.random(#colors)]
local randomBody = colors[math.random(#colors)]
local randomFeet = colors[math.random(#colors)]

local outfit = getCreatureOutfit(cid)
local tmp = {}

    if isPlayer(cid) then
        tmp = outfit
        tmp.lookType = outfit.lookType
        tmp.lookHead = randomHead
        tmp.lookLegs = randomLegs
        tmp.lookBody = randomBody
        tmp.lookFeet = randomFeet
        tmp.lookAddons = outfit.lookAddons

        doCreatureChangeOutfit(cid, tmp)
        setPlayerStorageValue(cid,14000,-1)
        local event = addEvent(changeOutfit, 200, cid)
        return TRUE

    elseif getPlayerStorageValue (cid, 14000) == 1 then
        stopEvent(event)
        return TRUE
    end
end

function onEquip(cid, item, slot)
                addEvent(changeOutfit, 200, cid)
        return TRUE

end


function onDeEquip(cid, item, slot)
    if getPlayerStorageValue(cid, 14000) == -1 then
        setPlayerStorageValue(cid,14000,1)
    end
end

thanks in advance :)
 
Last edited:
Solution
His server didn't have boolean in the onDeEquip function for whatever reason.

So if you have the same issue, just use this instead
Lua:
function onDeEquip(cid, item, slot)
    setPlayerStorageValue(cid, 14000, -1) -- setting storage to -1, so we know the outfitChange is 'disabled'
    return callFunction(cid, item.uid, slot)
end
i made this to work with a storage onDeEquip function but it wont stop looping

does anyone knows where the problem is???


I used the script from @Darkhaos here ----->>> Raibow Outfit (https://otland.net/threads/raibow-outfit.35629/)
TFS 0.4


Lua:
local colors = {94, 81, 79, 88, 18, 11, 92, 128}

function changeOutfit(cid)

local randomHead = colors[math.random(#colors)]
local randomLegs = colors[math.random(#colors)]
local randomBody = colors[math.random(#colors)]
local randomFeet = colors[math.random(#colors)]

local outfit = getCreatureOutfit(cid)
local tmp = {}

    if isPlayer(cid) then
        tmp = outfit
        tmp.lookType = outfit.lookType
        tmp.lookHead = randomHead
        tmp.lookLegs = randomLegs
        tmp.lookBody = randomBody
        tmp.lookFeet = randomFeet
        tmp.lookAddons = outfit.lookAddons

        doCreatureChangeOutfit(cid, tmp)
        setPlayerStorageValue(cid,14000,-1)
        local event = addEvent(repeatChangeOutfit, 200, cid)
        return TRUE
  
    elseif getPlayerStorageValue (cid, 14000) == 1 then
        stopEvent(event)
        return TRUE
    end
end

function repeatChangeOutfit(cid)

local randomHead = colors[math.random(#colors)]
local randomLegs = colors[math.random(#colors)]
local randomBody = colors[math.random(#colors)]
local randomFeet = colors[math.random(#colors)]

local outfit = getCreatureOutfit(cid)
local tmp = {}

    if isPlayer(cid) then
        tmp = outfit
        tmp.lookType = outfit.lookType
        tmp.lookHead = randomHead
        tmp.lookLegs = randomLegs
        tmp.lookBody = randomBody
        tmp.lookFeet = randomFeet
        tmp.lookAddons = outfit.lookAddons

        doCreatureChangeOutfit(cid, tmp)
        setPlayerStorageValue(cid,14000,-1)
        local event = addEvent(changeOutfit, 200, cid)
        return TRUE

    elseif getPlayerStorageValue (cid, 14000) == 1 then
        stopEvent(event)
        return TRUE
    end
end

function onEquip(cid, item, slot)
                addEvent(changeOutfit, 200, cid)
        return TRUE

end


function onDeEquip(cid, item, slot)
    if getPlayerStorageValue(cid, 14000) == -1 then
        setPlayerStorageValue(cid,14000,1)
    end
end

thanks in advance :)
I'd suggest incorporating this fix so you don't have things happening that you do not intend to happen.

Beyond that, your issue is in your if statements.

You check if cid is a player first, therefore your elseif statement checking the storage value is never executed.

Additionally, you can call the same function with your addEvent, instead of creating a duplicate function and swapping from one to the other.

Aside from those issues, I'd suggest swapping the storages around, where -1 means off and 1 means on. By default storages start at -1 so it just makes more sense. Additionally, I'd only set the storage during the onEquip and onDeEquip stages, instead of constantly changing it inside of the outfitChange function.

With all of the above things in mind, here's the modifications I'd suggest.
Lua:
local colors = {94, 81, 79, 88, 18, 11, 92, 128}

function changeOutfit(cid)
   
    -- check if player exists
    if not isPlayer(cid) then
        return
    end
   
    -- check if outfitChanges should continue
    if getPlayerStorageValue(cid, 14000) ~= 1 then
        return
    end
   
    -- rainbow the outfit   
    local outfit = getCreatureOutfit(cid)
    local tmp = {}
    tmp = outfit
    tmp.lookType = outfit.lookType
    tmp.lookHead = colors[math.random(#colors)]
    tmp.lookLegs = colors[math.random(#colors)]
    tmp.lookBody = colors[math.random(#colors)]
    tmp.lookFeet = colors[math.random(#colors)]
    tmp.lookAddons = outfit.lookAddons
    doCreatureChangeOutfit(cid, tmp)
   
    -- create an addEvent to loop the function
    addEvent(changeOutfit, 200, cid)
end

function onEquip(cid, item, slot, boolean)
    if boolean == false then
        setPlayerStorageValue(cid, 14000, 1) -- setting storage to 1, so we know the outfitChange is 'active'
        addEvent(changeOutfit, 0, cid) -- setting timer to 0, because we want the function to start ASAP
    end
    return callFunction(cid, item.uid, slot, boolean)
end

function onDeEquip(cid, item, slot, boolean)
    if boolean == false then
        setPlayerStorageValue(cid,14000, -1) -- setting storage to -1, so we know the outfitChange is 'disabled'
    end
    return callFunction(cid, item.uid, slot, boolean)
end
 
@Xikini thank you so much! I'm a little rusted on coding, been on hiatus 6-8 months was not good for me
I was thinking about you a moment ago "If I dont manage to solve this maybe should PM xhikini, or forget about using this script"

You are a valuable member of OTLand and I've followed some of your comments on other threads for the development of my OTserver
 
@Xikini thank you so much! I'm a little rusted on coding, been on hiatus 6-8 months was not good for me
I was thinking about you a moment ago "If I dont manage to solve this maybe should PM xhikini, or forget about using this script"

You are a valuable member of OTLand and I've followed some of your comments on other threads for the development of my OTserver
It's working as intended now, I hope?
If yes, feel free to mark my post as a solution. xP
 
@Xikini just tried it now but the error is still happening on DeEquip
Can you change your onDeEquip function with this, and tell me what prints to console?
Lua:
function onDeEquip(cid, item, slot, boolean)
    print(boolean)
    if boolean == false then
        setPlayerStorageValue(cid, 14000, -1) -- setting storage to -1, so we know the outfitChange is 'disabled'
        print(getPlayerStorageValue(cid, 14000))
    end
    return callFunction(cid, item.uid, slot, boolean)
end
 
His server didn't have boolean in the onDeEquip function for whatever reason.

So if you have the same issue, just use this instead
Lua:
function onDeEquip(cid, item, slot)
    setPlayerStorageValue(cid, 14000, -1) -- setting storage to -1, so we know the outfitChange is 'disabled'
    return callFunction(cid, item.uid, slot)
end
 
Solution
Back
Top