• 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 1.X+ Swimming is boged

Mjmackan

Mapper ~ Writer
Joined
Jul 18, 2009
Messages
1,480
Solutions
18
Reaction score
195
Location
Sweden
Hey! Using the swimming script (pretty much) with some changes onto new water id i get slowed until i cannot move, the addCondition seems to be the culprit.

I have tried adding:
creature:removeCondition(CONDITION_OUTFIT)
Before the setCondition, but didn't work, only thing that works seems to be removing the setCondition but then im just running on top of water like some jesus-ahh.

The script:
LUA:
local condition = Condition(CONDITION_OUTFIT)
condition:setOutfit({ lookType = 2015 })
condition:setTicks(-1)

function onStepIn(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        return false
    end

    if creature:getStorageValue(943943) <= os.time() then
        creature:sendTextMessage(MESSAGE_STATUS_SMALL, "This water isn't safe to swim in, rent a boat in order to enter.")

        local fromTile = Tile(fromPosition)

        if fromTile and fromTile:getItemById(33707) then
            -- Came from another water tile then send to safe position with delay
            creature:sendTextMessage(MESSAGE_STATUS_WARNING, "Your boat rental has expired. You have been returned to safety.")

            addEvent(function()
                if creature and creature:isPlayer() then
                    creature:teleportTo(Position(842, 1098, 6))
                    creature:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                end
            end, 300) -- 300ms delay

        else
            -- Normal case will teleport back immediately
            creature:teleportTo(fromPosition, false)
        end

    else
        creature:addCondition(condition)
    end

    return true
end

function onStepOut(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        return false
    end

    creature:removeCondition(CONDITION_OUTFIT)
    return true
end
 
LUA:
local swimStorage = 3330


function onStepIn(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        return false
    end

    local isswimming = creature:getStorageValue(swimStorage)


    local diverOutfit = {
        lookType = 267,
        lookHead = 0,
        lookBody = 0,
        lookLegs = 0,
        lookFeet = 0,
        lookAddons = 0
    }

    if isswimming ~= 1 then

        creature:setStorageValue(3331, creature:getOutfit().lookType)
        creature:setStorageValue(3332, creature:getOutfit().lookHead)
        creature:setStorageValue(3333, creature:getOutfit().lookBody)
        creature:setStorageValue(3334, creature:getOutfit().lookLegs)
        creature:setStorageValue(3335, creature:getOutfit().lookFeet)
        creature:setStorageValue(3336, creature:getOutfit().lookAddons)


        creature:setStorageValue(swimStorage, 1)
        creature:setOutfit(diverOutfit)
    end

    return true
end


function onStepOut(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        return false
    end

    local isswimming = creature:getStorageValue(swimStorage)

    if isswimming == 1 then
        local standardOutfit = {
            lookType = creature:getStorageValue(3331),
            lookHead = creature:getStorageValue(3332),
            lookBody = creature:getStorageValue(3333),
            lookLegs = creature:getStorageValue(3334),
            lookFeet = creature:getStorageValue(3335),
            lookAddons = creature:getStorageValue(3336)
        }

        creature:setStorageValue(swimStorage, -1)
        creature:setOutfit(standardOutfit)
    end

    return true
end
I got that weird problem before in my server as well, I didn't deep search for the solution but just replaced the whole swiming.lua with this one, I know it can be better but this is the only solution I have now.
 
LUA:
local swimStorage = 3330


function onStepIn(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        return false
    end

    local isswimming = creature:getStorageValue(swimStorage)


    local diverOutfit = {
        lookType = 267,
        lookHead = 0,
        lookBody = 0,
        lookLegs = 0,
        lookFeet = 0,
        lookAddons = 0
    }

    if isswimming ~= 1 then

        creature:setStorageValue(3331, creature:getOutfit().lookType)
        creature:setStorageValue(3332, creature:getOutfit().lookHead)
        creature:setStorageValue(3333, creature:getOutfit().lookBody)
        creature:setStorageValue(3334, creature:getOutfit().lookLegs)
        creature:setStorageValue(3335, creature:getOutfit().lookFeet)
        creature:setStorageValue(3336, creature:getOutfit().lookAddons)


        creature:setStorageValue(swimStorage, 1)
        creature:setOutfit(diverOutfit)
    end

    return true
end


function onStepOut(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        return false
    end

    local isswimming = creature:getStorageValue(swimStorage)

    if isswimming == 1 then
        local standardOutfit = {
            lookType = creature:getStorageValue(3331),
            lookHead = creature:getStorageValue(3332),
            lookBody = creature:getStorageValue(3333),
            lookLegs = creature:getStorageValue(3334),
            lookFeet = creature:getStorageValue(3335),
            lookAddons = creature:getStorageValue(3336)
        }

        creature:setStorageValue(swimStorage, -1)
        creature:setOutfit(standardOutfit)
    end

    return true
end
I got that weird problem before in my server as well, I didn't deep search for the solution but just replaced the whole swiming.lua with this one, I know it can be better but this is the only solution I have now.
Was afraid I had to do it like this, so it seems to be a deeper bug with the setCondition. Thanks however!
 
Back
Top