Advertisement
Hojjke

Untitled

Oct 15th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. @TypedServerCommand('wcs_teleport_new')
  2. def teleport_new(command_info, player:convert_userid_to_player, distance:int=0):
  3. if player is None:
  4. return
  5. coords = player.get_view_coordinates()
  6. pre_coords = player.origin
  7. post_coords = get_coord_with_distance(pre_coords, coords, distance)
  8. post_coords[2] += 10
  9.  
  10. if not is_player_stuck(player.index, post_coords):
  11. player.origin = post_coords
  12.  
  13. def is_player_stuck(player_index, origin):
  14. '''Return whether or not the given player is stuck in solid.'''
  15.  
  16. # Get the player's PlayerInfo instance...
  17. player_info = playerinfo_from_index(player_index)
  18.  
  19. # Get the player's origin...
  20. # origin = player_info.origin
  21.  
  22. # Get a Ray object based on the player physic box...
  23. ray = Ray(origin, origin, player_info.mins,
  24. player_info.maxs)
  25.  
  26. # Get a new GameTrace instance...
  27. trace = GameTrace()
  28.  
  29. # Do the trace...
  30. engine_trace.trace_ray(ray, ContentMasks.PLAYER_SOLID, TraceFilterSimple(
  31. PlayerIter()), trace)
  32.  
  33. # Return whether or not the trace did hit...
  34. return trace.did_hit()
  35.  
  36.  
  37. def get_coord_with_distance(player_coords, coords, distance):
  38. vector1 = Vector(*coords)
  39. vector2 = Vector(*player_coords)
  40.  
  41. length = (vector2 - vector1).length
  42.  
  43. velocity = vector1 - vector2
  44. velocity1 = [(velocity[x] / length) for x in (0, 1, 2)]
  45.  
  46. if length > distance + 80:
  47. length = distance + 80
  48.  
  49. velocity2 = Vector(*[velocity1[x] * (length - 80) for x in (0, 1, 2)])
  50.  
  51. return player_coords + velocity2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement