potinho
Advanced OT User
Hello everyone, everything good? I didn't find anything like it on the forum so I leave here my first contribution to the OTLand community.
It's a script that adds the chance of dropping an item to any monster in the game and It is possible to configure more than one item to be dropped. I found the script useful for events, saving time adding (and then removing) loot monster by monster.
Credits to Kemix from OTservBR and ChatGPT for helping fix the code.
In creaturescripts.xml
In creaturescripts/scripts we will create
Also we need to register event in creaturescripts/login.lua:
It's a script that adds the chance of dropping an item to any monster in the game and It is possible to configure more than one item to be dropped. I found the script useful for events, saving time adding (and then removing) loot monster by monster.
Credits to Kemix from OTservBR and ChatGPT for helping fix the code.
In creaturescripts.xml
XML:
<event type="kill" name="GlobalDrop" event="script" value="globaldrop.lua"/>
In creaturescripts/scripts we will create
globaldrop.lua
file, with this content:
Lua:
function isInArray(array, value)
for _, v in ipairs(array) do
if v == value then
return true
end
end
return false
end
function onKill(cid, target, lastHit)
local items = {{2688, 1000}} -- id and chance to drop item
local exmonster = {"Rat", "Bug"} -- monsters excluded from drop
if isMonster(target) and not isInArray(exmonster, getCreatureName(target)) then
for i=1, #items do
local rand = math.random(1, 100000)
if items[i][2] >= rand then
doPlayerAddItem(cid, items[i][1])
doPlayerSendTextMessage(cid, 25, "You have found a " .. getItemNameById(items[i][1]) .. ".")
end
end
end
return true
end
Also we need to register event in creaturescripts/login.lua:
Lua:
registerCreatureEvent(cid, "GlobalDrop")