Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var sched = [0,-1,-1,500,-1,-1,1000,-1,-1,1500,-1,-1,-1,-1,-1,2000,2500,3000,3500,4000,4500,5000,5500,6000,-1,-1,6500,-1,-1,7000,7500,8000,8500,9000,9500,10000,-1,-1,-1,-1,-1,-1,10500,-1,-1,11000,-1,11500,-1,12000,-1,12500,13000,13500,-1,14000,-1,14500,15000,15500,16000,16500,17000,17500,18000,18500,19000,19500,20000,20500,21000,21500,22000,22500,23000,23500
- ];
- var toX = [37,44,44,44,44,44,44,44,41,41,33,32,30,39,28,28,28,28,28,28,28,28,28,28,39,36,36,34,28,28,28,28,28,28,28,28,34,31,33,38,41,44,44,44,44,44,41,41,41,41,32,32,32,32,38,38,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37
- ];
- var toY = [81,80,80,80,80,80,80,80,80,80,76,70,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,71,70,72,79,80,80,80,80,80,80,80,80,80,81,81,81,81,80,80,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81,81
- ];
- var toZ = [143,142,140,140,145,143,143,144,143,143,157,174,187,195,197,197,197,197,197,197,197,197,197,197,195,195,195,198,197,197,197,197,197,197,197,197,191,187,176,161,150,140,140,145,143,143,143,143,139,139,146,146,146,146,140,140,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143
- ];
- var speed = 2;
- var worldtime = 0;
- var id = 0;
- var testc = 24000;
- var nextId = 0;
- var myX = 0;
- var myY = 0;
- var myZ = 0;
- var isStopped = false;
- var isDay = true;
- var check = false;
- var isNav = false;
- function init(event){
- event.npc.say("Testing, 1, 2, 3.");
- event.npc.timers.stop(2);
- event.npc.timers.start(2, 200, false); //Slow this down once code done.
- worldtime = (event.npc.world.getTime() % 24000);
- isDay = event.npc.world.isDay();
- //Check current point in schedule. Error catches despawning.
- testc = 24000;
- for(var c = 0; c < sched.length; c++){
- if(sched[c] > -1 && worldtime - sched[c] > -1 && worldtime - sched[c] < testc){
- testc = worldtime - sched[c];
- id = c;
- } // end if statement
- } // End for loop
- //Check next major point in schedule. This needs to be moved from init!
- for(var i =id; i < sched.length; i++){
- if(sched[i]>sched[id]){
- nextId = i;
- break;}
- }
- event.npc.say("The current schedule time is " + sched[id] + ".");
- } //end init event
- function interact(event){
- } //end interact event
- function target(event){
- isStopped = true;
- event.npc.say("I see something!");
- } //end target event
- function targetLost(event){
- isStopped = false;
- event.npc.say("I lost them...");
- } //end lost target event
- function timer(event){
- if(event.id == 2){
- worldtime = (event.npc.world.getTime() % 24000);
- if(isDay == false){
- isDay = event.npc.world.isDay();
- if(isDay == true){
- id = 0;
- }
- }
- event.npc.say("The time is " + worldtime + " and the current schedule id is " + id + ".");
- if(worldtime>=sched[id]){
- if(isStopped==false){
- myX = event.npc.getBlockX();
- myY = event.npc.getBlockY();
- myZ = event.npc.getBlockZ();
- if(myX == toX[id] && myY >= toY[id] - 1 && myZ == toZ[id]){
- event.npc.say("It's time to move.");
- id = id+1; //loop id once reaches end.
- event.npc.timers.stop(2);
- event.npc.timers.start(2, 10, false);
- }
- else{
- if((myX >= toX[id] -20 && myX <= toX[id] +20 && myY >= toY[id] -20 && myY <= toY[id] +20 && myZ >= toZ[id] -20 && myZ <= toZ[id] +20)){ //Is the NPC within navigating range?
- event.npc.say("I'm moving to " + toX[id] + ", " + toY[id] + " ," + toZ[id] + ".");
- isNav = event.npc.isNavigating();
- if (isNav == false){
- event.npc.navigateTo(toX[id],toY[id],toZ[id],speed);
- }
- event.npc.timers.stop(2);
- event.npc.timers.start(2, 20, false);
- }
- else{
- event.npc.say("I'm lost!");
- check = true;
- testc = 24000;
- for(var c = 0; c < sched.length; c++){
- if(sched[c] > -1 && worldtime - sched[c] > -1 && worldtime - sched[c] < testc){
- testc = worldtime - sched[c];
- id = c;
- } // end if statement
- } // End for loop
- for(var i =id; i < sched.length; i++){
- if(sched[i]>sched[id]){
- nextId = i;
- break;}
- }
- if (check = false){
- for (var n = id+1; n < nextId; n++){
- if(myX >= toX[n] -20 && myX <= toX[n] +20 && myY >= toY[n] -20 && myY <= toY[n] +20 && myZ >= toZ[n] -20 && myZ <= toZ[n] +20){
- id = n;
- check = false;
- break;
- }
- }
- }else{
- event.npc.setPosition(toX[id],toY[id],toZ[id]);
- check = false;
- }
- event.npc.timers.stop(2);
- event.npc.timers.start(2, 20, false);
- }
- }
- }
- else //isStopped==true; Aggression is inconsistent, and character may continue navigating mid-fight, or keep fighting.
- {
- event.npc.timers.stop(2);
- event.npc.timers.start(2, 100, false);
- }
- }
- else {
- event.npc.say("I'm where I need to be.");
- event.npc.timers.stop(2);
- event.npc.timers.start(2, 200, false); //slow this down once code done.
- }
- } //End world time check
- } //end timer events
- //Not happy with this code. Checks are too resource heavy. Main issue is that if the NPC gets stuck at a point they will constantly try to nav to that point and their schedule will not update.
- //Working on MK III, another rewrite, will use time blocks that are easier to index in the array, and force teleport the character if they are stuck. Will add arrays for time and animations too.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement