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

Solved (tfs 1.1) fluids not working

I just moved this line below the 'if' statement:
Code:
item:transform(item:getId(), 0)

Code:
local drunk = Condition(CONDITION_DRUNK)
drunk:setParameter(CONDITION_PARAM_TICKS, 60000)

local poison = Condition(CONDITION_POISON)
poison:setParameter(CONDITION_PARAM_DELAYED, true)
poison:setParameter(CONDITION_PARAM_MINVALUE, -50)
poison:setParameter(CONDITION_PARAM_MAXVALUE, -120)
poison:setParameter(CONDITION_PARAM_STARTVALUE, -5)
poison:setParameter(CONDITION_PARAM_TICKINTERVAL, 4000)
poison:setParameter(CONDITION_PARAM_FORCEUPDATE, true)

local fluidType = {3, 4, 5, 7, 10, 11, 13, 15, 19}
local fluidMessage = {"Aah...", "Urgh!", "Mmmh.", "Aaaah...", "Aaaah...", "Urgh!", "Urgh!", "Aah...", "Urgh!"}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local targetItemType = ItemType(target.itemid)
    if targetItemType and targetItemType:isFluidContainer() then
        if target.type == 0 and item.type ~= 0 then
            target:transform(target:getId(), item.type)
            item:transform(item:getId(), 0)
            return true
        elseif target.type ~= 0 and item.type == 0 then
            target:transform(target:getId(), 0)
            item:transform(item:getId(), target.type)
            return true
        end
    end

    if target:isCreature() then
        if item.type == 0 then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "It is empty.")
        elseif target == player then
            if item.type == 3 or item.type == 15 then
                player:addCondition(drunk)
            elseif item.type == 4 then
                player:addCondition(poison)
            elseif item.type == 7 then
                player:addMana(math.random(50, 150))
                fromPosition:sendMagicEffect(CONST_ME_MAGIC_BLUE)
            elseif item.type == 10 then
                player:addHealth(60)
                fromPosition:sendMagicEffect(CONST_ME_MAGIC_BLUE)
            end
            item:transform(item:getId(), 0)
            for i = 0, #fluidType do
                if item.type == fluidType[i] then
                    player:say(fluidMessage[i], TALKTYPE_MONSTER_SAY)
                    return true
                end
            end
            player:say("Gulp.", TALKTYPE_MONSTER_SAY)
        else
            Game.createItem(2016, item.type, toPosition):decay()
            item:transform(item:getId(), 0)
        end
    else
        local fluidSource = targetItemType and targetItemType:getFluidSource() or 0
        if fluidSource ~= 0 then
            item:transform(item:getId(), fluidSource)
        elseif item.type == 0 then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "It is empty.")
        else
            if toPosition.x == CONTAINER_POSITION then
                toPosition = player:getPosition()
            end
            Game.createItem(2016, item.type, toPosition):decay()
            item:transform(item:getId(), 0)
        end
    end
    return true
end
 
I just moved this line below the 'if' statement:
Code:
item:transform(item:getId(), 0)

Code:
local drunk = Condition(CONDITION_DRUNK)
drunk:setParameter(CONDITION_PARAM_TICKS, 60000)

local poison = Condition(CONDITION_POISON)
poison:setParameter(CONDITION_PARAM_DELAYED, true)
poison:setParameter(CONDITION_PARAM_MINVALUE, -50)
poison:setParameter(CONDITION_PARAM_MAXVALUE, -120)
poison:setParameter(CONDITION_PARAM_STARTVALUE, -5)
poison:setParameter(CONDITION_PARAM_TICKINTERVAL, 4000)
poison:setParameter(CONDITION_PARAM_FORCEUPDATE, true)

local fluidType = {3, 4, 5, 7, 10, 11, 13, 15, 19}
local fluidMessage = {"Aah...", "Urgh!", "Mmmh.", "Aaaah...", "Aaaah...", "Urgh!", "Urgh!", "Aah...", "Urgh!"}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local targetItemType = ItemType(target.itemid)
    if targetItemType and targetItemType:isFluidContainer() then
        if target.type == 0 and item.type ~= 0 then
            target:transform(target:getId(), item.type)
            item:transform(item:getId(), 0)
            return true
        elseif target.type ~= 0 and item.type == 0 then
            target:transform(target:getId(), 0)
            item:transform(item:getId(), target.type)
            return true
        end
    end

    if target:isCreature() then
        if item.type == 0 then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "It is empty.")
        elseif target == player then
            if item.type == 3 or item.type == 15 then
                player:addCondition(drunk)
            elseif item.type == 4 then
                player:addCondition(poison)
            elseif item.type == 7 then
                player:addMana(math.random(50, 150))
                fromPosition:sendMagicEffect(CONST_ME_MAGIC_BLUE)
            elseif item.type == 10 then
                player:addHealth(60)
                fromPosition:sendMagicEffect(CONST_ME_MAGIC_BLUE)
            end
            item:transform(item:getId(), 0)
            for i = 0, #fluidType do
                if item.type == fluidType[i] then
                    player:say(fluidMessage[i], TALKTYPE_MONSTER_SAY)
                    return true
                end
            end
            player:say("Gulp.", TALKTYPE_MONSTER_SAY)
        else
            Game.createItem(2016, item.type, toPosition):decay()
            item:transform(item:getId(), 0)
        end
    else
        local fluidSource = targetItemType and targetItemType:getFluidSource() or 0
        if fluidSource ~= 0 then
            item:transform(item:getId(), fluidSource)
        elseif item.type == 0 then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "It is empty.")
        else
            if toPosition.x == CONTAINER_POSITION then
                toPosition = player:getPosition()
            end
            Game.createItem(2016, item.type, toPosition):decay()
            item:transform(item:getId(), 0)
        end
    end
    return true
end
still same deal, just says gulp. The fluid goes away and everything, just no drunk effect or registering that its fluid type 15.
 
Replace
Code:
local fluidType = {3, 4, 5, 7, 10, 11, 13, 15, 19}
local fluidMessage = {"Aah...", "Urgh!", "Mmmh.", "Aaaah...", "Aaaah...", "Urgh!", "Urgh!", "Aah...", "Urgh!"}
with
Code:
local fluidMessage = {
    [3] = 'Aah...',
    [4] = 'Urgh!',
    [5] = 'Mmmh.',
    [7] = 'Aaaah...',
    [10] = 'Aaaah...',
    [11] = 'Urgh!',
    [13] = 'Urgh!',
    [15] = 'Aah...',
    [19] = 'Urgh!',
    [43] = 'Aaaah...'
}

and these lines
Code:
item:transform(item:getId(), 0)
for i = 0, #fluidType do
    if item.type == fluidType[i] then
        player:say(fluidMessage[i], TALKTYPE_MONSTER_SAY)
        return true
    end
end
player:say("Gulp.", TALKTYPE_MONSTER_SAY)
with
Code:
player:say(fluidMessage[item.type] or 'Gulp.', TALKTYPE_MONSTER_SAY)
item:transform(item:getId(), 0)
 
I fixed this issue by storing item.type at the beginning of the script. This fixes the issue because we need to preserve the container subtype so we know which status conditions to apply to the creature.

Below:
Code:
local targetItemType = ItemType(target.itemid)

Add:
Code:
local itemType = item.type

and replace all instances of "item.type" with "itemType"

Red
 
I fixed this issue by storing item.type at the beginning of the script. This fixes the issue because we need to preserve the container subtype so we know which status conditions to apply to the creature.

Below:
Code:
local targetItemType = ItemType(target.itemid)

Add:
Code:
local itemType = item.type

and replace all instances of "item.type" with "itemType"

Red
worked perfectly thanks!
 
Back
Top