Advertisement
Guest User

Untitled

a guest
Jun 29th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. from mcpi import minecraft
  2. from mcpi import block
  3. import math
  4. import sqlite3
  5. import time
  6.  
  7. log_times = 100 #現在位置を記録したい時間間隔[s]
  8. mc = minecraft.Minecraft.create()
  9.  
  10. #試しに1sずつ10回現在位置を記録してみます
  11. for i in range(0,10):
  12. playerPos = mc.player.getPos()
  13. #ユーザーが入力する事が無いのでSQLインジェクションなどは考えない物とします
  14. #現在のx,y,z座標を整数値で保持
  15. #小数点まで保持したい場合は、math.floorを取って下さい
  16. pos_x = (math.floor(playerPos.x))
  17. pos_y = (math.floor(playerPos.y))
  18. pos_z = (math.floor(playerPos.z))
  19. #SQLiteに接続し、Insert文を実行してコミット
  20. con = sqlite3.connect("data2.db")
  21. c = con.cursor()
  22. c.execute(u"insert into position(x,y,z) values(%f,%f,%f)" %(pos_x,pos_y,pos_z))
  23. con.commit()
  24. c.close()
  25. # print pos_x,pos_y,pos_z
  26. time.sleep(1.0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement