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

samco

4x4 Developer.
Joined
Jul 3, 2007
Messages
895
Reaction score
177
Location
Spain
this works great on 1.2, added to my server and added a couple of things like slot removal, based on this great script of course, thanks zbizu for this amazing system.
-"I was wondering if im missing something, the element damage attacks like fire and others work good on player vs player, but not on player vs monster."
its what i was writing while i fixed it. now it works great against player vs monster.
you can check it out on my server, info on my signature.
THANKS ZBIZU!
Why dont you share what you fix?
 

Danat

Excellent OT User
Joined
Jun 6, 2008
Messages
47
Reaction score
12
still testing, but here's the quick version
in events/scripts/creature.lua, add


sorry it got posted while editing post: add this

add those lines inside the function Creature:eek:nTargetCombat(target), before the monster check that starts with if target:isPlayer() then

i put the lines in spoiler, didnt show up.

Lua:
if self:isPlayer() and target:isMonster() then
        target:registerEvent("statHP")
        target:registerEvent("statMP")
    end
oh yeah, if you're interested i can also share a remove slot code to remove the last slot upgrade. So one can remove 4 slots with 4 items of this.
in actions add the item with reference to the slot.lua script
then add after the last end corresponding to this line

Lua:
if item.itemid == STATS_SYSTEM_CONFIG_ADD_SLOT then
    if..
        if..
        lots lines
        end
    end
    return false
end
this is around line 1320, then add this

Lua:
    if item.itemid == STATS_SYSTEM_CONFIG.GEM_REMOVE_SLOT then
        if not STATS_SYSTEM_CONFIG.removeSlotAction then
            return false
        end
       
        if not attempt then
            attempt = 1
        end
       
        if attempt == 10 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Unable to remove slot.")
            return true
        end
       
        local it_u = Item(itemEx.uid)
        if not it_u then
            return false
        end
       
        if not STATS_SYSTEM_CONFIG.simple.enabled then
            return false
        end
       
        if not STATS_SYSTEM_CONFIG.simple.randomSpells then
            -- popup modal
            -- popUpStatModal_index(player, item.uid)
            print("todo: modal window")
            return true
        end
       
        if isInArray(STATS_SYSTEM_CONFIG.ignoredIds, itemEx.itemid) then
            -- player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot upgrade this item.")
            return false
        end
       
        local it_id = ItemType(itemEx.itemid)
        local u = it_u:getUpgradeType()
       
        if not u then
            -- player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot upgrade this item.")
            return false
        end
       
       
       
        local stat = math.random(1, #u)
       
        local tries = player:getStorageValue(STATS_SYSTEM_CONFIG.skillTriesStorage)
        if tries < 0 then
            player:setStorageValue(STATS_SYSTEM_CONFIG.skillTriesStorage, 0)
        end
       
        local level = STATS_SYSTEM_CONFIG.useSkill and getEnchantingSkill(tries) or math.random(1, STATS_SYSTEM_CONFIG.maxLevel)
       
       
   

   
       
        local slotc = it_u:getStatSlotCount()
       
       
        local cur_slots = it_u:getStatSlots()
        for i = 1, slotc do
            if spellname == cur_slots[i][1] then
                -- player:sendTextMessage(MESSAGE_INFO_DESCR, "Duplicate stat, try again.")
                stat_onUse(player, item, fromPosition, itemEx, toPosition, attempt + 1)
                return true
            end
        end
        -- this line to remove slot
        if it_u:removeSlot(slotc) then
            toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Slot removed successful." )
            doRemoveItem(item.uid, 1)
            if STATS_SYSTEM_CONFIG.useSkill then
                player:setStorageValue(STATS_SYSTEM_CONFIG.skillTriesStorage, player:getStorageValue(STATS_SYSTEM_CONFIG.skillTriesStorage) + 1)
                local nlevel = STATS_SYSTEM_CONFIG.useSkill and getEnchantingSkill(player:getStorageValue(STATS_SYSTEM_CONFIG.skillTriesStorage)) or math.random(1, STATS_SYSTEM_CONFIG.maxLevel)
                if nlevel > level then
                    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You advanced to enchanting Level " .. (nlevel < STATS_SYSTEM_CONFIG.maxLevel and nlevel or nlevel .. " [max]") .. ".")
                end
            end
        end
        return true
    end
also add this line to config
Lua:
    GEM_REMOVE_SLOT = itemid, -- item has to be usable with crosshair
Here's another 'fix',
add these lines right after this: function stat_OnUse
Lua:
if not target:isItem() then
    return false
end
(...)
this is a simple check to avoid an error when enchanting items are not used on items

anyone adding the remove slot code,
add this too
Lua:
        if slotc == 0 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Item has no slots to be removed." )
            toPosition:sendMagicEffect(CONST_ME_POFF)
            return false
        end
it will check that the item has no slots and if it doesnt have any will fail the attempt, gets no exp for enchanting skill.
add those lines right before my annotation that says -- this line to remove slot

Ok so another fix because the previous
Lua:
if not target:isItem() then
    return false
end
those lines didnt work, remove them or dont add them.

here is what worked.
look for this line in lib/stats.lua
Lua:
-- player:sendTextMessage(MESSAGE_INFO_DESCR, "Duplicate stat, try again.")
change the next return true, two lines after that line,to: return false

if you added the remove slot, here is updated version (removed some lines, added others)

Lua:
    if item.itemid == STATS_SYSTEM_CONFIG.GEM_REMOVE_SLOT then
        if not STATS_SYSTEM_CONFIG.removeSlotAction then
            return false
        end
       
        if not attempt then
            attempt = 1
        end
       
        if attempt == 10 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Unable to remove slot.")
            return true
        end
       
        local it_u = Item(itemEx.uid)
        if not it_u then
            return false
        end
       
        if not STATS_SYSTEM_CONFIG.simple.enabled then
            return false
        end
       
        if not STATS_SYSTEM_CONFIG.simple.randomSpells then
            -- popup modal
            -- popUpStatModal_index(player, item.uid)
            print("todo: modal window")
            return true
        end
       
        if isInArray(STATS_SYSTEM_CONFIG.ignoredIds, itemEx.itemid) then
            -- player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot upgrade this item.")
            return false
        end
       
        local it_id = ItemType(itemEx.itemid)
        local u = it_u:getUpgradeType()
       
        if not u then
            -- player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot upgrade this item.")
            return false
        end
       
        local tries = player:getStorageValue(STATS_SYSTEM_CONFIG.skillTriesStorage)
        if tries < 0 then
            player:setStorageValue(STATS_SYSTEM_CONFIG.skillTriesStorage, 0)
        end
       
        local level = STATS_SYSTEM_CONFIG.useSkill and getEnchantingSkill(tries) or math.random(1, STATS_SYSTEM_CONFIG.maxLevel)
       
       
        local slotc = it_u:getStatSlotCount()
       
        if slotc == 0 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Item has no slots to be removed." )
            toPosition:sendMagicEffect(CONST_ME_POFF)
            return false
        end
       
        -- this line to remove slot
        if it_u:removeSlot(slotc) then
            toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Slot removed successful." )
            doRemoveItem(item.uid, 1)
            if STATS_SYSTEM_CONFIG.useSkill then
                player:setStorageValue(STATS_SYSTEM_CONFIG.skillTriesStorage, player:getStorageValue(STATS_SYSTEM_CONFIG.skillTriesStorage) + 1)
                local nlevel = STATS_SYSTEM_CONFIG.useSkill and getEnchantingSkill(player:getStorageValue(STATS_SYSTEM_CONFIG.skillTriesStorage)) or math.random(1, STATS_SYSTEM_CONFIG.maxLevel)
                if nlevel > level then
                    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You advanced to enchanting Level " .. (nlevel < STATS_SYSTEM_CONFIG.maxLevel and nlevel or nlevel .. " [max]") .. ".")
                end
            end
        end
        return true
    end
I forgot, to add the remove slot, add this line on config aswell
Lua:
    removeSlotAction = true,
 
Last edited by a moderator:

nugo

Australia OT Mapper
Joined
Apr 1, 2009
Messages
184
Reaction score
21


Anyone end up fixing this issue? I get wit when i login and get instant kicked. Using TFS 1.2
 

nugo

Australia OT Mapper
Joined
Apr 1, 2009
Messages
184
Reaction score
21
Figured it out in the end, for what ever reason it wouldn't work in lib directory even after i registered its path in lib.lau. Had to add it to global and place it in /data for it to work
 

Aeronx

Active Member
Joined
Dec 17, 2015
Messages
693
Reaction score
84
You are obviously missing either actions part at .xml or didnt declare it at global.

Double or triple check, because this system is pretty old and it works just fine.
 
OP
zbizu

zbizu

Veteran OT User
Joined
Nov 22, 2010
Messages
2,460
Reaction score
1,357
Location
Poland
because this system is pretty old and it works just fine.
It doesn't LOL
Many things were bugged and this spaghetti code isn't helping either. Guys just let me knkw which stats you want to keep and I will write a new one.
 

Shadow_

asgard-ot.com
Premium User
Joined
Jun 2, 2018
Messages
334
Reaction score
64
Location
Cairo, Egypt
You are obviously missing either actions part at .xml or didnt declare it at global.

Double or triple check, because this system is pretty old and it works just fine.
i already checked more than 4 times and i'am not missing anything :S
 

Aeronx

Active Member
Joined
Dec 17, 2015
Messages
693
Reaction score
84
@zbizu i had this system working since you released. It had some bugs applying some of the stats. It was easy fixeable, but it was extensive work since your code was so long, other than that code was good and great idea.

Also, what he's asking its always been working.
 

Ramirow

Advanced OT User
Joined
Aug 22, 2009
Messages
453
Reaction score
167
Location
Argentina
Is there any way I can make an NPC give an item with a determined upgrade? Not the slot, but the +x version of an item?
 

Aeronx

Active Member
Joined
Dec 17, 2015
Messages
693
Reaction score
84
Read the final part of the lib, there are some functions to do that kind of things.
 

Kyogron

New Member
Joined
May 6, 2018
Messages
4
Reaction score
0
Hi all, I would like to ask for a help, I installed everything correctly in the OTX 3 Series ... And it did not work, whenever I try to use the 8300 stone on any item, it gives the following "cancel", "You can not use this object. " although everything is configured as I said in the post, can anyone help me?
 

Aeronx

Active Member
Joined
Dec 17, 2015
Messages
693
Reaction score
84
Either you installed the action.xml/lua part incorrect, or OTX is not compatible. (Im using it on tfs 1.2)
The bugs on this systems have nothing to do with the action part, which work fine. So, recheck! :)
 

Awesomedudei

Revolutionot.com
Joined
Jan 20, 2010
Messages
261
Reaction score
34
Location
Sweden
Thanks :) working on 1.3
Only problem is that using a Rare, Epic or Legendary Gem on items such as Ring of healing, Life ring and many more items will freeze/crash the server.

I know that i could put all crashing item ids into, ignoredIds = {itemid, itemid, }

But i fear that there will always be one item im gonna miss out and someone will abuse that to crash the server.
Has anyone found a solution? Gone through all 14 pages and only found a "fix" with 1 item aka Aol one.
 
Last edited:

Aeronx

Active Member
Joined
Dec 17, 2015
Messages
693
Reaction score
84
The easy fix is to forbid using upgrade on items without armor. That fixes most of the problems on this system.
Also, ignoredIds part doesnt work fine. The system have plenty of bugs, you will find out the more you use it. Fixing them is not hard.
Eventually all those 2000+ lines feel like nothing. :)
 

Danat

Excellent OT User
Joined
Jun 6, 2008
Messages
47
Reaction score
12
@Awesomedudei

Here is my fix to that: rare epic, legendary and random do not work on items with decay.

Code:
    if isInArray({STATS_SYSTEM_CONFIG.GEM_RARE, STATS_SYSTEM_CONFIG.GEM_EPIC, STATS_SYSTEM_CONFIG.GEM_LEGENDARY, STATS_SYSTEM_CONFIG.GEM_RANDOM}, item.itemid) then
    local item2 = Item(itemEx.uid)
    if isInArray(STATS_SYSTEM_CONFIG.ignoredIds, itemEx.itemid) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot upgrade this item.")
        return false
    end
    
    
        if item2 then
            local u = item2:getUpgradeType()
            if u == upgrade_types.decay then
                player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot upgrade this item.")
                return false
            end
            if u then
                if item2:generateStats(u, STATS_SYSTEM_CONFIG.gems_power[item.itemid].sl(), math.random(STATS_SYSTEM_CONFIG.gems_power[item.itemid].min_wl, STATS_SYSTEM_CONFIG.gems_power[item.itemid].max_wl), math.floor(STATS_SYSTEM_CONFIG.maxLevel * STATS_SYSTEM_CONFIG.gems_power[item.itemid].min_el), math.ceil(STATS_SYSTEM_CONFIG.maxLevel * STATS_SYSTEM_CONFIG.gems_power[item.itemid].max_el)) then
                    toPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
                    doRemoveItem(item.uid, 1)
                    player:sendTextMessage(MESSAGE_INFO_DESCR, "Item modification successful.")
                    return true
                else
                    player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot upgrade this item.")
                    return false
                end
            else
                player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot upgrade this item.")
                return false
            end
        end
        return false
    end
 

Danat

Excellent OT User
Joined
Jun 6, 2008
Messages
47
Reaction score
12
To anyone Adding my previous SlotRemover Code,
WARNING: expoit; removing slot while an item has [atk+] or other, ( def, extra def,etc) it will get a boost on the stat each time the slots are removed and there is a slot thats not the last with [atk+] or other.
 
Top