This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
KingMinecrafter's profile picture

Need help with sensor door.

Started by KingMinecrafter, 26 June 2014 - 01:22 PM
KingMinecrafter #1
Posted 26 June 2014 - 03:22 PM
Hi, im trying to work out a better way to keep my door open. right now it keeps it open for 5 sec, then turns off just long enough for the door to close then open agian.
I tried removing the sleep command to keep the redstone constant but it doesnt work. Also im trying to figuire out a better way of whitelisting people, instead of having to whitelist each player with a "long" code i want everyone on a seperate program and just write theyre name and it whitelists/blacklists them. im fairly new to this.


here is the code:

p = peripheral.wrap("right")
m = peripheral.wrap("top")
local whiteList = {}
local blackList = {}
m.clear()
--whiteList["Player1"] = true
whiteList["KingMinecrafter"] = true
whiteList["Falmaze"] = true
whiteList["hayboy2001"] = true
whiteList["ryguy6011"] = true
whiteList["cody1904"] = true
whiteList["SkeliWar"] = true
blackList[""] = true

function centerText(text)
m.setTextScale(1,9)
x,y = m.getSize()
x1,y1 = m.getCursorPos()
m.setCursorPos((math.floor(x/2) - (math.floor(#text/2))), y1)
m.write(text)
end

function white(playerName)
y2 = 3
m.setTextColor(1)
m.setCursorPos(1, 3)
centerText(" Welcome back")
m.setCursorPos(1, 5)
m.setTextColor(32)
centerText(" "..playerName.." ")
m.setCursorPos(1, 7)
m.setTextColor(1)
centerText("Door is now open")
rs.setBundledOutput("back", colors.lime)
sleep(2)
end

function black(playerName)
m.clear()
y2 = 3
m.setCursorPos(1, y2)
centerText("Blacklisted player: "..playerName.." Recognized, lockdown initiated")
rs.setBundledOutput("back", 0)
rs.setBundledOutput("back", colors.red)
end


function nobody(playerName)
m.clear()
y2 = 3
m.setCursorPos(1, y2)
centerText("Unrecognised player: "..playerName.." Please leave")
end

function reset()
rs.setBundledOutput("back", 0)
end

while true do
sleep(1)
players = p.getPlayerNames()
for num,name in pairs(players) do

if whiteList[name] then
print("Whitelisted Players: "..name.."")
white(name)

elseif blackList[name] then
print("Blacklisted Players: "..name.."")
black(name)

else
print("System does not recognize player: "..name.."")
nobody(name)
rs.setBundledOutput("back",0)
end
rs.setBundledOutput("back", 0)
end
end
KingMinecrafter #2
Posted 26 June 2014 - 03:53 PM
Also, when whitelisted players leave i want the screen to go blank. same for blacklisted. I did a test with a blacklisted player near me and the text got mixed up. Could that be fixed? the code is probaly a mess. I want it so it sends a red signal when a blacklisted person is there, and when a whitelisted person shows up it opens the door and closes it but does not turn off the red signal.
Also is it possible to increase/decrease the range of the sensor? it is a bit big.
Also, when 2 whitelisted players are there the text bugs out and shows both players in the same line. can this also be fixed?
Edited on 26 June 2014 - 01:58 PM
KingMinecrafter #3
Posted 26 June 2014 - 05:44 PM
Really need help, im on a pvp server and people keep trying to raid. i need this working properly to defend my base
KingMinecrafter #4
Posted 26 June 2014 - 11:15 PM
Updated code: http://pastebin.com/D1Dxvvuv
GamerNebulae #5
Posted 26 June 2014 - 11:47 PM
What the hell is wrong exactly?! :S
Bomb Bloke #6
Posted 27 June 2014 - 02:57 AM
As mentioned in the OP, the door keeps opening/closing when it should just be staying open.

Though skimming the code, there are a few other issues in there as well…
For starters, opening the door as soon as a whitelisted player is detected isn't any good. A blacklisted player will be able to go through as well.

I recommend a read through this thread. The situation there is nearly identical.
KingMinecrafter #7
Posted 27 June 2014 - 10:41 AM
Yeah it seems to pulse the redstone signal. If i remove the sleep it wont even send a signal
KingMinecrafter #8
Posted 27 June 2014 - 11:24 AM
What would i do if i want it to write all the names on a list on the monitor? like left side it is a list going down with all green names (whitelisted) middle/centered is grey meaning outsiders and red on the right side for blacklisted? currently it only displays one name at a time on the monitor.
KingMinecrafter #9
Posted 27 June 2014 - 12:46 PM
And is there any ways to increase/decrease the range? i want a low range near the door and a high range for detecting enemies so i can use it for my control panel
theoriginalbit #10
Posted 27 June 2014 - 12:51 PM
well not really, but there is a way to calculate distance, what sensor are you using? OpenPeripheral or OpenCCSensors?
KingMinecrafter #11
Posted 27 June 2014 - 01:08 PM
OpenPeripheral. Is it possible to use modems and place the sensors further away and wrap the modem and sensor together?

Also i want the computer to send a constant bundled cable signal until player is no longer within range, aswell as put the player on a monitor. if more players arrive they get put under on a list on the monitor. like this

Whitelisted: Outsiders: Blacklisted
KingMinecrafter Ephox That guy
Falmaze
etc
theoriginalbit #12
Posted 27 June 2014 - 01:43 PM
Okay so with OpenPeripheral you can use getPlayerInfo(username) to get additional information about the player, including their x, y, and z coordinates relative to the sensor. This position is stored under position.x, position.y, and position.z in the player information table. You can apply these positions to the Euclidean distance formula to check how far the player actually is away from the sensor and act appropriately based on that.

local function playerDistance( player )
  local pos = player.position
  local x, y, z = pos.x, pos.y, pos.z
  return math.sqrt( x*x + y*y + z*z )
end

as for the bundled cabled support, take a look at the redstone API
KingMinecrafter #13
Posted 27 June 2014 - 01:48 PM
Okay so with OpenPeripheral you can use getPlayerInfo(username) to get additional information about the player, including their x, y, and z coordinates relative to the sensor. This position is stored under position.x, position.y, and position.z in the player information table. You can apply these positions to the Euclidean distance formula to check how far the player actually is away from the sensor and act appropriately based on that.

local function playerDistance( player )
  local pos = player.position
  local x, y, z = pos.x, pos.y, pos.z
  return math.sqrt( x*x + y*y + z*z )
end

as for the bundled cabledsupport, take a look at the redstone API

Thanks, but the redstone API page wont help, i set it as an output but after the sleep it turns off for a second then back on, if i remove the sleep after i set the output it doesnt work at all.
And im also looking for a way to use modems to connect sensor that are further away and wrap them and set them so instead of peripheral.wrap("etc") i do peripheral.wrap("etc") = p and use p instead.

Im really new to this and just watched some tutorials and i was really surprised how well this works. im also wondering about the multiple users on screen how i can get more than one to show up at a time

I also like it if outsiders + whitelist + blacklist/ whitelist + outsider etc then light up the corresponding colours but if one leaves it removes the colour, and if they are detected it would put theyre name in the corresponding colour on a monitor. if more than one blacklisted it would list them underneath eachother
Edited on 27 June 2014 - 12:27 PM
KingMinecrafter #14
Posted 27 June 2014 - 02:52 PM
I added something to make a ____ line at the bottom to make it look good and make lines to "sort" different things on the monitor this is the code i used:


while true do
m.setTextColor(1)
m.setTextScale(1)
m.setCursorPos(1, 19)
m.write("______________________________________________________________")
end

And now after i do that i cant force shutdown the computer or restart it, i have to break the monitor to get the computer to crash then break the computer and place it down before i place the monitor down. please help!
GamerNebulae #15
Posted 27 June 2014 - 05:43 PM
You only have to write it once to a monitor. You don't have to constantly write it over and over again. It's getting stuck in the while-loop.
KingMinecrafter #16
Posted 27 June 2014 - 05:54 PM
You only have to write it once to a monitor. You don't have to constantly write it over and over again. It's getting stuck in the while-loop.
But the whitelist/blacklist names have to do m.clear() Doesn't that affect it?
GamerNebulae #17
Posted 27 June 2014 - 09:10 PM
-snip-

You could just use this if you want to clear 1 line:

m.setCursorPos(1,y)
m.clearLine()
KingMinecrafter #18
Posted 27 June 2014 - 10:02 PM
-snip-

You could just use this if you want to clear 1 line:

m.setCursorPos(1,y)
m.clearLine()
Thanks, one thing down. 200 billion things to gooo :P/>
KingMinecrafter #19
Posted 28 June 2014 - 03:41 PM
Hey, im trying to get players on a list on a monitor when they get detected, and when they leave the dissapear. So far im only able to display one at a time. I want it to show Whitelisted Outsiders then Blacklisted
sort of this like this: WHITELIST: OUTSIDER: BLACKLIST
Player1 Player2 Player3
Player4

Here is the code:


--Made by KingMinecrafter! NOT URGIST!
p = peripheral.wrap("right")
m = peripheral.wrap("top")
--screen size
--61
--19

local whiteList = {}
local blackList = {}
m.clear()
--whiteList["Player1"] = true
whiteList["KingMinecrafter"] = true
whiteList["Falmaze"] = true
whiteList["hayboy2001"] = true
whiteList["ryguy6011"] = true
whiteList["cody1904"] = true
whiteList["SkeliWar"] = true
whiteList["deijndthoven123"] = true
whiteList["Marcusbolt"] = true
whiteList["ITZ_M1KE"] = true
blackList[""] = true
function text(text)
m.write(text)
end
function centerText(text)
m.setTextScale(1)
x,y = m.getSize()
x1,y1 = m.getCursorPos()
m.setCursorPos((math.floor(x/2) - (math.floor(#text/2))), y1)
m.write(text)
end
function black(playerName)
m.clear()
y2 = 3
m.setCursorPos(33, 1)
m.setTextColor(16384)
text(" "..playerName.." ")
rs.setBundledOutput("back", colors.red)
sleep(15)
end
function white(playerName)
m.clear()
y2 = 3
m.setCursorPos(1, 1)
m.setTextColor(32)
m.setTextScale(1)
text(" " ..playerName.. " ")
rs.setBundledOutput("back", colors.lime)
sleep(5)
rs.setBundledOutput("back", 0)
end
function nobody(playerName)
m.clear()
y2 = 3
m.setTextColor(1)
m.setCursorPos(17, 1)
m.setTextColor(128)
text(" " ..playerName.. " ")
rs.setBundledOutput("back", colors.blue)
sleep(15)
end
function reset()
rs.setBundledOutput("back", 0)
end
while true do
players = p.getPlayerNames()
for num,name in pairs(players) do
if whiteList[name] then
white(name)
elseif blackList[name] then
black(name)
else
nobody(name)
rs.setBundledOutput("back", 0)
sleep(2)
end
end
end
Carrots084 #20
Posted 28 June 2014 - 11:54 PM
Please include your error. its a bit of a wall of text also…
theoriginalbit #21
Posted 29 June 2014 - 07:37 AM
merged threads. please try to stick to one thread per program.

what attempt have you made to do this yourself? are you getting any errors, if so what are they? here is ask a pro it is not our job to give you code, but instead assist you in coding, you'll get greater satisfaction this way. The effort you're willing to put forth in figuring things out yourself is equal to the amour of effort people are willing to put forth in helping you.
Edited on 29 June 2014 - 05:39 AM
KingMinecrafter #22
Posted 30 June 2014 - 12:46 PM
merged threads. please try to stick to one thread per program.

what attempt have you made to do this yourself? are you getting any errors, if so what are they? here is ask a pro it is not our job to give you code, but instead assist you in coding, you'll get greater satisfaction this way. The effort you're willing to put forth in figuring things out yourself is equal to the amour of effort people are willing to put forth in helping you.
They are two different programs im working on, quite similar. One is a door which ive pretty much fixed but the other is a sortof control panel. First thing im trying to do is to get players names to get up on a list on the monitor. I am able to get one name but not get them in a list. I want it so it shows Whitelisted on the far left, Outsiders/Unknown in the middle and Blacklisted to the far right. I do not know the approuch i do to make this