Guest User

Untitled

a guest
Jan 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. //Put this on the MOBSPAWNERS OnUpdate
  2.  
  3. //Working out the monsters Co ords
  4. var x1 = ent.getPosition().x;
  5. var y1 = ent.getPosition().y;
  6. var z1 = ent.getPosition().z;
  7.  
  8. //Working out the players Co ords
  9. var x2 = player.getPosition().x;
  10. var y2 = player.getPosition().y;
  11. var z2 = player.getPosition().z;
  12.  
  13. //Working out the difference between the player and monster
  14. var xx = abs(x2 - x1) * abs(x2 - x1);
  15. var yy = abs(y2 - y1) * abs(y2 - y1);
  16. var zz = abs(z2 - z1) * abs(z2 - z1);
  17.  
  18. //Declaring variable ' D ' as the difference of the player and monster
  19. var D = Math.sqrt(xx + yy + zz);
  20.  
  21. //Script for distance mechanic
  22. if (D > 10){
  23. ent.setMoveSpeed(0.1);
  24. }else{
  25. ent.setMoveSpeed(100);
  26. }
  27.  
  28.  
  29. function abs (n){
  30. if (n < 0)
  31. n = 0 - n;
  32.  
  33. return n;
  34. }
Add Comment
Please, Sign In to add comment