Ir para conteúdo
  • 0
Entre para seguir isso  
shocks

Scripting Sistema de Unwrap

Pergunta

shocks    2
shocks

Base: TFS 1.3 Custom

Estou com problemas no sistema de unwrap de house items comprados no market, após o unwrap no decoration kit (ID: 26054), o mesmo não vira o item comprado no market e sim vira um item sem nome que esteja no meu item.xml

 

Codigo Atual

Spoiler

local function getDistanceBetween(pos1, pos2)
    return math.abs(pos1 - pos2)
end

local wrapItems = {
    "Magnificent Cabinet",
    "Magnificent Chair",
    "Magnificent Trunk",
    "Magnificent Table",
    "Ferocious Cabinet",
    "Ferocious Chair",
    "Ferocious Trunk",
    "Ferocious Table",
    "Rustic Cabinet",
    "Rustic Chair",
    "Rustic Trunk",
    "Rustic Table",
    "Yalaharian Carpet",
    "White Fur Carpet",
    "Bamboo Mat",
    "Crimson Carpet",
    "Azure Carpet",
    "Emerald Carpet",
    "Light Parquet",
    "Dark Parquet",
    "Marble Parquet",
    "Fish Tank",
    [26364] = "Dog House",
    [26098] = "Baby Dragon",
    [26107] = "Cat in a Basket",
    [26100] = "Hamster in a Wheel",
    "Protectress Lamp",
    "Predator Lamp",
    "Ornate Mailbox",
    "Royal Mailbox",
    "Lordly Tapestry",
    "Menacing Tapestry",
    "AllSeeing Tapestry",
    "Golden Dragon Tapestry",
    "Sword Tapestry",
    "Brocade Tapestry"
}

local function getItemId(name)
    for i, v in pairs(wrapItems) do
        if (i > 20000) then
            if (v == name) then
                return i
            end
        end

        if (v == name) then
            return ItemType(v):getId()
        end
    end
end

function onRecvbyte(player, msg, byte)
    if (Player.getExhaustion(player, 4820392) > 0) then
        return false
    end

    local positionItem = msg:getPosition()
    if (positionItem) then
        if (Tile(positionItem)) then
            local item = Tile(positionItem):getTopDownItem() or Tile(positionItem):getTopTopItem()
            if (item) then
                local itemId = item:getId()
                if (itemId == 26054) then
                    onUnWrap(player, positionItem)
                    Player.setExhaustion(player, 4820392, 0.2)
                elseif (table.contains(ItemType(itemId):getName(), wrapItems)) then
                    onWrap(player, positionItem, itemId)
                    Player.setExhaustion(player, 4820392, 0.2)
                else
                    player:sendCancelMessage("This item can't be wrap/unwrap.")
                    return false
                end
            end
        end
    end
end

function onWrap(player, positionItem, itemId)
    local playerPos = player:getPosition()
    if (getDistanceBetween(positionItem.x, playerPos.x) > 1 or
        getDistanceBetween(positionItem.y, playerPos.y) > 1) then
        player:sendCancelMessage("You need to reach decoration to wrap.")
        return false
    end

    local decoTile = Tile(positionItem)
    if (not decoTile) then
        player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return false
    end

    local decoItem = Tile(positionItem):getItemById(itemId)
    if (not decoItem) then
        player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return false
    end

    if (decoItem:isContainer() and
        Container(decoItem:getUniqueId()):getItemHoldingCount() > 0) then
        player:sendCancelMessage("You can't wrap with items inside of this container.")
        return false
    end

    if (decoTile:getHouse() == nil) then
        player:sendCancelMessage("You can't wrap this decoration out of a house.")
        return false
    end

    if (decoTile:getHouse():getOwnerGuid() ~= player:getGuid()) then
        player:sendCancelMessage("You can't wrap this decoration in a house of other player.")
        return false
    end

    decoItem:remove()
    positionItem:sendMagicEffect(CONST_ME_POFF)
    local kitDeco = Game.createItem(26054, 1, positionItem)
    kitDeco:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "You bought this item in the Store.\nUnwrap it in your own house to create a <" ..decoItem:getName()..">.")
end

function onUnWrap(player, positionItem)
    local playerPos = player:getPosition()
    if (positionItem.x == 65535) then
        player:sendCancelMessage("You can't unwrap this kit in a container.")
        return false
    end

    if (getDistanceBetween(positionItem.x, playerPos.x) > 1 or
        getDistanceBetween(positionItem.y, playerPos.y) > 1) then
        player:sendCancelMessage("You need to reach kit to unwrap.")
        return false
    end

    local kitTile = Tile(positionItem)
    if (not kitTile) then
        player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return false
    end

    if (kitTile:hasFlag(TILESTATE_BLOCKSOLID)) then
        player:sendCancelMessage("You can't unwrap item here, please put in ground and try again.")
        return false
    end

    for i, v in pairs(kitTile:getItems()) do
        if (v:getName() == "table") then
            player:sendCancelMessage("You can't unwrap item in table, please put in ground and try again.")
            return false
        end
    end

    local kitItem = Tile(positionItem):getItemById(26054)

    if (not kitItem) then
        player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return false
    end

    if (kitTile:getHouse() == nil) then
        player:sendCancelMessage("You can't use this kit out of a house.")
        return false
    end

    if (kitTile:getHouse():getOwnerGuid() ~= player:getGuid()) then
        player:sendCancelMessage("You can't use this kit in a house of other player.")
        return false
    end

    local decorationName = kitItem:getDescription():match("Unwrap it in your own house to create a <(.+)>.")
    if (not decorationName) then
        player:sendCancelMessage("Invalid item, please contact Administrator.")
        return false
    end

    kitItem:remove()
    positionItem:sendMagicEffect(CONST_ME_BLOCKHIT)
    Game.createItem(getItemId(name), 1, positionItem)
end

 

 

Imagens

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

2 respostass a esta questão

Recommended Posts

  • 1
Majesty    1755
Majesty

Em data/actions/scripts/other, crie um arquivo store_house.lua com o código abaixo:

Spoiler

local constructionKits = {
    [27850] = 27850, [27728] = 27728, [26075] = 26075, [26059] = 26059, [26083] = 26083,
    [26073] = 26073, [26077] = 26077, [26063] = 26063, [26079] = 26079, [26067] = 26067,
    [26356] = 26356, [26349] = 26349, [26358] = 26358, [26354] = 26354, [27897] = 27897,
    [27905] = 27905, [27901] = 27901, [27893] = 27893, [27892] = 27892, [27894] = 27894,
    [27895] = 27895, [27896] = 27896, [26109] = 26109, [26110] = 26110, [26111] = 26111,
    [26371] = 26371, [26372] = 26372, [26373] = 26373, [26374] = 26374, [26375] = 26375,
    [27084] = 27084, [27085] = 27085, [27086] = 27086, [27087] = 27087, [27088] = 27088,
    [27089] = 27089, [27090] = 27090, [27091] = 27091, [26370] = 26370, [26347] = 26347,
    [26364] = 26364, [26098] = 26098, [26107] = 26107, [26100] = 26100, [27100] = 27100,
    [27889] = 27889, [26094] = 26094, [26090] = 26090, [27102] = 27102, [27886] = 27886,
    [26057] = 26057, [26055] = 26055, [26104] = 26104, [26105] = 26105, [26106] = 26106,
    [26379] = 26379, [26380] = 26380, [26381] = 26381
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local kit = constructionKits[item.actionid]
    if not kit then
        return false
    end

    if fromPosition.x == CONTAINER_POSITION then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Put the construction kit on the floor first.")
    elseif not fromPosition:getTile():getHouse() then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You may construct this only inside a house.")
    else
        item:transform(kit)
        item:setActionId(0)
        fromPosition:sendMagicEffect(CONST_ME_POFF)
    end

    return true
end

 

Em data/actions/actions.xml adicione:

Spoiler

<action actionid="27850" script="other/store_house.lua" />
<action actionid="26347" script="other/store_house.lua" />
<action actionid="27100" script="other/store_house.lua" />
<action actionid="27886" script="other/store_house.lua" />
<action actionid="26106" script="other/store_house.lua" />
<action actionid="26109" script="other/store_house.lua" />
<action actionid="26373" script="other/store_house.lua" />
<action actionid="27086" script="other/store_house.lua" />
<action actionid="27091" script="other/store_house.lua" />
<action actionid="26107" script="other/store_house.lua" />
<action actionid="26090" script="other/store_house.lua" />
<action actionid="26104" script="other/store_house.lua" />
<action actionid="26381" script="other/store_house.lua" />
<action actionid="26059" script="other/store_house.lua" />
<action actionid="26079" script="other/store_house.lua" />
<action actionid="26354" script="other/store_house.lua" />
<action actionid="27892" script="other/store_house.lua" />
<action actionid="26110" script="other/store_house.lua" />
<action actionid="26374" script="other/store_house.lua" />
<action actionid="27087" script="other/store_house.lua" />
<action actionid="26370" script="other/store_house.lua" />
<action actionid="26100" script="other/store_house.lua" />
<action actionid="27102" script="other/store_house.lua" />
<action actionid="26105" script="other/store_house.lua" />
<action actionid="26083" script="other/store_house.lua" />
<action actionid="26067" script="other/store_house.lua" />
<action actionid="27897" script="other/store_house.lua" />
<action actionid="27894" script="other/store_house.lua" />
<action actionid="26111" script="other/store_house.lua" />
<action actionid="26375" script="other/store_house.lua" />
<action actionid="27088" script="other/store_house.lua" />
<action actionid="26356" script="other/store_house.lua" />
<action actionid="27905" script="other/store_house.lua" />
<action actionid="27895" script="other/store_house.lua" />
<action actionid="26371" script="other/store_house.lua" />
<action actionid="27084" script="other/store_house.lua" />
<action actionid="27089" script="other/store_house.lua" />
<action actionid="26057" script="other/store_house.lua" />
<action actionid="26379" script="other/store_house.lua" />
<action actionid="27728" script="other/store_house.lua" />
<action actionid="26077" script="other/store_house.lua" />
<action actionid="26349" script="other/store_house.lua" />
<action actionid="27901" script="other/store_house.lua" />
<action actionid="27896" script="other/store_house.lua" />
<action actionid="26372" script="other/store_house.lua" />
<action actionid="27085" script="other/store_house.lua" />
<action actionid="27090" script="other/store_house.lua" />
<action actionid="26098" script="other/store_house.lua" />
<action actionid="26094" script="other/store_house.lua" />
<action actionid="26055" script="other/store_house.lua" />
<action actionid="26380" script="other/store_house.lua" />
<action actionid="26075" script="other/store_house.lua" />
<action actionid="26063" script="other/store_house.lua" />
<action actionid="26358" script="other/store_house.lua" />
<action actionid="27893" script="other/store_house.lua" />
<action actionid="26073" script="other/store_house.lua" />
<action actionid="26364" script="other/store_house.lua" />

 

Créditos: Deletera.

Compartilhar este post


Link para o post
Compartilhar em outros sites
  • 0
shocks    2
shocks

Funcionando perfeitamente, só adicionar os items que restam agora, obrigado pela ajuda.

Compartilhar este post


Link para o post
Compartilhar em outros sites
Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×