CreatureEvent [TFS 1.1] Ultimate item stat system (elements, skills, exp, loot and more)

Danat

Excellent OT User
Joined
Jun 6, 2008
Messages
47
Reaction score
12
Here is my fixed version for the function Item:clearUpgrade()

Code:
function Item:clearUpgrades()
    local slots = self:getStatSlotCount()
    local slotstodo = slots
    if slots > 0 then
        while slotstodo ~= 0 do
            self:removeSlot(slotstodo)
            slotstodo = slotstodo - 1
        end
        
    end
    
    self:removeAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
    self:removeAttribute(ITEM_ATTRIBUTE_NAME)
    self:removeAttribute(ITEM_ATTRIBUTE_ARTICLE)
    self:removeAttribute(ITEM_ATTRIBUTE_PLURALNAME)
    self:removeAttribute(ITEM_ATTRIBUTE_ATTACK)
    self:removeAttribute(ITEM_ATTRIBUTE_DEFENSE)
    self:removeAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE)
    self:removeAttribute(ITEM_ATTRIBUTE_ARMOR)
    self:removeAttribute(ITEM_ATTRIBUTE_HITCHANCE)
    self:removeAttribute(ITEM_ATTRIBUTE_SHOOTRANGE)
    self:removeAttribute(ITEM_ATTRIBUTE_DURATION)
    self:removeAttribute(ITEM_ATTRIBUTE_CHARGES)
return true
end
This changed the order in which the slots are being removed, with these changes, it will remove them from last to first
 

Danat

Excellent OT User
Joined
Jun 6, 2008
Messages
47
Reaction score
12
Here is my version of the function Item:removeSlot:

This function should, maybe, fix the remove slot gem for the previous code i posted.
By preventing slots giving stats twice.
Code:
function Item:removeSlot(slotid)
    if not tonumber(slotid) then slotid = 0 end
    local slots = self:getStatSlotCount()
    if slotid == 0 then
        slotid = slots
    end
    local first_desc = self:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
    local slot_t = self:getStatSlots()
    --print("Item Upgrade;  Total slots: " .. slots .. " , current slotid: " .. slotid .. ".")
    self:removeAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
    for i = 1, slots do
        -- i slot number
        --print("Item Upgrade;  slot name: " .. slot_t[i][1] .. "  " .. slot_t[i][2])
        if i == slotid then -- its the slot to remove
            local spellname = slot_t[i][1]
            if isInArray({'charges', 'time', 'atk', 'def', 'extra def', 'arm', 'accuracy', 'range'}, spellname) then
                local enchantGain
                local lvlItem
                lvlItem = self:getLevel()
                local basestats = self:getBaseStatsInfo()
                local basestats2 = {
                    ['charges'] = basestats.charges,
                    ['time'] = basestats.duration,
                    ['atk'] = basestats.attack,
                    ['def'] = basestats.defense,
                    ['extra def'] = basestats.extraDefense,
                    ['arm'] = basestats.armor,
                    ['accuracy'] = basestats.hitChance,
                    ['range'] = basestats.shootRange
                }
               
                local gainstats = {
                    ['atk'] = STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.atk,
                    ['def'] = STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.def,
                    ['extra def'] = STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.extradef,
                    ['arm'] = STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.arm,
                    ['accuracy'] = STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.hitchance,
                    ['range'] = STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.shootrange,
                }
               
                local uid = self:getUniqueId()
                local fullstats = {
                    ['charges'] = getItemAttribute(uid, ITEM_ATTRIBUTE_CHARGES),
                    ['time'] = self:getBaseDuration(),
                    ['atk'] = getItemAttribute(uid, ITEM_ATTRIBUTE_ATTACK),
                    ['def'] = getItemAttribute(uid, ITEM_ATTRIBUTE_DEFENSE),
                    ['extra def'] = getItemAttribute(uid, ITEM_ATTRIBUTE_EXTRADEFENSE),
                    ['arm'] = getItemAttribute(uid, ITEM_ATTRIBUTE_ARMOR),
                    ['accuracy'] = getItemAttribute(uid, ITEM_ATTRIBUTE_HITCHANCE),
                    ['range'] = getItemAttribute(uid, ITEM_ATTRIBUTE_SHOOTRANGE)
                }
               
               
               
                if slot_t[i][2]:match("%%") then
                    local a, b = slot_t[i][2]:match('([+-])(%d+)%%')
                    --print (a .. b)
                    enchantGain = math.abs(math.floor((basestats2[spellname] * tonumber(a..b)/100)))
                    --mathstatgainItem = basestatsItem.attack + (lvlupGain * lvlItem) + enchantGain
                    self:setAttribute(attrkeys[spellname], basestats2[spellname] + (gainstats[spellname] * lvlItem))
                    --self:setAttribute(attrkeys[spellname], fullstats[spellname] - math.abs(math.floor((basestats2[spellname] * tonumber(a..b)/100))))
                else
                    enchantGain = slot_t[i][2]
                    --mathatkItem = basestatsItem.attack + (gainstats[spellname] * lvlItem) + enchantGain
                    self:setAttribute(attrkeys[spellname], basestats2[spellname] + (gainstats[spellname] * lvlItem))
                    --self:setAttribute(attrkeys[spellname], fullstats[spellname] - tonumber(slot_t[i][2]))
                end
            end
            --print("Item Upgrade; (removeslot) slot removed. slot: " .. slot_t[i][1] .. "  " .. slot_t[i][2])
        else -- its not the slot to remove
            local spellname = slot_t[i][1]
            if isInArray({'charges', 'time', 'atk', 'def', 'extra def', 'arm', 'accuracy', 'range'}, spellname) then
                local enchantGain
                local lvlItem
                lvlItem = self:getLevel()
                local basestats = self:getBaseStatsInfo()
                local basestats2 = {
                    ['charges'] = basestats.charges,
                    ['time'] = basestats.duration,
                    ['atk'] = basestats.attack,
                    ['def'] = basestats.defense,
                    ['extra def'] = basestats.extraDefense,
                    ['arm'] = basestats.armor,
                    ['accuracy'] = basestats.hitChance,
                    ['range'] = basestats.shootRange
                }
               
                local gainstats = {
                    ['atk'] = STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.atk,
                    ['def'] = STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.def,
                    ['extra def'] = STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.extradef,
                    ['arm'] =STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.arm,
                    ['accuracy'] = STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.hitchance,
                    ['range'] = STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.shootrange
                }
               
                local uid = self:getUniqueId()
                local fullstats = {
                    ['charges'] = getItemAttribute(uid, ITEM_ATTRIBUTE_CHARGES),
                    ['time'] = self:getBaseDuration(),
                    ['atk'] = getItemAttribute(uid, ITEM_ATTRIBUTE_ATTACK),
                    ['def'] = getItemAttribute(uid, ITEM_ATTRIBUTE_DEFENSE),
                    ['extra def'] = getItemAttribute(uid, ITEM_ATTRIBUTE_EXTRADEFENSE),
                    ['arm'] = getItemAttribute(uid, ITEM_ATTRIBUTE_ARMOR),
                    ['accuracy'] = getItemAttribute(uid, ITEM_ATTRIBUTE_HITCHANCE),
                    ['range'] = getItemAttribute(uid, ITEM_ATTRIBUTE_SHOOTRANGE)
                }
               
               
               
                if slot_t[i][2]:match("%%") then
                    local a, b = slot_t[i][2]:match('([+-])(%d+)%%')
                    --print (a .. b)
                    enchantGain = math.abs(math.floor((basestats2[spellname] * tonumber(a..b)/100)))
                    --mathstatgainItem = basestatsItem.attack + (lvlupGain * lvlItem) + enchantGain
                    self:setAttribute(attrkeys[spellname], basestats2[spellname] + (gainstats[spellname] * lvlItem) + enchantGain)
                    --self:setAttribute(attrkeys[spellname], fullstats[spellname] - math.abs(math.floor((basestats2[spellname] * tonumber(a..b)/100))))
                else
                    enchantGain = slot_t[i][2]
                    --mathatkItem = basestatsItem.attack + (gainstats[spellname] * lvlItem) + enchantGain
                    self:setAttribute(attrkeys[spellname], basestats2[spellname] + (gainstats[spellname] * lvlItem) + enchantGain)
                    --self:setAttribute(attrkeys[spellname], fullstats[spellname] - tonumber(slot_t[i][2]))
                end
            end
           
       
       
            --print("Item Upgrade;  " "slot_t i: " .. slot_t[i][1])

            if slot_t[i][2]:match("%%") then
                local a, b = slot_t[i][2]:match('([+-])(%d+)%%')
                self:addSlot(slot_t[i][1], tonumber(a..b), true)
            else  
                self:addSlot(slot_t[i][1], tonumber(slot_t[i][2]), false)
            end
            --print("Item Upgrade; (removeslot) slot added. slot: " .. slot_t[i][1] .. "  " .. slot_t[i][2])
        end
       
    end  
    return true
end
 
Last edited:

Danat

Excellent OT User
Joined
Jun 6, 2008
Messages
47
Reaction score
12
and last modification to the function Item.addStat

Code:
function Item.addStat(item, spellname, spellvalue, suffix, cid)
    if isInArray({'charges', 'time', 'atk', 'def', 'extra def', 'arm', 'accuracy', 'range'}, spellname) then
        local basestats = item:getBaseStatsInfo()
        local basestats2 = {
            ['charges'] = basestats.charges,
            ['time'] = basestats.duration,
            ['atk'] = basestats.attack,
            ['def'] = basestats.defense,
            ['extra def'] = basestats.extraDefense,
            ['arm'] = basestats.armor,
            ['accuracy'] = basestats.hitChance,
            ['range'] = basestats.shootRange
        }
        local gainstats = {
            ['atk'] = STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.atk,
            ['def'] = STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.def,
            ['extra def'] = STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.extradef,
            ['arm'] =STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.arm,
            ['accuracy'] = STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.hitchance,
            ['range'] = STATS_SYSTEM_CONFIG.UPGRADE_STATS_VALUES_PER_LVL.shootrange
        }
        
        local uid = item:getUniqueId()
        local fullstats = {
            ['charges'] = getItemAttribute(uid, ITEM_ATTRIBUTE_CHARGES),
            ['time'] = item:getBaseDuration(),
            ['atk'] = getItemAttribute(uid, ITEM_ATTRIBUTE_ATTACK),
            ['def'] = getItemAttribute(uid, ITEM_ATTRIBUTE_DEFENSE),
            ['extra def'] = getItemAttribute(uid, ITEM_ATTRIBUTE_EXTRADEFENSE),
            ['arm'] = getItemAttribute(uid, ITEM_ATTRIBUTE_ARMOR),
            ['accuracy'] = getItemAttribute(uid, ITEM_ATTRIBUTE_HITCHANCE),
            ['range'] = getItemAttribute(uid, ITEM_ATTRIBUTE_SHOOTRANGE)
        }
        
        
        if suffix == "%" then
            if basestats2[spellname] == 0 then
                if cid then
                    Player(cid):sendTextMessage(MESSAGE_INFO_DESCR, "Spell " .. spellname .. "% is not available for this item.")
                end
                return false
            end
            if spellname ~= 'charges' or 'time' then
                item:setAttribute(attrkeys[spellname], basestats2[spellname] + (gainstats[spellname]*item:getLevel()) + math.abs(math.floor((basestats2[spellname] * spellvalue/100))))
            else
                item:setAttribute(attrkeys[spellname], fullstats[spellname] + math.abs(math.floor((basestats2[spellname] * spellvalue/100))))
            end
            --item:setAttribute(attrkeys[spellname], fullstats[spellname] + math.abs(math.floor((basestats2[spellname] * spellvalue/100)))) -- basestat intended to prevent too high values when combined with upgrade system
        else
            if spellname ~= 'charges' or 'time' then
                item:setAttribute(attrkeys[spellname], basestats2[spellname] + (gainstats[spellname]*item:getLevel()) + math.abs(spellvalue))
            else
                item:setAttribute(attrkeys[spellname], fullstats[spellname] + math.abs(spellvalue))
            end
        end
    end
    item:addStatSlot(spellname, spellvalue, suffix)
    return true
end
 

Danat

Excellent OT User
Joined
Jun 6, 2008
Messages
47
Reaction score
12
you can try using the function Item.addStat i posted. Let me know if that fixes it!
 

Danat

Excellent OT User
Joined
Jun 6, 2008
Messages
47
Reaction score
12
This one should fix the function improveStackables

Code:
function improveStackables(c, v)
    local h = c:getItemHoldingCount()
    if h > 0 then
        for i = 1, h do
            local it_u = c:getItem(i - 1)
            --local it_id = ItemType(it_u) --not working with isStackable
            local it_id = it_u:getType()

            if it_id:isStackable() then
                local amount = math.random(0, v)
                if amount > 0 then
                    c:addItem(it_u:getId(), amount)
                end
            elseif it_u:isContainer() then   
                improveStackables(it_u, v)
            end
        end
    end
return true
end
 

gustavo_hso

New Member
Joined
Jul 24, 2012
Messages
4
Reaction score
0
@Danat
Attributes disappear when you increase stats with any upgrade gems...
Before placing +4:
34808


after setting the stats +4:

34809
 

wafuboe

Intermediate OT User
Joined
Dec 24, 2010
Messages
816
Reaction score
13
Im lookin x2 x3

10:15 You see a common royal helmet -1 (Arm:7).
Imbuements: (Empty Slot, Empty Slot).
It weighs 48.00 oz.
An excellent masterpiece of a smith.a common royal helmet -1 (Arm:7).
Imbuements: (Empty Slot, Empty Slot).
It weighs 48.00 oz.
An excellent masterpiece of a smith.
 

Kodak

Excellent OT User
Joined
Jun 7, 2007
Messages
40
Reaction score
6
I been attempting to get this to apply to EVERY piece of equipment dropped by monsters. I assume I need to figure out how to remove the random application and make it a constant but can't figure it out. I looked through the original Item stat script that this one was based off of in part. In that thread there is someone who provides and updated version of that script to apply to all equipment dropped by creatures, as well as provides C++ edits for the source to change loot from hard coded source to lua (Page 5 of replies). I've compared all three scripts, and while similar they are very different. has anyone ever edited this script to apply to all equipment dropped by creatures? I'm basically trying to get it to where at minimum the item drops as a common, with it randomly being applied to other item levels as well. Anyone have any advice? thank you.
 

samco

4x4 Developer.
Joined
Jul 3, 2007
Messages
882
Reaction score
173
Location
Spain
I been attempting to get this to apply to EVERY piece of equipment dropped by monsters. I assume I need to figure out how to remove the random application and make it a constant but can't figure it out. I looked through the original Item stat script that this one was based off of in part. In that thread there is someone who provides and updated version of that script to apply to all equipment dropped by creatures, as well as provides C++ edits for the source to change loot from hard coded source to lua (Page 5 of replies). I've compared all three scripts, and while similar they are very different. has anyone ever edited this script to apply to all equipment dropped by creatures? I'm basically trying to get it to where at minimum the item drops as a common, with it randomly being applied to other item levels as well. Anyone have any advice? thank you.
I think it is not that hard - it comes with a config where you can change the chance value for getting slots in the item:
Code:
[LIST=1]
[*] maxSlotCount = 4,
[*]        slotChances = {
[*]                [1] = 1000,
[*]                [2] = 5000,
[*]                [3] = 15000,
[*]                [4] = 25000
[*]
[/LIST]
play with those values
 

Kodak

Excellent OT User
Joined
Jun 7, 2007
Messages
40
Reaction score
6
@samco Yea I have tried raising those aswell as weapon level chances but that does not seem to increase the chances of looting a weapon made by this script, it just seems to increase the chances of selecting levels, slots and attributes after that script has already ran a choice on the loot to apply anything at all or leave regular
 

samco

4x4 Developer.
Joined
Jul 3, 2007
Messages
882
Reaction score
173
Location
Spain
@samco Yea I have tried raising those aswell as weapon level chances but that does not seem to increase the chances of looting a weapon made by this script, it just seems to increase the chances of selecting levels, slots and attributes after that script has already ran a choice on the loot to apply anything at all or leave regular
Im not sure about taht, if you set the chance of the 1st slot to 100000, It should apply at least one slot to every item
 

Kodak

Excellent OT User
Joined
Jun 7, 2007
Messages
40
Reaction score
6
Thank you @samco you appear to be correct. I guess I had not raised the chance amounts enough on slots. I misunderstood the script somewhat I think. I assumed slots were used as in "This armor has 2 slots, apply a gem to add an antribute" but this appears incorrect. It looks like it works as "This armor has 2 slots, now run chance on what attribute will be applied to these slots". So when I ramp up the chance value for slots, yes, more if not all items are effected, and it applies an effect to the number of slots. eg: 2 slots, +holy & + death applied". Although it appears increasing slot chances only increases the amount of items that receive attributes, it does not seem to effect the 'weapon level' category. Simply increasing the chances on these weapon levels produces the results I first reported, in that only a small percentage of items were effected. While the current results of an increase in items with attributes is defiantly an improvement, I was aiming for more use/chances of receiving a leveled weapon over a magical attribute weapon. eg. a common weapon or any moderate leveled weapon to be more common then an item with a magical attribute attached. Any suggestions how to increase the chances of a leveled weapon without magical attributes attached? or am I just completely misunderstanding exactly how this script applies it self to looted items?
 
Top