• 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
Premium User
Joined
Jul 18, 2009
Messages
1,424
Solutions
15
Reaction score
176
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
        if ItemType(item.itemId):isStackable() then
            itemCount =...
The loot chance code is here
and here

You'd probably have to pass the player on to Container.createLootItem, and then either also pass it on to getLootRandom and do your logic there, or do it inside Container.createLootItem.
 
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
 
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?
 
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?
 
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
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!
 
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.
Sorry for bumping this old thread, I finally got to this stage to add this feature, I cant for any way in the world pass a player onto the Container.createLootItem. It just indexes that player is nil whenever im trying to call for player.
 
to add a new argument you have to change it in function definition (this way: function Container.createLootItem(self, item, player))

now most places in your datapack probably call it without third parameter. The easiest way around it is:
Code:
if player then
    -- your code
else
    -- the code you execute if there is no player parameter
end
 
to add a new argument you have to change it in function definition (this way: function Container.createLootItem(self, item, player))

now most places in your datapack probably call it without third parameter. The easiest way around it is:
Code:
if player then
    -- your code
else
    -- the code you execute if there is no player parameter
end
I tried to do it like that but then it never called " -- your code".
And if i force it, i just get player is nil.


Edit: Shouldn't the loot chance be configured in events/scripts/monster.lua instead?
 
you forgot to pass it from the script - there should be , player after monsterLoot here
local item = corpse:createLootItem(monsterLoot[i])
 
Back
Top