Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.80 KB | None | 0 0
  1. #define MAIN_MAP "map1" //you only want clicks to work on the main map element. You should change this define to the id of your main map
  2. #define TARGET_LOSE_THRESHOLD 16 //don't bother chasing something if it is more than 16 tiles away.
  3.  
  4. #define TICK_LAG 0.25 //set this to 10 divided by world.FPS
  5.  
  6. //this is where you would define your binds. Simply define them as numbers starting at 1, then update the BindKey() verb as necessary to handle behavior.
  7. #define BIND_JUMP 1
  8. #define BIND_INVENTORY 2
  9.  
  10. #define TAP_THRESHOLD 2.5
  11.  
  12. client
  13. var/tmp
  14. move_keys = 0 //stores the actual state of the movement keys
  15. move_dir = 0 //stores the direction the client is trying to move the mob in
  16. move_loop = 0 //stores the current move_loop's starting time
  17.  
  18. last_key = 0 //stores the last key that was actually pressed
  19. //these lists must be as long as 4+ the number of binds you define.
  20. list/key_state = list(0,0,0,0,0,0) //stores the on-off state of each registered key
  21. list/key_time = list(-1#INF,-1#INF,-1#INF,-1#INF,-1#INF,-1#INF) //stores the time that the registered key was pressed or released
  22. list/key_taps = list(0,0,0,0,0,0) //stores the number of times a key has been pressed in sequence. This allows for dealing with double and triple taps.
  23. atom/move_target
  24. proc
  25. //this drives movement behavior.
  26. MoveLoop()
  27. if(move_loop) return //only call once while active
  28. move_loop = world.time
  29. //repeat while move_keys are being held down
  30. var/turf/t
  31. var/tdist
  32. var/tdir
  33. while(move_keys||move_target) //add a clause for click movement
  34. if(move_dir)
  35. t = get_step(mob,move_dir)
  36. if(t)
  37. Move(t,move_dir)
  38. if(move_target)
  39. move_target = null
  40. else if(move_target) //this branch handles click movement
  41. tdist = get_dist(src,move_target)
  42. if(!tdist||tdist>TARGET_LOSE_THRESHOLD||move_target.z!=mob.z) //if the target is already in range, out of range or z is not equal to mob's
  43. move_target = null //remove the move_target
  44. else //otherwise, chase it like a dummy
  45. tdir = get_dir(src,move_target)
  46. if(!Move(get_step(src,tdir),tdir)) //stop chasing when an obstacle is encountered
  47. move_target = null
  48. sleep(TICK_LAG)
  49. move_loop = 0
  50. verb
  51. //called when a movement key has been pressed.
  52. MoveKey(dir as num,state as num)
  53. set hidden = 1
  54. var/opp = turn(dir,180)
  55. var/pos = log(2,dir)+1
  56. if(move_target) //if we currently have a move target, pressing any move keys will stop chasing that target
  57. move_target = null
  58. if(state&&++key_state[pos]==1)
  59. //key track of the keytap state
  60. if(world.time-key_time[pos]>TAP_THRESHOLD)
  61. key_taps[pos] = 1
  62. else if(last_key==pos)
  63. ++key_taps[pos]
  64. else
  65. key_taps[pos] = 1
  66. last_key = pos
  67.  
  68. //keep track of the move keys and direction
  69. move_keys |= dir
  70. if(move_keys&opp)
  71. move_dir &= ~opp
  72. else
  73. move_dir |= dir
  74. //store the time of the event
  75. key_time[pos] = world.time
  76. //this is an example of handling double-taps for movement
  77. /*if(move_keys==dir&&key_taps[pos]==2)
  78. mob.Dash(dir,0,pos)*/
  79. else if(!state&&--key_state[pos]==0)
  80. //this is a key release
  81. move_keys &= ~dir
  82. if(move_keys&opp)
  83. move_dir |= opp
  84. else
  85. move_dir &= ~dir
  86. //store the time of the event
  87. key_time[pos] = world.time
  88. //attempt to call MoveLoop if there are keys being held down
  89. if(move_keys&&!move_loop)
  90. MoveLoop()
  91.  
  92. //called when a registered bind has been pressed
  93. BindKey(key as num,state as num)
  94. set hidden = 1
  95. var/pos = key+4
  96. key_state[pos] = state
  97. //this is a keypress
  98. if(state)
  99. last_key = pos
  100. //keep track of double, triple, quadruple, etc taps
  101. if(world.time-key_time[pos]>TAP_THRESHOLD)
  102. key_taps[pos] = 1
  103. else
  104. ++key_taps[pos]
  105. /*switch(key)
  106. //these are just examples, use your game's binds and functions here.
  107. if(BIND_JUMP)
  108. if(state)
  109. switch(move_dir&(EAST|WEST))
  110. if(EAST)
  111. mob.Jump(60)
  112. if(WEST)
  113. mob.Jump(120)
  114. else
  115. mob.Jump(90)
  116. if(BIND_INVENTORY)
  117. if(state)
  118. if(interface.inventory.showing)
  119. interface.inventory.Hide()
  120. interface.equipment.Hide()
  121. else
  122. interface.inventory.Show()
  123. interface.equipment.Show()*/
  124.  
  125. Click(atom/movable/object,location,control,params)
  126. . = object.Click(location,control,params) // by default, atom.Click() doesn't return anything. If you want the atom's Click() function to not trigger a click-to-move and instead consume the client's Click, return 1 in that atom's Click() function.
  127. if(!.&&control==MAIN_MAP&&object.z&&!move_keys) //ensure object is on the map, and not in the screen or in a statpanel/grid. Also ensure the client isn't currently attempting to move using the movement keys.
  128. if(istype(object))
  129. move_target = object
  130. else
  131. var/turf/t = object
  132. if(!istype(t))
  133. var/list/l = params2list(params)
  134. l = screen_loc2num(l["screen-loc"]) //from DM.StdLib
  135. t = locate((bound_x+l[1]-1)/TILE_WIDTH+1,(bound_y+l[2]-1)/TILE_HEIGHT+1,eye:z) //get the turf location; uses BYOND 509 feature that is currently broken.
  136. if(!t) return
  137. move_target = t
  138. if(!move_loop)
  139. MoveLoop()
  140.  
  141. North()
  142. South()
  143. East()
  144. West()
  145. Northeast()
  146. Southeast()
  147. Southwest()
  148. Northwest()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement