Jump to content




Help with tables and OpenPeripheral's "Sensor"? First project.


  • You cannot reply to this topic
4 replies to this topic

#1 BrandenKP

  • New Members
  • 2 posts

Posted 01 June 2014 - 06:28 AM

Hi, I'm currently writing a program for people on a server to show stats about players of interest. I was really interested in Watch_Dogs, and it seemed like a fun project to create a "profiler" that allowed you to look up a player on the fly, know some information about them, and perhaps challenge them to a duel. As you can see by the source code, however, I haven't been having much luck getting anything that would be helpful to show in a concise (and correct!) way.

Anyhow, I don't have a lot of coding experience (I've just picked up LUA a few days ago, if I can be honest) but I came into a few snares:

  • I can loop through s.getPlayerData to get EVERYTHING, and I can loop through tables WITHIN tables (s.getPlayerData.position, for instance) but I can't seem to get values within tables to display (health, for instance, will give nil if I try to do s.getPlayerData.health, although I KNOW it simply doesn't work like that..)

  • One of the drawbacks to the sensor is that it gives data relative to itself, not relative to 0,0. Typically, that's fine, but it means that the coordinates will have to be calibrated to the sensor's position. Is there any way to "grab" the information from s.getPlayerData.position, and then apply a little math to it so it spits out the right coordinates? (For example, if the sensor is at x1, y1, z1, and the target is at x10, y10, z10, the program prints x10, y10, z10 instead of x11, y11, z11.)

Edit: I should mention I am using the CrackPack's most recent version, if that helps. (/r/crackpack)

Edited by Lyqyd, 01 June 2014 - 07:46 AM.
fix formatting


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 01 June 2014 - 07:47 AM

Please don't change the size of the text. I had to edit your post to make it readable.

#3 Whitecatblack

  • Members
  • 49 posts
  • LocationUnited States (EST)

Posted 01 June 2014 - 08:43 AM

So, as a foreword, I don't use sensors or terminal glasses much, but lets see what I can do.

BrandenKP said:

I can loop through s.getPlayerData to get EVERYTHING, and I can loop through tables WITHIN tables (s.getPlayerData.position, for instance) but I can't seem to get values within tables to display (health, for instance, will give nil if I try to do s.getPlayerData.health, although I KNOW it simply doesn't work like that..)
Well the correct way to call a value in a table is like this:
s.getPlayerData("username")["health"]
Which will return the target's current health, out of 20 (i.e. 16/20 being 8 hearts full). So you can apply that to anything you need to pull from that table.

BrandenKP said:

One of the drawbacks to the sensor is that it gives data relative to itself, not relative to 0,0. Typically, that's fine, but it means that the coordinates will have to be calibrated to the sensor's position. Is there any way to "grab" the information from s.getPlayerData.position, and then apply a little math to it so it spits out the right coordinates? (For example, if the sensor is at x1, y1, z1, and the target is at x10, y10, z10, the program prints x10, y10, z10 instead of x11, y11, z11.)
So for this, the sensor, as far as I can tell, reads out position in reference to itself. This could be useful, but from what I can guess, you sound like you want to know the true co-ordinates of the player. If the sensor itself isn't going to move or anything, then this can be done much simpler by manually entering the sensor's co-ordinates and adding the relative position of the player to it:
x = math.floor("sensorPositionX"+s.getPlayerData("playername")["position"]["x"])
x is now equal to target player's actual position in the world, rounded down to the nearest whole number. This tactic can be applied to the y and z values as well.

Hope this is what you were looking for,
Whitecatblack

Edited by Whitecatblack, 01 June 2014 - 08:56 AM.


#4 BrandenKP

  • New Members
  • 2 posts

Posted 01 June 2014 - 04:17 PM

View PostLyqyd, on 01 June 2014 - 07:47 AM, said:

Please don't change the size of the text. I had to edit your post to make it readable.

Sorry, I copied and pasted it from a different post I made on reddit. :(

View PostWhitecatblack, on 01 June 2014 - 08:43 AM, said:

So, as a foreword, I don't use sensors or terminal glasses much, but lets see what I can do.

BrandenKP said:

words
Well the correct way to call a value in a table is like this:
s.getPlayerData("username")["health"]
Which will return the target's current health, out of 20 (i.e. 16/20 being 8 hearts full). So you can apply that to anything you need to pull from that table.

BrandenKP said:

words
So for this, the sensor, as far as I can tell, reads out position in reference to itself. This could be useful, but from what I can guess, you sound like you want to know the true co-ordinates of the player. If the sensor itself isn't going to move or anything, then this can be done much simpler by manually entering the sensor's co-ordinates and adding the relative position of the player to it:
x = math.floor("sensorPositionX"+s.getPlayerData("playername")["position"]["x"])
x is now equal to target player's actual position in the world, rounded down to the nearest whole number. This tactic can be applied to the y and z values as well.

Hope this is what you were looking for,
Whitecatblack

Thank you for the quick response! I'll try what you suggested immediately.

#5 Whitecatblack

  • Members
  • 49 posts
  • LocationUnited States (EST)

Posted 01 June 2014 - 09:39 PM

BrandenKP said:

Thank you for the quick response! I'll try what you suggested immediately.
No problem. I've been fooling around a bit with your whole idea, so if something doesn't work or you are looking for a way to do something, just post a response and I'll probably be able to help.

Whitecatblack





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users