Page 2 of 4
Re: Return to Inventory
Posted: Thu Sep 20, 2012 6:55 pm
by Malveus
I'm working on a related problem, I'd like to make cursed items that return after a short interval when dropped.They will be able to be destroyed only by placing them on an altar with a plate and delete item script.
Re: Return to Inventory
Posted: Thu Sep 20, 2012 6:59 pm
by Komag
that's such a cool idea, where do you come up with this stuff?!
But what if everyone's inventory is full and their hands are full too?
Re: Return to Inventory
Posted: Thu Sep 20, 2012 7:00 pm
by Xzalander
As Montis said, a script that checks those and then drops to the floor in the event no space is free.
I'm just stuck with how to search for the presence of "something" (something being a vague item). I'm guessing that it would be easier to search for the existence of something rather than nothing, but then I'm unsure of how to do that :p
Just thinking if == means exactly equal to then is there a counter symbol like "Is not equal to"? I used to use the symbol != would that work?
Re: Return to Inventory
Posted: Thu Sep 20, 2012 7:05 pm
by Malveus
Komag wrote:that's such a cool idea, where do you come up with this stuff?!
But what if everyone's inventory is full and their hands are full too?
There isn't enough items in my dungeon to do that. "Burden Hands - These gauntlets are insanely heavy, but still worth two in the bush." "Chitin Trousers - Someone Chitin these trousers, but they're still wearable.I guess"
Re: Return to Inventory
Posted: Thu Sep 20, 2012 7:19 pm
by Montis
Xzalander wrote:Just thinking if == means exactly equal to then is there a counter symbol like "Is not equal to"? I used to use the symbol != would that work?
it's ~=
Re: Return to Inventory
Posted: Thu Sep 20, 2012 7:23 pm
by Xzalander
Yeah; I thought it was.
Heres what i'm working with so far.
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)
print("item removed")
y = party:getChampion(champ):getItem(empty)
if y == nil then
if y.name ~= " " then
party:getChampion(champ):insertItem(y,x)
print("item put in inventory")
end
end
end
end
end
end
end
end
Sorry my ending is so bad.
The only problem with doing it this way, is... I need to know what to call the nothing or listing every single item in the game to get it pass on that item slot and then check the next one.
Re: Return to Inventory
Posted: Thu Sep 20, 2012 7:26 pm
by Montis
you should try to make a simple function to print() what an empty slot returns, then you can have that as a comparison. probably nil or maybe false.
Re: Return to Inventory
Posted: Thu Sep 20, 2012 7:36 pm
by Xzalander
Yep an empty slot is nil.
Re: Return to Inventory
Posted: Thu Sep 20, 2012 7:42 pm
by Emciel
i can confirm that
Code: Select all
x = "torch"
party:getChampion(2):insertItem(11,x)
still brings up the error message from earlier.
i had a returnItem script which i've tested and it works, except of course you can't insertItem() xD
Code: Select all
function returnItem(item)
local itemReturned = false
for slot = 11,32 do
for champ = 1,4 do
if itemReturned == false then
if slot < 32 then
if party:getChampion(champ):getItem(slot) == nil then
print("item returned")
-- Disabled due to bug
-- party:getChampion(champ):insertItem(slot,item)
itemReturned = true
end
else
spawn(item,player.level,player.x,player.y,player.facing)
itemReturned = true
end
end
end
end
end
on a side note, this is genius ^_^
Malveus wrote: "Burden Hands - These gauntlets are insanely heavy, but still worth two in the bush." "Chitin Trousers - Someone Chitin these trousers, but they're still wearable.I guess"
edit: switched round the for/do in the function, as i realised it would end up reaching 32 before checking the next character.
Re: Return to Inventory
Posted: Thu Sep 20, 2012 7:48 pm
by Xzalander
Emciel;
I have it successfully reinserting a torch after removing one
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)
print("item removed")
y = party:getChampion(champ):getItem(empty)
if y == nil then
print("Slot is available")
party:getChampion(champ):insertItem(empty,x)
print("item put in inventory")
end
end
end
end
end
end
end
HOWEVER, I cannae make it insert into the next slot available, despite it checking the slots.
This current script sets it so that the player who loses a torch, has a torch put back in its inventory.
However in the event a player is holding two torches, it doesn't work and as I said, it only puts the torch into slot 11 (backpack slot 1)
ONE STEP CLOSER!
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)
print("item removed")
y = party:getChampion(champ):getItem(empty)
print (y)
if y == nil then
party:getChampion(champ):insertItem(empty,x)
print("item put in inventory")
else
print ("Slot not available")
end
end
end
end
end
end
end
This code now out puts whether or not the slot is available for insertion.
Now I just need to get it to check the next slot and insert.