DaX

Rekia Zp ammo bank +rep

Recommended Posts


http://forums.alliedmods.net/showthread.php?p=1119813

tikuosi tiks.

arba sita.

#include 
#include 
#include 
#include 
#include 

static const version[] = "1.0";
static const plugin[] = "ZP Ammo";
static const author[] = "for-free";

enum pcvar
{
   enable = 0,
   cap
}

new pcvars[pcvar];

new bool:CreateTables = true
new Sql:gMySQL = SQL_FAILED
new sql_host, sql_user, sql_pass
new sql_db, persistent

new g_maxplayers
new g_msgSayText

public plugin_init()
{
   register_plugin(plugin, version, author);

   register_dictionary("credits_bank.txt");

   g_msgSayText = get_user_msgid("SayText")

   pcvars[enable] = register_cvar("zp_bank", "1");
   sql_host = register_cvar("zp_sql_host", "localhost");
   sql_user = register_cvar("zp_sql_user", "pasword");
   sql_pass = register_cvar("zp_sql_pass", "Pasword");
   sql_db = register_cvar("zp_sql_db", "usjs_ammo");
   persistent = register_cvar("zp_sql_persistence", "0");

   register_clcmd("say", "handle_say");
   register_clcmd("say_team", "handle_say");
}

public handle_say(id)
{
   if (!get_pcvar_num(pcvars[enable])) return PLUGIN_CONTINUE;

   new text[70], arg1[32], arg2[32], arg3[32], arg4[6];
   read_args(text, sizeof(text)-1);
   remove_quotes(text);
   arg1[0] = '^0';
   arg2[0] = '^0';
   arg3[0] = '^0';
   arg4[0] = '^0';
   parse(text, arg1, sizeof(arg1)-1, arg2, sizeof(arg2)-1, arg3, sizeof(arg3)-1);
   //dbg_log("cmd_say() arg1:#%s# arg2:#%s# arg3:#%s#" arg4:#%s#", arg1, arg2, arg3, arg4);

   // if the chat line has more than 2 words, we're not interested at all
   if (arg4[0] == 0)
   {
   if ( equali(arg1, "/kreditai", 5) )
       {
           showinfo(id);
       }
   }

   return PLUGIN_CONTINUE;
}

public client_disconnect(id)
   save_data(id)

public client_putinserver(id)  
   retrieve_data(id)

mySQLConnect()
{
   if ( gMySQL >= SQL_OK ) {
       if ( !get_pcvar_num(persistent) ) close_mysql();
       else return;
   }

   static host[64], user[32], pass[32], db[32], error[128];

   get_pcvar_string(sql_host, host, 63);
   get_pcvar_string(sql_user, user, 31);
   get_pcvar_string(sql_pass, pass, 31);
   get_pcvar_string(sql_db, db, 31);

   if ( host[0] == '^0' && user[0] == '^0' && db[0] == '^0' ) {
       get_cvar_string("amx_mysql_host", host, 63);
       get_cvar_string("amx_mysql_user", user, 31);
       get_cvar_string("amx_mysql_pass", pass, 31);
       get_cvar_string("amx_mysql_db", db, 31);
   }

   gMySQL = dbi_connect(host, user, pass, db, error, 127)
   if ( gMySQL <= SQL_FAILED ) {
       log_amx("MySQL connect error: '%s' (%s,%s,%s)", error, host, user, db);
       return;
   }
   else if ( CreateTables ) {
       // Only try to create the tables once
       static sql[512];
       new Result:retval;

       copy(sql, 511, "CREATE TABLE IF NOT EXISTS `zp_bank` ( `IP` varchar(32) binary NOT NULL default '', `Credits` int(10) NOT NULL default '0', PRIMARY KEY  (`IP`) ) TYPE=MyISAM COMMENT='ZP Credits saving table'");
       retval = dbi_query(gMySQL, sql);
       if ( retval <= RESULT_FAILED ) {
           dbi_error(gMySQL, error, 127);
           log_amx("Error Making Tables: '%s' - '%s'", error, sql);
           return;
       }
       CreateTables = false;
   }
}

close_mysql()
{
   if ( gMySQL <= SQL_FAILED || get_pcvar_num(persistent) ) return;

   dbi_close(gMySQL);
}

save_data(id)
{
   mySQLConnect();

   new IP[35];
   get_user_ip(id, IP, 29, 1)
   static error[128], sql[512];
   new Result:retval, Result:retvalins;

   formatex(sql, 511, "SELECT * FROM `zp_bank` WHERE `IP` = '%s'", IP)
   retval = dbi_query(gMySQL, sql)

   if ( retval <= RESULT_FAILED ) {
       dbi_error(gMySQL, error, 127);
       log_amx("Error Querying MySQL DB for %s: '%s' - '%s'", IP, error, sql);
       return;
   }
   else if ( retval == RESULT_NONE || !dbi_nextrow(retval) ) {
       formatex(sql, 511, "INSERT INTO `zp_bank` (IP,Credits) VALUES ('%s','%d')", IP, zp_get_user_ammo_packs(id));
       retvalins = dbi_query(gMySQL, sql);
       if ( retvalins <= RESULT_FAILED ) {
           dbi_error(gMySQL, error, 127);
           log_amx("Error Writing MySQL Ammo Packs for %s: '%s' - '%s'", IP, error, sql);
           return;
       }
   }

   if ( retval >= RESULT_OK ) dbi_free_result(retval);

   //Update users entry with current data
   formatex(sql, 511, "UPDATE `zp_bank` SET `Credits`='%d' WHERE IP='%s'", zp_get_user_ammo_packs(id), IP);
   retval = dbi_query(gMySQL, sql);
   if (retval <= RESULT_FAILED) {
       dbi_error(gMySQL, error, 127);
       log_amx("Error Writing MySQL XP for %s: '%s' - '%s'", IP, error, sql);
       return;
   }

   //Closes the connection if set not to be persistent
   close_mysql()
}

retrieve_data(id)
{
   new IP[35];
   get_user_ip(id, IP, 29, 1)

   mySQLConnect();
   if ( gMySQL <= SQL_FAILED ) return;

   static sql[512], error[128];
   new Result:retvalxp;

   formatex(sql, 511, "SELECT `Credits` FROM `zp_bank` WHERE `IP` = '%s'", IP);
   retvalxp = dbi_query(gMySQL, sql);

   if ( retvalxp <= RESULT_FAILED ) {
       dbi_error(gMySQL, error, 127);
       log_amx("Error Loading MySQL Credits for %s: '%s' - '%s'", IP, error, sql);
       return;
   }
   else if ( retvalxp == RESULT_NONE || !dbi_nextrow(retvalxp) ) {
       dbi_error(gMySQL, error, 127);
       log_amx("No Saved Ammmo Packs Loaded for %s: '%s'", IP, error);

       if ( retvalxp >= RESULT_OK ) dbi_free_result(retvalxp);

       //Closes the connection if set not to be persistent
       close_mysql();

       return;
   }

   static amp[13];
   new storagenum

   dbi_field(retvalxp, 1, amp, 12);
   storagenum = str_to_num(amp);
   zp_set_user_ammo_packs(id, storagenum)

   if ( retvalxp >= RESULT_OK ) dbi_free_result(retvalxp);

   //Closes the connection if set not to be persistent
   close_mysql();  

}

zp_colored_print(target, const message[], any:...)
{
   static buffer[512], i, argscount
   argscount = numargs()

   // Send to everyone
   if (!target)
   {
       static player
       for (player = 1; player <= g_maxplayers; player++)
       {
           // Not connected
           if (!is_user_connected(player))
               continue;

           // Remember changed arguments
           static changed[5], changedcount // [5] = max LANG_PLAYER occurencies
           changedcount = 0

           // Replace LANG_PLAYER with player id
           for (i = 2; i < argscount; i++)
           {
               if (getarg(i) == LANG_PLAYER)
               {
                   setarg(i, 0, player)
                   changed[changedcount] = i
                   changedcount++
               }
           }

           // Format message for player
           vformat(buffer, sizeof buffer - 1, message, 3)

           // Send it
           message_begin(MSG_ONE, g_msgSayText, _, player)
           write_byte(player)
           write_string(buffer)
           message_end()

           // Replace back player id's with LANG_PLAYER
           for (i = 0; i < changedcount; i++)
               setarg(changed[i], 0, LANG_PLAYER)
       }
   }

   // Send to specific target
   else
   {
       /*
       // Replace LANG_PLAYER with player id
       for (i = 2; i < argscount; i++)
       {
           if (getarg(i) == LANG_PLAYER)
               setarg(i, 0, target)
       }
       */

       // Format message for player
       vformat(buffer, sizeof buffer - 1, message, 3)

       // Send it
       message_begin(MSG_ONE, g_msgSayText, _, target)
       write_byte(target)
       write_string(buffer)
       message_end()
   }
}

public showinfo(id)
{
   zp_colored_print(id, "^x04[ZP Credits]^x01 Visa informacija pateikta MOTD lange >>", id);

   show_motd(id,"credits.txt","Kreditu pirkimas")
}

Dalintis šį pranešimą


Nuoroda iki šio pranešimo
Dalintis per kitą puslapį

Prisijungti prie diskusijos

Palikti atsakymą galite iš karto, o užsiregistruoti vėliau. Jeigu jau turite paskyrą mūsų forume, Prisijunkite.

Svečias
Atsakyti šioje temoje...

×   Įklijuotas tekstas turi teksto formatavimą.   Pašalinti teksto formatavimą

  Galimi tik 75 veidukai.

×   Nuoroda buvo automatiškai įterpta.   Įterpti nuorodą paprastai

×   Jūsų ankstesnis pranešimas buvo atkurtas.   Išvalyti redaktorių

×   Jūs negalite įkelti nuotraukas tiesiogiai.Įkelkite arba įdėkite nuotraukas iš URL.


  • Šiame puslapyje naršo:   0 nariai

    Nėra registruotų narių peržiūrinčių šį forumą.