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

Solved loot message creaturescripts

Stellow

C++/C#/PHP/LUA
Joined
Oct 23, 2008
Messages
1,106
Reaction score
214
Location
Germany
GitHub
eubrunomiguel
I am trying to addapt a script I found on this forum, to send loot message to a player (on kill monsters).
The scripts is working in parts. It send a message when kill a monsters but they do not drop a container(bag), and do not count items, for example:
17:35 Loot of rat: a gold coin, a gold coin (it droped 13, and 28 gold coins respectely)
When a monsters drops a bag I get a luascriptinterface::luagetcontainersice(). container not found

sources> lastest otserv trunk


script:

function getContentDescription(uid, comma)
local ret, i, containers = '', 0, {}
while i < getContainerSize(uid) do
local v, s = getContainerItem(uid, i), ''
local k = getItemDescriptions(v.itemid)
if k.name ~= '' then
if v.type > 1 and k.stackable and k.showCount then
s = v.type .. ' ' .. getItemDescriptions(v.itemid).plural
else
local article = k.article
s = (article == '' and '' or article .. ' ') .. k.name
end
ret = ret .. (i == 0 and not comma and '' or ', ') .. s
if isContainer(v.uid) and getContainerSize(v.uid) > 0 then
table.insert(containers, v.uid)
end
else
ret = ret .. (i == 0 and not comma and '' or ', ') .. 'an item of type ' .. v.itemid .. ', please report it to gamemaster'
end
i = i + 1
end
for i = 1, #containers do
ret = ret .. getContentDescription(containers, true)
end
return ret
end

local function send(cid, pos, name, party)
local corpse = getTileItemByType(pos, ITEM_TYPE_CONTAINER).uid
local ret = isContainer(corpse) and getContentDescription(corpse)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Loot of ' .. name .. ': ' .. (ret ~= '' and ret or 'nothing'))
if party then
for _, pid in ipairs(getPartyMembers(party)) do
doPlayerSendChannelMessage(pid, '', 'Loot of ' .. name .. ': ' .. (ret ~= '' and ret or 'nothing'), TALKTYPE_CHANNEL_W, CHANNEL_PARTY)
end
end
end

function onKill(cid, target, lastHit)
if not isPlayer(target) then
addEvent(send, 0, cid, getThingPos(target), getCreatureName(target), getPartyMembers(cid))
end
return true
end
 
Last edited:
The way to fix it is very simple, depends what distro that you are using.
I'll post the fix for OTServ_SVN or OTHire, whatever you call it ;)

If you don't have it, follow those steps:

1 - Open your file luascript.cpp, and find this

And add this below setField(L, "plural", it.pluralName.c_str());

Now build/rebuild your engine and you're done with that !!!

And the last part:


Hope you all enjoy it, since our incredible member @Stellow didn't posted the fix ;)

Stellow sucks ;]
Since your wasted 6 posts talking shit before haha. You are amazing dude! Wow. Thanks for helping the others bb ;*
 
The way to fix it is very simple, depends what distro that you are using.
I'll post the fix for OTServ_SVN or OTHire, whatever you call it ;)

If you don't have it, follow those steps:

1 - Open your file luascript.cpp, and find this

And add this below setField(L, "plural", it.pluralName.c_str());

Now build/rebuild your engine and you're done with that !!!

And the last part:


Hope you all enjoy it, since our incredible member @Stellow didn't posted the fix ;)

Stellow sucks ;]

When in party that's an error with:
Code:
doPlayerSendChannelMessage(pid, '', 'Loot of ' .. name .. ': ' .. (ret ~= '' and ret or 'nothing'), TALKTYPE_CHANNEL_W, CHANNEL_PARTY)

Code:
Lua Script Error: [CreatureScript Interface]
in a timer event called from:
data/creaturescripts/scripts/loot.lua:onKill

data/creaturescripts/scripts/loot.lua:34: attempt to call global 'doPlayerSendChannelMessage' (a nil value)
stack traceback:
        data/creaturescripts/scripts/loot.lua:34: in function <data/creaturescripts/scripts/loot.lua:28>

OTHire doesn't have doPlayerSendChannelMessage function, you need to add I suppose, or change to:
Code:
doPlayerSendTextMessage(pid, MESSAGE_INFO_DESCR, 'Loot of ' .. name .. ': ' .. (ret ~= '' and ret or 'nothing'))
 
Last edited:
Back
Top