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

[simple] proximity sensor change

Started by aeroverra, 18 May 2016 - 04:58 AM
aeroverra #1
Posted 18 May 2016 - 06:58 AM
i found this program on youtube that detects a specific list of players and then sends a signal to another pc that then sends a redstone signal. Works wonderfully but how can i change it to send a signal to the other pc if its all but those specific players.

Video https://www.youtube.com/watch?v=HxUQlLKc1NE
openDoor(recieving computer that puts off redstone): http://pastebin.com/PR1RKuUK
proxDetect:(sending computer that detects) http://pastebin.com/3pbVFyu6

I have changed the "opendoor" program to send a positive redstone signal instead of a negative on detection and works good but heres where my knowledge ends.

I have tried changing the code in the detector from

  if value == playerName and item == nil then

to


  if not value == playerName and item == nil then
and no signal is ever made.

I obviously don't know what im doing haha.. could someone please help me.
KingofGamesYami #2
Posted 18 May 2016 - 02:23 PM
It's actually really simple. Currently the arrayCheck function sends a signal ("not_player") when it ends. Simply make the function end earlier and that signal ("not_player") means nobody on the list was detected.


function arrayCheck(playerNames,playerName,secretPhrase,portNum,item,heldItem)
    local port = tonumber(portNum)
    for key, value in pairs(playerNames) do
        if value == playerName and item == nil then
            modem.transmit(port,524,secretPhrase)
            return
        elseif value == playerName and item == heldItem then
            modem.transmit(port,524,secretPhrase)
            return
        end      
    end
    modem.transmit(port,524,"not_player")
end
aeroverra #3
Posted 18 May 2016 - 04:43 PM
It's actually really simple. Currently the arrayCheck function sends a signal ("not_player") when it ends. Simply make the function end earlier and that signal ("not_player") means nobody on the list was detected.


function arrayCheck(playerNames,playerName,secretPhrase,portNum,item,heldItem)
	local port = tonumber(portNum)
	for key, value in pairs(playerNames) do
		if value == playerName and item == nil then
			modem.transmit(port,524,secretPhrase)
			return
		elseif value == playerName and item == heldItem then
			modem.transmit(port,524,secretPhrase)
			return
		end	  
	end
	modem.transmit(port,524,"not_player")
end

I don't quite understand still. All you seem to have added is "return". I also don't want to to send a positive signal when noone is around. Only when a player is around who is not on the list. Idk if I was clear on that.
aeroverra #4
Posted 18 May 2016 - 04:46 PM
Couldnt edit post cuz im waiting on mod approval but I think I understand. I should have it end before the "for" loop ends rather than before the function?
KingofGamesYami #5
Posted 18 May 2016 - 06:09 PM
The way it works is if it finds a player that's supposed to be there, it'll transmit then exit the function. If it doesn't, it'll continue and transmit the other message. I've edited the code to also make sure there are, in fact, players nearby when it sends the other message (preventing the false positive)


function arrayCheck(playerNames,playerName,secretPhrase,portNum,item,heldItem)
        local port = tonumber(portNum)
        for key, value in pairs(playerNames) do
                if value == playerName and item == nil then
                        modem.transmit(port,524,secretPhrase)
                        return
                elseif value == playerName and item == heldItem then
                        modem.transmit(port,524,secretPhrase)
                        return
                end       
        end
        if #playerNames > 0 then
          modem.transmit(port,524,"unauthorized_player")
        end
end