Page 3 of 4
Re: Return to Inventory
Posted: Thu Sep 20, 2012 7:59 pm
by Emciel
ahhhh i see how you can make insertItem work now =)
therefore i present 100% working (i'm sure you can find some problem if you look xD) remove item and return item to inventory script!!!
- create a timer and a script entity
- set the timer to running and connect it on activate to the checkTorch() function
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")
returnItem(item)
end
end
end
end
end
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")
party:getChampion(champ):insertItem(slot,x)
itemReturned = true
end
else
spawn(item,player.level,player.x,player.y,player.facing)
end
end
end
end
end
function checkTorch()
itemCheck("torch")
end
if you guys want to check it out that'd be good, then we can add it to the useful scripts repository =) (my first entry ^_^)
Re: Return to Inventory
Posted: Thu Sep 20, 2012 8:05 pm
by Xzalander
Kudos Emciel. Much more elegant than my attempt
Oh god you've created it perfectly. I'm not kidding. I even tried overloading one character with notes and he just passed the torch onto character #2. So I overloaded all of them with notes.
It drops to the floor.
I'd try to fill a floor tile but I don't think you can.... Excellent dude!
Ah wait sorry rain parade...
second try at overloading ALL the characters, and it crashed.
Code: Select all
spawn(item,player.level,player.x,player.y,player.facing)
"Attempt to index a global 'player' (nil value)"
edit:
Just reloaded the scenario and its done it again;
The issue is on that spawn code line; where it drops the item to the floor. I'm guessing the first time I misclicked or something?
Although as it stands it is very robust, I doubt anyone will ever manage to fill ALL their inventory slots at once.
Re: Return to Inventory
Posted: Thu Sep 20, 2012 8:15 pm
by Montis
"-- Disabled due to bug"?
What is?
Anyway, nice work. I wanted to comment before that you shouldn't include the "empty slot search" in every loop since you only need it when actually finding an empty slot for the torch. But now you seem to have integrated that for yourself already, good job.
I think the last touch would be to print a message like "No torchlight allowed" or something like that so the player will know that he can find the torch in his inventory.
for the error: it should be
party.level etc, not
player.level
Re: Return to Inventory
Posted: Thu Sep 20, 2012 8:22 pm
by Malveus
With a tiny bit of tweaking, I could make a cursed item with this code that not only returns the item to the champion's bag, but duplicates itself in the process , right?. Picture a 5 pound tribble.Or a 50 pound one. Prepare to get overburdened as a new way of tormenting adventurers.
Re: Return to Inventory
Posted: Thu Sep 20, 2012 8:24 pm
by Montis
Ah yeah, one additional thing: I would suggest that you only use the inventory of the character that actually holds the torch, so you would need to forward that variable as a parameter.
The following should work: (yet untested)
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")
returnItem(item,champ)
end
end
end
end
end
function returnItem(item,champ)
for slot = 11,32 do
if slot < 32 then
if party:getChampion(champ):getItem(slot) == nil then
print(item.." returned")
party:getChampion(champ):insertItem(slot,x)
break
end
else
spawn(item,party.level,party.x,party.y,party.facing)
end
end
end
function checkTorch()
itemCheck("torch")
end
Re: Return to Inventory
Posted: Thu Sep 20, 2012 8:26 pm
by Xzalander
Now that I fixed the player/party bug. Ive found another.
Torch Multiplication!
It takes the one torch off you, but then drops 4 (1 for each player).
If it takes four off you, it drops 8.
If it takes 8 off you it places 32.
Conditions:
All inventory full. Floor space empty.
Re: Return to Inventory
Posted: Thu Sep 20, 2012 8:29 pm
by Montis
Xzalander wrote:Now that I fixed the player/party bug. Ive found another.
Torch Multiplication!
It takes the one torch off you, but then drops 4 (1 for each player).
If it takes four off you, it drops 8.
If it takes 8 off you it places 32.
Conditions:
All inventory full. Floor space empty.
lol
try it with my updated script, that should work if I didn't make a mistake with removing one "end" too much/less.
Re: Return to Inventory
Posted: Thu Sep 20, 2012 8:34 pm
by Xzalander
Yup Montis that fixed it.
Great job guys! You all well and truly
'd it
Re: Return to Inventory
Posted: Thu Sep 20, 2012 8:37 pm
by Emciel
following all comments i've revised the script =D
thanks for the help guys!
Code: Select all
function itemCheck(item)
-- checks for the item in champions hands
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
-- if found it is removed and the returnItem function is triggered
party:getChampion(champ):removeItem(slot)
print("item removed")
returnItem(item,champ)
end
end
end
end
end
function returnItem(item,champ)
-- checks backpacks for empty slot
for slot = 11,32 do
if slot < 32 then
if party:getChampion(champ):getItem(slot) == nil then
-- once found, the item is placed in a slot and the player is told where
print("item returned")
party:getChampion(champ):insertItem(slot,x)
hudPrint("The torch is too hot to hold,\nso is put into "..party:getChampion(champ):getName().."'s bag.")
break
end
else
-- if no slots are empty, the item is dropped
spawn(item,party.level,party.x,party.y,party.facing)
hudPrint("The torch is too hot to hold,\nand drops to the floor")
break
end
end
end
function checkTorch()
itemCheck("torch")
end
Re: Return to Inventory
Posted: Thu Sep 20, 2012 8:47 pm
by Xzalander
using your revised script I've added a couple of things:
1. Flavoured the text up a bit.
2. Added a sound
Code: Select all
function itemCheck(item)
-- checks for the item in champions hands
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
-- if found it is removed and the returnItem function is triggered
party:getChampion(champ):removeItem(slot)
print("item removed")
returnItem(item,champ)
end
end
end
end
end
function returnItem(item,champ)
-- checks backpacks for empty slot
for slot = 11,32 do
if slot < 32 then
if party:getChampion(champ):getItem(slot) == nil then
-- once found, the item is placed in a slot and the player is told where
print("item returned")
party:getChampion(champ):insertItem(slot,x)
hudPrint("The torch fizzles out, and a voice booms 'Scared of the Dark? You will be!!'\n Laughter echoes through the halls maniacally.\nIt is put into "..party:getChampion(champ):getName().."'s bag." )
playSound("lightning_bolt_hit")
break
end
else
-- if no slots are empty, the item is dropped
spawn(item,party.level,party.x,party.y,party.facing)
hudPrint("Your bags are full. The torch is dropped to the floor.")
break
end
end
end
function checkTorch()
itemCheck("torch")
end