• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

[TFS 1.4] Small Upgrade System (allowed wand and rods)

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,222
Solutions
137
Reaction score
1,512
Location
London
GitHub
MillhioreBT
Twitch
millhiore_bt
YouTube
millhiorebt
If you want the latest update click here, however you can read this first post to understand the configuration a bit...

Small upgrade system, The upgrade of wands and rods is allowed.
You can add several types of object to use the system, in example code I have configured two objects
per example:
1637567078617.png
Each object has its well defined properties and it is already a matter of you using your imagination
||||||||: Here we have a 100% chance so it will be very easy to improve with this object, however we will give few attributes
||||||||: Here we have a 50% chance so it will be easy to improve with this object, in this case we will give more attributes for the difficulty

per example:
1637566703747.png
||||||||: We only define the variable chance here, this is because it is level 0
||||||||: We only define downLvl and chance here, This is because we can have a degradation or an increase
||||||||: We only define downLvl here, This is because we can have a degradation but not an increase

others:
1637567339426.png
||||||||: If this variable is true, then failed attempts degrade the object
||||||||: If this variable is true, the attempts are infinite

images:
GIF 22-11-2021 04-11-00 a. m..gif

data/scripts/small_upgrade_system.lua

Lua:
local config = {
    interfaceName = "Sarah Wesker Attributes",
    chances = {
        [0] = { chance=100 },
        [1] = { downLvl=0, chance=100 },
        [2] = { downLvl=1, chance=90 },
        [3] = { downLvl=2, chance=80 },
        [4] = { downLvl=3, chance=70 },
        [5] = { downLvl=4, chance=60 },
        [6] = { downLvl=5, chance=50 },
        [7] = { downLvl=6, chance=40 },
        [8] = { downLvl=7, chance=30 },
        [9] = { downLvl=8, chance=20 },
        [10] = { downLvl=9 }
    },
    downgradeEnabled = false,
    debugMode = false,
    values = {
        --[[[number] = {
            chance=number,
            effect=number,
            upgrade={
                armor = number,
                defense = number,
                extraDefense = number,
                attack = number,
                wandDamage = number
            }
        },]]--
        --.............START.............--
        [2178] = { -- Mind Stone
            chance=100,
            effect=CONST_ME_FIREWORK_YELLOW,
            upgrade={
                armor = 2,
                defense = 2,
                extraDefense = 1,
                attack = 2,
                wandDamage = 10
            }
        },
        [2174] = { -- Strange Simbol
            chance=50,
            effect=CONST_ME_FIREWORK_BLUE,
            upgrade={
                armor = 3,
                defense = 3,
                extraDefense = 2,
                attack = 3,
                wandDamage = 25
            }
        }
        --..............END..............--
    }
}
local function getPlayerWeapon(player)
    local weapon = player:getSlotItem(CONST_SLOT_LEFT)
    if not weapon or weapon:getType():getWeaponType() == WEAPON_NONE then
        weapon = player:getSlotItem(CONST_SLOT_RIGHT)
        if not weapon or weapon:getType():getWeaponType() == WEAPON_NONE then
            return
        end
    end
    return weapon
end
[email protected] number
local function getObjLevel(weapon)
    return weapon:getCustomAttribute("SarahWesker_Level") or 0
end
local function setObjLevel(weapon, level)
    return weapon:setCustomAttribute("SarahWesker_Level", level or 0)
end
[email protected] boolean
local function isValidObj(item)
    local type = item:getType()
    return type:getWeaponType() ~= WEAPON_NONE or type:getArmor() > 0 or type:getDefense() > 0 or type:getExtraDefense() > 0 or type:getAttack() > 0
end
[email protected] boolean
local function isWand(item)
    return item:getType():getWeaponType() == WEAPON_WAND
end
[email protected] target userdata
[email protected] attr number
[email protected] upgradeValue number
[email protected] newLevel number
[email protected] iTypeMethod function
local function setAttribute(target, attr, upgradeValue, newLevel, iTypeMethod)
    local valueAttr = iTypeMethod(target:getType())
    if valueAttr > 0 then
        return target:setAttribute(attr, valueAttr + (upgradeValue * newLevel))
    end
end
[email protected] target userdata
[email protected] attr string
[email protected] upgradeValue number
[email protected] newLevel number
local function setCustomAttribute(target, attr, upgradeValue, newLevel)
    return target:setCustomAttribute(attr, upgradeValue * newLevel)
end
[email protected] item userdata
[email protected] this table
[email protected] newLevel number
local function doUpgradeItem(item, this, newLevel)
    if newLevel <= 0 then
        item:removeAttribute(ITEM_ATTRIBUTE_ARMOR)
        item:removeAttribute(ITEM_ATTRIBUTE_DEFENSE)
        item:removeAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE)
        item:removeAttribute(ITEM_ATTRIBUTE_ATTACK)
        item:removeCustomAttribute("SarahWesker_WandDamage")
        return
    end
    setAttribute(item, ITEM_ATTRIBUTE_ARMOR, this.upgrade.armor, newLevel, ItemType.getArmor)
    setAttribute(item, ITEM_ATTRIBUTE_DEFENSE, this.upgrade.defense, newLevel, ItemType.getDefense)
    setAttribute(item, ITEM_ATTRIBUTE_EXTRADEFENSE, this.upgrade.extraDefense, newLevel, ItemType.getExtraDefense)
    setAttribute(item, ITEM_ATTRIBUTE_ATTACK, this.upgrade.attack, newLevel, ItemType.getAttack)
    if isWand(item) then
        setCustomAttribute(item, "SarahWesker_WandDamage", this.upgrade.wandDamage, newLevel)
    end
end
local action = Action()
function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    if not target:isItem() then
        player:sendCancelMessage("It can only be applied to items.")
        return true
    end
    if not isValidObj(target) then
        player:sendCancelMessage("It is not a valid item to upgrade.")
        return true
    end
    local this = config.values[item:getId()]
    local objLevel = getObjLevel(target)
    local foundChance = config.chances[objLevel]
    if not foundChance then
        player:sendCancelMessage("The level of your item is unknown")
        return true
    end
    if not foundChance.chance then
        player:sendCancelMessage("This item is at max level.")
        return true
    end
    local function use()
        if not config.debugMode then
            item:remove(1)
        end
        return true
    end
    local totalChance = foundChance.chance * (this.chance/100)
    if foundChance.chance < math.random(1, 100) then
        local newLevel = foundChance.downLvl or 0
        setObjLevel(target, newLevel)
        doUpgradeItem(target, this, newLevel)
        player:sendCancelMessage("The attempt to upgrade this item has failed.")
        target:getPosition():sendMagicEffect(CONST_ME_POFF)
        return use()
    end
    player:sendCancelMessage("The upgrade of the item is successful.")
    target:getPosition():sendMagicEffect(this.effect or CONST_ME_FIREWORK_YELLOW)
    local newLevel = objLevel +1
    setObjLevel(target, newLevel)
    doUpgradeItem(target, this, newLevel)
    return use()
end
for id, _ in pairs(config.values) do
    action:id(id)
end
action:register()
local ec = EventCallback
function ec.onLook(player, thing, position, distance, description)
    if thing:isItem() then
        local objLevel = getObjLevel(thing)
        if objLevel > 0 then
            description = string.format("%s\n%s (level: %d", description, config.interfaceName, objLevel)
           
            local wandDamage = thing:getCustomAttribute("SarahWesker_WandDamage") or 0
            if wandDamage > 0 then
                description = string.format("%s, extraDamage: +%d hpts", description, wandDamage)
            end
            description = string.format("%s)", description)
        end
    end
    return description
end
ec:register(7)
local creatureEvent = CreatureEvent("SarahWesker_onHealthChange")
function creatureEvent.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if origin == ORIGIN_WAND then
        if attacker:isPlayer() then
            local weapon = getPlayerWeapon(attacker)
            if isWand(weapon) then
                local wandDamage = weapon:getCustomAttribute("SarahWesker_WandDamage") or 0
                if wandDamage > 0 then
                    primaryDamage = primaryDamage + wandDamage
                end
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
creatureEvent:register()
local ec = EventCallback
function ec.onTargetCombat(creature, target)
    if creature and target then
        if creature:isPlayer() then
            target:registerEvent("SarahWesker_onHealthChange")
        end
    end
    return RETURNVALUE_NOERROR
end
ec:register(7)

Note:
I will try to add more attributes to it in the future.
If you notice any bug you can leave me a comment.
I know there are better systems and with many more details, but I just wanted to share my small version
 
Last edited:

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,202
Solutions
27
Reaction score
669
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Hi @Sarah Wesker iv'e waited a lot for this system! I tried it by upgrading a wand of vortex but it doesn't have aditional damage when attacking, here's the example.

testing_01.png

Going to test and look forward for this, if eventually this allow players to raise spellbook's magic level or possibly adding % crit, or mana/hp leech would be great. I have this critical script working on my libs, maybe could be good to merge something like this in the revscript, and simply add critical by using storages

Code:
--[[
    Dodge & Critical fixado por Movie (Movie#4361)
    Disponibilizado para o TibiaKing e não autorizo outras reproduções
    Mantenha os créditos <3
--]]

STORAGEVALUE_DODGE = 48900
STORAGEVALUE_CRITICAL = 48901

DODGE = {
    LEVEL_MAX = 100, -- máximo de level que o dodge será
    PERCENT = 0.2 -- porcentagem que irá defender o ataque
}

CRITICAL = {
    LEVEL_MAX = 100, -- máximo de level que o critical será
    PERCENT = 0.4 -- porcentagem que irá aumentar o ataque 
}

function Player.getDodgeLevel(self)
    return self:getStorageValue(STORAGEVALUE_DODGE)
end

function Player.setDodgeLevel(self, value)
    return self:setStorageValue(STORAGEVALUE_DODGE, value)
end

function Player.getCriticalLevel(self)
    return self:getStorageValue(STORAGEVALUE_CRITICAL)
end

function Player.setCriticalLevel(self, value)
    return self:setStorageValue(STORAGEVALUE_CRITICAL, value)
end

Thanks a lot for the contribution, regards!! :)
 
OP
OP
Sarah Wesker

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,222
Solutions
137
Reaction score
1,512
Location
London
GitHub
MillhioreBT
Twitch
millhiore_bt
YouTube
millhiorebt
Hi @Sarah Wesker iv'e waited a lot for this system! I tried it by upgrading a wand of vortex but it doesn't have aditional damage when attacking, here's the example.

View attachment 63531

Going to test and look forward for this, if eventually this allow players to raise spellbook's magic level or possibly adding % crit, or mana/hp leech would be great. I have this critical script working on my libs, maybe could be good to merge something like this in the revscript, and simply add critical by using storages

Code:
--[[
    Dodge & Critical fixado por Movie (Movie#4361)
    Disponibilizado para o TibiaKing e não autorizo outras reproduções
    Mantenha os créditos <3
--]]

STORAGEVALUE_DODGE = 48900
STORAGEVALUE_CRITICAL = 48901

DODGE = {
    LEVEL_MAX = 100, -- máximo de level que o dodge será
    PERCENT = 0.2 -- porcentagem que irá defender o ataque
}

CRITICAL = {
    LEVEL_MAX = 100, -- máximo de level que o critical será
    PERCENT = 0.4 -- porcentagem que irá aumentar o ataque
}

function Player.getDodgeLevel(self)
    return self:getStorageValue(STORAGEVALUE_DODGE)
end

function Player.setDodgeLevel(self, value)
    return self:setStorageValue(STORAGEVALUE_DODGE, value)
end

function Player.getCriticalLevel(self)
    return self:getStorageValue(STORAGEVALUE_CRITICAL)
end

function Player.setCriticalLevel(self, value)
    return self:setStorageValue(STORAGEVALUE_CRITICAL, value)
end

Thanks a lot for the contribution, regards!! :)
If the damage is not applied, you will probably need this PR:
 

vexler222

Active Member
Joined
Apr 22, 2012
Messages
710
Solutions
15
Reaction score
46
If the damage is not applied, you will probably need this PR:

I add this what u linked and for me not work too, wand attack same like before upgrade, other upgrades worked perfect, but i have other problem cuz when i upgraded weapon i have normal description, none info with upgrad :/

Im using tfs 1.3 8.6 downgraded by nekiro (i have eventcallback and i added what u say in post up)

L4X3Vff.png
 
OP
OP
Sarah Wesker

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,222
Solutions
137
Reaction score
1,512
Location
London
GitHub
MillhioreBT
Twitch
millhiore_bt
YouTube
millhiorebt
I add this what u linked and for me not work too, wand attack same like before upgrade, other upgrades worked perfect, but i have other problem cuz when i upgraded weapon i have normal description, none info with upgrad :/

Im using tfs 1.3 8.6 downgraded by nekiro (i have eventcallback and i added what u say in post up)

L4X3Vff.png
If you really have EventCallback included it shouldn't fail, maybe you should check the events.xml, it should look like this:
XML:
<event class="Creature" method="onTargetCombat" enabled="1" />
--...
<event class="Player" method="onLook" enabled="1" />

on events/scripts/player.lua the onLook and events/scripts/creature.lua onTargetCombat event should look like this:
Lua:
-- player.lua
function Player:onLook(thing, position, distance)
    local description = ""
    if hasEventCallback(EVENT_CALLBACK_ONLOOK) then
        description = EventCallback(EVENT_CALLBACK_ONLOOK, self, thing, position, distance, description)
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

-- creature.lua
function Creature:onTargetCombat(target)
    if hasEventCallback(EVENT_CALLBACK_ONTARGETCOMBAT) then
        return EventCallback(EVENT_CALLBACK_ONTARGETCOMBAT, self, target)
    else
        return RETURNVALUE_NOERROR
    end
end

If the files are not similar and you don't see the word EventCallback anywhere, you may need to add the EventCallback changes again more carefully and not forget anything:


table.pack
luascript.cpp

luascript.h

 
Last edited:
OP
OP
Sarah Wesker

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,222
Solutions
137
Reaction score
1,512
Location
London
GitHub
MillhioreBT
Twitch
millhiore_bt
YouTube
millhiorebt
New update of the system, it is no longer small, but it is still in a single file, it is possible that problems may be found, but if you want to use it and test it, it is welcome, any error, or suggestion you can leave it in the comments, this way I will find out and then I will do my best to update it one more time.

¡Warning!
The system will only work correctly if you are using the latest version of TFS master, to be sure, you must use the version that contains the latest changes of today, November 29, 2021

¡The File!
The file is a bit big so I will upload it to a repository on github and they must download it from there, Click Here to see the file.
Remember: that the file must be located in the data/scripts/ folder
Don't forget to trigger the following events in the events.xml file
XML:
<event class="Creature" method="onTargetCombat" enabled="1" />
...
<event class="Player" method="onItemMoved" enabled="1" />

¿What is this system about?
This is a simple system that updates item attributes.
per example:
Attack from a weapon
The armor of an legs
The abilities of a shield or something else
in general any attribute can be upgradeable

You must bear in mind that not all attributes can be upgrade, but here I will leave a list of the attributes that can be upgrade
Lua:
attack
defense
extraDefense
armor
wandDamage
elementDamage
fist fighting
club fighting
sword fighting
axe fighting
distance fighting
shielding
fishing
max health
max mana
magic level
reg health
reg mana
speed
critical hit chance
critical extra damage
hitpoints leech chance
hitpoints leech amount
manapoints leech chance
mana points leech amount
 

wafuboe

Member
Joined
Dec 24, 2010
Messages
851
Solutions
2
Reaction score
15
New update of the system, it is no longer small, but it is still in a single file, it is possible that problems may be found, but if you want to use it and test it, it is welcome, any error, or suggestion you can leave it in the comments, this way I will find out and then I will do my best to update it one more time.

¡Warning!
The system will only work correctly if you are using the latest version of TFS master, to be sure, you must use the version that contains the latest changes of today, November 29, 2021

¡The File!
The file is a bit big so I will upload it to a repository on github and they must download it from there, Click Here to see the file.
Remember: that the file must be located in the data/scripts/ folder
Don't forget to trigger the following events in the events.xml file
XML:
<event class="Creature" method="onTargetCombat" enabled="1" />
...
<event class="Player" method="onItemMoved" enabled="1" />

¿What is this system about?
This is a simple system that updates item attributes.
per example:
Attack from a weapon
The armor of an legs
The abilities of a shield or something else
in general any attribute can be upgradeable

You must bear in mind that not all attributes can be upgrade, but here I will leave a list of the attributes that can be upgrade
Lua:
attack
defense
extraDefense
armor
wandDamage
elementDamage
fist fighting
club fighting
sword fighting
axe fighting
distance fighting
shielding
fishing
max health
max mana
magic level
reg health
reg mana
speed
critical hit chance
critical extra damage
hitpoints leech chance
hitpoints leech amount
manapoints leech chance
mana points leech amount
hey thanks for your work i appreciate it:)
i have a question

Im working on tfs 1.4 8.6 protocol of nekiro.
does
critical hit chance
critical extra damage
hitpoints leech chance
hitpoints leech amount
manapoints leech chance
mana points leech amount workss? even if its 8.6.

Sorry if its a dumb question thanks
 

Nefre

Member
Joined
May 17, 2012
Messages
41
Reaction score
10
hey thanks for your work i appreciate it:)
i have a question

Im working on tfs 1.4 8.6 protocol of nekiro.
does
critical hit chance
critical extra damage
hitpoints leech chance
hitpoints leech amount
manapoints leech chance
mana points leech amount workss? even if its 8.6.

Sorry if its a dumb question thanks
No it will not work. You need to delete this part. Upgrade damage, def will work, but idk if max hp, mana will work
 

Xikini

I whore myself out for likes
Senator
Joined
Nov 17, 2010
Messages
6,245
Solutions
545
Reaction score
4,487
¡The File!
The file is a bit big so I will upload it to a repository on github and they must download it from there, Click Here to see the file.
Just posting to note that the file is uploaded to OtLand in this comment, so it won't be lost accidentally. :)
 

Attachments

  • sarah_upgrade_system.lua
    22 KB · Views: 57 · VirusTotal

Nefre

Member
Joined
May 17, 2012
Messages
41
Reaction score
10
Hello. I tried this script in tfs 1.5 8.6 downgrade. I have lifeleech, manaleech, critical in my server. When I upgrade item this item get attack, def but dont get skills, special skills and I got error in console:
Lua:
Lua Script Error: [Scripts Interface]
/home/ots/data/scripts/sarah_upgrade_system.lua:callback
/home/ots/data/scripts/sarah_upgrade_system.lua:472: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        /home/ots/data/scripts/sarah_upgrade_system.lua:472: in function 'doUpgradeItem'
        /home/ots/data/scripts/sarah_upgrade_system.lua:610: in function </home/ots/data/scripts/sarah_upgrade_system.lua:550>

#Edit I tested your first script without special skills. Everything works for me there, including wands damage. But got problems after update scripts.
 
Last edited:

helmut7414

New Member
Joined
Mar 3, 2012
Messages
14
Solutions
1
Reaction score
2
Hey,
first of all nice script its very usefull.
I had some problems with the application of the wand damge but I have solved it. Now I have a new problem comming up, the script upgrades each skill perfectly but not the magic level, I am useing the latest TFS 1.4 Version and your newest script.
 

Sardinha

New Member
Joined
Feb 19, 2011
Messages
20
Reaction score
1
If you really have EventCallback included it shouldn't fail, maybe you should check the events.xml, it should look like this:
XML:
<event class="Creature" method="onTargetCombat" enabled="1" />
--...
<event class="Player" method="onLook" enabled="1" />

on events/scripts/player.lua the onLook and events/scripts/creature.lua onTargetCombat event should look like this:
Lua:
-- player.lua
function Player:onLook(thing, position, distance)
    local description = ""
    if hasEventCallback(EVENT_CALLBACK_ONLOOK) then
        description = EventCallback(EVENT_CALLBACK_ONLOOK, self, thing, position, distance, description)
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

-- creature.lua
function Creature:onTargetCombat(target)
    if hasEventCallback(EVENT_CALLBACK_ONTARGETCOMBAT) then
        return EventCallback(EVENT_CALLBACK_ONTARGETCOMBAT, self, target)
    else
        return RETURNVALUE_NOERROR
    end
end

If the files are not similar and you don't see the word EventCallback anywhere, you may need to add the EventCallback changes again more carefully and not forget anything:


table.pack
luascript.cpp

luascript.h

I use Nekiro's TFS 1.3 version 8.6
My server doesn't have support for eventcallbacks, so I added it according to this pull you left, when compiling everything goes right, no errors, but when I kill a monster in the debug game. Do you know the cause of this?
 

Tacabala22

New Member
Joined
Jun 6, 2022
Messages
12
Reaction score
1
@Sarah Wesker
[US] Hi, I'm also having the same problem as the other one. But I use nekiro's tfs 1.5 downgrade.

C++:
Lua Script Error: [Scripts Interface]
/home/tfs/baiak/data/scripts/upgradesystem.lua:callback
/home/tfs/baiak/data/scripts/upgradesystem.lua:472: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        /home/tfs/baiak/data/scripts/upgradesystem.lua:472: in function 'doUpgradeItem'
        /home/tfs/baiak/data/scripts/upgradesystem.lua:610: in function </home/tfs/baiak/data/scripts/upgradesystem.lua:550>

Can you tell me where I can find the solution? Thank you for your attention!

New update of the system, it is no longer small, but it is still in a single file, it is possible that problems may be found, but if you want to use it and test it, it is welcome, any error, or suggestion you can leave it in the comments, this way I will find out and then I will do my best to update it one more time.

¡Warning!
The system will only work correctly if you are using the latest version of TFS master, to be sure, you must use the version that contains the latest changes of today, November 29, 2021

¡The File!
The file is a bit big so I will upload it to a repository on github and they must download it from there, Click Here to see the file.
Remember: that the file must be located in the data/scripts/ folder
Don't forget to trigger the following events in the events.xml file
XML:
<event class="Creature" method="onTargetCombat" enabled="1" />
...
<event class="Player" method="onItemMoved" enabled="1" />

¿What is this system about?
This is a simple system that updates item attributes.
per example:
Attack from a weapon
The armor of an legs
The abilities of a shield or something else
in general any attribute can be upgradeable

You must bear in mind that not all attributes can be upgrade, but here I will leave a list of the attributes that can be upgrade
Lua:
attack
defense
extraDefense
armor
wandDamage
elementDamage
fist fighting
club fighting
sword fighting
axe fighting
distance fighting
shielding
fishing
max health
max mana
magic level
reg health
reg mana
speed
critical hit chance
critical extra damage
hitpoints leech chance
hitpoints leech amount
manapoints leech chance
mana points leech amount
 
Last edited by a moderator:

jora157

New Member
Joined
Jan 18, 2009
Messages
23
Reaction score
1
If you want the latest update click here, however you can read this first post to understand the configuration a bit...

Small upgrade system, The upgrade of wands and rods is allowed.
You can add several types of object to use the system, in example code I have configured two objects
per example:
View attachment 63526
Each object has its well defined properties and it is already a matter of you using your imagination
||||||||: Here we have a 100% chance so it will be very easy to improve with this object, however we will give few attributes
||||||||: Here we have a 50% chance so it will be easy to improve with this object, in this case we will give more attributes for the difficulty

per example:
View attachment 63525
||||||||: We only define the variable chance here, this is because it is level 0
||||||||: We only define downLvl and chance here, This is because we can have a degradation or an increase
||||||||: We only define downLvl here, This is because we can have a degradation but not an increase

others:
View attachment 63527
||||||||: If this variable is true, then failed attempts degrade the object
||||||||: If this variable is true, the attempts are infinite

images:
View attachment 63529

data/scripts/small_upgrade_system.lua

Lua:
local config = {
    interfaceName = "Sarah Wesker Attributes",
    chances = {
        [0] = { chance=100 },
        [1] = { downLvl=0, chance=100 },
        [2] = { downLvl=1, chance=90 },
        [3] = { downLvl=2, chance=80 },
        [4] = { downLvl=3, chance=70 },
        [5] = { downLvl=4, chance=60 },
        [6] = { downLvl=5, chance=50 },
        [7] = { downLvl=6, chance=40 },
        [8] = { downLvl=7, chance=30 },
        [9] = { downLvl=8, chance=20 },
        [10] = { downLvl=9 }
    },
    downgradeEnabled = false,
    debugMode = false,
    values = {
        --[[[number] = {
            chance=number,
            effect=number,
            upgrade={
                armor = number,
                defense = number,
                extraDefense = number,
                attack = number,
                wandDamage = number
            }
        },]]--
        --.............START.............--
        [2178] = { -- Mind Stone
            chance=100,
            effect=CONST_ME_FIREWORK_YELLOW,
            upgrade={
                armor = 2,
                defense = 2,
                extraDefense = 1,
                attack = 2,
                wandDamage = 10
            }
        },
        [2174] = { -- Strange Simbol
            chance=50,
            effect=CONST_ME_FIREWORK_BLUE,
            upgrade={
                armor = 3,
                defense = 3,
                extraDefense = 2,
                attack = 3,
                wandDamage = 25
            }
        }
        --..............END..............--
    }
}
local function getPlayerWeapon(player)
    local weapon = player:getSlotItem(CONST_SLOT_LEFT)
    if not weapon or weapon:getType():getWeaponType() == WEAPON_NONE then
        weapon = player:getSlotItem(CONST_SLOT_RIGHT)
        if not weapon or weapon:getType():getWeaponType() == WEAPON_NONE then
            return
        end
    end
    return weapon
end
[email protected] number
local function getObjLevel(weapon)
    return weapon:getCustomAttribute("SarahWesker_Level") or 0
end
local function setObjLevel(weapon, level)
    return weapon:setCustomAttribute("SarahWesker_Level", level or 0)
end
[email protected] boolean
local function isValidObj(item)
    local type = item:getType()
    return type:getWeaponType() ~= WEAPON_NONE or type:getArmor() > 0 or type:getDefense() > 0 or type:getExtraDefense() > 0 or type:getAttack() > 0
end
[email protected] boolean
local function isWand(item)
    return item:getType():getWeaponType() == WEAPON_WAND
end
[email protected] target userdata
[email protected] attr number
[email protected]am upgradeValue number
[email protected] newLevel number
[email protected] iTypeMethod function
local function setAttribute(target, attr, upgradeValue, newLevel, iTypeMethod)
    local valueAttr = iTypeMethod(target:getType())
    if valueAttr > 0 then
        return target:setAttribute(attr, valueAttr + (upgradeValue * newLevel))
    end
end
[email protected] target userdata
[email protected] attr string
[email protected] upgradeValue number
[email protected] newLevel number
local function setCustomAttribute(target, attr, upgradeValue, newLevel)
    return target:setCustomAttribute(attr, upgradeValue * newLevel)
end
[email protected] item userdata
[email protected] this table
[email protected] newLevel number
local function doUpgradeItem(item, this, newLevel)
    if newLevel <= 0 then
        item:removeAttribute(ITEM_ATTRIBUTE_ARMOR)
        item:removeAttribute(ITEM_ATTRIBUTE_DEFENSE)
        item:removeAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE)
        item:removeAttribute(ITEM_ATTRIBUTE_ATTACK)
        item:removeCustomAttribute("SarahWesker_WandDamage")
        return
    end
    setAttribute(item, ITEM_ATTRIBUTE_ARMOR, this.upgrade.armor, newLevel, ItemType.getArmor)
    setAttribute(item, ITEM_ATTRIBUTE_DEFENSE, this.upgrade.defense, newLevel, ItemType.getDefense)
    setAttribute(item, ITEM_ATTRIBUTE_EXTRADEFENSE, this.upgrade.extraDefense, newLevel, ItemType.getExtraDefense)
    setAttribute(item, ITEM_ATTRIBUTE_ATTACK, this.upgrade.attack, newLevel, ItemType.getAttack)
    if isWand(item) then
        setCustomAttribute(item, "SarahWesker_WandDamage", this.upgrade.wandDamage, newLevel)
    end
end
local action = Action()
function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    if not target:isItem() then
        player:sendCancelMessage("It can only be applied to items.")
        return true
    end
    if not isValidObj(target) then
        player:sendCancelMessage("It is not a valid item to upgrade.")
        return true
    end
    local this = config.values[item:getId()]
    local objLevel = getObjLevel(target)
    local foundChance = config.chances[objLevel]
    if not foundChance then
        player:sendCancelMessage("The level of your item is unknown")
        return true
    end
    if not foundChance.chance then
        player:sendCancelMessage("This item is at max level.")
        return true
    end
    local function use()
        if not config.debugMode then
            item:remove(1)
        end
        return true
    end
    local totalChance = foundChance.chance * (this.chance/100)
    if foundChance.chance < math.random(1, 100) then
        local newLevel = foundChance.downLvl or 0
        setObjLevel(target, newLevel)
        doUpgradeItem(target, this, newLevel)
        player:sendCancelMessage("The attempt to upgrade this item has failed.")
        target:getPosition():sendMagicEffect(CONST_ME_POFF)
        return use()
    end
    player:sendCancelMessage("The upgrade of the item is successful.")
    target:getPosition():sendMagicEffect(this.effect or CONST_ME_FIREWORK_YELLOW)
    local newLevel = objLevel +1
    setObjLevel(target, newLevel)
    doUpgradeItem(target, this, newLevel)
    return use()
end
for id, _ in pairs(config.values) do
    action:id(id)
end
action:register()
local ec = EventCallback
function ec.onLook(player, thing, position, distance, description)
    if thing:isItem() then
        local objLevel = getObjLevel(thing)
        if objLevel > 0 then
            description = string.format("%s\n%s (level: %d", description, config.interfaceName, objLevel)
         
            local wandDamage = thing:getCustomAttribute("SarahWesker_WandDamage") or 0
            if wandDamage > 0 then
                description = string.format("%s, extraDamage: +%d hpts", description, wandDamage)
            end
            description = string.format("%s)", description)
        end
    end
    return description
end
ec:register(7)
local creatureEvent = CreatureEvent("SarahWesker_onHealthChange")
function creatureEvent.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if origin == ORIGIN_WAND then
        if attacker:isPlayer() then
            local weapon = getPlayerWeapon(attacker)
            if isWand(weapon) then
                local wandDamage = weapon:getCustomAttribute("SarahWesker_WandDamage") or 0
                if wandDamage > 0 then
                    primaryDamage = primaryDamage + wandDamage
                end
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
creatureEvent:register()
local ec = EventCallback
function ec.onTargetCombat(creature, target)
    if creature and target then
        if creature:isPlayer() then
            target:registerEvent("SarahWesker_onHealthChange")
        end
    end
    return RETURNVALUE_NOERROR
end
ec:register(7)

Note:
I will try to add more attributes to it in the future.
If you notice any bug you can leave me a comment.
I know there are better systems and with many more details, but I just wanted to share my small version
sara, how is posible to configure this script to:
stone A = 0 to +5
stone B = +6 to +10
stone C = +11 to +20
or
Stone B = 0 to +10
Stone C = 0 to +20
thank you
Post automatically merged:

Just posting to note that the file is uploaded to OtLand in this comment, so it won't be lost accidentally. :)
main sarah scripts work
Just posting to note that the file is uploaded to OtLand in this comment, so it won't be lost accidentally. :)
sarah script works ok, but your script dont works well for me and I rly want this system (until x level upgrade use a item tipe a, after this item tipe b~) :(
 
Last edited:

Tofame

Active Member
Joined
Aug 17, 2021
Messages
47
Solutions
1
Reaction score
26
Location
Poland
sara, how is posible to configure this script to:
stone A = 0 to +5
stone B = +6 to +10
stone C = +11 to +20
or
Stone B = 0 to +10
Stone C = 0 to +20
thank you
Post automatically merged:


main sarah scripts work

sarah script works ok, but your script dont works well for me and I rly want this system (until x level upgrade use a item tipe a, after this item tipe b~) :(
I completed the thing with stones that you wanted. I will also soon create pull request on her github. It seems that there were minRequireLvl and maxRequireLvl settings but they weren't used at all in the script. So I used them and finished the script.

Open the script and find this line:
Lua:
local totalChance = foundChance.chance * (this.chance/100)
Above it paste:
Lua:
local isLevelReq = getObjLevel(target)
if isLevelReq < this.minRequireLvl then -- if upgrade item minimum level is higher than weapon's level
    return player:sendCancelMessage("Your upgrade item can only be used on " .. this.minRequireLvl .. "lvl or higher")
end
if isLevelReq >= this.maxRequireLvl then -- if your upgrade item achieved its own max level
    return player:sendCancelMessage("Your upgrade item can only upgrade up to " .. this.maxRequireLvl .. "!")
end
I also created another pull request there, basically 3 lines of code, that allows for ignoring chance formula and just give 100% chance for upgrade.


Thanks for the script :)
 
Last edited:

Musaab

NoxOts
Joined
May 13, 2010
Messages
208
Solutions
3
Reaction score
77
Location
Sweden
Its strange, something in the latest script is causing items not being able to be "look"ed at? If i remove the script then everything works as normal but with the script it just shows nothing.

The script seems to work and i have no errors in console for that matter. I tried to upgrade a sword and was successfull , i was able to "look" at it but just showed nil, picture below!

Edit: Yes am using latest 1.4.2 from git, clean aswell

1667034809400.png
 
Top