3 posts
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=HxUQlLKc1NEopenDoor(recieving computer that puts off redstone): http://pastebin.com/PR1RKuUKproxDetect:(sending computer that detects) http://pastebin.com/3pbVFyu6I 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.
3057 posts
Location
United States of America
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
3 posts
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.
3 posts
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?
3057 posts
Location
United States of America
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