• TibiaFace

    Tibiaface | Una comunidad Open Tibia donde encontras : mapas, scripts, Otserver, npc y amigos etc ...

    .
    demo menumenu

    Afiliados



    Votar:

    [Codigo] codigo para obtener outfit aleatorio

    Compartir:

    Ver el tema anterior Ver el tema siguiente Ir abajo  Mensaje (Página 1 de 1.)

    danigym

    danigym
    Miembro
    Miembro
    Tengo este codigo escrito con un server 13.x y tfs 1.3 el cual al dar clic a un item te da un outfit aleatorio. El problema está en que no cotempla si eres de sexo masculino o femenino. Las outfit te las da igual. Claro si eres sexo femenino las outfit no llegán. ¿Cómo puedo solucionarlo? Este es el codigo:


    Código:
    local itemDollId = 12057  ---- ID del item
    local outfits = { --- Skins
        {1618, 1618, "Armoured Archer"},
        {1612, 1612, "Frost Tracer"},
        {1597, 1597, "Ancient Aucar"},
        {1581, 1581, "Shadowlotus Disciple"}
       
    }

    local randOutfit = Action("RandomOutfitForNewPlayers")

    function randOutfit.onUse(player, item, fromPosition, target, toPosition, isHotkey)
        if player:getLevel() < 8 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Necesitas ser nivel 8 para usar este objeto.")
            return true
        end

        local outfit = outfits[math.random(1, #outfits)]
        local addon = math.random(1, 2)

        local hasOutfit = false
        for _, existingOutfit in ipairs(outfits) do
            if player:hasOutfit(existingOutfit[1], addon) and player:hasOutfit(existingOutfit[2], addon) then
                hasOutfit = true
                break
            end
        end

        if hasOutfit then
            repeat
                outfit = outfits[math.random(1, #outfits)]
            until not (player:hasOutfit(outfit[1], addon) and player:hasOutfit(outfit[2], addon))
        end

        player:addOutfitAddon(outfit[1], addon)
        player:addOutfitAddon(outfit[2], addon)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("¡Has obtenido la skin %s gracias por jugar a la ruleta!", outfit[3]))
        item:remove(1)
        player:getPosition():sendMagicEffect(40)
        return true
    end

    randOutfit:id(itemDollId)
    randOutfit:register()

    2 participantes

    akane

    akane
    Miembro
    Miembro
    prueba con esto
    Código:
    local itemDollId = 12057 -- ID del item
    local maleOutfits = {
        {1618, 1618, "Armoured Archer (Hombre)"},
        {1612, 1612, "Frost Tracer (Hombre)"},
        -- Agrega más outfits para hombres aquí
    }

    local femaleOutfits = {
        {1597, 1597, "Ancient Aucar (Mujer)"},
        {1581, 1581, "Shadowlotus Disciple (Mujer)"},
        -- Agrega más outfits para mujeres aquí
    }

    local randOutfit = Action("RandomOutfitForNewPlayers")

    function randOutfit.onUse(player, item, fromPosition, target, toPosition, isHotkey)
        if player:getLevel() < 8 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Necesitas ser nivel 8 para usar este objeto.")
            return true
        end

        local outfit
        local gender = player:getSex()

        if gender == PLAYERSEX_FEMALE then
            outfit = femaleOutfits[math.random(1, #femaleOutfits)]
        else
            outfit = maleOutfits[math.random(1, #maleOutfits)]
        end

        local addon = math.random(1, 2)

        local hasOutfit = false
        for _, existingOutfit in ipairs(femaleOutfits) do
            if player:hasOutfit(existingOutfit[1], addon) and player:hasOutfit(existingOutfit[2], addon) then
                hasOutfit = true
                break
            end
        end

        if hasOutfit then
            repeat
                if gender == PLAYERSEX_FEMALE then
                    outfit = femaleOutfits[math.random(1, #femaleOutfits)]
                else
                    outfit = maleOutfits[math.random(1, #maleOutfits)]
                end
            until not (player:hasOutfit(outfit[1], addon) and player:hasOutfit(outfit[2], addon))
        end

        player:addOutfitAddon(outfit[1], addon)
        player:addOutfitAddon(outfit[2], addon)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("¡Has obtenido la skin %s gracias por jugar a la ruleta!", outfit[3]))
        item:remove(1)
        player:getPosition():sendMagicEffect(40)
        return true
    end

    randOutfit:id(itemDollId)
    randOutfit:register()

    2 participantes

    danigym

    danigym
    Miembro
    Miembro
    Me funcionó, eres el mejor!! Gracias!!!

    2 participantes

    Contenido patrocinado


    2 participantes

    Ver el tema anterior Ver el tema siguiente Volver arriba  Mensaje (Página 1 de 1.)

    Permisos de este foro:
    No puedes responder a temas en este foro.

     

    BienvenidosTibiaFace es una comunidad de Open Tibia. Para participar debes estar registrado (click para Regístrate).