

/* AMX Mod Script 
* 
* PlayerTrails 
* 
* 2003 - Lazy <the_lazy_one_09@hotmail.com> 
* 
* Allows players to give themselves a trail that is persistant even through death. 
good for clan training 
* 
* New Client Commands: trailme <r> <g> <b> (Without rgb specified, color will be random),,, 
*         killtrail 
* 
* Note: This requires SpaceDude's XtraFun module in order to run!!! 
*/ 

#include <amxmod> 
#include <xtrafun> 

new Trailing[33] 
new TempKill[33] 
new TrailR[33] 
new TrailG[33] 
new TrailB[33] 
new laserbeam 

public remove_trail(id) 
{ 
   message_begin(MSG_BROADCAST, SVC_TEMPENTITY) 
   write_byte(99) 
   write_short(id) 
   message_end() 
} 

public make_trail(id, iRed, iGreen, iBlue, spr) 
{ 
   message_begin(MSG_BROADCAST, SVC_TEMPENTITY) 
   write_byte(22) 
   write_short(id) 
   write_short(spr) 
   write_byte(45) 
   write_byte(8) 
   write_byte(iRed) 
   write_byte(iGreen) 
   write_byte(iBlue) 
   write_byte(150) 
   message_end() 
} 

public plugin_init() 
{ 
   register_plugin("PlayerTrails", "1.0", "Lazy") 
   register_clcmd("trailme", "TrailCMD", 0, "Usage: trailme <r> <g> <b>") 
   register_clcmd("killtrail", "TrailKILL", 0, " kills a trail") 
    
   register_event("DeathMsg", "DeathIsBad", "a") 
   register_event("ResetHUD", "LifeIsGood", "be") 
    
   set_task(3.0, "MoveCheck", 24, "", 0, "b") 
    
   return PLUGIN_CONTINUE 
} 

public plugin_precache() 
{ 
   laserbeam = precache_model("sprites/laserbeam.spr") 
    
   return PLUGIN_CONTINUE 
} 

public DeathIsBad()   // User still has a trail, but remove it until he/she spawns again 
{ 
   new victim = read_data(2)    
    
   if (Trailing[victim] == 1) 
   { 
      remove_trail(victim) 
      TempKill[victim] = 1 
   } 
} 

public LifeIsGood() 
{ 
   // Loop through all the players, kill beams and re-add them 
    
   new i 
    
   for (i = 1; i < 33; i++) 
   { 
      if (Trailing[i] != 0) 
      { 
         remove_trail(i) 
         make_trail(i, TrailR[i], TrailG[i], TrailB[i], laserbeam) 
         TempKill[i] = 0 
      } 
   } 
} 

public MoveCheck() 
{ 
   new Velocity[3] 
   new i 
    
   for (i = 1; i < 33; i++) 
   { 
      if (Trailing[i] == 1) 
      { 
         if (TempKill[i] == 1) 
            continue 
          
         get_user_velocity(i, Velocity) 
          
         if (Velocity[0] == 0 && Velocity[1] == 0 && Velocity[2] == 0) 
         { 
            remove_trail(i) 
            make_trail(i, TrailR[i], TrailG[i], TrailB[i], laserbeam) 
         } 
      } 
   } 
} 

public TrailCMD(id) 
{ 
   if (Trailing[id] != 0) 
      return PLUGIN_HANDLED 
    
   new iRed 
   new iGreen 
   new iBlue 
    
   if (read_argc() == 1) 
   { 
      iRed = random_num(0, 255) 
      iGreen = random_num(0, 255) 
      iBlue = random_num(0, 255) 
   } 
   else 
   { 
      new sRed[4] 
      new sGreen[4] 
      new sBlue[4] 
       
      read_argv(1, sRed, 4) 
      read_argv(2, sGreen, 4) 
      read_argv(3, sBlue, 4) 
       
      iRed = strtonum(sRed) 
      iGreen = strtonum(sGreen) 
      iBlue = strtonum(sBlue) 
   } 
    
   Trailing[id] = 1 
   TrailR[id] = iRed 
   TrailG[id] = iGreen 
   TrailB[id] = iBlue 
    
   make_trail(id, iRed, iGreen, iBlue, laserbeam); 
    
   return PLUGIN_HANDLED 
} 

public TrailKILL(id) 
{ 
   if (Trailing[id] != 1) 
      return PLUGIN_HANDLED 
    
   Trailing[id] = 0 
   TrailR[id] = 0 
   TrailG[id] = 0 
   TrailB[id] = 0 
   TempKill[id] = 0 
    
   remove_trail(id) 
    
   return PLUGIN_HANDLED 
} 


