• 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:
Well, first of all, did you read all the script ?
Did you know what functions your server has ?

K = getItemDescriptions, right ?
local k = getItemDescriptions(v.itemid)
Did your searched that function?
Do you know that function doesn't have sub-options like stackable and showCount ??

Next time, try/test everything before posting here, and don't ask people to do it for you ;)
 
Thanks
Well, first of all, did you read all the script ?
Did you know what functions your server has ?

K = getItemDescriptions, right ?

Did your searched that function?
Do you know that function doesn't have sub-options like stackable and showCount ??

Next time, try/test everything before posting here, and don't ask people to do it for you ;)
I do not see where I passed this arguments to that function, you are talking dumb.
 
@Nottinghster he just copied the code from here https://otland.net/threads/player-loot-message-display.187728/ or anything similar to that, somewhere posted on this forum previous..(I guess the Mod loot ring thing, just removed some of it)

Thats why I said he should think some and not only copy and paste to implent any shit into his ot
as I said on the first line of my topic, I got this code from topic, I addapted it to my server (functions). I asked for help because it works perfectly on others distro, and even after I substitute the old functions with my servers ones, the script is not working. When I read the script, it make sense, now I do not understand why a container is bugging the function to count itens. Anyway, seems like you all just like to troll around.
Still waiting for some light.
 
@Stellow

When I said it was really easy to fix it, trust me ;)
I've only added 2 lines in source code to make it work perfectly, no errors !!!

riNVQtqFl.gif


Agora em português:
Brincadeiras a parte brother, me adiciona no Skype: rodrigo.sales.paixao, vi que você é o criador do D2server.net, talvez eu possa te dar uma luz em algo ;]
 
Wha
@Stellow

When I said it was really easy to fix it, trust me ;)
I've only added 2 lines in source code to make it work perfectly, no errors !!!

riNVQtqFl.gif


Agora em português:
Brincadeiras a parte brother, me adiciona no Skype: rodrigo.sales.paixao, vi que você é o criador do D2server.net, talvez eu possa te dar uma luz em algo ;]
how did u fixed it?
 
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 ;)
local k = getItemDescriptions(v.itemid) -- You need to check that function in your luascript.cpp if have those sub-options (stackable and showCount), if don't, will not work, you should add them

if v.type > 1 and k.stackable and k.showCount then
If you don't have it, follow those steps:

1 - Open your file luascript.cpp, and find this
int LuaScriptInterface::luaGetItemDescriptions(lua_State *L)
{
//getItemDescriptions(itemid)
//returns the name, the article and the plural name of the item
uint32_t itemid = popNumber(L);
const ItemType& it = Item::items[itemid];

lua_newtable(L);
setField(L, "name", it.name.c_str());
setField(L, "article", it.article.c_str());
setField(L, "plural", it.pluralName.c_str());
return 1;
}
And add this below setField(L, "plural", it.pluralName.c_str());
setField(L, "stackable", it.stackable);
setField(L, "showCount", it.showCount);
Now build/rebuild your engine and you're done with that !!!
ret = ret .. getContentDescription(containers, true) --> Here's the error that @Stellow reported about the getContainerSize(uid), it was missing the , so it should be like ret = ret .. getContentDescription(containers[ i ], true) "remove space ;)"
And the last part:
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 -- Should be getPartyMembers(cid)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Loot of ' .. name .. ': ' .. (ret ~= '' and ret or 'nothing'))
end
end
end

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

Stellow sucks ;]
 
Back
Top