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

Two Questions

Started by sirjason, 06 August 2015 - 01:26 PM
sirjason #1
Posted 06 August 2015 - 03:26 PM
Hello,

I have 2 Questions, but let me explain the server setup first. We are running Pixelmon (yeah yeah I know, but members of my group love it so what can I do), SGCraft which adds StarGates to the game and ComputerCraft along with a few more mods.

First question, how would I go about making it so that a computer was useable just once a person? I wanted to change the way the entrance to our server is. I want to give Pixelmon via ComputerCraft (since unless I read wrong would be possible as it could access the op command /pokegive) but I only want the player to be able to do that once, then not be able to either use the computer or pick a selection again, is this possible?

Second question, I know that SGCraft works with Computer Craft, already have it setup, but I was wondering is their a way to have a Wireless Computer that could access a computer on the other side (The main base this gate is at has a chunk loader and is always loaded) to give it a password so that it would shut down the protection (called an Iris) around the stargate so the player didn't get killed coming through. I already have the programs that come with SGCraft and have altered them to my liking.

If anyone could point me in the right direction for any existing programs I may be able to alter or any help at all, I would be very thankful.
Lupus590 #2
Posted 06 August 2015 - 05:29 PM
To answer you first question, you could use a peripheral mod which allows for unique identification of players (look for one where the layer touches a block to be read by the computer) you can then store this unique id and have your computer check this database for returning users.

For your second question, SGCraft provides a way for computers to send messages through a stargate, try using that.
Edited on 06 August 2015 - 03:34 PM
KingofGamesYami #3
Posted 06 August 2015 - 05:29 PM
First Question: Impossible, unless you can figure out who is using the computer. For example, some mods add a player detector block you can click. Put a computer behind one, have it check for the appropriate events and viola. You can use the fs API and a table (possibly saved by textutils.serialize) to make sure nobody gets to do it twice.

Example (may not be 100% accurate in all details:


local t = {}
if fs.exists( ".players" ) then
  local file = fs.open( ".players" )
  t = textutils.unserialize( file.readAll() )
  file.close()
end

local function save()
  local file = fs.open( ".players" )
  file.write( textutils.serialize( t ) )
  file.close()
end

while true do
  local event = {os.pullEvent()}
  if event[ 1 ] == "player" and not t[ event[ 2] ] then --#I'm not sure if I got the event parameters right, or the correct event name even!
    --#the player hasn't clicked before
    --#do things
    t[ event[2] ] = true
    save()
  end
end

If you've got questions about anything I did there, please ask!

Second Question: I've got no idea here.
Dog #4
Posted 06 August 2015 - 05:59 PM
In regard to your second question, ccDHD (shameless plug) provides that feature. It requires having programs from the ccDHD suite installed on computers at both gates, then you can use ccDialer to wirelessly dial gates and remotely open the target iris when the gates are connected.
H4X0RZ #5
Posted 07 August 2015 - 02:36 AM
If your server supports Bukkit you could make a custom plug-in to block the usage of a computer.
HPWebcamAble #6
Posted 07 August 2015 - 05:40 AM
For the the first question, you could definitely achieve this with a plugin, I could write it in about 15 minutes or less (if I wasn't on vacation right now - using my spare laptop)
However you would need to get Forge and Spigot or some similar Bukkit implementation to work together, which can be a hassle.

You can actually do it with a Command Computer assuming they are…
Only accessible by op and creative mode players
Explosion resistant
I believe these features were added in a recent version, so it should work.

If you'd like some pointers on how you'd do it either way, just ask :)/>
Bomb Bloke #7
Posted 07 August 2015 - 10:01 AM
Command blocks can assign stats to a special "scoreboard", and then choose whether to run them again based on those stats (like this). Given that you're probably going to want to use a command computer attached to an external touch-screen for this task anyway, you should be able to simply use the same method.
HPWebcamAble #8
Posted 07 August 2015 - 06:47 PM
Command blocks can assign stats to a special "scoreboard", and then choose whether to run them again based on those stats (like this). Given that you're probably going to want to use a command computer attached to an external touch-screen for this task anyway, you should be able to simply use the same method.

You could use the Command Computer to alter scoreboard values, but it isn't easy. To get the value of an objective, you have to temporarily increase or decrease it, which makes it return a statement that contains the new score. And no, you can't add 0, that was the first thing I tried :P/>

Personally, I think it would be easier to just use the computer to store if a player has received the item.
sirjason #9
Posted 07 August 2015 - 09:54 PM
For the the first question, you could definitely achieve this with a plugin, I could write it in about 15 minutes or less (if I wasn't on vacation right now - using my spare laptop)
However you would need to get Forge and Spigot or some similar Bukkit implementation to work together, which can be a hassle.

You can actually do it with a Command Computer assuming they are…
Only accessible by op and creative mode players
Explosion resistant
I believe these features were added in a recent version, so it should work.

If you'd like some pointers on how you'd do it either way, just ask :)/>

If your asking are the commands OP only, then yes, the command is /pokegive arg1 arg2 which is only avaible to OP players.
HPWebcamAble #10
Posted 07 August 2015 - 09:58 PM
If your asking are the commands OP only, then yes, the command is /pokegive arg1 arg2 which is only avaible to OP players.

Actually I meant the Command Computers, I believe when they were first introduced, anyone could access them, and therefore run OP-only commands.

I think that's been changed, but you might want to test it in your version just in case.
Bomb Bloke #11
Posted 07 August 2015 - 11:53 PM
They've always been OP-only in terms of "use", but initially other players could take a pickaxe to them. That's since changed.
cmdpwnd #12
Posted 08 August 2015 - 03:39 AM
why not just have each computer have a startup login for each user and check to see if the user has authenticated before, then if true shutdown?


  local users = {--[[username]]={--[[false or true]],--[[password]]}}

  writeLine("Username: ")
  local userN = read()
  writeLine("\n Password: ")
  local phrase = read("*")
  if not users[userN][1] then os.shutdown end
  if not phrase == users[userN][2] then 
   print("Wrong Password")
   os.sleep(2)
   os.reboot()
  end
Edited on 08 August 2015 - 01:47 AM
HPWebcamAble #13
Posted 08 August 2015 - 05:15 AM
why not just have each computer have a startup login for each user and check to see if the user has authenticated before, then if true shutdown?

Why would you shutdown the computer? Then new players that join can't use it unless the chunk reloads

The code would be more like this:

--# Load users that have already gotten the items from a file

while true do
  --# Wait for some signal to check nearby users - maybe a redstone signal from a button or pressure plate

  --# Use the /tp @a[r=10] ~ ~ ~ command to find out who is near the computer

  --# Check if each nearby user has gotten the items
  --# If so, do nothing for that user
  --# If not, /give them the items, add them to the list and save the list

end
I'd love to write the full program, but don't have time at the moment
Edited on 08 August 2015 - 10:09 PM
Bomb Bloke #14
Posted 08 August 2015 - 07:02 AM
why not just have each computer have a startup login for each user and check to see if the user has authenticated before, then if true shutdown?

Because then an administrative user would have to create each account in the first place - in which case they might as well just /pokegive themselves. The point is to handle new users on the server automatically.

Why would you shutdown the computer? Then new players that join can't use it unless the chunk reloads

If the computer shut itself down, then it'll stay off until someone turns it back on (which, yes, would require an OP in the case of command computers). Merely reloading chunks won't restart computers unless they were already turned on when their chunks unloaded.
Astrophylite #15
Posted 08 August 2015 - 01:17 PM
If you have MoarPeripherals then attach a player detector to the command computer.
Then put this code in the startup:

local tPlayers = {}
if fs.exists(".player") then
  local file = fs.open(".player","r")
  local sPlayers = file.readAll()
  table.insert(tPlayers,#tPlayers+1,sPlayers)
  file.close()
end
local file = fs.open(".player","a")
function add(playerAdd)
  file.writeLine(playerAdd)
  file.flush()
  table.insert(tPlayers,#tPlayers+1,playerAdd)
end
while true do
  local _, _, player = os.pullEvent("player")
	for i = 1,#tPlayers do
	  if tPlayers[i] == player then
		--do nothing
	  else
		add(player)
		commands.execute(" pokegive command goes here " )
		sleep(1)
	end
  end
end
Edited on 08 August 2015 - 11:44 AM
HPWebcamAble #16
Posted 09 August 2015 - 12:12 AM
If you have MoarPeripherals then attach a player detector to the command computer.

If you already have MoarPeripherals, that would make the program a little easier, but if you don't, it should still be do-able.


Why would you shutdown the computer? Then new players that join can't use it unless the chunk reloads
Merely reloading chunks won't restart computers unless they were already turned on when their chunks unloaded.

Ah ok, I can never remember how that works.
sirjason #17
Posted 09 August 2015 - 07:44 AM
Thanks for the help so far guys, looks like I will have to add this MoarPeripherals mod to the server. Let me ask this, is it possible to have the computer still use that code, but offer a menu select where they can pick one of the ones we have setup to be starters? If I understand the way it works I would add if input == 1 then etc etc part of the command for each one I which to offer correct?
Bomb Bloke #18
Posted 09 August 2015 - 08:55 AM
Yes, you'd connect a command computer to an advanced monitor. The touchpoint API would make the interface easy - when someone hits the player detector, show 'em three buttons, then give them whichever they choose.