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

[OpenPeripheral] find location of player

Started by Creeper9207, 15 February 2015 - 12:13 AM
Creeper9207 #1
Posted 15 February 2015 - 01:13 AM
i made a snippet of code to get player locations, inventory data, and other various data down to whether the player is on a ladder, and write it to the file.

the coordinates are relative to the sensor, add you're coordinates to the coordinates displayed
in the output file to get the actual coordinates

make sure to replace "NAME_OF_REPORT_FILE" and "USERNAME_HERE" with the respected properties

--code by creeper9207
ip = peripheral.wrap("left")
ifile = fs.open("/NAME_OF_REPORT_FILE", "w")
i = peripheral.call("top", "getPlayerData", "USERNAME_HERE")
i2 = textutils.serialize(i)
ifile.write(i2)
ifile.flush()
ifile.close()
Edited on 21 March 2015 - 12:59 AM
Jandras #2
Posted 17 February 2015 - 04:56 PM
Problem with using the sensor like this is that it only has like a 5-6 block radius. Also the code is too short and generic to call it "my work".
Creeper9207 #3
Posted 18 February 2015 - 12:37 AM
very true, this is more of a tutorial
Lupus590 #4
Posted 12 March 2015 - 08:22 PM
change your code tags << to [ (and >> to ])

looks good though
Edited on 12 March 2015 - 07:31 PM
Kouksi44 #5
Posted 12 March 2015 - 09:02 PM
Is there any particular reason you call flush on the file handle right before you close it ? As soon as you close a file handle everything is written to the file . No flushing necessary ?

Also why are you wrapping the peripheral on the left side to "ip" but call the peripheral on the top manually on peripheral.call() ?
This way ip is rather pointless ^^
Creeper9207 #6
Posted 21 March 2015 - 01:57 AM
I like to jump the gun.

note: only works in Older versions of OPA, ex: it works in crackpack 1.5.1.0
Edited on 21 March 2015 - 12:59 AM