Colors
♥
- Joined
- Mar 22, 2013
- Messages
- 812
- Solutions
- 4
- Reaction score
- 271
First of all, I didn't make the entire system by myself, I took some functions/ideas from other people who posted them here on OtLand (credits on the functions itself).
Special thanks to @Ninja for the help with the table config.
This system is/was based on TERA's crafting system (NA), this means that you CAN'T fail at crafting.
Gathering system isn't included atm, but I might add it later.
This should be the config on you map (Please IGNORE the map lol)
Some screens of the system:
Actions:
actions.xml
- 50501 is the first profession on the config file, and 50506 is the last one. You can add more if you want but need to add all the new professions ids in some files.
actions/scripts/craftsys.lua
Creaturescripts:
creaturescripts.xml
creaturescripts/scripts/crafting.lua
Special thanks to @Ninja for the help with the table config.
This system is/was based on TERA's crafting system (NA), this means that you CAN'T fail at crafting.
Gathering system isn't included atm, but I might add it later.
This should be the config on you map (Please IGNORE the map lol)
Some screens of the system:
Actions:
actions.xml
Code:
<action fromaid="50501" toaid="50506" script="craftsys.lua"/>
actions/scripts/craftsys.lua
Code:
function onUse(player, item, fromPosition, itemEx, toPosition)
local found = 0
local recipes = craftingProfessionsConfig[item.actionid].skillRecipes
local modal = ModalWindow(item.actionid, ""..craftingProfessionsConfig[item.actionid].skillName.." (Crafting Skill: "..player:getCustomSkill(item.actionid).."/"..craftingProfessionsConfig.maxSkill..")", craftingProfessionsConfig[item.actionid].message)
if item.itemid == 8046 and isInArray({50501, 50502, 50503, 50504, 50505, 50506}, item.actionid) then
if getCreatureCondition(player, CONDITION_SPELLCOOLDOWN, 160) then --I don't really know how to use :getCreatureCondition, it never works for me.
return player:sendCancelMessage("You are already crafting.")
end
if not player:isProfession(item.actionid) then
return player:sendCancelMessage("You need to learn "..craftingProfessionsConfig[item.actionid].skillName.." before using this.")
end
for i = 1, #recipes do
if player:getStorageValue(craftingProfessionsConfig.baseRecipeStorage + recipes[i].storage) == 1 then
modal:addChoice(i, capAll(getItemName(recipes[i].item))--[[.." ["..recipes[i].skill.."]"]])
end
end
craftingProfessionsConfig.extraData[player:getId()] = {
lastPos = Item(item.uid):getPosition()
}
if modal:getChoiceCount() ~= 0 then
modal:addButton(1, "Create")
modal:setDefaultEnterButton(1)
modal:addButton(2, "Exit")
modal:setDefaultEscapeButton(2)
modal:addButton(3, "Materials")
modal:sendToPlayer(player)
else
player:sendCancelMessage("You need to learn some "..craftingProfessionsConfig[item.actionid].skillName.." recipes first.")
end
elseif item.itemid == 1967 and item.actionid >= craftingProfessionsConfig.baseRecipeStorage then
for i = 1, #recipes do
if recipes[i].storage == tonumber(Item(item.uid):getAttribute(ITEM_ATTRIBUTE_TEXT)) then
found = i
end
end
if found == 0 then return player:sendCancelMessage(RETURNVALUE_CANNOTUSETHISOBJECT) end
if player:getStorageValue(craftingProfessionsConfig.baseRecipeStorage + recipes[found].storage) == -1 then
if player:getCustomSkill(item.actionid) >= recipes[found].skill then
player:setStorageValue(craftingProfessionsConfig.baseRecipeStorage + recipes[found].storage, 1)
player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You learned how to make "..capAll(getItemName(recipes[found].item))..".")
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
Item(item.uid):remove(1)
else
player:sendCancelMessage("You require "..recipes[found].skill.." crafting skill in "..craftingProfessionsConfig[item.actionid].skillName.." to learn this recipe.")
end
else
player:sendCancelMessage("You have already learned this recipe.")
end
elseif item.itemid == 2217 and item.actionid >= craftingProfessionsConfig.baseRecipeStorage then
if player:getStorageValue(item.actionid) == -1 then
player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You have learned "..craftingProfessionsConfig[item.actionid].skillName..", then the book burned to ashes after learning it's secrets.")
player:getPosition():sendMagicEffect(CONST_ME_EXPLOSIONHIT)
player:setStorageValue(item.actionid, 10)
Item(item.uid):remove(1)
else
player:sendCancelMessage("You already know "..craftingProfessionsConfig[item.actionid].skillName..".")
end
end
return true
end
Creaturescripts:
creaturescripts.xml
Code:
<event type="modalwindow" name="craftingMW" script="crafting.lua"/>
creaturescripts/scripts/crafting.lua
Code:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
if not isInArray({50501, 50502, 50503, 50504, 50505, 50506}, modalWindowId) or buttonId == 2 then
return false
end
local count = 0
local recipes = craftingProfessionsConfig[modalWindowId].skillRecipes
local str = ""..capAll(getItemName(recipes[choiceId].item)).."\n Skill Needed: "..recipes[choiceId].skill.." - Point Cost: 1p\n\nMaterials:"
if buttonId == 3 then
for i = 1, #recipes[choiceId].mats do
str = str.."\n- "..capAll(getItemName(recipes[choiceId].mats[i][1])).." ("..player:getItemCount(recipes[choiceId].mats[i][1]).."/"..recipes[choiceId].mats[i][2]..")"
end
if str ~= "" then
player:showTextDialog(recipes[choiceId].item, str)
end
return true
end
for i = 1, #recipes[choiceId].mats do
if player:getItemCount(recipes[choiceId].mats[i][1]) >= recipes[choiceId].mats[i][2] then
count = count + 1
end
end
if count == #recipes[choiceId].mats then
local craftCD = Condition(CONDITION_SPELLCOOLDOWN)
craftCD:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)
craftCD:setParameter(CONDITION_PARAM_SUBID, 160)
craftCD:setParameter(CONDITION_PARAM_TICKS, recipes[choiceId].time * 1000)
player:addCondition(craftCD)
player:allowMovement(false)
player:say("Crafting...", TALKTYPE_MONSTER_SAY)
local itemPos = craftingProfessionsConfig.extraData[player:getId()].lastPos
function sendAnimation(times) --This needs to be improved
itemPos:sendMagicEffect(CONST_ME_BLOCKHIT)
if times == 0 then
return true
end
addEvent(sendAnimation, 1000, times - 1)
end
sendAnimation(recipes[choiceId].time)
for i = 1, count do
player:removeItem(recipes[choiceId].mats[i][1], recipes[choiceId].mats[i][2])
end
addEvent(function(id)
local player = Player(id)
if player then
local craftedItem = player:addItem(recipes[choiceId].item, 1)
if craftedItem then
player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "You've successfully crafted "..craftedItem:getArticle().." "..capAll(craftedItem:getName())..".")
craftedItem:setAttribute(ITEM_ATTRIBUTE_NAME, "crafted "..craftedItem:getName())
player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
--doWriteLogFile("data/logs/craf.log", player:getName() .." crafted the following item: ".. craftedItem:getName() .." [".. craftedItem:getId() .."].")
if craftedItem:getType():getDescription() ~= "" then
craftedItem:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, craftedItem:getType():getDescription().."\nCrafted by "..player:getName()..".")
else
craftedItem:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Crafted by "..player:getName()..".")
end
if craftedItem:getType():getAttack() > 0 and recipes[choiceId].attr ~= nil and recipes[choiceId].attr.attack ~= nil then
craftedItem:setAttribute(ITEM_ATTRIBUTE_ATTACK, craftedItem:getType():getAttack() + recipes[choiceId].attr.attack)
end
if craftedItem:getType():getDefense() > 0 and recipes[choiceId].attr ~= nil and recipes[choiceId].attr.defense ~= nil then
craftedItem:setAttribute(ITEM_ATTRIBUTE_DEFENSE, craftedItem:getType():getDefense() + recipes[choiceId].attr.defense)
end
if craftedItem:getType():getExtraDefense() > 0 and recipes[choiceId].attr ~= nil and recipes[choiceId].attr.extradefense ~= nil then
craftedItem:setAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE, craftedItem:getType():getExtraDefense() + recipes[choiceId].attr.extradefense)
end
if craftedItem:getType():getArmor() > 0 and recipes[choiceId].attr ~= nil and recipes[choiceId].attr.armor ~= nil then
craftedItem:setAttribute(ITEM_ATTRIBUTE_ARMOR, craftedItem:getType():getArmor() + recipes[choiceId].attr.armor)
end
if craftedItem:getType():getHitChance() > 0 and recipes[choiceId].attr ~= nil and recipes[choiceId].attr.hitchance ~= nil then
craftedItem:setAttribute(ITEM_ATTRIBUTE_HITCHANCE, craftedItem:getType():getHitChance() + recipes[choiceId].attr.hitchance)
end
if craftedItem:getType():getShootRange() > 0 and recipes[choiceId].attr ~= nil and recipes[choiceId].attr.shootrange ~= nil then
craftedItem:setAttribute(ITEM_ATTRIBUTE_SHOOTRANGE, craftedItem:getType():getShootRange() + recipes[choiceId].attr.shootrange)
end
end
skillGain = (recipes[choiceId].difficulty / 10)
for i = 1, skillGain do
player:addCustomSkillTry(craftingProfessionsConfig[modalWindowId].skillName, modalWindowId)
end
player:allowMovement(true)
end
end, recipes[choiceId].time * 1000, player:getId())
else
player:sendCancelMessage("You don't have all the materials to craft this item.")
end
return true
end
Last edited: