abdala ragab
Veteran OT User
Hello, I use the upgrade items system Xikini, but I want the weapons to be upgraded with one Coin
To upgrade the weapon there you must use two coin
I tried to edit the script Here's what I implemented
script work and develop the weapon and there is no error, but the weapon does not increase of damage
@Xikini
I hope you can help, thanks in advance
Lua - Xikini's Free Scripting Service TFS 1.4.2
Request whatever you want, within reason. Please do not request for things that require source editing or database queries. ------------------------------------ If I've reacted to your post, it means I've read it. 👍😍🤣😲🙁😡🤔😉 ------------------------------------ Completed Requests A boss that...
otland.net
Lua:
{statType = "critical hit damage", value = 1},
{statType = "critical hit chance", value = 1},
Lua:
local conditionSubId = 45083 -- must be a unique subId not used for other buffs in your server
local config = {
maxUpgradesPerItem = 5,
upgradeItems = {
[9112] = {statType = "weaponPower", value = 1.9}, -- ID 9112 used to increase weapon power by 10%
},
specialDisallowedItems = {} -- any items that shouldn't be upgradeable, add them here
}
local function updateStatBonus(playerId)
local player = Player(playerId)
if not player then return end
-- Define the slots for equipment
local CONST_SLOT_FIRST = CONST_SLOT_HEAD
local CONST_SLOT_LAST = CONST_SLOT_AMMO
for i = CONST_SLOT_FIRST, CONST_SLOT_LAST do
local item = player:getSlotItem(i)
if item and item:getCustomAttribute("Upgrade Counter") then
local weaponPower = item:getCustomAttribute("weaponPower") or 0
local critChance = item:getCustomAttribute("critical Hit Chance") or 0
local critDamage = item:getCustomAttribute("critical Hit Damage") or 0
-- Apply these stats to the player if needed
-- Example: player:setWeaponPower(player:getWeaponPower() + weaponPower)
end
end
end
local action = Action()
function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if not target or not target:isItem() then
return false
end
local itemIndex = config.upgradeItems[item:getId()]
if not itemIndex then
return false
end
local itemType = target:getType()
if not itemType or not itemType:isWeapon() then
player:sendTextMessage(MESSAGE_STATUS_SMALL, "This item cannot be upgraded.")
target:getPosition():sendMagicEffect(CONST_ME_POFF, player)
return true
end
if config.specialDisallowedItems[target:getId()] then
player:sendTextMessage(MESSAGE_STATUS_SMALL, "This item cannot be upgraded.")
target:getPosition():sendMagicEffect(CONST_ME_POFF, player)
return true
end
local itemUpgradeCount = target:getCustomAttribute("Upgrade Counter") or 0
if itemUpgradeCount >= config.maxUpgradesPerItem then
player:sendTextMessage(MESSAGE_STATUS_SMALL, "Item has reached max upgrades.")
target:getPosition():sendMagicEffect(CONST_ME_POFF, player)
return true
end
local currentStatAmount = target:getCustomAttribute(itemIndex.statType) or 0
target:setCustomAttribute(itemIndex.statType, currentStatAmount + itemIndex.value)
target:setCustomAttribute("Upgrade Counter", itemUpgradeCount + 1)
-- Ensure critical hit chance and critical hit damage are also updated
local currentCritChance = target:getCustomAttribute("critical Hit Chance") or 0
local currentCritDamage = target:getCustomAttribute("critical Hit Damage") or 0
target:setCustomAttribute("critical Hit Chance", currentCritChance + (itemIndex.value / 100)) -- Increase crit chance by 1%
target:setCustomAttribute("critical Hit Damage", currentCritDamage + (itemIndex.value * 10)) -- Increase crit damage by 20%
target:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN, player)
player:sendTextMessage(MESSAGE_STATUS_SMALL, "Item has been upgraded.")
item:remove(1)
if toPosition.x == CONTAINER_POSITION and toPosition.y <= 10 then
addEvent(updateStatBonus, 0, player:getId())
end
return true
end
for itemId, _ in pairs(config.upgradeItems) do
action:id(itemId)
end
action:register()
local creatureevent = CreatureEvent("onLogin_updateItemStatBonus")
function creatureevent.onLogin(player)
updateStatBonus(player:getId())
return true
end
creatureevent:register()
local ec = EventCallback
ec.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
if not (toPosition.x == CONTAINER_POSITION and toPosition.y <= 10 or fromPosition.x == CONTAINER_POSITION and fromPosition.y <= 10) then
return RETURNVALUE_NOERROR
end
addEvent(updateStatBonus, 0, self:getId())
return RETURNVALUE_NOERROR
end
ec:register()
@Xikini
I hope you can help, thanks in advance