SHARE
TWEET

Untitled

a guest Aug 14th, 2019 67 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 updateNpc(npc) { //Tick friendly function
  30.     var hasChanged = false;
  31.    
  32.     for(var getname in npcSettings) {
  33.         var getter = npc['get'+getname](); //result of: npc.getDisplay(), npc.getAi(), ...
  34.         for(var setting in npcSettings[getname]) { //Loop settings, variable 'setting' =key
  35.             var value = npcSettings[getname][setting]; //value of setting
  36.  
  37.             if(getter['get'+setting]() != value) { //if current (ai,display,...) setting is not wanted value
  38.                 getter['set'+setting](value); //Update value of current (ai,display,...) setting
  39.                 hasChanged = true; //Mark updated
  40.             }
  41.         }
  42.     }
  43.     if(hasChanged) { //Npc only resets now when something has changed, no unneccesary updates
  44.         npc.reset();
  45.     }
  46. }
  47.  
  48. function interact(e) {
  49.    
  50.     //Change the values! Will only update when needed!!!
  51.     npcSettings['Display']['Size']++;
  52. }
  53.  
  54. function tick(e) {
  55.     updateNpc(e.npc);
  56. }
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