Light fading made easy!

I thought i’d share this simple light fading script seeing as it’s part useful and there are scripts here which are far less sophisticated(I s’pose).
So here it is!

This is the weapon which you need not worry about, it’ll automatically take care of values being input to make sure a number doesn’t get
caught in a state where it could cause possible epilepsy.

// NPC made by tricxta
if (playerenters){
  if (!isweapon)toweapons -lightFade;
  setarray this.data,4;
  this.loop = 1;//keep track of changes so the timeout isn't used unnecessarily

  timeout = 0.05;
}

if (fadeLight){
  //red,green,blue,alpha,fade-speed
  this.replace = {strtofloat(#p(0)),strtofloat(#p(1)),strtofloat(#p(2)),strtofloat(#p(3)),strtofloat(#p(4))};

  this.factor = this.replace[4];

  for (this.i = 0;this.i<5;this.i++){//make all numbers factors of the increment value
    this.replace[this.i] = int(this.replace[this.i]/this.factor)*this.factor;
    this.data[this.i] = int(this.data[this.i]/this.factor)*this.factor;
  }

  this.loop = 1;
  timeout = 0.05;
}

if (timeout && this.loop == 1 && isweapon){
  seteffect this.data[0],this.data[1],this.data[2],this.data[3];

  this.loop = 0;
  for (this.i = 0;this.i<4;this.i++){
    if (!this.data[this.i] == this.replace[this.i]){
      this.data[this.i] += (this.replace[this.i]-this.data[this.i])/abs(this.replace[this.i]-this.data[this.i])*this.replace[4];
      this.loop = 1;
    }
  }

  timeout = 0.05;
}

And here’s a simple script toggling between two light stages, for the sake of this example i’ve used messy numbers to
demonstrate the script fixes it all up and still gives an effect close to the original requested.
The lightFade request can obviously be triggered by anything but for this example i’ve just used playertouchsme.

[CODE]
// NPC made by tricxta
if (playerenters){
setshape 1,32,32;
}

if (playertouchsme){
this.touched = (this.touched + 1)%2;
for (this.i = 0;this.i<weaponscount;this.i++){
if (strequals(#w(this.i),-lightFade)){
//red,green,blue,alpha,fade-speed
if (this.touched == 1)callweapon this.i,fadeLight,0,0.423,0.03,0.2,0.1;
else callweapon this.i,fadeLight,0,0,0.03,0.3,0.1;
}
}
}
[/php]

Note: don’t be a derp and make any of the values greater than 1 or less than 0 then complain it messes up because of course it will.

it was already easy ~_~
Over complicating things as always, eh? Oh well, practice is practice.

Nope, if you used the example given you’d find to script it otherwise requires alot more effort then what it requires to use this.
This also works moving across levels as well. Something a npc can’t do!