No time to see why your code doesn't work (since i'm at work), but I like to write stuff the way I actually say or explain it to others.
- The teleporter needs to open if member1 holds the item and member2 and member3 and member4, else it needs to deactivate.
- A member holding it means it actually in their left or right hands.
Without compiler and such (so probably full of errors), the script could be like this:
Code: Select all
function lightCheck()
local j = "blue_gem"
if holdsItem(1, j) and holdsItem(2, j) and holdsItem(3, j) and holdsItem(4, j) then
teleporter_34:activate()
else
teleporter_34:deactivate()
end
end
function holdsItem(champ, name)
local leftItem = party:getChampion(champ):getItem(7)
local rightItem = party:getChampion(champ):getItem(8)
return leftItem ~= nil and rightItem~= nil and leftItem.name==name and rightItem.name==name
end
To answer your questions
1) in your statement you had 2 loops, first you checked slot 7 and then slot 8. Those are 2 seperate loops and there was nothing to link the result of the 2 together
2) not sure what happens, but you use the same variablename multiple times (once as the item name and once as the loop counter). Try to avoid that for more predictable results
3) i don't think it's a lua loophole and it can work if you introduced more local variables, but might be possible to cheat then (player one holding 2 items and player 2 none).
But because I'm not sure I wrote an alternative, hope it works for you.
4) my way is not more correct than yours (assuming they both work). In environments where people have to maintain scripts for others there are rules on how to write code, but find a way you find most understandable and readable and stick with it. Personally I don't mind writing longer scripts if it makes me understand better, but I know others like to keep their code as short as possible.
Alternative way of writing with just one function:
Code: Select all
function lightCheck()
local j = "blue_gem"
if (party:getChampion(1):getItem(7).name==j or party:getChampion(1):getItem(8).name==j) and
(party:getChampion(2):getItem(7).name==j or party:getChampion(2):getItem(8).name==j) and
(party:getChampion(3):getItem(7).name==j or party:getChampion(3):getItem(8).name==j) and
(party:getChampion(4):getItem(7).name==j or party:getChampion(4):getItem(8).name==j) then
teleporter_34:activate()
else
teleporter_34:deactivate()
end
end