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

CreatureEvent [OTX 2] Global Drop Item

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,403
Solutions
17
Reaction score
151
Location
Brazil
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
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")
 
Do you have a script like this for the tfs 1.5 engine?
 
Back
Top