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

Increase amount of dropped gold from monsters

Kliz

New Member
Joined
Apr 1, 2019
Messages
7
Reaction score
0
Hello!

So basically when for example in mummy.xml file I have:
Code:
<item id="3031" countmax="100" chance="400" /> <!-- a gold coin -->
It drops a random amount of gold. Sometimes 10, 20 and sometimes 100.

I want to make it dropping around 60-100 gold, but as I though and tested there is no countmin.

As far as I know only basics of lua scripts I add this in my mummy.xml
Code:
<script>
        <event name="LootGoldMonster"/>
</script>
This in creaturesscripts.xml:
<event type="death" name="LootGoldMonster" script="lootgoldmonster.lua"/>
And this my lua script:
Code:
local config = {
    ["mummy"] = {min = 50, max = 96}
}
function onDeath(cid, corpse)
    local amount = math.random(config[cid:getName()].min, config[cid:getName()].max)
    local itemDropped = doCreateItemEx(3031, amount)
    doAddContainerItemEx(corpse.uid, itemDropped)
    return true
end
Well i know it not perfect, but it works fine for me.
Anyway now gold is on the last free slot in dead mummy container even after bag. It just looks weird and make it hard to drag and drop gold to my backpack.

Forgot to say before. In config.lua I can make moneyRate = 2 but then my mummy can drop even 200gold coins at once, which also is kinda bad for me.

So is there any way to make gold appear at first slot in the dead body or maybe there is something like coutmin? Or maybe can I do something with moneyRate, I mean when dropped gold is >100 then make it =100? I tried do everything on my own, but oh well. The code, which I posted is best I got as far.
 
Solution
It happens because loot is generated by server engine (sources), then your script is executed and the gold is added to last slot.

You can:
1. Find (if it exists idk) lua function to move item in container
2. Best option - add countmin xml param in sources - just check how countmax works and write the countmin the same way
I just created some weird lua and c functions that will add items to corpes but as I can see "your code" its working, doesnt it?
I mean it add the item but in the first slot, for sure (like you are dropping items on a bag), so whats wrong?
 
I mean it doesnt. It adds the item on very last slot, even after the bag (on tibia 7.4). I want to add item in that case gold coins on a first slot.
 
I can guess thats because ondeath event is executed before droploot function.
Can I ask if you know how to compile your sources?
 
Well if onDeath would be first than the gold should take first slot. Of course if Im thinking good.
Here on screen gold is last slot even after bag. I want to somehow move the gold on first slot. Or just make something to instant appearing gold on first slot so I wont have to move it.
And yes I guess I know. I compiled my source and Im on my OT. Why are you asking? Did I compile wrong, is this possible?
 

Attachments

Last edited:
Well if onDeath would be first than the gold should take first slot. Of course if Im thinking good.
Here on screen gold is last slot even after bag.
And yes I guess I know. I compiled my source and Im on my OT. Why are you asking? Did I compile wrong, is this possible?
I will try to create a fork with my loot code, then you add it to your server :p
 
It happens because loot is generated by server engine (sources), then your script is executed and the gold is added to last slot.

You can:
1. Find (if it exists idk) lua function to move item in container
2. Best option - add countmin xml param in sources - just check how countmax works and write the countmin the same way
 
Solution
Well if onDeath would be first than the gold should take first slot. Of course if Im thinking good.
Well... No. If you drag items to the container you will see that last item you dragged will be in first slot. Same thing is happening here. You add gold before default loot. You can create event to be executed with a delay, 100ms should be enough, and add gold there, now it'll be in first slot.
 
@pasiak12
I was also trying to find that function but i didnt.
Ty for solution with source. I set moneyRate = 2 in config.lua and added 2 lines in source monster.cpp.
Code:
if (itemCount > 100)
                itemCount = 100;
And it works fine. Will check out later how about countMin
@oen432
Ahh yea you are right. Didnt try your solution cuz delay in lua is pretty werid for me. Well Im getting only errors in lua scripts lul.
Anyway ty guys.
 
@pasiak12
I was also trying to find that function but i didnt.
Ty for solution with source. I set moneyRate = 2 in config.lua and added 2 lines in source monster.cpp.
Code:
if (itemCount > 100)
                itemCount = 100;
And it works fine. Will check out later how about countMin
@oen432
Ahh yea you are right. Didnt try your solution cuz delay in lua is pretty werid for me. Well Im getting only errors in lua scripts lul.
Anyway ty guys.
I actually reworked drop loot function to work as event, imma pull this to forgottenserver and then you can see the diff changes :p
 
Back
Top