Page 2 of 2
Re: Coding advice needed
Posted: Thu Dec 04, 2014 3:58 pm
by Isaac
WaspUK1966 wrote:That code. Are you talking about LOG 2 here, as I don't recognise the creature or commands/class? I`m coding a LOG 1 game...
George
You know... you are right; I cut & paste from the wrong editor.
Try this instead:
Code: Select all
cloneObject {
name="snail_thief",
baseObject = "snail",
onDealDamage = function(self, champion, damage)
local x = 3 --math.random(1,6)
local y = math.random(7,8) --math.random(1,10)
local it = champion:getItem(y)
if x == 3 and it ~= nil then
hudPrint(it:getUIName().." has been absorbed!")
champion:removeItem(y)
playSound("consume_food")
end
end,
}
The differences [afaik] in the onDealDamage function, are that getUIName() does have an uppercase i ~as you had in the script; the removeItem() call, and the slot Ids are changed.
https://www.dropbox.com/s/vypa461lx4xja ... f.avi?dl=0
Re: Coding advice needed
Posted: Sat Dec 06, 2014 11:07 am
by WaspUK1966
Thanks for that. I`m sure I tried that code before but couldn't get it to work! Works now, so I've just adapted it for my game. Appreciate the help. While I'm on here, I've asked this question before but no one responded: How do you stop a player swapping items from one champion to another? I'm thinking of having a champion that can be enabled in certain circumstances (to help out ), who has superior weapons, armour etc. But what I don't want is the player to enable this "super champion", remove all his stuff, then use it on the main champion when he/she switches back. Is it possible? I've tried setting required skills, levels etc. for the items, but you can still remove the items and put them on the other champion even though you don't have the necessary skills/levels etc. Maybe the returnItem function? Don`t know. Any ideas?
Thanks for your help
George
Re: Coding advice needed
Posted: Sat Dec 06, 2014 7:31 pm
by Isaac
Place this in the definition of each item to be restricted:
Code: Select all
onEquipItem = function(champion, slot)
local item = getMouseItem()
restrict.objectUse(nil, champion, slot, item)
end,
Place this in a script entity on the map: (Name the script: restrict)
Code: Select all
super_champion_ordinal = 2 --change this to the correct ordinal of your super_champion
champion = nil
slot = nil
itemName = nil
itemUIName = nil
function objectUse(caller, tChampion, tSlot, tItem)
if caller == nil then
champion = tChampion
slot = tSlot
itemName = tItem.name
itemUIName = tItem:getUIName()
local timer = findEntity(spawn("timer", party.level, party.x, party.y, party.facing).id)
timer:addConnector("activate", "restrict", "objectUse")
timer:setTimerInterval(0.01)
timer:activate()
return
end
caller:destroy()
if champion:getOrdinal() ~= super_champion_ordinal then
if slot < 11 then
champion:removeItem(slot)
setMouseItem(spawn(itemName))
hudPrint("") hudPrint("") hudPrint("") hudPrint("")
hudPrint("Only "..party:getChampion(super_champion_ordinal):getName().." may use "..itemUIName.."!")
end
end
end
Example:
https://www.dropbox.com/s/qqc5smi74q8gq ... s.avi?dl=0
Re: Coding advice needed
Posted: Sun Dec 07, 2014 4:11 pm
by WaspUK1966
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
Re: Coding advice needed
Posted: Sun Dec 07, 2014 5:03 pm
by Isaac
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
Re: Coding advice needed
Posted: Tue Dec 09, 2014 12:21 pm
by WaspUK1966
That`s great! Thank you so much
George