Kame's PlayerDetector(Misc Peripherals) Program

Discussion in 'ComputerCraft Programming' started by Kamefrede, Sep 22, 2013.

  1. Kamefrede

    Kamefrede Pig morphing Artic Fox

    Joined:
    Sep 19, 2013
    Messages:
    8
    Likes Received:
    2
    A couple months ago i made a fairly simple code for a friend of mine, that basicly was a lock system that if the player was authorized the door would open if he wasnt, he would get a portal's pellet energy and would go from earth to heaven(aka he would die)

    Carrying on
    13 m4st3r c0d3
    Le Master Code
    Code:
    local event
    local name
    local found
     
    function door()
       redstone.setOutput("back",true)
       sleep(2)
       redstone.setOutput("back",false)
    end
     
    function floor()
       redstone.setOutput("front",true)
       sleep(1)
       redstone.setOutput("front",false)
    end
     
    function reset()
       name = ""
       found = false
    end
     
    function waitClick()
       event, name = os.pullEvent("player")
       print(name)
    end
     
    function checkName()
       file = io.open("perms", "r")
       for line in file:lines() do
          if name == line then
             found = true
          end
       end
    end
     
    function run()
       if found == true then
          print("Player Authorized, Opening Door.")
          door()
       else
          print("PLAYER NOT AUTHORIZED INITIATING FLOOR/KILLING PROCESS")
          floor()
       end
    end
     
    os.pullEvent = os.pullEventRaw
     
    while true do
      reset()
      waitClick()
      checkName()
      run()
    end
    Pastebin link: http://pastebin.com/ceNTDJdj
    Or through computer ftp or the skcraft IDE! :)
    For Maximum Protection its better that it is on startup
    It Outputs a redstone signal on the front, if the player isnt authorized
    And Outputs a redstone signal on the back if the player is authorized
    Those can be changeable on the code
    Also, Player Detector is on the top(Can also be changed)
     
  2. hsun324

    hsun324 Programmer, Gamer

    Joined:
    May 14, 2012
    Messages:
    362
    Likes Received:
    90
    Bad code is bad.
     
    Neonbeta likes this.
  3. Kamefrede

    Kamefrede Pig morphing Artic Fox

    Joined:
    Sep 19, 2013
    Messages:
    8
    Likes Received:
    2
    I didnt say it was efficient or good i only said it was simple and it does its job.
     
  4. hsun324

    hsun324 Programmer, Gamer

    Joined:
    May 14, 2012
    Messages:
    362
    Likes Received:
    90
    So easy to bypass.
    HINT: literal quote splice, pullEventRaw
     
  5. punk_and_goth

    punk_and_goth AFK a minimum of 23 hours, 59 minutes per day.

    Joined:
    Feb 7, 2013
    Messages:
    312
    Likes Received:
    128
    tonius11 likes this.
  6. 0070071

    0070071 Too many arguments with Neon/Shad, or about GT.

    Joined:
    Jan 21, 2012
    Messages:
    210
    Likes Received:
    14
  7. Tonius

    Tonius 555 Eternal Server Error

    Joined:
    Jan 30, 2012
    Messages:
    480
    Likes Received:
    392

    all lies

    mine is constantly trying to detect players, causing lag
     
  8. Kamefrede

    Kamefrede Pig morphing Artic Fox

    Joined:
    Sep 19, 2013
    Messages:
    8
    Likes Received:
    2
    Ty 0070071 ill edit the op when i get on my pc, my phone dosent allows copy paste
     
    0070071 likes this.
  9. 0070071

    0070071 Too many arguments with Neon/Shad, or about GT.

    Joined:
    Jan 21, 2012
    Messages:
    210
    Likes Received:
    14
    I nearly died 'cos ocd' :)
    Anyway, I like helping if I care about something :p
     
  10. Kamefrede

    Kamefrede Pig morphing Artic Fox

    Joined:
    Sep 19, 2013
    Messages:
    8
    Likes Received:
    2
    There! Changed pastebin link dam school makes me be late
     
  11. punk_and_goth

    punk_and_goth AFK a minimum of 23 hours, 59 minutes per day.

    Joined:
    Feb 7, 2013
    Messages:
    312
    Likes Received:
    128
    no u!
     
  12. Magi1053

    Magi1053 That one guy
    Staff Member

    Joined:
    Jun 26, 2012
    Messages:
    159
    Likes Received:
    49
    I recommend doing nested if/else, that way it doesn't evaluate each function every time it loops, but only the first if statement, then if true continues through the rest of the program.