Talkaction:
function onSay(cid, words, param)
local stats = getPlayerStorageValue(cid, 45600) == -1 and "ativado." or "desativado."
doPlayerSendTextMessage(cid, 25, "O sistema de captura de gold foi " .. stats)
setPlayerStorageValue(cid, 45600, stats == "ativado." and 1 or -1)
end
Tag:
<talkaction words="/autogold" script="NomeDoArquivo.lua" />
Creaturescripts:
function onKill(cid, target, lastHit)
if getPlayerStorageValue(cid, 45600) == 1 then
addEvent(check, 1000, cid, getThingPos(target))
end
return true
end
function check(cid, pos)
local cont = getThingFromPos(pos).uid
if isCorpse(cont) then
if isContainer(cont) then
doPlayerAddCoin(cid, getItemsInContainerById(cont, 2148))
doPlayerAddCoin(cid, getItemsInContainerById(cont, 2152))
doPlayerAddCoin(cid, getItemsInContainerById(cont, 2160))
end
end
end
function doPlayerAddCoin(cid, tab)
for _, uids in pairs(tab) do
doPlayerAddItem(cid, getThing(uids).itemid, getThing(uids).type)
doRemoveItem(uids)
end
end
function getItemsInContainerById(container, itemid) -- Function By Kydrai
local items = {}
if isContainer(container) and getContainerSize(container) > 0 then
for slot=0, (getContainerSize(container)-1) do
local item = getContainerItem(container, slot)
if isContainer(item.uid) then
local itemsbag = getItemsInContainerById(item.uid, itemid)
for i=0, #itemsbag do
table.insert(items, itemsbag[i])
end
else
if itemid == item.itemid then
table.insert(items, item.uid)
end
end
end
end
return items
end
login.lua:
registerCreatureEvent(cid, "Autogold")
Tag:
<event type="kill" name="Autogold" event="script" value="NomeDoArquivo.lua"/>