Help with a "check for item" script
Posted: Sun Jan 04, 2015 9:03 pm
Hey all,
I am sure someone can point out to me quickly what Ive been doing wrong here...
I just want the item to either:
- stay as the mouse item
- or if thats not possible be spawned into champs inventory
- or if thats not possible just dropped on the ground
Some champs will have a "light equipment" trait meaning they can not equip heavy armour and weapons...
And the part that has taken me so much time is the dropping on the ground bit!! Geezz
So I am pretty sure its almost ok, but yeah help please!!
I am sure someone can point out to me quickly what Ive been doing wrong here...
I just want the item to either:
- stay as the mouse item
- or if thats not possible be spawned into champs inventory
- or if thats not possible just dropped on the ground
Some champs will have a "light equipment" trait meaning they can not equip heavy armour and weapons...
And the part that has taken me so much time is the dropping on the ground bit!! Geezz

So I am pretty sure its almost ok, but yeah help please!!
SpoilerShow
Code: Select all
defineTrait{
name = "light_equipment",
uiName = "Light Equipment",
icon = 45,
charGen = false,
description = "Can not carry heavy stuff.",
onRecomputeStats = function(champion, level)
if level > 0 then
local heavyItem = nil
for slot = 1,ItemSlot.OffHand2 do
local item = champion:getItem(slot)
if item then
if item:hasTrait("heavy_weapon")
or item:hasTrait("heavy_armour") then
heavyItem = champion:getItem(slot)
local stackSize = nil
if heavyItem:getStackable() then
stackSize = heavyItem:getStackSize()
end
local m = getMouseItem()
if m == nil then
champion:removeItemFromSlot(slot)
if stackSize then
heavyItem:setStackSize(stackSize)
end
setMouseItem(heavyItem)
playSound("item_drop")
hudPrint("Can not carry heavy stuff.")
return false
else
heavyItem = champion:getItem(slot)
local newItem = spawn(heavyItem)
if heavyItem then
heavyItem:destroy()
end
local slot2 = nil
for slot2 = 1, 32 do
if champion:getItem(slot2) == nil then
if slot2 ~= nil then
champion:insertItem(slot2, newItem )
playSound("item_drop")
hudPrint("Can not carry heavy stuff.")
return false
else
spawn( newItem , party.level, party.x , party.y, party.facing ,party.elevation)
playSound("item_drop")
hudPrint("Can not carry heavy stuff.")
return false
end
end
end
end
end
end
end
end
end,
}