How can I make levers tables? I have 6 levers and I have to set them in the appropriate setting. By what I have to write in the script 6 conditions and make 6 files in actions. Can I somehow go around it, to write less code and be more readable?
local lever_trans = {
[1945] = 1946,
[1946] = 1945
}
local levers = {
{Position(104, 129, 7), 1945}, --lever position, desired id (1945 lever to the left, 1946 lever to the right)
{Position(104, 130, 7), 1946},
{Position(104, 131, 7), 1945},
{Position(106, 129, 7), 1946},
{Position(106, 130, 7), 1945},
{Position(106, 131, 7), 1946}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local correct_levers = 0
item:transform(lever_trans[item:getId()])
for i = 1, #levers do
local lever = getTileItemById(levers[i][1], levers[i][2]).uid
if lever > 0 then
correct_levers =...
It's simple no matter what distribution you are using, if it has actionscripts then you can use item.itemid to index a table.How can I make levers tables? I have 6 levers and I have to set them in the appropriate setting. By what I have to write in the script 6 conditions and make 6 files in actions. Can I somehow go around it, to write less code and be more readable?
-- this should defined outside of onUse
local levers = {
-- 1234 would be if it was a lever item id
[1234] = {--[[ put whatever u want in here]]}
}
-- and this should be defined inside of onUse
if levers[item.itemid] then
-- do something
end
Do you mean that until (IE) 2 are to the left and 4 to the right x action will trigger? or that until they are used in a certain order x action will trigger?
Also remember to tell us which server you're using (TFS 0.x, 1.x, etc)
It's simple no matter what distribution you are using, if it has actionscripts then you can use item.itemid to index a table.
Lua:-- this should defined outside of onUse local levers = { -- 1234 would be if it was a lever item id [1234] = {--[[ put whatever u want in here]]} } -- and this should be defined inside of onUse if levers[item.itemid] then -- do something end
It really depends on what your trying to do.That's exactly what I mean. I am using otx server 3.
I must enter the id of my 6 levers in local leavers?
local levers = {
[11111] = {},
[22222] = {},
[33333] = {},
[44444] = {},
[55555] = {},
[66666] = {}
}
function onUse(a,item,c,d,e)
if levers[item.uid] then
-- do stuff
end
return true
end
That's exactly what I mean. I am using otx server 3.
I must enter the id of my 6 levers in local leavers?
Just post the script or scripts and then people can help you.I do not know if you understend me well. I have 6 levers, in the map editor there is uniqueid: 1111,2222,3333,4444,5555,6666. In the action file, I add my leavers and in the action folder I have to add 6 files, which change the variables which then I check when I enter the teleport. What the teleport condition looks like: if lever1 == 1 and lever2 == 1 ... And lever6 == 1 then
To something.
End
So I wanted to find out if I could improve it, not to create 6 files in actions and compare 6 variables in the teleport condition. I would like my code to be more readable. Is it possible to put these levers in the table and compare all the loops?
local lever_trans = {
[1945] = 1946,
[1946] = 1945
}
local levers = {
{Position(104, 129, 7), 1945}, --lever position, desired id (1945 lever to the left, 1946 lever to the right)
{Position(104, 130, 7), 1946},
{Position(104, 131, 7), 1945},
{Position(106, 129, 7), 1946},
{Position(106, 130, 7), 1945},
{Position(106, 131, 7), 1946}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local correct_levers = 0
item:transform(lever_trans[item:getId()])
for i = 1, #levers do
local lever = getTileItemById(levers[i][1], levers[i][2]).uid
if lever > 0 then
correct_levers = correct_levers + 1
end
end
if correct_levers == #levers then
print("All levers in correct position")
end
return true
end
local levers = {
{Position(104, 129, 7), 1945},
{Position(104, 130, 7), 1946},
{Position(104, 131, 7), 1945},
{Position(106, 129, 7), 1946},
{Position(106, 130, 7), 1945},
{Position(106, 131, 7), 1946}
}
function onStepIn(creature, item, position, fromPosition)
local correct_levers = 0
for i = 1, #levers do
local lever = getTileItemById(levers[i][1], levers[i][2]).uid
if lever > 0 then
correct_levers = correct_levers + 1
end
end
if correct_levers == #levers then
print("All levers in correct position")
end
return true
end