Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor")
- rednet.open("left")
- local prox = sensor.wrap("right")
- local playername = "mattivapa"
- local player = {}
- player.X = 14
- player.Y = 24
- player.dX = -1
- player.dY = 0
- player.energize = false
- local gold = 0
- local diamonds = 0
- local offset = {}
- offset.X = 20
- offset.Z = 14
- local facings = {{-1,0},{0,1},{1,0},{0,-1}}
- local yawToFacing = function(yaw)
- local ind = math.floor(math.fmod(math.abs(yaw)+45,360)/90)
- return facings[ind+1]
- end
- local worldToGame = function(X,Z)
- return {offset.Z+Z,offset.X-X}
- end
- local updatePlayerPos = function(p)
- -- print(1)
- local details = prox.getTargetDetails(playername)
- -- print(2)
- if details ~= nil then
- local pos = worldToGame(details.Position.X,details.Position.Z)
- local facing = yawToFacing(details.Yaw)
- p.X = pos[1]
- p.Y = pos[2]
- p.dX = facing[1]
- p.dY = facing[2]
- local g = 0
- local d = 0
- for k,v in pairs(details.Inventory) do
- if v["Name"] == "Diamond" then
- d = d+v["Size"]
- elseif v["Name"] == "Gold Ore" then
- g = g+v["Size"]
- end
- end
- if g > gold then
- gold = g
- print("Score: "..tostring(10*gold+50*diamonds))
- end
- if d > diamonds then
- diamonds = d
- print("Score: "..tostring(10*gold+50*diamonds))
- player.energize = true
- end
- end
- end
- while true do
- updatePlayerPos(player)
- --print("Sending:")
- --print(textutils.serialize(player))
- rednet.broadcast(textutils.serialize(player))
- if player.energize == true then
- player.energize = false
- rednet.broadcast(textutils.serialize(player))
- rednet.broadcast(textutils.serialize(player))
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment