
   /*********************************************************************
   ******
   * amx_ejl_jedipunish.sma     version 1.8   Date: 1/12/2003
   *  Author: Eric Lidman      ejlmozart@hotmail.com
   *  Alias: Ludwig van        Upgrade:
   http://lidmanmusic.com/cs/plugins.html
   *
   *  A  retribution  plugin with a Starwars Jedi theme to it in that you
   can
   *  punish/abuse  a  player with the lighnining that the emperor shoots
   out at
   *  young  Skywalyker  just  like  in Return of the Jedi. It also has a
   non-
   *  lethal version just so you can enjoy the special effects without
   *  hurting anyone. Go ahead and spam with it -- lots of blue lightning
   is
   *  cool!  Lighning  goes from the admin to the player being zapped, if
   the
   *  admin  zaps  himself, lighning origin is random. There is an option
   to
   *  zap  whoever  is  in  your  crosshairs.  I  would  suggest you bind
   "amx_zap_aim"
   *  to a key, and use that as your zapping 'fire button' so to speak.
   *  When  I  get  around to it, Ill finish the lightsaber too. See BETA
   below:
   *
   *
   * COMMANDS:
   *
   *    amx_zap  <part  of nick> <optional health to take - default is to
   kill>
   *    amx_zap_jk <part of nick>
   *    amx_zap_aim <optional health to take - default is to kill>
   *    amx_zap_aim_jk
   *
   * EXAMPLES OF ACTUAL USAGE:
   *
   *    amx_zap Lud     --- zaps Lud and kills him
   *    amx_zap Lud 45  --- zaps Lud and takes 45 health away
   *    amx_zap_jk Lud  --- zaps Lud and takes no health away
   *    amx_zap_aim     --- zaps player in your crosshairs and kills him
   *    amx_zap_aim  5   ---  zaps  player in your crosshairs and takes 5
   health
   *
   * ADDITIONAL SETUP:
   *  There  is  a  sound cut from Return of the Jedi that can be used to
   enhance
   *  the effect. You may need to make/edit some res files to get it to
   *  download  to  your clients or use my sound download manager plugin.
   The
   *  sound goes in the ..sound/misc folder on your server.
   *  Thanks  to  maddmaxx  from  the AMXmod forums for getting the sound
   clip.
   *  Get the sound off the forum amx_jedizap.zip, or at this link:
   *  http://lidmanmusic.com/cs/amx_jedizap_v3.zip
   *
   *  BETA:  amx_lightsaber  <mode 1, 2, 3, 4, 5> <color - done like tsay
   color>
   *
   **********************************************************************
   ****/
   #include <amxmod>
   #include <amxmisc>
   new light
   new smoke
   new saber
   new just_k[33]
   new ZAP_WIDTH = 100
   new Float:LastZapTime[33]
   new ls_stat[33]
   new bool:dod_running
   #define MAX_CLR 8
   new ncolors[MAX_CLR][] =
   {"!","white","red","green","blue","yellow","magenta","cyan"}
   new vcolors[MAX_CLR][3] =
   {{255,255,255},{255,255,255},{255,0,0},{0,255,0},{0,0,255},{255,255,0}
   ,{255,0,255},{0,255,255}}
   new adcolors[33][4]
   new adscolors[64][43]
   lightning(vec1[3],vec2[3])
   {
      //Lightning
      message_begin( MSG_BROADCAST,SVC_TEMPENTITY)
      write_byte( 0 )
      write_coord(vec1[0])
      write_coord(vec1[1])
      write_coord(vec1[2])
      write_coord(vec2[0])
      write_coord(vec2[1])
      write_coord(vec2[2])
      write_short( light )
      write_byte( 1 ) // framestart
      write_byte( 5 ) // framerate
      write_byte( 2 ) // life
      write_byte( 20 ) // width
      write_byte( 30 ) // noise
      write_byte( 12 ) // r, g, b
      write_byte( 50 ) // r, g, b
      write_byte( 200 ) // r, g, b
      write_byte( 200 ) // brightness
      write_byte( 200 ) // speed
      message_end()
      //Sparks
      message_begin( MSG_PVS, SVC_TEMPENTITY,vec2)
      write_byte( 9 )
      write_coord( vec2[0] )
      write_coord( vec2[1] )
      write_coord( vec2[2] )
      message_end()
      //Smoke
      message_begin( MSG_BROADCAST,SVC_TEMPENTITY,vec2)
      write_byte( 5 ) // 5
      write_coord(vec2[0])
      write_coord(vec2[1])
      write_coord(vec2[2])
      write_short( smoke )
      write_byte( 10 )  // 10
      write_byte( 10 )  // 10
      message_end()
   }
   public punish_zap(sidargs[]){
       new iid,iplayer,uht,sb
       iplayer = sidargs[0]
       iid = sidargs[1]
       new origin[3]
       new origin1[3]
       get_user_origin(iid,origin1)
       get_user_origin(iplayer,origin)
       if(iid == iplayer){
           origin1[0] = random(3000)
           origin1[1] = random(3000)
           origin1[2] = random(1000)
           sb = random(2)
           if(sb == 0)
               origin1[0] = origin1[0] * -1
           sb = random(2)
           if(sb == 0)
               origin1[1] = origin1[1] * -1
       }
       lightning(origin1,origin)
       if(just_k[iid] == 0){
           uht = get_user_health(iplayer)-5
           if(uht < 1)
               user_kill(iplayer,1)
           else
               set_user_health(iplayer,uht)
       }
       new snd_cmd[32]
       new e_snd = random(3)
       switch(e_snd){
           case 0: format(snd_cmd,31,"weapons/electro4.wav")
           case 1: format(snd_cmd,31,"weapons/electro5.wav")
           case 2: format(snd_cmd,31,"weapons/electro6.wav")
       }
       emit_sound(iplayer,CHAN_ITEM,    snd_cmd,   1.0,   ATTN_NORM,   0,
   PITCH_NORM)
       emit_sound(iid,CHAN_ITEM, snd_cmd, 1.0, ATTN_NORM, 0, PITCH_NORM)
       return PLUGIN_CONTINUE
   }
   public admin_zap(id,level,cid){
       if (!cmd_access(id,level,cid,1))
           return PLUGIN_HANDLED
       if(!is_dedicated_server()){
           if(!id)
               id = 1
       }
       new cmd[32]
       new hp_take[8]
       new aname[32]
       new name[32]
       new idargs[3]
       new ihp_take
       read_argv(0,cmd,32)
       new player
       if(equal(cmd[8],"a",1)){
           new aorigin[3]
           new vorigin[3]
           get_user_origin(id,aorigin,3)
           new maxpl = get_maxplayers() +1
           for(new a = 1; a < maxpl; a++) {
               if(is_user_alive(a) != 0){
                   get_user_origin(a,vorigin)
                   if (get_distance(aorigin,vorigin)<ZAP_WIDTH){
                       player = a
                   }
               }
           }
           read_argv(1,hp_take,8)
       }else{
           new argc = read_argc()
           if (argc < 2) {
               client_print(id,print_console,"[AMX]   Usage:  amx_zap   <
   part of nick >  < health > ")
               return PLUGIN_HANDLED
           }
           read_argv(1,name,32)
           read_argv(2,hp_take,8)
           player = cmd_target(id,name,3)
           if (!player) return PLUGIN_HANDLED
       }
       if (player)    {
           if (get_user_flags(player)&ADMIN_IMMUNITY){
               client_print(id,print_console,"[AMX]    The   player   has
   immunity")
               return PLUGIN_HANDLED
           }
           get_user_name(player,name,32)
           get_user_name(id,aname,32)
           ihp_take = strtonum(hp_take)
           if( (ihp_take > get_user_health(player)) || (ihp_take < 1 ) )
               ihp_take = get_user_health(player) + 20
           if(ihp_take > 500)
               ihp_take = 500
           idargs[0] = player
           idargs[1] = id
           if(equal(cmd[8],"j",1)){
               just_k[id] = 1
               ihp_take = 150
               log_message("[AMX]  %s  used                       command
   amx_zap_jk  %s",aname,name)
               set_task(0.2,"punish_zap",0,idargs,2,"a",ihp_take/5-1)
           }
           else if(equal(cmd[12],"j",1)){
               just_k[id] = 1
               ihp_take = 150
               log_message("[AMX]  %s  used                       command
   amx_zap_aim_jk  %s",aname,name)
               set_task(0.2,"punish_zap",0,idargs,2,"a",ihp_take/5-1)
           }else{
               just_k[id] = 0
               client_print(id,print_console,"[AMX]   Client   ^"%s^"  is
   being eletrocuted",name)
               log_message("[AMX]  %s  used      command      amx_zap  %s
   %s",aname,name,hp_take)
               if(ihp_take >= get_user_health(player)){
                   if (get_gametime() > (LastZapTime[player] + 10.0)){
                       LastZapTime[player] = get_gametime()
                        client_print(0,print_chat,"[AMX]  %s  :  And now,
   young %s , ...... you will die.",aname,name)
                       client_cmd(0,"spk misc/amx_jedizap_v3")
                   }
                   idargs[2] = ihp_take/5-1
                   set_task(6.5,"delayed_zap",0,idargs,3)
               }else{
                       client_print(0,print_chat,"[AMX]  Admin:    %s  is
   zapping  %s",aname,name)
                   set_task(0.2,"punish_zap",0,idargs,2,"a",ihp_take/5-1)
               }
           }
       }else {
           client_print(id,print_console,"[AMX]  Client  in  your  aim or
   with that part of nick not found")
       }
       return PLUGIN_HANDLED
   }
   public delayed_zap(idargs[]){
       set_task(0.2,"punish_zap",0,idargs,2,"a",idargs[2])
       return PLUGIN_CONTINUE
   }
   public ls_off(id[]){
       set_user_godmode(id[0],0)
       ls_stat[id[0]] = 0
       emit_sound(id[0],CHAN_ITEM,  "vox/_period.wav", 1.0, ATTN_NORM, 0,
   PITCH_NORM)
       return PLUGIN_CONTINUE
   }
   public sqrt(num) {
       new div = num
       new result = 1
       while (div > result) { // end when div == result, or just below
           div = (div + result) / 2 // take mean value as new divisor
           result = num / div
       }
       return div
   }
   public admin_ls(id,level,cid){
       if (!cmd_access(id,level,cid,1))
           return PLUGIN_HANDLED
       if(!is_dedicated_server()){
           if(!id)
               id = 1
       }
       if( (is_user_alive(id) == 0) || (ls_stat[id] != 0) ){
           client_print(id,print_console,"[AMX]  You  cannot  use a light
   saber when you are dead or have an active one already")
           return PLUGIN_HANDLED
       }
       client_print(id,print_console,"Usage:     amx_lightsaber    <type>
   <color>   [type=1|2|3|4|5  &&  color=green,red,blue  -see  tsay  color
   info]")
       new arg1[8]
       new tid[5]
       tid[0] = id
       tid[1] = 0
       read_argv(1,arg1,8)
       if( (!(get_user_flags(id)&ADMIN_SLAY)) && (strtonum(arg1) > 0) ){
           client_print(id,print_console,"[AMX]  You  have  no  access to
   that part of this command")
           return PLUGIN_HANDLED
       }
       if(  (!(get_user_flags(id)&ADMIN_LEVEL_B)) && (strtonum(arg1) > 2)
   ){
           client_print(id,print_console,"[AMX]  You  have  no  access to
   that part of this command")
           return PLUGIN_HANDLED
       }
       if(strtonum(arg1) == 4){
           set_user_godmode(id,1)
           tid[1] = 2
       }
       else if(strtonum(arg1) == 3){
           set_user_godmode(id,1)
           tid[1] = 1
       }
       else if(strtonum(arg1) == 2){
           tid[1] = 2
       }
       else if(strtonum(arg1) == 1){
           tid[1] = 1
       }
       new authid[16]
       new color[10]
       read_argv(2,color,10)
       new found = 0,a = 0
       if(equal(color[0],"!",1)){
           found = 1
           new sred[4],sgreen[4],sblue[4],ired,igreen,iblue
           if( (strlen(color) < 2) && (adcolors[id][3] == 1) ){
               vcolors[0][0] = adcolors[id][0]
               vcolors[0][1] = adcolors[id][1]
               vcolors[0][2] = adcolors[id][2]
           }else{
               copy(sred,3,color[1])
               copy(sgreen,3,color[4])
               copy(sblue,3,color[7])
               ired = strtonum(sred)
               igreen = strtonum(sgreen)
               iblue = strtonum(sblue)
               if(ired < 0 || ired > 255)
                   ired = 255
               if(igreen < 0 || igreen > 255)
                   igreen = 255
               if(iblue < 0 || iblue > 255)
                   iblue = 255
               if(  (strlen(sred)  ==  0)  ||  (strlen(sgreen)  ==  0) ||
   (strlen(sblue) == 0) )
                   ired = 255,igreen=255,iblue=255
               vcolors[0][0] = ired
               vcolors[0][1] = igreen
               vcolors[0][2] = iblue
               adcolors[id][0] = ired
               adcolors[id][1] = igreen
               adcolors[id][2] = iblue
               adcolors[id][3] = 1
           }
       }else{
           a = 1
           for(new i=1;i<MAX_CLR;++i){
               if (equal(color,ncolors[i])) {
                   a = i
                   found = 1
                   break
               }
           }
           if((found != 1) && (id !=0)){
               get_user_authid(id,authid,16)
               for(new i=0;i<64;++i){
                   if(equal(authid,adscolors[i][3])) {
                       vcolors[0][0] = adscolors[i][0]
                       vcolors[0][1] = adscolors[i][1]
                       vcolors[0][2] = adscolors[i][2]
                       a = 0
                       break
                   }
               }
           }
       }
       tid[2] = vcolors[a][0]
       tid[3] = vcolors[a][1]
       tid[4] = vcolors[a][2]
       set_task(0.1,"lightsaber",0,tid,5,"a",200)
       set_task(20.0,"ls_off",413,tid,1)
       ls_stat[id] = 1
       emit_sound(id,CHAN_ITEM,      "ambience/zapmachine.wav",      1.0,
   ATTN_NORM, 0, PITCH_NORM)
       return PLUGIN_HANDLED
   }
   public lightsaber(id[]){
       if(is_user_alive(id[0]) == 0)
           return PLUGIN_CONTINUE
       new vec[3]
       new aimvec[3]
       new lseffvec[3]
       new length
       new speed = 65
       get_user_origin(id[0],vec,1)
       get_user_origin(id[0],aimvec,2)
       lseffvec[0]=aimvec[0]-vec[0]
       lseffvec[1]=aimvec[1]-vec[1]
       lseffvec[2]=aimvec[2]-vec[2]
       length=sqrt(lseffvec[0]*lseffvec[0]+lseffvec[1]*lseffvec[1]+lseffv
   ec[2]*lseffvec[2])
       lseffvec[0]=lseffvec[0]*speed/length
       lseffvec[1]=lseffvec[1]*speed/length
       lseffvec[2]=lseffvec[2]*speed/length
       new vorigin[3]
       new maxpl = get_maxplayers() +1
       new teama[32],teamv[32]
       get_user_team(id[0],teama,31)
       for(new a = 1; a < maxpl; a++) {
           if(is_user_alive(a) != 0){
               get_user_origin(a,vorigin)
               if (get_distance(vec,vorigin)<100){
                   if(a != id[0]){
                       get_user_team(a,teamv,31)
                       if(!equal(teama,teamv,2)){
                           if(id[1] != 0){
                               user_kill(a,1)
                               client_print(a,print_chat,"[AMX] The power
   of the force has killed you.")
                           }
                       }
                       else if(id[1] == 2){
                           user_kill(a,1)
                           client_print(a,print_chat,"[AMX]  The power of
   the force has killed you.")
                       }
                   }
               }
           }
       }
       // beam effect between point and entity
       message_begin( MSG_BROADCAST,SVC_TEMPENTITY)
       write_byte ( 1 )     //TE_BEAMENTPOINT 1
       write_short (id[0])     // ent
       write_coord (lseffvec[0]+vec[0])//end position
       write_coord (lseffvec[1]+vec[1])
       write_coord (lseffvec[2]+vec[2]+10)
       write_short (saber)  // sprite
       write_byte (0)       // start frame
       write_byte (15)      // frame rate in 0.1's
       write_byte (1)     // byte (life in 0.1's
       write_byte (20)      // line width in 0.1's
       write_byte (5)      // noise amplitude in 0.01's
       write_byte (id[2])       // RGB color
       write_byte (id[3])
       write_byte (id[4])
       write_byte (255)     // brightness
       write_byte (10)      // scroll speed in 0.1's
       message_end()
       return PLUGIN_CONTINUE
   }
   public plugin_precache(){
       light = precache_model("sprites/lgtning.spr")
       new mod_name[32]
       get_modname(mod_name,31)
       dod_running = equal(mod_name,"dod") ? true : false
       if(!dod_running)
           smoke = precache_model("sprites/steam1.spr")
       else
           smoke = precache_model("sprites/smoke.spr")
       saber = precache_model("sprites/laserbeam.spr")
       precache_sound("weapons/electro4.wav")
       precache_sound("weapons/electro5.wav")
       precache_sound("weapons/electro6.wav")
       precache_sound("ambience/zapmachine.wav")
       precache_sound("vox/_period.wav")
       return PLUGIN_CONTINUE
   }
   public plugin_init()
   {
       register_plugin("Jedi Punsishments","1.8","EJL")
       register_concmd("amx_zap","admin_zap",ADMIN_SLAY,"< part of nick >
   < health > -- real zap")
       register_concmd("amx_zap_jk","admin_zap",ADMIN_SLAY,"<   part   of
   nick > < health > -- fake zap")
       register_concmd("amx_zap_aim","admin_zap",ADMIN_SLAY,"<  health  >
   -- real zap")
       register_concmd("amx_zap_aim_jk","admin_zap",ADMIN_SLAY,"  -- fake
   zap")
       register_concmd("amx_lightsaber","admin_ls",ADMIN_SLAY,"")
       new line, stxtsize
       new data[100]
       new sr[4],sg[4],sb[4]
       if(file_exists("addons/amx/ejl_hud_colors.ini") == 1){
           while((line=read_file("addons/amx/ejl_hud_colors.ini",line,dat
   a,100,stxtsize))!=0){
               parse(data,adscolors[line][3],39,sr,4,sg,4,sb,4)
               adscolors[line][0] = strtonum(sr)
               adscolors[line][1] = strtonum(sg)
               adscolors[line][2] = strtonum(sb)
           }
       }
       return PLUGIN_CONTINUE
   }
