Raised This Month: $ Target: $400
 0% 

Capture the Flag


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
helpjoe
Junior Member
Join Date: Apr 2004
Old 06-27-2004 , 02:57   Capture the Flag
#1

Original post amxmod http://djeyl.net/forum/index.php?showtopic=16910

converted it to amxx:

Code:
/* AMXMOD script. 
*
* (c) Copyright 2000-2002, Made by Rich - This file is provided as is (no warranties). 
*
*
* CAPTURE THE FLAG VERSION 1.0 - Tested to work on CS
*
* V1.1 - Changed messages to help avoid confusion
*
* v1.0 - Added CTF guard feature
*      - Improved scoreboard tracking
*      - Fixed some run time errors
*      - Various bug fixes
* 
* v0.9 - Public release
*
*/ 

#include <amxmodx>
#include <fun>
#include <cstrike>

#define TE_BEAMPOINTS 0

new ctfrunning, beam, gmsgTeamScore

new fr_stand[3], fr_origin[3], fr_holder, fr_return, fr_score, fr_status[33] = "Base"
new fb_stand[3], fb_origin[3], fb_holder, fb_return, fb_score, fb_status[33] = "Base"

new protected[33], guard_time

new fr_team[33] = "TERRORIST"
new fb_team[33] = "CT"

public plugin_init()
{ 
  register_plugin("CTF", "0.9", "Rich")
  set_task(0.1,"drawflag",0,"",0,"b")
  set_task(0.5,"checkflag",0,"",0,"b")
  set_task(1.0,"drawflagstand",0,"",0,"b")
  set_task(5.0,"check_cvar",0,"",0,"b")
  register_event("DeathMsg","checkdeath","a")
  register_event("Damage", "checkdamage", "b", "2!0")
  register_event("ResetHUD", "startofround", "bce")
  register_event("CurWeapon","switchweapon","be","1=1","2!29")
  register_cvar("amx_ctf","1")
  register_cvar("amx_ctf_guard", "16")
  register_cvar("amx_ctf_version", "1.1",FCVAR_SERVER)
  gmsgTeamScore = get_user_msgid("TeamScore")
} 

public plugin_precache()
{
  beam = precache_model("sprites/dot.spr")
}

public check_cvar()
{ 
  if (get_cvar_num("amx_ctf"))
  {
    message_begin(MSG_ALL, gmsgTeamScore)
    write_string(fr_team)
    write_short(fr_score)
    message_end()

    message_begin(MSG_ALL, gmsgTeamScore)
    write_string(fb_team)
    write_short(fb_score)
    message_end()

    new team1, team2

    for(new a = 1; a <= get_maxplayers(); ++a)
    {
      if (get_user_team(a) == 1)
      {
        team1 += 1

        if (!(is_user_alive(a)) && ctfrunning == 1 )
        {
          new ids[1]
          ids[0] = a
          spawnplayer(ids)
        }
      }
      else if (get_user_team(a) == 2)
      {
        team2 += 1

        if (!(is_user_alive(a)) && ctfrunning == 1 )
        {
          new ids[1]
          ids[0] = a
          spawnplayer(ids)
        }
      }
    }

    guard_time = get_cvar_num("amx_ctf_guard")
   
    if (guard_time < 4)
    {
      guard_time = 4
      set_cvar_num("amx_ctf_guard", 4)
    }

    if (ctfrunning == 1)
    {
      return PLUGIN_CONTINUE
    }

    if (team1 > 1 && team2 > 1)
    {
      ctfrunning = 1
      set_cvar_num("sv_restartround", 3)
      set_cvar_num("mp_buytime", 7)
      set_cvar_num("mp_roundtime", 7)
      set_cvar_num("mp_startmoney", 1800)
      set_cvar_num("amx_spawn_protect", 0)
    }
    else
    {
      set_hudmessage(0, 100, 0, -1.0, 0.85, 0, 4.0, 4.0, 1.0, 1.0, 20)
      show_hudmessage(0,"CTF 1.1 - WAITING FOR 2 PLAYERS ON EACH TEAM")
    }
  }
  else if (!(get_cvar_num("amx_ctf")))
  {
    ctfrunning = 0
  }
  return PLUGIN_CONTINUE
}

public switchweapon(id)
{
  if (!(ctfrunning))
  {
    return PLUGIN_CONTINUE
  }

  new weapon=read_data(2)

  if (protected[id] > 0)
  {
    client_print(id,print_chat,"CTF GUARD INFO: YOU CAN USE A GUN IN %i SECONDS",protected[id])
    engclient_cmd(id,"weapon_knife")
  }    

  if (weapon == 6)
  {
    client_print(id,print_chat,"BOMB PLANTING NOT ALLOWED IN CTF")
    engclient_cmd(id,"weapon_knife")
  }
  return PLUGIN_CONTINUE
}

public drawflag()
{
  if (!(ctfrunning))
  {
    return PLUGIN_CONTINUE
  }

  new s_origin[3], f_origin[3]

  if (is_user_alive(fr_holder))
  {
    get_user_origin(fr_holder,fr_origin)
    fr_origin[2] += 15
  }

  if (is_user_alive(fb_holder))
  {
    get_user_origin(fb_holder,fb_origin)
    fb_origin[2] += 15
  }

  s_origin = fr_origin
  f_origin = fr_origin
  f_origin[2] += 20
  drawbeam(s_origin,f_origin,1,3,200,200,200)
  s_origin[2] = f_origin[2]
  f_origin[2] += 20
  drawbeam(s_origin,f_origin,1,80,200,0,0)

  s_origin = fb_origin
  f_origin = fb_origin
  f_origin[2] += 20
  drawbeam(s_origin,f_origin,1,3,200,200,200)
  s_origin[2] = f_origin[2]
  f_origin[2] += 20
  drawbeam(s_origin,f_origin,1,80,0,0,200)

  return PLUGIN_CONTINUE
}

public client_disconnect(id)
{
  if (!(ctfrunning))
  {
    return PLUGIN_CONTINUE
  }

  protected[id] = 0

  if (id == fr_holder)
  {
    set_hudmessage(0, 200, 0, -1.0, 0.4, 0, 3.0, 6.0, 0.1, 0.0, 9)
    show_hudmessage(0,"%s HAS DROPPED THE %s FLAG !!!",fr_status,fr_team)
    fr_return = 30
    fr_holder = -1
    fr_origin[2] -= 10
  }

  if (id == fb_holder)
  {
    set_hudmessage(0, 200, 0, -1.0, 0.6, 0, 3.0, 6.0, 0.1, 0.0, 10)
    show_hudmessage(0,"%s HAS DROPPED THE %s FLAG !!!",fb_status,fb_team)
    fb_return = 30
    fb_holder = -1
    fb_origin[2] -= 10
  }
  return PLUGIN_CONTINUE
}

public checkdeath()
{
  if (!(ctfrunning))
  {
    return PLUGIN_CONTINUE
  }

  new killer = read_data(1)
  new victim = read_data(2)

  if (victim == fr_holder)
  {
    set_hudmessage(0, 200, 0, -1.0, 0.4, 0, 3.0, 6.0, 0.1, 0.0, 9)
    show_hudmessage(0,"%s HAS DROPPED THE %s FLAG !!!",fr_status,fr_team)

    fr_return = 30
    fr_holder = -1
    fr_origin[2] -= 25

    new money = cs_get_user_money(killer)
    cs_set_user_money(killer,money+1000,1)
  }

  if (victim == fb_holder)
  {
    set_hudmessage(0, 200, 0, -1.0, 0.6, 0, 3.0, 6.0, 0.1, 0.0, 10)
    show_hudmessage(0,"%s HAS DROPPED THE %s FLAG !!!",fb_status,fb_team)

    fb_return = 30
    fb_holder = -1
    fb_origin[2] -= 25

    new money = cs_get_user_money(killer)
    cs_set_user_money(killer,money+1000,1)
  }

  new ids[1]
  ids[0] = victim
  set_task(0.8,"spawnplayer",0,ids,1)

  return PLUGIN_CONTINUE
}

public checkdamage(id)
{
  if (!(ctfrunning))
  {
    return PLUGIN_CONTINUE
  }

  if (protected[id] > 0)
  {
    set_user_health(id,250)
//  client_print(id,print_chat,"CTF GUARD IS PROTECTING YOU")
  }

  return PLUGIN_CONTINUE
}


public spawnplayer(ids[])
{
  new victim = ids[0]
  protected[victim] = guard_time

  spawn(victim)
  set_user_health(victim,250)

  new money = cs_get_user_money(victim)

  if (money < 1800)
  {
    money = 1800
  }

  cs_set_user_money(victim,money,0)

  new pl_origin[3]
  get_user_origin(victim,pl_origin)
  pl_origin[2] -= 2000
  set_user_origin(victim,pl_origin)
  new iweapons[32], wpname[32], inum
  get_user_weapons(victim,iweapons,inum)
  for(new a=0;a<inum;++a)
  { 
    get_weaponname(iweapons[a],wpname,31)
    engclient_cmd(victim,"drop",wpname)
  }
  pl_origin[2] += 2005
  give_item(victim,"weapon_knife")
  set_user_origin(victim,pl_origin)
  set_user_rendering(victim,kRenderFxGlowShell,200,200,100,kRenderNormal)

  return PLUGIN_CONTINUE
}

public checkflag() 
{
  if (!(ctfrunning))
  {
    return PLUGIN_CONTINUE
  }

  for(new a = 1; a <= get_maxplayers(); ++a)
  {
    if (is_user_alive(a))
    {
      new pl_origin[3]
      get_user_origin(a,pl_origin)

      if (pl_origin[0] > (fb_origin[0] - 40) && pl_origin[0] < (fb_origin[0] + 40))
      {
        if (pl_origin[1] > (fb_origin[1] - 40) && pl_origin[1] < (fb_origin[1] + 40))
        {
          if (pl_origin[2] > (fb_origin[2] - 60) && pl_origin[2] < (fb_origin[2] + 80))
          {
            if (get_user_team(a) == 1 && fb_holder < 1)
            {
              if (protected[a] > 0)
              {
                client_print(a,print_chat,"NO FLAG TAKING UNTIL YOUR CTF GUARD ENDS. WAIT.")
              }
              else
              {
                fb_holder = a
                get_user_name(a,fb_status,32)
                set_user_rendering(a,kRenderFxGlowShell,200,0,0,kRenderNormal)
                new money = cs_get_user_money(a)
                cs_set_user_money(a,money + 1000,1)
                set_hudmessage(0, 200, 0, -1.0, 0.4, 0, 3.0, 6.0, 0.1, 0.0, 9)
                show_hudmessage(0,"%s HAS TAKEN THE %s FLAG !!!",fb_status,fb_team)
              }
            }
            else if (get_user_team(a) == 2 && fb_holder == -1)
            {
              if (protected[a] > 0)
              {
                client_print(a,print_chat,"NO FLAG RETURNING UNTIL YOUR CTF GUARD ENDS. GUARD.")
              }
              else
              {
                fb_return = 1
              }
            }
          }
        }
      }

      if (pl_origin[0] > (fr_origin[0] - 40) && pl_origin[0] < (fr_origin[0] + 40))
      {
        if (pl_origin[1] > (fr_origin[1] - 40) && pl_origin[1] < (fr_origin[1] + 40))
        {
          if (pl_origin[2] > (fr_origin[2] - 60) && pl_origin[2] < (fr_origin[2] + 80))
          {
            if (get_user_team(a) == 2 && fr_holder < 1)
            {
              if (protected[a] > 0)
              {
                client_print(a,print_chat,"NO FLAG TAKING UNTIL YOUR CTF GUARD ENDS. WAIT.")
              }
              else
              {
                fr_holder = a
                get_user_name(a,fr_status,32)
                set_user_rendering(a,kRenderFxGlowShell,0,0,200,kRenderNormal)
                new money = cs_get_user_money(a)
                cs_set_user_money(a,money + 1000,1)
                set_hudmessage(0, 200, 0, -1.0, 0.6, 0, 3.0, 6.0, 0.1, 0.0, 10)
                show_hudmessage(0,"%s HAS TAKEN THE %s FLAG !!!",fr_status,fr_team)
              }
            }
            else if (get_user_team(a) == 1 && fr_holder == -1)
            {
              if (protected[a] > 0)
              {
                client_print(a,print_chat,"NO FLAG RETURNING UNTIL YOUR CTF GUARD ENDS. GUARD.")
              }
              else
              {
                fr_return = 1
              }
            }
          }
        }
      }
    }
  }

  if (fr_holder == 0 && fb_holder != 0)
  {
    if (is_user_alive(fb_holder))
    {
      new pl_origin[3]
      get_user_origin(fb_holder,pl_origin)

      if (pl_origin[0] > (fr_stand[0] - 40) && pl_origin[0] < (fr_stand[0] + 40))
      {
        if (pl_origin[1] > (fr_stand[1] - 40) && pl_origin[1] < (fr_stand[1] + 40))
        {
          if (pl_origin[2] > (fr_stand[2] - 40) && pl_origin[2] < (fr_stand[2] + 40))
          {
            for(new a = 1; a <= get_maxplayers(); ++a)
            {
              if (get_user_team(a) == 1)
              {
                new money = cs_get_user_money(a)

                if (a == fb_holder)
                {
                  money += 6000
                }
                else
                {
                  money += 4000
                }

                cs_set_user_money(a,money,1)
              }
            }

            fr_score += 1
            set_user_frags(fb_holder, get_user_frags(fb_holder) + 1)
            set_hudmessage(0, 200, 0, -1.0, -1.0, 0, 3.0, 6.0, 0.1, 0.0, 10)
            show_hudmessage(0,"%s CAPTURED THE %s FLAG !!!    %s: %i - %s: %i",fb_status,fb_team,fr_team,fr_score,fb_team,fb_score)
            set_user_rendering(fb_holder,kRenderFxNone,0,0,0,kRenderNormal)
            fb_holder = 0
            fb_origin = fb_stand
            fb_status = "Base"
          }
        }
      }
    }
  }

  if (fb_holder == 0 && fr_holder != 0)
  {
    if (is_user_alive(fr_holder))
    {
      new pl_origin[3]
      get_user_origin(fr_holder,pl_origin)

      if (pl_origin[0] > (fb_stand[0] - 40) && pl_origin[0] < (fb_stand[0] + 40))
      {
        if (pl_origin[1] > (fb_stand[1] - 40) && pl_origin[1] < (fb_stand[1] + 40))
        {
          if (pl_origin[2] > (fb_stand[2] - 40) && pl_origin[2] < (fb_stand[2] + 40))
          {
            for(new a = 1; a <= get_maxplayers(); ++a)
            {
              if (get_user_team(a) == 2)
              {
                new money = cs_get_user_money(a)

                if (a == fr_holder)
                {
                  money += 6000
                }
                else
                {
                  money += 4000
                }

                cs_set_user_money(a,money,1)
              }
            }
            fb_score += 1
            set_user_frags(fr_holder, get_user_frags(fr_holder) + 1)
            set_hudmessage(0, 200, 0, -1.0, -1.0, 0, 3.0, 6.0, 0.1, 0.0, 10)
            show_hudmessage(0,"%s CAPTURED THE %s FLAG !!!    %s: %i - %s: %i",fr_status,fr_team,fb_team,fb_score,fr_team,fr_score)
            set_user_rendering(fr_holder,kRenderFxNone,0,0,0,kRenderNormal)
            fr_holder = 0
            fr_origin = fr_stand
            fr_status = "Base"
          }
        }
      }
    }
  }
  return PLUGIN_CONTINUE
}

public startofround() 
{
  if (!(ctfrunning))
  {
    return PLUGIN_CONTINUE
  }

  if (fr_stand[0] != fb_stand[0])
  {
    return PLUGIN_CONTINUE
  }

  set_task(3.0,"locateflagstand")

  return PLUGIN_CONTINUE
}

public locateflagstand()
{
  for(new a = 1; a <= get_maxplayers(); ++a)
  {
    if (get_user_team(a) == 1)
    {
      get_user_origin(a,fr_stand)
      fr_origin = fr_stand
    }
    else if (get_user_team(a) == 2)
    {
      get_user_origin(a,fb_stand)
      fb_origin = fb_stand
    }
  }
  return PLUGIN_CONTINUE
}

public drawflagstand(id) 
{
  if (!(ctfrunning))
  {
    return PLUGIN_CONTINUE
  }

  if (fr_stand[1] != 0 || fb_stand[1] != 0)
  {
    new s_origin[3], f_origin[3]

    s_origin = fr_stand
    f_origin = fr_stand
    s_origin[2] += 10
    f_origin[2] -= 35
    f_origin[1] -= 30
    f_origin[0] -= 30
    drawbeam(s_origin,f_origin,10,10,0,200,0)
    f_origin[1] += 60
    drawbeam(s_origin,f_origin,10,10,0,200,0)
    f_origin[0] += 60
    drawbeam(s_origin,f_origin,10,10,0,200,0)
    f_origin[1] -= 60
    drawbeam(s_origin,f_origin,10,10,0,200,0)

    s_origin = fb_stand
    f_origin = fb_stand
    s_origin[2] += 10
    f_origin[2] -= 35
    f_origin[1] -= 30
    f_origin[0] -= 30
    drawbeam(s_origin,f_origin,10,10,0,200,0)
    f_origin[1] += 60
    drawbeam(s_origin,f_origin,10,10,0,200,0)
    f_origin[0] += 60
    drawbeam(s_origin,f_origin,10,10,0,200,0)
    f_origin[1] -= 60
    drawbeam(s_origin,f_origin,10,10,0,200,0)
  }

  set_hudmessage(200, 0, 0, -1.0, 0.03, 0, 0.9, 1.0, 0.1, 0.0, 7)
  show_hudmessage(0,"RED FLAG: %s",fr_status)
  set_hudmessage(0, 0, 200, -1.0, 0.06, 0, 0.9, 1.0, 0.1, 0.0, 8)
  show_hudmessage(0,"BLUE FLAG: %s",fb_status)

  if (fr_holder == -1)
  {
    fr_return -= 1

    num_to_str(fr_return, fr_status, 3)

    if (fr_return == 0)
    {
      set_hudmessage(0, 200, 0, -1.0, 0.6, 0, 3.0, 3.0, 0.1, 0.0, 9)
      show_hudmessage(0,"%s FLAG HAS BEEN RETURNED TO BASE",fr_team)

      fr_holder = 0
      fr_origin = fr_stand
      fr_status = "Base"
    }
  }

  if (fb_holder == -1)
  {
    fb_return -= 1

    num_to_str(fb_return, fb_status, 3)

    if (fb_return == 0)
    {
      set_hudmessage(0, 200, 0, -1.0, 0.4, 0, 3.0, 3.0, 0.1, 0.0, 10)
      show_hudmessage(0,"%s FLAG HAS BEEN RETURNED TO BASE",fb_team)

      fb_holder = 0
      fb_origin = fb_stand
      fb_status = "Base"
    }
  }

  for(new a = 1; a <= get_maxplayers(); ++a)
  {
    if (protected[a] == 1)
    {
      set_user_health(a,100)
      set_user_rendering(a,kRenderFxNone,0,0,0,kRenderNormal)
    }

    if (protected[a] == (guard_time - 1))
    {
      set_user_rendering(a,kRenderFxGlowShell,200,200,100,kRenderNormal)
      client_print(a,print_chat,"CTF GUARD INFO: YOU CAN NOT BE KILLED FOR %i SECONDS",protected[a])
    }

    if (protected[a] > 0)
    {
      protected[a] -= 1
      set_hudmessage(200, 200, 200, 0.03, 0.89, 0, 0.9, 1.0, 0.1, 0.0, 13)
      show_hudmessage(a,"CTF GUARD TIME: %i",protected[a])
    }
  }
  return PLUGIN_CONTINUE
}

public drawbeam(s_origin[3],f_origin[3],blife,bwidth,bred,bgreen,bblue)
{
  message_begin(MSG_BROADCAST, SVC_TEMPENTITY) 
  write_byte( TE_BEAMPOINTS )
  write_coord(s_origin[0]) 
  write_coord(s_origin[1]) 
  write_coord(s_origin[2]) 
  write_coord(f_origin[0]) 
  write_coord(f_origin[1]) 
  write_coord(f_origin[2]) 
  write_short( beam ) 
  write_byte( 1 )      // framestart 
  write_byte( 1 )      // framerate 
  write_byte( blife )  // life in 0.1's 
  write_byte( bwidth ) // width 
  write_byte( 0 )      // noise 
  write_byte( bred )   // red
  write_byte( bgreen ) // green
  write_byte( bblue )  // blue
  write_byte( 200 )    // brightness 
  write_byte( 0 )      // speed 
  message_end()
}
If anything is wrong, well then ill just have to fix it, but there were no compilation errors, i will run it on my server, for awhile!
Attached Files
File Type: sma Get Plugin or Get Source (ctf.sma - 769 views - 16.4 KB)
__________________
Hmmm, I found a Superhero mod Counter Strike SOURCE server @ 72.232.91.93:27015
helpjoe is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:11.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode