
   /* AMXMOD script.
   *
   * (c) Copyright 2000-2002, Vantage (aka Mouse)
   * This file is provided as is (no warranties).
   *
   * unlimitedmoney.sma
   *
   */
   /*
   *    This  plugin  uses  real money and plays by CS rules. (accept for
   money limits of course!)
   *
   *    If you want to change default start money and max money:
   *    Place  amx_startmoney  and  amx_maxmoney  with proper ammounts in
   appropriate server cfg files.
   *
   *    amx_startmoney 55000
   *    amx_maxmoney 250000
   *
   *    Do  not  use  command  amx_money or a plugin that changes peoples
   money (strange,but not fatal?,things may happen)
   *
   *    Use: amx_um {@team, #userid, or name(partial allowed)} <ammount>
   *
   *  Not that any mod makers would do this but why not...
   *  For  mod  makers  use  server  commands: set_user_um <id> <ammount>
   <flash = 0> (flash = 1 if only id and ammount sent)
   *
   *  In your code you would use it like this: server_cmd("set_user_um %d
   %d 0",id,ammount) or server_cmd("set_user_um %d %d",id,ammount)
   *  You can also do set_user_um <id> to set player id's money to 0
   *
   *  I  was going to do a dumb(with a cvar) way to get_user_um but gonna
   put it off till I figure a better way.
   *
   */
   #include <amxmod>
   #include <amxmisc>
   #define  MONEY_TIER  8000 // DON'T MESS WITH, Money total at which the
   plugin switches over keeping track of money
   new money_total[33] // Keep track of peeps money if above MONEY_TIER
   new gmsg_Money
   public client_connect(id)
   {
       set_cvar_float("mp_startmoney", 801.0) // So you can track when to
   change to amx_startmoney ammount, I know.. a crude method
       money_total[id] = 0
   }
   public read_gmsg_Money(id)
   {
       new current_total = read_data(1)

       if(current_total == 801){            // If CS is spawning you with
   mp_startmoney default
           current_total    =    get_cvar_num("amx_startmoney")        //
   current total is actually amx_startmoney
           set_user_money(id,  current_total,0)            // so set user
   money to amx_startmoney
           money_total[id] = 0 // reset
       }
       if(current_total  >=  MONEY_TIER  && !money_total[id]) // If first
   time above MONEY_TIER
       {
           money_total[id] = current_total // Keep track of current total
           send_moneymsg(id,1) // send money msg of current total

           return PLUGIN_CONTINUE
       }
       if(money_total[id]) // If was over tier on last money message
       {
           money_total[id]  +=  current_total - MONEY_TIER  // figure the
   term of current total - tier
           if(money_total[id]  <  MONEY_TIER){  //  If less then tier set
   user money to money_total[id] and stop keeping track
               set_user_money(id,money_total[id],1)
               money_total[id] = 0
           }
           else{
               send_moneymsg(id,1) // else send money message
           }

           return PLUGIN_CONTINUE
       }
       return PLUGIN_CONTINUE
   }
   public send_moneymsg(id,flash)
   {
       set_user_money(id,MONEY_TIER,flash)   //Set  user  money  to  tier
   ammount so easy to track add and subtract terms

       static MAXAMMOUNT

       MAXAMMOUNT = get_cvar_num("amx_maxmoney")

       if(money_total[id] > MAXAMMOUNT)
           money_total[id] = MAXAMMOUNT
       message_begin(  MSG_ONE  ,  gmsg_Money , {0,0,0}, id) //Send money
   message with ammount stored in money_total[id]
       write_long(money_total[id])
       write_byte(flash)
       message_end()
   }
   public find_money_target(id, level, cid)
   {
       if(!cmd_access(id, level, cid, 3))
           return PLUGIN_HANDLED
       new target[16], ammount[8], players[32]
       new num
       read_argv(1,target,15)
       read_argv(2,ammount,7)
       if(target[0] == '@'){    //If trying to give a team money
           if(target[1] == 'C' || target[1] == 'c'){
               get_players(players, num ,"e", "CT")
           }
           else if(target[1] == 'T' || target[1] == 't'){
               get_players(players, num ,"e", "TERRORIST")
           }
           else{
               console_print(id, "*** No known team by that name. ***")
               return PLUGIN_HANDLED
           }

       }
       else  if(target[0]  == '#'){  //If trying to give a player(userid)
   money
           new userid = strtonum(target[1])
           players[0] = find_player("k", userid)
       }
       else{  // else search for matching name to try and give money
           players[0] = find_player("bl", target)
       }
       if(players[0] == 0){  //If no target(s) could be found
           console_print(id, "*** No target(s) could be found. ***")
           return PLUGIN_HANDLED
       }
       else
           give_money(players, strtonum(ammount))
       return PLUGIN_HANDLED
   }
   public give_money(players[], ammount)
   {
       new i
       while(players[i]){
           if(money_total[players[i]]){
               money_total[players[i]]   +=  ammount  //  Keep  track  of
   current total
               send_moneymsg(players[i],1)  //  send money msg of current
   total
           }
           else    if(    (get_user_money(players[i])   +   ammount)   >=
   MONEY_TIER){
               money_total[players[i]]   =  get_user_money(players[i])  +
   ammount // Keep track of current total
               send_moneymsg(players[i],1)  //  send money msg of current
   total
           }
           else{
               ammount += get_user_money(players[i])
               set_user_money(players[i],ammount,1)
               money_total[players[i]] = 0
           }
           ++i
       }

   }
   public get_cmd_info()
   {
       new s_id[3], s_ammount[8]
       new id,ammount
       new num_args = read_argc()
       if(num_args < 2){ // If no id set
           server_print("***    Not    enough    arguments   when   using
   set_user_um() ***")
           return PLUGIN_HANDLED
       }
       read_argv(1,s_id,2) // Get id and see if valid
       id = strtonum(s_id)
       if(!is_user_connected(id))
           return PLUGIN_HANDLED
       if(num_args < 3){  // If only id sent set id's money to 0
           set_user_um(id,0,1)
           return PLUGIN_HANDLED
       }

       read_argv(2,s_ammount,7) // Get ammount
       ammount = strtonum(s_ammount)
       if(num_args < 4){ // If no flash specified then flash
           set_user_um(id,ammount,1)
           return PLUGIN_HANDLED
       }
       else{
           set_user_um(id,ammount,0) // Don't flash
           return PLUGIN_HANDLED
       }
       return PLUGIN_HANDLED
   }
   public set_user_um(id,ammount,flash)
   {
       if(ammount < MONEY_TIER){
           set_user_money(id,ammount,flash)
           money_total[id] = 0
       }
       else{
           money_total[id] = ammount // Keep track of current total
           send_moneymsg(id,flash) // send money msg of current total
       }
   }
   public plugin_init()
   {
       register_plugin("Unlimited Money","0.9.6","Vantage aka Mouse")

      register_event("Money","read_gmsg_Money","b")

       register_cvar("amx_startmoney", "800")
       register_cvar("amx_maxmoney", "16000")
       register_concmd("amx_um",       "find_money_target",ADMIN_LEVEL_A,
   "{@team, #userid, or name(can be partial)} <ammount>")
       register_srvcmd("set_user_um", "get_cmd_info")
   //    register_srvcmd("get_user_um", "get_user_um")
       gmsg_Money = get_user_msgid("Money")
       return PLUGIN_CONTINUE
   }
