SHARE
TWEET

Untitled

a guest Aug 14th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. How to let npc settings stay updated tick-friendly
  4.  
  5.  
  6. this script is more for a reference how to write tick friendly
  7.  
  8. */
  9.  
  10. var npcSettings = {
  11.     "Stats": {
  12.         "MaxHealth": 500,
  13.         "HealthRegen": 0,
  14.         "AggroRange": 24,
  15.         "CreatureType": 1, //Undede
  16.         "RespawnType": 0, //"Yes",
  17.         "RespawnTime": 86400,
  18.         "HideDeadBody": true,
  19.     },
  20.     "Ai": {    
  21.         "StopOnInteract": false,
  22.         "ReturnsHome": false,
  23.     },
  24.     "Display": {
  25.         "Size": 5,
  26.     }
  27. };
  28.  
  29. function interact(e) {
  30.    
  31.     //Change the values! Will only update when needed!!!
  32.     npcSettings['Display']['Size']++;
  33. }
  34.  
  35. function tick(e) {
  36.     updateNpc(e.npc);
  37. }
  38.  
  39. function updateNpc(npc) {
  40.     var hasChanged = false;
  41.  
  42.     for(var getname in npcSettings) {
  43.         var getter = npc['get'+getname](); //result of: npc.getDisplay(), npc.getAi(), ...
  44.         for(var setting in npcSettings[getname]) { //Loop settings, variable 'setting' =key
  45.             var value = npcSettings[getname][setting]; //value of setting
  46.  
  47.             if(getter['get'+setting]() != value) { //if current (ai,display,...) setting is not wanted value
  48.  
  49.                 getter['set'+setting](value); //Update value of current (ai,display,...) setting
  50.                 hasChanged = true; //Mark updated
  51.             }
  52.         }
  53.     }
  54.     if(hasChanged) { //Npc only resets now when something has changed, no unneccesary updates
  55.         npc.reset();
  56.     }
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top