• 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,484
Solutions
18
Reaction score
196
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!
 
Any conditions appear in conditions bar? Does the speed value in Skills panel decrease and after stepping out becomes normal?
No conditions appear, no it does not.
LUA:
CONDITION_PARAM_SUBID
That was it, thanks!
Post automatically merged:

LUA:
CONDITION_PARAM_SUBID
How to remove the condition then?
Tried this but did not work.
creature:removeCondition(CONDITION_OUTFIT, 19991)

Edit:

Okay this is so weird, i added this to remove the condition:
creature:removeCondition(CONDITION_OUTFIT, condition, 19991)
And when i did that the bug came back LOL.
 
Last edited:
You dont remove the condition when you add more params, you remove the CONDITION_OUTFIT and the CONDITIONID_~

Code:
// creature:removeCondition(conditionType[, conditionId = CONDITIONID_COMBAT[, subId = 0[, force = false]]])
// creature:removeCondition(condition[, force = false])

Code:
local condition = Condition(CONDITION_OUTFIT)

defaults to CONDITIONID_COMBAT

Code:
local condition = Condition(CONDITION_OUTFIT)

condition:setParameter(CONDITION_PARAM_SUBID, 19991)
condition:setOutfit({ lookType = 2015 })
condition:setTicks(-1)

its remove should be

Code:
creature:removeCondition(CONDITION_OUTFIT, CONDITIONID_COMBAT, 19991)

or just

Code:
creature:removeCondition(condition)
 
LUA:
local condition = Condition(CONDITION_OUTFIT)
condition:setParameter(CONDITION_PARAM_SUBID, 19991)
condition:setOutfit({ lookType = 2015 })
condition:setTicks(-1)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true) // If you want to see it in buff bars

LUA:
creature:removeCondition(CONDITION_OUTFIT, CONDITIONID_COMBAT, 19991, true)
 
Last edited:
Code:
addEvent(function()
                if creature and creature:isPlayer() then
                    creature:teleportTo(Position(842, 1098, 6))
                    creature:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                end
            end, 300)

Crash xd

You cannot pass userdata to addEvent.

Always use creatureId, then in your function check creature like this:

Code:
local creature = Creature(creatureId)
if not creature return end
 
local condition = Condition(CONDITION_OUTFIT) condition:setParameter(CONDITION_PARAM_SUBID, 19991) condition:setOutfit({ lookType = 2015 }) condition:setTicks(-1)
local condition = Condition(CONDITION_OUTFIT) condition:setParameter(CONDITION_PARAM_SUBID, 19991) condition:setOutfit({ lookType = 2015 }) condition:setTicks(-1)
It seems that while this works to remove the condition, the issue persists of moving slowly until a total stop just as the video i uploaded.
When removing the 'removeCondition' it works as it should in the water but then the condition stays when you're on land, aka the outfit.
 
It seems that while this works to remove the condition, the issue persists of moving slowly until a total stop just as the video i uploaded.
When removing the 'removeCondition' it works as it should in the water but then the condition stays when you're on land, aka the outfit.
When I use the code I gave you on my side the outfit is changed back to whatever was present before the condition was given. The slow moving may have to do with tile walk speeds somehow. I am not sure about the walk speed but on my end the outfit is set back to normal without a walk speed problem. This is just for information for you. I tested on a god and normal character.
 
Since we dont seem to get to the ground with this issue, here's how i solved it in case anyone else needs.

LUA:
-- ============================================================
-- Swimming / Boat Rental Outfit Script
-- ============================================================

local SWIMMING_OUTFIT = {
    lookType = 2015,
    lookHead = 0,
    lookBody = 0,
    lookLegs = 0,
    lookFeet = 0,
    lookAddons = 0
}

-- Storage values
local STORAGE_BOAT_RENTAL   = 943943
local STORAGE_PREV_LOOKTYPE = 943944
local STORAGE_PREV_HEAD     = 943945
local STORAGE_PREV_BODY     = 943946
local STORAGE_PREV_LEGS     = 943947
local STORAGE_PREV_FEET     = 943948
local STORAGE_PREV_ADDONS   = 943949


local function saveCurrentOutfit(player)
    if not player then return end
    local outfit = player:getOutfit()
    if not outfit then return end

    player:setStorageValue(STORAGE_PREV_LOOKTYPE, outfit.lookType or 0)
    player:setStorageValue(STORAGE_PREV_HEAD,     outfit.lookHead or 0)
    player:setStorageValue(STORAGE_PREV_BODY,     outfit.lookBody or 0)
    player:setStorageValue(STORAGE_PREV_LEGS,     outfit.lookLegs or 0)
    player:setStorageValue(STORAGE_PREV_FEET,     outfit.lookFeet or 0)
    player:setStorageValue(STORAGE_PREV_ADDONS,   outfit.lookAddons or 0)
end

local function restoreSavedOutfit(player)
    if not player then return end

    local lookType = player:getStorageValue(STORAGE_PREV_LOOKTYPE)
    if lookType <= 0 then return end

    local restoreOutfit = {
        lookType   = lookType,
        lookHead   = player:getStorageValue(STORAGE_PREV_HEAD) or 0,
        lookBody   = player:getStorageValue(STORAGE_PREV_BODY) or 0,
        lookLegs   = player:getStorageValue(STORAGE_PREV_LEGS) or 0,
        lookFeet   = player:getStorageValue(STORAGE_PREV_FEET) or 0,
        lookAddons = player:getStorageValue(STORAGE_PREV_ADDONS) or 0
    }

    player:setOutfit(restoreOutfit)

    player:setStorageValue(STORAGE_PREV_LOOKTYPE, -1)
    player:setStorageValue(STORAGE_PREV_HEAD,     -1)
    player:setStorageValue(STORAGE_PREV_BODY,     -1)
    player:setStorageValue(STORAGE_PREV_LEGS,     -1)
    player:setStorageValue(STORAGE_PREV_FEET,     -1)
    player:setStorageValue(STORAGE_PREV_ADDONS,   -1)
end


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

    -- Boat rental expired
    if creature:getStorageValue(STORAGE_BOAT_RENTAL) <= 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)
        local cameFromWater = fromTile and fromTile:getItemById(33707)

        if cameFromWater then
            -- Came from another water tile send to safe position
            creature:sendTextMessage(MESSAGE_STATUS_WARNING, "Your boat rental has expired. You have been returned to safety.")
            creature:teleportTo(Position(842, 1098, 6))
            creature:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        else
            -- Normal case push back to previous position
            creature:teleportTo(fromPosition, false)
        end
        return true
    end

    -- Valid rental apply swimming outfit
    if creature:getStorageValue(STORAGE_PREV_LOOKTYPE) <= 0 then
        saveCurrentOutfit(creature)
    end

    creature:setOutfit(SWIMMING_OUTFIT)
    return true
end


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

    restoreSavedOutfit(creature)
    return true
end
 
Back
Top