Hi guys,
I use this script on my custom server and I would like to add a varying number of atk to weapons and defence to equipments.
I try to add this:
But the itens is crafted with the same atk always. No errors on TFS.
script/craft.xml - I cut a few of recipes out because it was too much code to put here
I use this script on my custom server and I would like to add a varying number of atk to weapons and defence to equipments.
I try to add this:
Lua:
local item = self:addItem(recipes[Type[p]].options[Option[p]].id, recipes[Type[p]].options[Option[p]].count)
if item:hasAttribute(ITEM_ATTRIBUTE_ATTACK) then
item:setAttribute(ITEM_ATTRIBUTE_ATTACK, ItemType(recipes[Type[p]].options[Option[p]].id):getAttack()+ math.random(0, 5))
end
But the itens is crafted with the same atk always. No errors on TFS.
script/craft.xml - I cut a few of recipes out because it was too much code to put here
Lua:
local recipes = {
[26] = {name = "Spellbook",
options = {
[1] = {name = "Soft Leather Spellbook", learned = false, learnStorage = 0, storage = {40000, 40026}, level = {1, 1}, tries = 1, count = 1, id = 2398,
needed = {
[1] = {name = "Soft Leather", id = 27851, count = 5},
[2] = {name = "Poisonous Slimes", id = 10557, count = 10},
[3] = {name = "Cave Rat Tail", id = 4843, count = 1}
}
},
[2] = {name = "Crude Umbral Blade", learned = false, learnStorage = 0, storage = {40004, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22398,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[3] = {name = "Crude Umbral Bow", learned = false, learnStorage = 0, storage = {40004, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22416,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[4] = {name = "Crude Umbral Chopper", learned = false, learnStorage = 0, storage = {40004, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22407,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[5] = {name = "Crude Umbral Crossbow", learned = false, learnStorage = 0, storage = {40004, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22419,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[6] = {name = "Crude Umbral Hammer", learned = false, learnStorage = 0, storage = {40004, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22413,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[7] = {name = "Crude Umbral Mace", learned = false, learnStorage = 0, storage = {40004, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22410,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[8] = {name = "Crude Umbral Slayer", learned = false, learnStorage = 0, storage = {40004, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22401,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[9] = {name = "Umbral Axe", learned = false, learnStorage = 0, storage = {40005, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22405,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[10] = {name = "Umbral Blade", learned = false, learnStorage = 0, storage = {40005, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22399,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[11] = {name = "Umbral Bow", learned = false, learnStorage = 0, storage = {40005, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22417,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[12] = {name = "Umbral Chopper", learned = false, learnStorage = 0, storage = {40005, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22408,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[13] = {name = "Umbral Crossbow", learned = false, learnStorage = 0, storage = {40005, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22420,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[14] = {name = "Umbral Hammer", learned = false, learnStorage = 0, storage = {40005, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22414,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[15] = {name = "Umbral Mace", learned = false, learnStorage = 0, storage = {40005, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22411,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[16] = {name = "Umbral Slayer", learned = false, learnStorage = 0, storage = {40005, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22402,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[17] = {name = "Umbral Master Axe", learned = false, learnStorage = 0, storage = {40006, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22406,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[18] = {name = "Umbral Masterblade", learned = false, learnStorage = 0, storage = {40006, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22400,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[19] = {name = "Umbral Master Bow", learned = false, learnStorage = 0, storage = {40006, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22418,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[20] = {name = "Umbral Master Chopper", learned = false, learnStorage = 0, storage = {40006, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22409,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[21] = {name = "Umbral Master Crossbow", learned = false, learnStorage = 0, storage = {40006, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22421,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[22] = {name = "Umbral Master Hammer", learned = false, learnStorage = 0, storage = {40006, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22415,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[23] = {name = "Umbral Master Mace", learned = false, learnStorage = 0, storage = {40006, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22412,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
[24] = {name = "Umbral Master Slayer", learned = false, learnStorage = 0, storage = {40006, 40008}, level = {100, 10}, tries = 1, count = 1, id = 22403,
needed = {
[1] = {name = "iron ingot", id = 18337, count = 5},
[2] = {name = "wood", id = 5901, count = 2},
[3] = {name = "dream matter", id = 22397, count = 2}
}
},
}
},
[27] = {name = "Quiver",
options = {
[1] = {name = "Ranger Quiver", learned = false, learnStorage = 0, storage = {40000}, level = {1}, tries = 1, count = 1, id = 2312,
needed = {
[1] = {name = "Piece Of Simple Wood", id = 27952, count = 1},
[2] = {name = "Poisonous Slimes", id = 10557, count = 10},
[3] = {name = "Cave Rat Tail", id = 4843, count = 1}
}
},
}
},
[28] = {name = "Backpack",
options = {
[1] = {name = "Leather Backpack", learned = false, learnStorage = 0, storage = {40000}, level = {1}, tries = 1, count = 1, id = 26516,
needed = {
[1] = {name = "Soft Leather", id = 27851, count = 5}
}
},
}
}
}
local modalId = 1005
local Type = {}
local Option = {}
local training = {
[40000] = "Basic Smithing",
[40001] = "Advanced Smithing",
[40002] = "Legendary Smithing",
[40003] = "Ammunition Smithing",
[40004] = "Amulet Smithing",
[40005] = "Axe Smithing",
[40006] = "Bow Smithing",
[40007] = "Claw Smithing",
[40008] = "Club Smithing",
[40009] = "Crossbow Smithing",
[40010] = "Dagger Smithing",
[40011] = "Gun Smithing",
[40012] = "Heavy Armor Smithing",
[40013] = "Heavy Boots Smithing",
[40014] = "Heavy Helmet Smithing",
[40015] = "Heavy Legs Smithing",
[40016] = "Light Armor Smithing",
[40017] = "Light Boots Smithing",
[40018] = "Light Helmet Smithing",
[40019] = "Light Legs Smithing",
[40020] = "Medium Armor Smithing",
[40021] = "Medium Boots Smithing",
[40022] = "Medium Helmet Smithing",
[40023] = "Medium Legs Smithing",
[40024] = "Ring Smithing",
[40025] = "Shield Smithing",
[40026] = "Spellbook Smithing",
[40027] = "Staff Smithing",
[40028] = "Sword Smithing",
}
-- Checks if player has the items required for a recipe - used for bringing the craft option back up after each craft if they have enough to do it again - enables quick, easy crafting
function Player:hasReq(recipe)
for i = 1, #recipe.needed do
if self:getItemCount(recipe.needed[i].id) < recipe.needed[i].count then
return false
end
end
return true
end
function Player:sendSortedWindow(type)
local window = ModalWindow(1011, recipes[type].name, "Expand the item you want to produce to view the requirements.\nYou are trained in the following specialties:\n")
local choices = 0
local temp = 0
for i = 40000, 40028 do
if self:getCSkill(training[i]) >= 10 then
temp = temp + 1
window:setMessage(window:getMessage() .. training[i] .. " (" .. self:getCSkill(training[i]) .. ")\n")
end
end
if temp == 0 then
window:setMessage(window:getMessage() .. "No specialty training.\n")
end
for i = 1, #recipes[type].options do
if (recipes[type].options[i].learned and self:getStorageValue(recipes[type].options[i].learnStorage) >= 1) or not recipes[type].options[i].learned then
if recipes[type].options[i].count > 1 then
window:addChoice(i, recipes[type].options[i].count .. " " .. recipes[type].options[i].name)
else
window:addChoice(i, recipes[type].options[i].name)
end
end
end
window:addButton(1, "Expand")
window:setDefaultEnterButton(1)
window:addButton(2, "Back")
window:setDefaultEscapeButton(2)
window:sendToPlayer(self)
return true
end
function Player:sendEquipmentWindow()
local window = ModalWindow(modalId, "Smithing", "Expand the type of item you want to craft to view the available items.\nYou are trained in the following specialties:\n")
local choices = 0
local temp = 0
for i = 40000, 40028 do
if self:getCSkill(training[i]) >= 10 then
temp = temp + 1
window:setMessage(window:getMessage() .. training[i] .. " (" .. self:getCSkill(training[i]) .. ")\n")
end
end
if temp == 0 then
window:setMessage(window:getMessage() .. "No specialty training.\n")
end
for i = 1, #recipes do
local t = false
for j = 1, #recipes[i].options do
if (recipes[i].options[j].learned and self:getStorageValue(recipes[i].options[j].learnStorage) >= 1) or not recipes[i].options[j].learned then
t = true
break
end
end
if t then
window:addChoice(i, recipes[i].name)
end
end
window:addButton(1, "Expand")
window:setDefaultEnterButton(1)
window:addButton(2, "Exit")
window:setDefaultEscapeButton(2)
window:sendToPlayer(self)
return true
end
function Player:sendERecipeWindow(type, option)
local window = ModalWindow(modalId + 1, recipes[type].options[option].name, "To produce this item, you need:\n")
for i = 1, #recipes[type].options[option].needed do
window:setMessage(window:getMessage() .. recipes[type].options[option].needed[i].count .. " " .. recipes[type].options[option].needed[i].name .. " (" .. self:getItemCount(recipes[type].options[option].needed[i].id) .. ")\n")
end
if recipes[type].options[option].storage then
for i = 1, #recipes[type].options[option].storage do
local lev = self:getCSkill(training[recipes[type].options[option].storage[i]])
window:setMessage(window:getMessage() .. training[recipes[type].options[option].storage[i]] .. " " .. recipes[type].options[option].level[i] .. " (" .. lev .. ")\n")
end
end
for i = 1, #recipes[type].options[option].needed do
if self:getItemCount(recipes[type].options[option].needed[i].id) < recipes[type].options[option].needed[i].count then
return window:addButton(2, "Back"), window:setDefaultEscapeButton(2), window:setDefaultEnterButton(2), window:sendToPlayer(self)
end
end
for i = 1, #recipes[type].options[option].storage do
if self:getCSkill(training[recipes[type].options[option].storage[i]]) < recipes[type].options[option].level[i] then
return window:addButton(2, "Back"), window:setDefaultEscapeButton(2), window:setDefaultEnterButton(2), window:sendToPlayer(self)
end
end
window:addButton(1, "Make It!")
window:setDefaultEnterButton(1)
window:addButton(2, "Back")
window:setDefaultEscapeButton(2)
window:sendToPlayer(self)
return true
end
function Player:sortedWindowChoice(windowId, buttonId, choiceId)
local p = self:getGuid()
if windowId == 1011 then
if buttonId == 1 then
Option[p] = choiceId
self:sendERecipeWindow(Type[p], Option[p])
return true
elseif buttonId == 2 then
self:sendEquipmentWindow()
return true
end
return false
end
return false
end
function Player:equipmentWindowChoice(windowId, buttonId, choiceId)
local p = self:getGuid()
if windowId == modalId then
if buttonId == 1 then
Type[p] = choiceId
self:sendSortedWindow(Type[p])
return true
else
Type[p] = nil
Option[p] = nil
return false
end
end
return false
end
function Player:eRecipeWindowChoice(windowId, buttonId, choiceId)
local p = self:getGuid()
if windowId == modalId + 1 then
if buttonId == 1 then
local rand = math.random(1,100000)
local half = false
local chance = (cSkills[training[recipes[Type[p]].options[Option[p]].storage[1]]].bonus * self:getCSkill(training[recipes[Type[p]].options[Option[p]].storage[1]])) * 100
if rand < chance * 1000 then
half = true
end
for i = 1, #recipes[Type[p]].options[Option[p]].needed do
if half then
self:removeItem(recipes[Type[p]].options[Option[p]].needed[i].id, math.ceil(recipes[Type[p]].options[Option[p]].needed[i].count / 2))
else
self:removeItem(recipes[Type[p]].options[Option[p]].needed[i].id, recipes[Type[p]].options[Option[p]].needed[i].count)
end
end
local item = self:addItem(recipes[Type[p]].options[Option[p]].id, recipes[Type[p]].options[Option[p]].count)
if item:hasAttribute(ITEM_ATTRIBUTE_ATTACK) then
item:setAttribute(ITEM_ATTRIBUTE_ATTACK, ItemType(recipes[Type[p]].options[Option[p]].id):getAttack()+ math.random(0, 5))
end
if half then
self:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have crafted " .. recipes[Type[p]].options[Option[p]].count .. " " .. recipes[Type[p]].options[Option[p]].name .. " at half the usual cost!")
else
self:sendTextMessage(MESSAGE_INFO_DESCR, "You have crafted " .. recipes[Type[p]].options[Option[p]].count .. " " .. recipes[Type[p]].options[Option[p]].name .. "!")
end
for i = 1, #recipes[Type[p]].options[Option[p]].storage do
self:addCSkillTries(training[recipes[Type[p]].options[Option[p]].storage[i]], recipes[Type[p]].options[Option[p]].tries)
end
if recipes[Type[p]].options[Option[p]].set then
if self:getStorageValue(sets[recipes[Type[p]].options[Option[p]].set].pieces[recipes[Type[p]].options[Option[p]].piece].storage) ~= 1 then
self:setStorageValue(sets[recipes[Type[p]].options[Option[p]].set].pieces[recipes[Type[p]].options[Option[p]].piece].storage, 1)
end
local tempStore = true
for i = 1, #sets[recipes[Type[p]].options[Option[p]].set].pieces do
if self:getStorageValue(sets[recipes[Type[p]].options[Option[p]].set].pieces[recipes[Type[p]].options[Option[p]].piece].storage) ~= 1 then
tempStore = false
end
end
if tempStore then
self:addAchievement(sets[recipes[Type[p]].options[Option[p]].set].achievement)
end
end
return self:hasReq(recipes[Type[p]].options[Option[p]]) and self:sendERecipeWindow(Type[p], Option[p]) or self:sendSortedWindow(Type[p])
elseif buttonId == 2 then
self:sendSortedWindow(Type[p])
end
return false
end
return false
end