• 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!

TFS 1.X+ TFS 1.3 lootchance

Mjmackan

Mapper ~ Writer
Joined
Jul 18, 2009
Messages
1,117
Solutions
2
Reaction score
68
Location
Sweden
Hello! Im using newest repo of tfs 1.3!
How can I change the lootchance for a specific player?
I want to increase lootchance by x% to y player, I cant find much related to this in the sources and Im not good with c++.

Regards,
Mjmackan
 
Solution
the method (Container.createLootItem(self, item)) responsible for generating loot is here: data/lib/core/container.lua

the event callback (ec.onDropLoot) responsible for dropping the loot is here: data/scripts/eventcallbacks/monster/default_onDropLoot.lua

if you add third parameter (player) to createLootItem and pass it from ec.onDropLoot, you may use player object to obtain whatever you need to determine player's personal loot rate

final piece of code you have to adjust (container.lua)

change this:
Lua:
    local itemCount = 0
    local randvalue = getLootRandom()
    if randvalue < item.chance then...

Alpha

Relentless
Joined
Apr 3, 2011
Messages
549
Solutions
28
Reaction score
321
Location
South Korea

Codinablack

Dreamer
Content Editor
Premium User
Joined
Dec 26, 2013
Messages
1,288
Solutions
4
Reaction score
416
Hello! Im using newest repo of tfs 1.3!
How can I change the lootchance for a specific player?
I want to increase lootchance by x% to y player, I cant find much related to this in the sources and Im not good with c++.

Regards,
Mjmackan
You can find the current logic for loot drops in the file default_onDropLoot.lua


The script is found in the scripts folder, inside the eventcallbacks folder, inside monster folder, file path looks like this

~data/scripts/eventcallbacks/monster/default_onDropLoot.lua
 
OP
Mjmackan

Mjmackan

Mapper ~ Writer
Joined
Jul 18, 2009
Messages
1,117
Solutions
2
Reaction score
68
Location
Sweden
You can find the current logic for loot drops in the file default_onDropLoot.lua


The script is found in the scripts folder, inside the eventcallbacks folder, inside monster folder, file path looks like this

~data/scripts/eventcallbacks/monster/default_onDropLoot.lua
I don't have the eventcallbacks folder, I'm using an older datapack, how do I register this folder without effing up something else?
 

Codinablack

Dreamer
Content Editor
Premium User
Joined
Dec 26, 2013
Messages
1,288
Solutions
4
Reaction score
416
Im using newest repo of tfs 1.3!

I'm using an older datapack
An older datapack? What does that even mean, did you just delete the data folder after downloading the newest repo and insert an old one? Do you not get errors when starting the server? Can you point me towards the data pack you are using?
 

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,864
Solutions
12
Reaction score
1,940
Location
Poland
the method (Container.createLootItem(self, item)) responsible for generating loot is here: data/lib/core/container.lua

the event callback (ec.onDropLoot) responsible for dropping the loot is here: data/scripts/eventcallbacks/monster/default_onDropLoot.lua

if you add third parameter (player) to createLootItem and pass it from ec.onDropLoot, you may use player object to obtain whatever you need to determine player's personal loot rate

final piece of code you have to adjust (container.lua)

change this:
Lua:
    local itemCount = 0
    local randvalue = getLootRandom()
    if randvalue < item.chance then
        if ItemType(item.itemId):isStackable() then
            itemCount = randvalue % item.maxCount + 1
        else
            itemCount = 1
        end
    end

to this:
Lua:
    local itemCount = 0
    local randvalue = getLootRandom()
   
    local personalLootRate = 1
    if player then
        -- personalLootRate = player storage or something idk
    end
   
    local lootChance = item.chance * personalLootRate
   
    if randvalue < lootChance then
        if ItemType(item.itemId):isStackable() then
            itemCount = randvalue % item.maxCount + 1
        else
            itemCount = 1
        end
    end

if you don't have event callbacks, the function responsible for loot dropping and all necessary variables should be located in data/events/scripts/monster.lua.
 
Solution
OP
Mjmackan

Mjmackan

Mapper ~ Writer
Joined
Jul 18, 2009
Messages
1,117
Solutions
2
Reaction score
68
Location
Sweden
An older datapack? What does that even mean, did you just delete the data folder after downloading the newest repo and insert an old one? Do you not get errors when starting the server? Can you point me towards the data pack you are using?
I got a lot of errors doing exactly that but I solved them, the data folder belongs to an older repo of tfs 1.3 so it wasnt that much of a difference.


the method (Container.createLootItem(self, item)) responsible for generating loot is here: data/lib/core/container.lua

the event callback (ec.onDropLoot) responsible for dropping the loot is here: data/scripts/eventcallbacks/monster/default_onDropLoot.lua

if you add third parameter (player) to createLootItem and pass it from ec.onDropLoot, you may use player object to obtain whatever you need to determine player's personal loot rate

final piece of code you have to adjust (container.lua)

change this:
Lua:
    local itemCount = 0
    local randvalue = getLootRandom()
    if randvalue < item.chance then
        if ItemType(item.itemId):isStackable() then
            itemCount = randvalue % item.maxCount + 1
        else
            itemCount = 1
        end
    end

to this:
Lua:
    local itemCount = 0
    local randvalue = getLootRandom()
  
    local personalLootRate = 1
    if player then
        -- personalLootRate = player storage or something idk
    end
  
    local lootChance = item.chance * personalLootRate
  
    if randvalue < lootChance then
        if ItemType(item.itemId):isStackable() then
            itemCount = randvalue % item.maxCount + 1
        else
            itemCount = 1
        end
    end

if you don't have event callbacks, the function responsible for loot dropping and all necessary variables should be located in data/events/scripts/monster.lua.
Thank you, so much!
 
Top