RevScript [TFS 1.3] Craft System With Levels

Alex

Miembro del equipo
Webdesigner
LV
58
 
Awards
38
Hola a todos,

Hoy les compartiré el sistema de Crafting con niveles que hize en Hellgrave v6.0,


Primeramente, nos iremos en data/events/scripts y crearemos un archivo llamado craft_system.lua, pondremos lo siguiente:

Antes de continuar, verán por el medio del script 3 líneas que empiezan por guiones ( ---- ) con un texto.
Si no tocan nada la ventana, mostrará los crafts posibles, categorías y recetas, al pulsar en recetas mostrará los items necesarios y podrán volver atrás.
Lo que hay entre guiones, es un otro método de mostrar la receta con un Texto de Book, pero mostrando la imagen del item craft, pero este ultimo no tiene botón para atrás, por lo cual deben de volver a clicar encima de la tabla de craft para abrir las categorías de crafting.

Código Lua:
function Player:sendMainCraftWindow(config)
    local function buttonCallback(button, choice)
        if button.text == "Select" then
            self:sendVocCraftWindow(config, choice.id)
        end   
    end
    
    local window = ModalWindow {
        title = config.mainTitleMsg,
        message = config.mainMsg.."\n\n"
    }
 
    window:addButton("Select", buttonCallback)
    window:addButton("Exit", buttonCallback)
 
    for i = 1, #config.system do
        window:addChoice(config.system[i].tiers)
    end
    window:setDefaultEnterButton("Select")
    window:setDefaultEscapeButton("Exit")
    window:sendToPlayer(self)
end
local CraftTables = {
    maxLevel = 1000,
    experiencePerLevel = 200,
    storage = {
        level = 30568,
        experience = 30569
    },
}

local function giveCraftTablesExperience(playerId, amount)
    local player = Player(playerId)
    if not player then
        print("Error in function giveCraftTablesExperience -> player does not exist (check to ensure playerId being passed to function is correct)")
        return false
    end
 
    local CraftTablesLevel = player:getStorageValue(CraftTables.storage.level)
    CraftTablesLevel = CraftTablesLevel >= 0 and CraftTablesLevel or 0
 
    local CraftTablesIndenExperience = player:getStorageValue(CraftTables.storage.experience)
    CraftTablesIndenExperience = CraftTablesIndenExperience >= 0 and CraftTablesIndenExperience or 0
 
    
    CraftTablesIndenExperience = CraftTablesIndenExperience + amount
 
    if CraftTablesLevel < CraftTables.maxLevel then
        repeat   
            local ExperienceRequiredForNextLevel = CraftTablesLevel * CraftTables.experiencePerLevel
            if CraftTablesIndenExperience >= ExperienceRequiredForNextLevel then
                CraftTablesIndenExperience = CraftTablesIndenExperience - ExperienceRequiredForNextLevel
                CraftTablesLevel = CraftTablesLevel + 1
                local text = "You have advanced to Crafting level " .. CraftTablesLevel .. "."
                if CraftTablesLevel == CraftTables.maxLevel then
                    text = "You have reached the maximum Crafting level. You are a Legend."
                end
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, text)
            else
                break
            end
        until (CraftTablesLevel == CraftTables.maxLevel)
    end
 
    player:setStorageValue(CraftTables.storage.level, CraftTablesLevel)
    player:setStorageValue(CraftTables.storage.experience, CraftTablesIndenExperience)
    return true
end

function Player:sendVocCraftWindow(config, lastChoice)
    local function buttonCallback(button, choice)   
        local levels = {
            expgainmin = 150, -- DO NOT CHANGE !
            expgainmax = 250, -- DO NOT CHANGE !
        }
        local experienceRan = math.random(levels.expgainmin, levels.expgainmax)
        if button.text == "Back" then
            self:sendMainCraftWindow(config)
        end
        if button.text == "Recipe" then
        local item = config.system[lastChoice].items[choice.id].item
        local details = "In order to craft "..item.." you must collect the following items.\n\nRequired Items:\n\n"
 
            for i = 1, #config.system[lastChoice].items[choice.id].reqItems do
            local reqItems = config.system[lastChoice].items[choice.id].reqItems[i].item
            local reqItemsCount = config.system[lastChoice].items[choice.id].reqItems[i].count
            local reqItemsOnPlayer = self:getItemCount(config.system[lastChoice].items[choice.id].reqItems[i].item)
                details = details.."\n- "..capAll(getItemName(reqItems).." { "..reqItemsOnPlayer.."/"..reqItemsCount.." }")
            end   
            ---- This part, can show the picture in recipe, but cannot add a button "Go Back": self:showTextDialog(item, details)
            ---- If you wish to use it delete the code below (before the end tag) and replace with self:showTextDialog(item, details)
            ---- Solution by Alexv45:
             local window = ModalWindow {
                title = "Recipe",
                message = details,
            }
            window:addButton("Go Back", function() self:sendVocCraftWindow(config, lastChoice) end)
            window:sendToPlayer(self)
        end
 
        if button.text == "Craft" then
        local item = config.system[lastChoice].items[choice.id].item
            for i = 1, #config.system[lastChoice].items[choice.id].reqItems do
                if self:getItemCount(config.system[lastChoice].items[choice.id].reqItems[i].item) < config.system[lastChoice].items[choice.id].reqItems[i].count then
                    self:say(config.needItems..config.system[lastChoice].items[choice.id].item, TALKTYPE_MONSTER_SAY)
                    return false
                end
            end   
            for i = 1, #config.system[lastChoice].items[choice.id].reqItems do
                self:removeItem(config.system[lastChoice].items[choice.id].reqItems[i].item, config.system[lastChoice].items[choice.id].reqItems[i].count)
            end       
            if giveCraftTablesExperience(self:getId(), experienceRan) then
                self:sendTextMessage(MESSAGE_INFO_DESCR, "You have gained "..experienceRan.." experience on crafting skill.")
                
            end       
        self:addItem(config.system[lastChoice].items[choice.id].itemID)
        self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have crafted x1 ["..item.."].")
        self:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
        end   
    end
 
    local window = ModalWindow {
        title = config.craftTitle..config.system[lastChoice].tiers,
        message = config.craftMsg..config.system[lastChoice].tiers..".\n\n",
    }

    window:addButton("Back", buttonCallback)
    window:addButton("Exit")
    window:addButton("Recipe", buttonCallback)
    window:addButton("Craft", buttonCallback)
    window:setDefaultEnterButton("Craft")
    window:setDefaultEscapeButton("Exit")
 
    for i = 1, #config.system[lastChoice].items do
        window:addChoice(config.system[lastChoice].items[i].item)
    end
 
    window:sendToPlayer(self)
end

En el script que acabamos de poner, podremos configurar la Experiencia en el código:
Código Lua:
 local levels = {

            expgainmin = 150, -- DO NOT CHANGE !

            expgainmax = 250, -- DO NOT CHANGE !

        }
Pero también el nivel al principio en el local CrafTables maxLevel = 1000,

Nos iremos al data/global.lua y agregaremos:

Código Lua:
dofile('data/events/scripts/craft_system.lua')

Ahora , tendréis una tabla en el juego o un item que habéis creado por el cual cogeréis ese Item ID como punto para abrir la tabla de craft, ejemplo:
un Horno con item o clientID XXXX,
Nos iremos a data/scripts/ crearemos un script, con el nombre que desean, y pondrán esto dentro el siguiente código.

Aquí tendremos 2 Categorías, y dentro de cada una 1 item, ese item esta compuesto de X items/ recursos necesarios para poder craftearlo.

Código Lua:
local scrollsCraft = Action()

function capAll(str)
    return str:gsub("^(%a)", string.upper):gsub("([^%a]%a)", string.upper)
end
local config = {
    mainTitleMsg = "Scroll Table",
    mainMsg = "Welcome to the Scroll Table.\nPlease choose a category:",
 
    craftTitle = "Scroll Craft: ",
    craftMsg = "Click on Recipe to see the necessary items to craft a Scroll.\n\nHere is a list of all Scrolls available to craft. Scrolls are used to Learn how to craft an item or resources learning recipes: ",
    needItems = "You do not have all the required items to make ",
    system = {
    [1] = {tiers = "Job Scrolls",
            items = {
                [1] = {item = "Skinner's Scroll",
                        itemID = 6120,
                        reqItems = {
                                [1] = {item = 10100, count = 25}, -- 25 Large Chunk of Meat
                                [2] = {item = 10032, count = 25}, -- 25 Monster Pawn
                                [3] = {item = 2152, count = 50}, -- 50 Platinum Coins
                            },
                        },
                },
            },
            [2] = {tiers = "Equipments Scroll",
            items = {
                [1] = {item = "Rare Equipment Discovery Scroll",
                        itemID = 24334,
                        reqItems = {
                                [1] = {item = 42053, count = 1}, -- 1 Feather of fate
                                [2] = {item = 41995, count = 7}, -- 7 Dusts
                            },
                        },

                },
            },
            },
            }
 
function scrollsCraft.onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
        player:sendMainCraftWindow(config)
        return true
end
scrollsCraft:id(15389)
scrollsCraft:register()

Con Esto, hemos creado nuestra primera tabla de craft, que permite craft items / recursos, ganar experiencia y llegar a un nivel maximo.
Pueden agregar varias tablas, pero tomen en cuenta todas utilizan el mismo archivo craft_system.lua por el cual no se puede poner niveles differentes a cada tabla ( por mi parte no supe hacerlo ).

Pueden obviamente en la tabla antes del player:sendMainCraftWindow(config) agregar restricciones de tipo: El jugador no a alcanzado el nivel X de otro sistema, o no ha hecho X quest, tan simplemente agregan un if statement con su codigo.

Este script ( los items, nombres de recursos ) son nombres y recursos unicos utilizados en el servidor Hellgrave RPG V6.0
 

Damian1234

Miembro
LV
14
 
Awards
15
Oye amigo, todo bien en Canary perooo al momento de elegir entre job o equipment al darle "select" no pasa nada, y no arroja ningun error la consola.
Ya modifique los lua y quedaron asi a modo de si hay algun problema con los ID pero noCaptura de pantalla 2023-12-08 152615.png

Código:
local scrollsCraft = Action()

function capAll(str)
    return str:gsub("^(%a)", string.upper):gsub("([^%a]%a)", string.upper)
end
local config = {
    mainTitleMsg = "Scroll Table",
    mainMsg = "Welcome to the Scroll Table.\nPlease choose a category:",
 
    craftTitle = "Scroll Craft: ",
    craftMsg = "Click on Recipe to see the necessary items to craft a Scroll.\n\nHere is a list of all Scrolls available to craft. Scrolls are used to Learn how to craft an item or resources learning recipes: ",
    needItems = "You do not have all the required items to make ",
    system = {
    [1] = {tiers = "Job Scrolls",
            items = {
                [1] = {item = "Magic Plate Armor",
                        itemID = 3366,
                        reqItems = {
                                [1] = {item = 3043, count = 25}, -- 25 Large Chunk of Meat
                                [2] = {item = 3043, count = 25}, -- 25 Monster Pawn
                                [3] = {item = 3043, count = 50}, -- 50 Platinum Coins
                            },
                        },
                },
            },
            [2] = {tiers = "Equipments Scroll",
            items = {
                [1] = {item = "Golden Legs",
                        itemID = 3364,
                        reqItems = {
                                [1] = {item = 3043, count = 1}, -- 1 Feather of fate
                                [2] = {item = 3043, count = 7}, -- 7 Dusts
                            },
                        },

                },
            },
            },
            }
 
function scrollsCraft.onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
        player:sendMainCraftWindow(config)
        return true
end
scrollsCraft:id(21846, 21849)
scrollsCraft:register()
 

Damian1234

Miembro
LV
14
 
Awards
15
O creo que me estoy equivocando y se requiere algun writeable para poder leer lo que se necesita para craftear y yo estoy poniendo los items directamente?
 

Alex

Miembro del equipo
Webdesigner
LV
58
 
Awards
38
O creo que me estoy equivocando y se requiere algun writeable para poder leer lo que se necesita para craftear y yo estoy poniendo los items directamente?
Hola ,

Funcionar , funcionará pero me di cuenta que canary ha cambiado el modal Windows helper y el modal Windows lib , por lo cual no funciona en canary , si no se revierten esos dos archivos.
Recuérdamelo , por la tarde te mando esos dos archivos, pero toma en cuenta que cualquier otra cosa del servidor con modal Windows no funcionará si cambias esos dos archivos y deberás de arreglar cada script que usaba ese modal Windows
 

vilelafred

Miembro
LV
0
 
Awards
1
@Alex its possible to put quantity ? exemple:


[1] = {item = "Arrow", -- I NEED 50x arrow
itemID = 2544,
reqItems = {
[1] = {item = 3043, count = 25}, -- 25 Large Chunk of Meat
},
},
 
Arriba