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

Lua [0.4] Destroy item (like diablo barrels), get item item

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
586
Solutions
2
Reaction score
61
Location
México
Hello, otlanders, im trying to make this script but im failing, i want it to have these conditions:
1-.Player uses weapon on destroyable item
2-. destro-Item poof until it breaks
3-. 20% chance to get 1-100 gold, 20% chance to get 1 - 10 potions, 5% chance to get weapons/armors and so (its an example)

i already started this failure script, but it might improve with your help :D
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local rand = math.random(1,7)
   if rand == 1 then
       doCreateItem(2148,math.random(1, 22), toPosition)
   end
   return destroyItem(cid, itemEx, toPosition)
end
/code

the bug: it gives item and barrel is still dont destroyed
 
Only way I know how to do this is to edit default.lua
XML:
<action default="yes" event="script" value="default.lua"/>
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   local item = getItemInfo(item.itemid)
   if(item.weaponType == WEAPON_SWORD or item.weaponType == WEAPON_CLUB or item.weaponType == WEAPON_AXE) then
       local rand = math.random(1,7)
       if rand == 1 then
           doCreateItem(2148, math.random(1, 22), toPosition)
           return destroyItem(cid, itemEx, toPosition)
       end
   end
   return false
end
Be sure how you code this though.. either you use for a table of items, or you use for all items.
 
Only way I know how to do this is to edit default.lua
XML:
<action default="yes" event="script" value="default.lua"/>
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   local item = getItemInfo(item.itemid)
   if(item.weaponType == WEAPON_SWORD or item.weaponType == WEAPON_CLUB or item.weaponType == WEAPON_AXE) then
       local rand = math.random(1,7)
       if rand == 1 then
           doCreateItem(2148, math.random(1, 22), toPosition)
           return destroyItem(cid, itemEx, toPosition)
       end
   end
   return false
end
Be sure how you code this though.. either you use for a table of items, or you use for all items.
it doesnt give item when container (id:1770) is destroyed, it gives item using weapon on destroyed containers(id:2250), wtf XD?
 
Found the wae :D

/lib/actions.lua
Lua:
if(math.random(1, 7) >= 4) then
if(isInArray({1738, 1739, 1770, 2098, 1774, 1775, 2064}, itemEx.itemid) or
(itemEx.itemid >= 2581 and itemEx.itemid <= 2588)) then
doCreateItem(2250, 1, toPosition)
elseif((itemEx.itemid >= 1747 and itemEx.itemid <= 1749) or itemEx.itemid == 1740) then
doCreateItem(2251, 1, toPosition)
elseif((itemEx.itemid >= 1714 and itemEx.itemid <= 1717)) then
doCreateItem(2252, 1, toPosition)
elseif((itemEx.itemid >= 1650 and itemEx.itemid <= 1653) or
(itemEx.itemid >= 1666 and itemEx.itemid <= 1677) or
(itemEx.itemid >= 1614 and itemEx.itemid <= 1616) or
(itemEx.itemid >= 3813 and itemEx.itemid <= 3820) or
(itemEx.itemid >= 3807 and itemEx.itemid <= 3810)) then
doCreateItem(2253, 1, toPosition)
elseif((itemEx.itemid >= 1724 and itemEx.itemid <= 1737) or
(itemEx.itemid >= 2080 and itemEx.itemid <= 2085) or
(itemEx.itemid >= 2116 and itemEx.itemid <= 2119) or
isInArray({2094, 2095}, itemEx.itemid)) then
doCreateItem(2254, 1, toPosition)
elseif((itemEx.itemid >= 1750 and itemEx.itemid <= 1753) or isInArray({1619, 1741}, itemEx.itemid)) then
doCreateItem(2255, 1, toPosition)
elseif(itemEx.itemid == 2602) then
doCreateItem(2257, 1, toPosition)
elseif(itemEx.itemid == 3805 or itemEx.itemid == 3806) then
doCreateItem(2259, 1, toPosition)
end
--here start config
if(math.random(1, 7) == 1) then
doCreateItem(2148,math.random(1, 100), toPosition)
end
if(math.random(1, 7) == 2) then
doCreateItem(7620,math.random(1, 10), toPosition)
end
if(math.random(1, 7) == 3) then
doCreateItem(7618,math.random(1, 10), toPosition)
end
if(math.random(1, 7) == 4) then
doCreateItem(2544,math.random(1, 10), toPosition)
end -- here ends
doRemoveItem(itemEx.uid, 1)
end

doSendMagicEffect(toPosition, CONST_ME_POFF)
return true
end
 
Back
Top