Posted 22 May 2014 - 11:32 PM
Hey, I'm wanting to edit a piece of code I received from a player on my server, but I'm not sure where to start.
The existing code is for the sensor from OpenPeripherals and opens the door when a specified player goes near it. What I want to do, is modify the code so it emits redstone for any player when they go near it, but the names specified.
A friend of mine, who doesn't know much lua but writes mods in Java added this to see if it would work:
I couldn't get that to work so now I'm pretty much lost as to where to go with this. Any help would be greatly appreciated.
Thanks, Bio
The existing code is for the sensor from OpenPeripherals and opens the door when a specified player goes near it. What I want to do, is modify the code so it emits redstone for any player when they go near it, but the names specified.
local sensor = peripheral.wrap('top') -- where the sensor is
local output = 'left' -- Where to output the signal
local initial = true -- What to output when no one's around
-- How close you need to be to the sensor in order to use it.
local minX = -2 local maxX = 2
local minY = 0 local maxY = 2
local minZ = -2 local maxZ = 2
-- Initial output
redstone.setOutput(output, initial)
while true do
players = sensor.getPlayerNames()
-- Don't do checks if there are no players.
if #players == 0 then
redstone.setOutput(output, initial)
sleep(0.7)
else -- There are players
for _, name in pairs(players) do
if name == 'player1' or name == 'player2' or name == 'player3' then
info = sensor.getPlayerData(name)
pos = info.position
if pos.x >= minX and pos.x <= maxX
and pos.y >= minY and pos.y <= maxY
and pos.z >= minZ and pos.z <= maxZ then
redstone.setOutput(output, not initial)
break
end
end
end
-- There are players around, we need to be more responsive
sleep(0.5)
end
end
A friend of mine, who doesn't know much lua but writes mods in Java added this to see if it would work:
if name == 'player1' or name == 'player2' or name == 'player3' then
end
else
info = sensor.getPlayerData(name)
I couldn't get that to work so now I'm pretty much lost as to where to go with this. Any help would be greatly appreciated.
Thanks, Bio