Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.25 KB | None | 0 0
  1. --[[
  2. Script by Mock the bear
  3. ]]
  4. SNAKE = {
  5. _VERSION="1.0 by mock",
  6. ---Snake config
  7. itemid=1739,
  8. freeglobalstorage=28103,
  9. itemFood=6394,
  10. controlpos={x=1465,y=2629,z=6},
  11. exitpos = {x=1470,y=2620,z=7},
  12. centerpos={x=1464,y=2628,z=7},
  13. timer = function(cid,n,pos_,time)
  14. local pos_ = pos_ or {{SNAKE.centerpos}}
  15. setGlobalStorageValue(SNAKE.freeglobalstorage,cid)
  16. if not isPlayer(cid) then
  17. SNAKE.clean()
  18. return
  19. end
  20. for i,pos in pairs(pos_) do
  21. SNAKE.find_and_delete(pos[1])
  22. if i == 1 then
  23. pos[2] = SNAKE.copypos(pos[1])
  24. pos[1] = getPosByDir({x=pos[1].x,y=pos[1].y,z=pos[1].z,stackpos=255},getCreatureLookDir(cid))
  25. else
  26. pos[2] = SNAKE.copypos(pos[1])
  27. pos[1] = pos_[i-1][2]
  28. end
  29. local ret,p,walk = SNAKE.check(pos[1])
  30. if ret == 1 or ret == 3 then
  31. addEvent(doTeleportThing,1000,cid,SNAKE.exitpos)
  32. addEvent(doCreatureSay,1100,cid,'Points '..(#pos_-1)..'.')
  33. SNAKE.clean()
  34. setGlobalStorageValue(SNAKE.freeglobalstorage,0)
  35. return
  36. end
  37. if ret == 2 then
  38. doRemoveItem(p.uid,-1)
  39. if p.itemid == SNAKE.itemFood then
  40. pos_[#pos_+1] = {pos[2],pos[2]}
  41. for i=1,5 do
  42. addEvent(doSendMagicEffect,100*i,pos[1],29)
  43. end
  44. SNAKE.generateFood()
  45. end
  46. end
  47. doCreateItem(SNAKE.itemid,1,pos[1])
  48.  
  49. end
  50. local plpos = getCreaturePosition(cid)
  51. local generated = {}
  52. for i=0,3 do
  53. generated = getPosByDir({x=SNAKE.controlpos.x,y=SNAKE.controlpos.y,z=SNAKE.controlpos.z},i)
  54. end
  55. for i,pos in pairs(generated) do
  56. if SNAKE.samepos(plpos,pos) then
  57.  
  58. doTeleportThing(cid,SNAKE.controlpos,false)
  59. end
  60. addEvent(doSendMagicEffect,100,pos,56,cid)
  61. end
  62. addEvent(SNAKE.timer,time,cid,n,pos_,time)
  63. end,
  64. copypos = function(p)
  65. return {x=p.x,y=p.y,z=p.z,stackpos=p.stackpos}
  66. end,
  67. samepos = function(p1,p2)
  68. if p1.x == p2.x and p2.y == p2.y then
  69. return true
  70. end
  71. return false
  72. end,
  73. generateFood = function()
  74. local pp = {x=SNAKE.centerpos.x+math.random(-6,6),y=SNAKE.centerpos.y+math.random(-4,4),z=SNAKE.centerpos.z}
  75. for i=1,5 do
  76. addEvent(doSendMagicEffect,100*i,pp,30)
  77. end
  78. doCreateItem(SNAKE.itemFood,1,pp)
  79. end,
  80. clean = function()
  81. for y=-4,4 do
  82. for x=-6,6 do
  83. local pp = {x=SNAKE.centerpos.x+x,y=SNAKE.centerpos.y+y,z=SNAKE.centerpos.z}
  84. for i=250,255 do
  85. pp.stackpos = i
  86. local p = getThingFromPos(pp)
  87. if p.itemid ~= 0 then
  88. doRemoveItem(p.uid,-1)
  89. doSendMagicEffect(pp,15)
  90. end
  91. end
  92. end
  93. end
  94. end,
  95. check = function(pos)
  96. for i=1,10 do
  97. pos.stackpos = i
  98. local p = getThingFromPos(pos)
  99. if p.itemid == SNAKE.itemid then
  100. return 1,p,true
  101. elseif not SNAKE.isWalkable(pos) then
  102. return 3,p,false
  103. elseif p.itemid ~= 0 then
  104. return 2,p
  105. end
  106. end
  107. return false
  108. end,
  109. find_and_delete = function(pos)
  110. for i=0,255 do
  111. pos.stackpos = 255-i
  112. local p = getThingFromPos(pos)
  113. if p.itemid == SNAKE.itemid then
  114. return doRemoveItem(p.uid,1)
  115. end
  116. end
  117. end,
  118. isWalkable = function(pos, creature, proj, pz)-- by Nord
  119. if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
  120. if getTopCreature(pos).uid > 0 and creature then return false end
  121. if getTileInfo(pos).protection and pz then return false, true end
  122. local n = not proj and 3 or 2
  123. for i = 0, 255 do
  124. pos.stackpos = i
  125. local tile = getTileThingByPos(pos)
  126. if tile.itemid ~= 0 and not isCreature(tile.uid) then
  127. if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
  128. return false
  129. end
  130. end
  131. end
  132. return true
  133. end,
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement