View Single Post
  #1  
Old 10-04-2012, 08:11 PM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Cooldown display.

Looks like this:
Name:  cooldown.gif
Views: 948
Size:  3.1 KB
Imagine that the chest is a skill icon and has the number of seconds left on the cooldown on it.

The code plus example of use (weapon script):
PHP Code:
//#CLIENTSIDE

function onCreated()
{
  
this.skillIconImg findimg(200);
  
with (this.skillIconImg) {
    
this.image "chest.png";
    
this.int(screenwidth 16);
    
this.int(screenheight 16);
    
this.layer 4;
  }
  
  
this.cooldownImg findimg(201);
  
with (this.cooldownImg) {
    
this.red 1;
    
this.green 1;
    
this.blue 1;
    
this.alpha 0.75;
    
this.mode 2;
    
this.layer 5;
  }
  
  
this.trigger("onTimeout"null);
}

function 
onTimeout()
{
  
this.cooldownProgress -= 0.01;
  if (
this.cooldownProgress 0this.cooldownProgress += 1;
  
  
this.cooldownImg.polygon this.getCooldownPolygon(this.cooldownProgress);
  for (
temp.0temp.this.cooldownImg.polygon.size(); temp.+= 2) {
    
this.cooldownImg.polygon[temp.0] *= 32;
    
this.cooldownImg.polygon[temp.0] += this.skillIconImg.x;
    
    
this.cooldownImg.polygon[temp.1] *= 32;
    
this.cooldownImg.polygon[temp.1] += this.skillIconImg.y
  }
  
  
setTimer(0.05);
}

//temp.progress goes from 0.0 to 1.0, where 0.0 is no cooldown and 1.0 is full cooldown.
//Returns an array compatible with TShowImg.polygon with coordinates ranging from (0, 0) to (1, 1).
function getCooldownPolygon(temp.progress)
{
  
temp.angleInDegrees temp.progress 360;
  
  if (
temp.angleInDegrees <= 0) return null;
  if (
temp.angleInDegrees >= 360) return {0.00.01.00.01.01.00.01.0};
  
  
temp.polygon = {
    
0.50.5,
    
0.50.0
  
};
  
  
temp.degtorad(90 temp.angleInDegrees);
  
temp.dx = +cos(temp.a);
  
temp.dy = -sin(temp.a);
  
  if (
temp.angleInDegrees 0) {
    if (
temp.angleInDegrees 45) {
      
temp.polygon.add(0.5 - (temp.dx/temp.dy) * 0.5);
      
temp.polygon.add(0);
    }
    else {
      
temp.polygon.add(0.0);
      
temp.polygon.add(0.0);
    }
  }
  
  if (
temp.angleInDegrees >= 45) {
    if (
temp.angleInDegrees 135) {
      
temp.polygon.add(0.0);
      
temp.polygon.add(0.5 - (temp.dy/temp.dx) * 0.5);
    }
    else {
      
temp.polygon.add(0.0);
      
temp.polygon.add(1.0);
    }
  }
  
  if (
temp.angleInDegrees >= 135) {
    if (
temp.angleInDegrees 225) {
      
temp.polygon.add(0.5 + (temp.dx/temp.dy) * 0.5);
      
temp.polygon.add(1.0);
    }
    else {
      
temp.polygon.add(1.0);
      
temp.polygon.add(1.0);
    }
  }
  
  if (
temp.angleInDegrees >= 225) {
    if (
temp.angleInDegrees 315) {
      
temp.polygon.add(1.0);
      
temp.polygon.add(0.5 + (temp.dy/temp.dx) * 0.5);
    }
    else {
      
temp.polygon.add(1.0);
      
temp.polygon.add(0.0);
    }
  }
  
  if (
temp.angleInDegrees >= 315) {
    if (
temp.angleInDegrees 360) {
      
temp.polygon.add(0.5 - (temp.dx/temp.dy) * 0.5);
      
temp.polygon.add(0.0);
    }
    else {
      
temp.polygon.add(0.5);
      
temp.polygon.add(0.0);
    }
  }
  
  return 
temp.polygon;

The important code with all the math in it is the getCooldownPolygon function.
Assembly required. "Batteries not included."
__________________
Testbed user: I figured since I can never find any scripters it was time to take desperate measures...and...TEACH MYSELF 0.0
Reply With Quote