Page 1 of 4
Return to Inventory
Posted: Thu Sep 20, 2012 3:24 pm
by Xzalander
Komag wrote:Steal an item being held or equiped by a party member
(such as removing the torch from Contar Stoneskull's left hand)
example from petri:
Assuming Contar is the first champion in the party:
Code: Select all
party:getChampion(1):removeItem(7)
7 is the slot number of the left hand, defined in Champion:insertItem()'s documentation.
Just wondering is there anyway to get this code to return the item to the affected characters inventory instead of being deleted?
I plan to use it so that characters can carry torches in their packs and place them, but not carry them in hand so as to avoid the player breaking lighting atmosphere.
Or do I need to use a different type of script?
Re: Return to Inventory
Posted: Thu Sep 20, 2012 3:30 pm
by petri
Xzalander wrote:Just wondering is there anyway to get this code to return the item to the affected characters inventory instead of being deleted?
Sure there is!
Re: Return to Inventory
Posted: Thu Sep 20, 2012 3:34 pm
by Xzalander
Ah found it!
Code: Select all
Champion:insertItem(slot, item)
Inserts an item to an equipment slot. Slot must be one of the following: 1 (head), 2 (torso), 3 (legs), 4 (feet), 5 (cloak), 6 (neck), 7 (left hand), 8 (right hand), 9 (gaunlets), 10 (bracers), 11-31 (backpack slots).
So I could simply remove the item then add the item back again. Completed script coming up for the repository soon!
Re: Return to Inventory
Posted: Thu Sep 20, 2012 3:49 pm
by Montis
Remember to check for free inventory space and if none is available drop the item
to the ground.
Re: Return to Inventory
Posted: Thu Sep 20, 2012 4:33 pm
by Xzalander
Edit: sussed it.
Why is it that if I name this scripts ID to 'checkInventory' it doesnt work, but if I name it anything else it does?
Code: Select all
function itemCheck(thisItem)
local thisPlayer = 1
local itemSlot = 1
local currItem
for thisPlayer=1,4,1 do
for itemSlot=7,8,1 do
if party:getChampion(thisPlayer):getItem(itemSlot) ~= nil then
currItem = party:getChampion(thisPlayer):getItem(itemSlot).name
if currItem == "torch" then
return true
end
end
itemSlot = itemSlot + 1
end
thisPlayer = thisPlayer + 1
end
end
function checkInventory()
if itemCheck("torch") then
print("found it!!")
party:getChampion(1):removeItem(7)
else
print("no such item in inventory.")
end
end
As a final note I have that working thus far to detect items in left and right hand and if detected to remove it, but it only removes it from the left hand, not the right and only on the character in slot 1.
Re: Return to Inventory
Posted: Thu Sep 20, 2012 5:48 pm
by Emciel
was just trying to figure out a script for this. got a working removal script, but i can't make the insertItem function work
even just testing
Code: Select all
party:getChampion(2):insertItem(11,"torch")
returns an error
"bad argument #2 to 'insertItem' (Item expected, got ???)
is this a bug? or am i doing something wrong? O.o
Re: Return to Inventory
Posted: Thu Sep 20, 2012 5:49 pm
by Xzalander
Emciel, I'm suffering the same and Im not sure either.
My focus right now is trying to get the game to remove torches from -any- person hand not just the slot1character.
Ugh I don't think Im being specific enough in that code either. Axe in left torch in right. Trigger script deletes the axe. My brain is fuzzing up.
Re: Return to Inventory
Posted: Thu Sep 20, 2012 5:54 pm
by Emciel
the working code i've got for removing the torch is:
Code: Select all
function itemCheck(item)
for champ = 1,4 do
for slot = 7,8 do
x = party:getChampion(champ):getItem(slot)
if x ~= nil then
if x.name == item then
party:getChampion(champ):removeItem(slot)
print("item removed")
end
end
end
end
end
function checkTorch()
itemCheck("torch")
end
then create a timer which is set to running, and connect it on activate to "checkTorch()".
Re: Return to Inventory
Posted: Thu Sep 20, 2012 6:12 pm
by Montis
Emciel wrote:was just trying to figure out a script for this. got a working removal script, but i can't make the insertItem function work
even just testing
Code: Select all
party:getChampion(2):insertItem(11,"torch")
returns an error
"bad argument #2 to 'insertItem' (Item expected, got ???)
is this a bug? or am i doing something wrong? O.o
An item is program-wise a function, but you inserted a string.
The code that you posted above should have the item as variable "x", so you could try it with that, after removing the item from slot 7 or 8.
Code: Select all
party:getChampion(champ):insertItem(11,x)
Can't test right now but it might work. If it does, you can implement an additional loop to check for free inventory space as I mentioned above.
Re: Return to Inventory
Posted: Thu Sep 20, 2012 6:20 pm
by Xzalander
Emciel I cant get that code to work at all if I tie it to a pressure plate (Doing that so I know when to expect a response from the function).
Infact, I can't even get mine to work now, despite it having worked before saving and reloading.
Edit oh god whats wrong with my brain today! I forgot to set the action to the second function!
EDIT: What I have so far.
Insert an extra for stated as Empty. Now I just need to figure out how to get empty to check for an empty slot instead of using =11,31
Code: Select all
function itemCheck(thisItem)
for champ = 1,4 do
for slot = 7,8 do
for empty = 11,31 do
x = party:getChampion(champ):getItem(slot)
if x ~= nil then
if x.name == "torch" then
party:getChampion(champ):removeItem(slot)
party:getChampion(champ):insertItem(empty,x)
print("item removed")
end
end
end
end
end
end