iMagicBae

Walking NPC - iMagic

Apr 27th, 2020
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Scripted by Graal2007722
  2. //#CLIENTSIDE
  3. function onCreated() {
  4.   showcharacter();
  5.   this.head = "mum_head71.png";
  6.   this.colors[0] = "orange";
  7.   this.colors[1] = "black";
  8.   this.colors[2] = "black";
  9.   this.colors[3] = "black";
  10.   this.colors[4] = "black";
  11.   this.shield = "no-shield.png";
  12.   setcharani("idle",NULL);
  13.   this.ap = 50;
  14.   this.nick = "Mary";
  15.   this.speed = 0.25;  // Customizable.
  16.   this.range = 1;  // Non-Customizable.
  17.   onNewState();
  18. }
  19.  
  20. function onNewState() {
  21.   temp.state = randomstring("walk", "idle");
  22.   if (temp.state == "walk") {
  23.     this.ani = temp.state;
  24.     this.isWalking = true;
  25.     setTimer(random(3,8));  // Timer to choose arbitrary state.
  26.     onNewDir();
  27.   } else {
  28.     this.ani = temp.state;
  29.     this.isWalking = false;
  30.     setTimer(random(3, 8));  // Timer to choose arbitrary state.
  31.   }
  32. }
  33.  
  34. function onNewDir(olddir) {
  35.   this.dir = int(random(0,4));
  36.   if (this.dir == olddir) {
  37.     onNewDir(this.dir);
  38.   }
  39.   switch (this.dir) {
  40.     case 0:
  41.     onMove(this.dir);
  42.     break;
  43.  
  44.     case 1:
  45.     onMove(this.dir);
  46.     break;
  47.  
  48.     case 2:
  49.     onMove(this.dir);
  50.     break;
  51.  
  52.     case 3:
  53.     onMove(this.dir);
  54.     break;
  55.   }
  56. }
  57.  
  58. function onMove(this.dir) {
  59.   if (this.isWalking) {
  60.     switch (this.dir) {
  61.       case 0:  // Move up.
  62.       for (i = this.y; i > 4; i -= this.speed) {
  63.         if (onwall(this.x,this.y - this.range)) { break; }
  64.         if (!this.isWalking) { break; }
  65.         sleep(0.01);
  66.         this.y -= this.speed;
  67.       }
  68.       onNewDir(this.dir);
  69.       break;
  70.  
  71.       case 1:  // Move left.
  72.       for (i = this.x; i > 4; i -= this.speed) {
  73.         if (onwall(this.x - this.range,this.y)) { break; }
  74.         if (!this.isWalking) { break; }
  75.         sleep(0.01);
  76.         this.x -= this.speed;
  77.       }
  78.       onNewDir(this.dir);
  79.       break;
  80.  
  81.       case 2:  // Move down.
  82.       for (i = this.y; i < 60; i += this.speed) {
  83.         if (onwall(this.x,this.y + this.range)) { break; }
  84.         if (!this.isWalking) { break; }
  85.         sleep(0.01);
  86.         this.y += this.speed;
  87.       }
  88.       onNewDir(this.dir);
  89.       break;
  90.  
  91.       case 3:  // Move right.
  92.       for (i = this.x; i < 60; i += this.speed) {
  93.         if (onwall(this.x + this.range,this.y)) { break; }
  94.         if (!this.isWalking) { break; }
  95.         sleep(0.01);
  96.         this.x += this.speed;
  97.       }
  98.       onNewDir(this.dir);
  99.       break;
  100.     }
  101.   }
  102. }
  103.  
  104. function onPlayerTouchsMe() {
  105.   sleep(0.01);
  106.   onNewDir(this.dir);
  107. }
  108.  
  109. function onTimeout() {
  110.   onNewState();
  111. }
Advertisement
Add Comment
Please, Sign In to add comment