WaspUK1966 wrote:Very clever coding! How do you think of these things!?

. Is it possible to refine it? I mean, in it`s present state, the item can be removed from one champion but triggers the "cannot use "message when you try to equip another champion with it. But is it possible to code it so that the item cant be removed from its original slot in the first place? ie when you click on it etc nothing happens? Would make things easier, and more realistic...
Thanks for all your help Isaac
George
The first concept was indeed unequippable items, but I thought that the the super-champion should have the freedom to unequip their own gear; and later on... that other PCs should at least be able to carry the items...
The <11 condition allows other party members to carry the items. Removing it means that only the super-champion can carry the equipment.
I'm out for part the day, but when I get back, I will post an updated script.
_________________
Here is an updated [one champion] version that supports unequippable items:
Script name: restrict
Code: Select all
super_champion_ordinal = 2 --change to correct ordinal of the super_champion
champion = nil
slot = nil
itemName = nil
itemUIName = nil
comment = true -- set to false if the text comments should not appear.
function _objectUse(caller, tChampion, tSlot, tItem, hook)
if caller == nil then
champion = tChampion
slot = tSlot
if tItem == nil then return end
itemName = tItem.name
itemUIName = tItem:getUIName()
local timer = findEntity(spawn("timer", party.level, party.x, party.y, party.facing).id)
timer:setTimerInterval(0.01)
timer:activate()
if hook == nil then
timer:addConnector("activate", "restrict", "_objectUse")
else
timer:addConnector("activate", "restrict", "_noUnequip")
end
return
end
caller:destroy()
if champion:getOrdinal() ~= super_champion_ordinal then
if slot < 11 then
champion:removeItem(slot)
setMouseItem(spawn(itemName))
if comment then
hudPrint("") hudPrint("") hudPrint("") hudPrint("")
hudPrint("Only "..party:getChampion(super_champion_ordinal):getName().." may use "..itemUIName.."!")
end
end
end
end
function _noUnequip(caller)
caller:destroy()
champion:insertItem(slot, spawn(itemName))
if comment then
hudPrint("") hudPrint("") hudPrint("") hudPrint("")
hudPrint(party:getChampion(super_champion_ordinal):getName().." refuses to part with this!")
end
setMouseItem()
end
Any Items that should be non-removable, should have this added to their definition.
(Actually the onEquipItem hook can be removed from these. The items should initially be equipped on the PC; there is no check to prevent them from being stuck in the hand or inventory if they don't belong there.)
Code: Select all
gameEffect = "(Cannot be removed)",
onUnequipItem = function(champion, slot)
local item = getMouseItem()
restrict._objectUse(nil, champion, slot, item, "noUnequip")
end,
https://www.dropbox.com/s/glex8xzeqlgr8 ... 2.avi?dl=0