[Plugin] Gold System
Results 1 to 6 of 6

Thread: Gold System

  1. #1
    Senior Member Array
    Join Date
    Jun 2015
    Location
    Home
    Karma
    3

    Default Gold System

    Gold System
    Version 0.1
    by Croxeye

    * OPIS PLUGINA *
    • 1 KILL = 1 GOLD
    • Kada igrac planta/deaktivira c4, dobije gratis +5 Goldova.
    • Pomocu goldova mozete kupiti VIPA tako sto u chat ukucate /buyvip ili /kupivipa
    • Svoje goldove mozete provjeriti tako što u chat ukucate /golds
    • Također sam napravio komandu pomocu koje mozete davati goldove drugim igracima (KOMANDA JE ZASTICENA PASSWORDOM, Password mozete mijenjati u kodu plugina)
    • Vip traje 30 dana
    • Goldovi se mogu spasavati pomocu NVAULT-a ili MySQL-a (Zavisno od toga sta izabereta), Default je MySQL (Ali to mozete promijeniti tako sto stavite ' // ' prije '#define USING MYSQL')
    • Igrac kada kupuje vipa, moze birati password koji hoce pomocu messagemode-a


    * SMA *
    PHP Code:
    #define USING_MYSQL
    //#define USING_NVAULT

    #include <amxmodx>
    #include <amxmisc>
    #if defined USING_NVAULT
    #include <nvault>
    #endif
    #if defined USING_MYSQL
    #include <sqlx>
    #endif
    #include <ColorChat>

    #define PLUGIN "Buy VIP"
    #define VERSION "1.0"
    #define AUTHOR "Croxeye"

    #define CMD_PASSWORD "password"

    new gGolds[33]

    #if defined USING_NVAULT
    new gName32 ]
    new 
    gVault
    new vKey64 ];
    new 
    vData64 ];
    #endif

    #if defined USING_MYSQL
    new Host[]     = ""
    new User[]    = ""
    new Pass[]     = ""
    new Db[]     = ""

    new Handle:g_SqlTuple
    new g_Error[512]
    #endif


    public plugin_init() {
        
    register_plugin(PLUGINVERSIONAUTHOR)
        
        
    register_concmd("amx_golds""cmd_set"ADMIN_USER"<name> <golds> <password> - give golds to player" );
        
    register_clcmd"say /golds""cmd_showgolds" );
        
    register_event"DeathMsg""Hook_Deathmessage""a" );
        
    register_clcmd("say /buyvip""cmd_buy");
        
    register_clcmd("say /kupivipa""cmd_buy");
        
        
    register_clcmd("SLOT_PASSWORD""set_password");
        
        
    #if defined USING_MYSQL
        
    set_task(1.0"MySql_Init")
        
    #endif
    }

    #if defined USING_MYSQL
    public MySql_Init()
    {
        
    g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db)

        new 
    ErrorCode,Handle:SqlConnection SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
        if(
    SqlConnection == Empty_Handle)
            
    set_fail_state(g_Error)
           
        new 
    Handle:Queries
        Queries 
    SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS save_golds (SteamID varchar(32), Golds INT(11))")

        if(!
    SQL_Execute(Queries))
        {
            
    SQL_QueryError(Queries,g_Error,charsmax(g_Error))
            
    set_fail_state(g_Error)
        }

        
    SQL_FreeHandle(Queries)

        
    SQL_FreeHandle(SqlConnection)   
    }
    #endif

    public plugin_end()
    {
        
    #if defined USING_MYSQL
        
    SQL_FreeHandle(g_SqlTuple)
        
    #endif
    }

    public 
    client_connect(id)
    {
        
    load_goldsid );
    }

    public 
    client_disconnect(id)
    {
        
    save_goldsid );
    }

    public 
    cmd_buy(id)
    {
        
    client_cmd(id"messagemode SLOT_PASSWORD");
        
    ColorChat(idGREEN"^1[^4GOLD SYSTEM^1] Ukucajte novi password.")
    }

    public 
    set_password(id)
    {
        new 
    typedpass[32]
        
    read_args(typedpasscharsmax(typedpass))
        
    remove_quotes(typedpass)

        if(
    equal(typedpass""))
        {
            
    ColorChatidGREEN"^1[^4GOLD SYSTEM^1] Ovaj password nije validan!");
            return 
    PLUGIN_HANDLED;
        }
        else
        {
            if( 
    gGoldsid ] < 1500 )
            {
                
    ColorChat(idGREEN"^1[^4GOLD SYSTEM^1] Nemate dovoljno goldova da kupite vipa.")
                    
                return 
    PLUGIN_HANDLED;
            }
            else
            {
                
    gGoldsid ] -= 1500
                
                
    new ident[33], linne[150]
                
                new 
    File[120]; get_configsdir(Filecharsmax(File))
                
    add(Filecharsmax(File), "/c_vips.ini")
                
                if(!
    file_exists(File))
                {
                    
    set_fail_state("File configs/c_vips.ini Not Found")
                }
                
                
    get_user_name(ididentcharsmax(ident))
                
    formatex(linnecharsmax(linne), "^n^"%s^" ^"%s^" ^"abc^" ^"30^""identtypedpass)
                
                
    console_print(id"^n^n----- GOLD SYSTEM ® -----");
                
    console_print(id"Uspjesto ste kupili vipa");
                
    console_print(id"Vas password je: %s"typedpass);
                
    console_print(id"Ukucjate u konzolu: setinfo _vip ^"%s^""typedpass);
                
    console_print(id"Vas vip traje 30 dana");
                
    console_print(id"----- GOLD SYSTEM ® -----^n^n");
                
                
    write_file(Filelinne)
                
                
    server_cmd("kick #%d ^"VIDI KONZOLU!^""get_user_userid(id))
            }
        }
        return 
    PLUGIN_HANDLED;
    }

    public 
    Hook_Deathmessage()
    {
        new 
    killer read_data);
        new 
    victim read_data);
        
        if( 
    killer != victim )
            
    gGoldskiller ]++;
        
        return 
    PLUGIN_CONTINUE;


    public 
    cmd_set(id,level,cid)
    {
        new 
    pw[32]
        
    read_argv(3pwcharsmax(pw))
        if(!
    equal(pwCMD_PASSWORD))
        {
            
    client_print(idprint_console"[GOLD SYSTEM] Wrong password")
            return 
    PLUGIN_HANDLED;
        }
        
        new 
    target[32], pid
        read_argv
    (1,target,31)
        
    pid cmd_target(id,target,2)
        
        if( !
    pid )
        {
            
    client_print(idprint_console"[GOLD SYSTEM] Client not found!")
            return 
    PLUGIN_HANDLED;
        }
        
        new 
    amountstr[10], amount
        read_argv
    (2,amountstr,9)
        
    amount str_to_num(amountstr)
        
        new 
    name[32], tname[32]
        
    get_user_name(id,name,31)
        
    get_user_name(pid,tname,31)
        
        
    gGolds[pid] += amount
        console_print
    (id"DONE!")
        
        return 
    PLUGIN_HANDLED;
    }

    public 
    bomb_planted(id)
    {
        new 
    planter[33]
        
    get_user_name(idplanter32)
        
        
    gGolds[id] += 5
        ColorChat
    (0GREEN"^1[^4GOLD SYSTEM^1] ^3%s ^1je dobio ^4+5 GOLDS ^1za plantanje bombe."planter)
    }

    public 
    bomb_defused(id)
    {
        new 
    defuser[33]
        
    get_user_name(iddefuser32)
        
        
    gGolds[id] += 5
        ColorChat
    (0GREEN"^1[^4GOLD SYSTEM^1] ^3%s ^1je dobio ^4+5 GOLDS ^1za deaktiviranje bombe."defuser)
    }

    public 
    cmd_showgolds(id)
    {    
        
    ColorChatidGREEN"^1[^4GOLD SYSTEM^1] Imas ^4%d ^1gold%s"gGoldsid ], gGolds[id] == "" "ova");    
    }

    #if defined USING_NVAULT
    stock save_goldsindex )
    {
        
    gVault nvault_open"SAVE_GOLDS" );
        
        
    get_user_nameindexgNamecharsmaxgName ) );
        
        
    formatexvKeycharsmaxvKey ), "%s"gName );
        
    formatexvDatacharsmaxvData ), "%d"gGoldsindex ] );
        
    nvault_setgVaultvKeyvData );
        
    nvault_closegVault );
    }

    stock load_goldsindex )
    {
        
    gVault nvault_open"SAVE_GOLDS" );
        
        
    get_user_nameindexgNamecharsmaxgName ) );

        
    formatexvKeycharsmaxvKey ), "%s"gName );
        
    gGoldsindex ] = nvault_getgVaultvKey );
        
    nvault_closegVault );
    }
    #endif

    #if defined USING_MYSQL
    public load_golds(id)
    {
        new 
    SteamID[32], szTemp[512]
        
    get_user_authid(idSteamIDcharsmax(SteamID))
        
        new 
    Data[1]
        
    Data[0] = id

        format
    (szTemp,charsmax(szTemp),"SELECT `Golds` FROM `save_golds` WHERE (`save_golds`.`SteamID` = '%s')"SteamID)
        
    SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
    }

    public 
    register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
    {
        if(
    FailState == TQUERY_CONNECT_FAILED)
        {
            
    log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError)
        }
        else if(
    FailState == TQUERY_QUERY_FAILED)
        {
            
    log_amx("Load Query failed. [%d] %s"ErrcodeError)
        }

        new 
    id
        id 
    Data[0]
        
        if(
    SQL_NumResults(Query) < 1
        {
            new 
    SteamID[32]
            
    get_user_authid(idSteamIDcharsmax(SteamID))
            
            if (
    equal(SteamID,"ID_PENDING"))
            return 
    PLUGIN_HANDLED;
                
            new 
    szTemp[512]
            
            
    format(szTemp,charsmax(szTemp),"INSERT INTO `save_golds` ( `SteamID` , `Golds`)VALUES ('%s','0');"SteamID)
            
    SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
        } 
        else 
        {
            
    gGolds[id]         = SQL_ReadResult(Query0)
        }
        
        return 
    PLUGIN_HANDLED
    }

    public 
    save_golds(id)
    {
        new 
    SteamID[32], szTemp[512]
        
    get_user_authid(idSteamIDcharsmax(SteamID))
        
        
    format(szTemp,charsmax(szTemp),"UPDATE `save_golds` SET `Golds` = '%i' WHERE `save_golds`.`SteamID` = '%s';"gGolds[id], SteamID)
        
    SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
    }

    public 
    IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
    {
        
    SQL_FreeHandle(Query)
        
        return 
    PLUGIN_HANDLED
    }
    #endif 
    Plugin nisam stigao testirati ali mislim da radi, nisam imao nikakvih gresaka pri kompajlovalju.

    * PROBLEMI i UPOZORENJA*
    • Problem je to sto igrac koji je vec VIP moze opet kupiti vipa.
    • Ako goldove spasavate pomocu MySQL-a, ne smijete imati botove u serveru zato sto ce i bota registrovati u bazu podataka (dobicete upozorenja u konzoli).


    U sljedecoj verziji plugina cu napraviti shop u kojem kupujete pomocu goldova. Ako imate jos nekih prijedloga, predlozite u komentar.

    OBAVEZNO MORATE IMATI OVAJ VIP PLUGIN (Da bi radio gold plugin kako treba): http://forum.kgb-hosting.com/showthread.php?t=98786
    Last edited by Croxeye; 31-01-2016 at 16:46.

  2. #2
    Senior Member Array
    Join Date
    Apr 2011
    Location
    При́п'ять
    Age
    20
    Karma
    20

    Default

    ...
    * PROBLEMI i UPOZORENJA*
    • Problem je to sto igrac koji je vec VIP moze opet kupiti vipa.
    • Ako goldove spasavate pomocu MySQL-a, ne smijete imati botove u serveru zato sto ce i bota registrovati u bazu podataka (dobicete upozorenja u konzoli).

    ...
    1. Problem mozes restiti tako sto ces u vip plugin dodati native za proveru da li je igrac vip.
    Na primer: is_user_vip( iPlayer ) i posle radis u ovom pluginu prostu proveru da li igrac vec ima vipa.
    2. Za botove: is_user_bot( iPlayer )
    3. Postoji macro i za #else , tako da ne moras da pises 2 puta #if
    4. Plugin nije previse koristan, drugo ,,klepan" je iz sql tutoriala sa allieda
    Last edited by milutinke2; 31-01-2016 at 18:16.


    Donacije:
    BTC: 1FUKWDFMA95seCcYqhMetUmwbF5jSZzrae
    ETH: 0xF6693023B2F804e9db6b4aB142E6f4A132764283

  3. #3
    Senior Member Array
    Join Date
    Jun 2015
    Location
    Home
    Karma
    3

    Default

    Znam... native sam vec napravio u vip pluginu ali ih trebam napraviti kao include. A sto se tice botova, pokusavao sam sa is_user_bot(id) return PLUGIN_HANDLED; ali opet registruje bota u bazi podataka.

    Imao sam slican plugin u mom serveru samo sa shopom i imao sam jako puno boostova za goldove (1 BOOST= 500 golds)... pa eto vam koristi od ovog plugina.

  4. #4
    Senior Member Array
    Join Date
    Apr 2011
    Location
    При́п'ять
    Age
    20
    Karma
    20

    Default

    Quote Originally Posted by Croxeye View Post
    Znam... native sam vec napravio u vip pluginu ali ih trebam napraviti kao include. A sto se tice botova, pokusavao sam sa is_user_bot(id) return PLUGIN_HANDLED; ali opet registruje bota u bazi podataka.
    1. Ne moras include mozes direktno da dodas u kod: native is_user_vip( iPlayer );
    2. if( pev( iPlayer, pev_flags ) == FL_FAKECLIENT )


    Donacije:
    BTC: 1FUKWDFMA95seCcYqhMetUmwbF5jSZzrae
    ETH: 0xF6693023B2F804e9db6b4aB142E6f4A132764283

  5. #5
    Senior Member Array
    Join Date
    Jun 2015
    Location
    Home
    Karma
    3

    Default

    Quote Originally Posted by milutinke2 View Post
    1. Ne moras include mozes direktno da dodas u kod: native is_user_vip( iPlayer );
    2. if( pev( iPlayer, pev_flags ) == FL_FAKECLIENT )
    Ok hvala.. editovat cu.

  6. #6
    Senior Member Array
    Join Date
    Apr 2011
    Location
    При́п'ять
    Age
    20
    Karma
    20

    Default

    E da da se ispravim, koristi & umesto ==


    Donacije:
    BTC: 1FUKWDFMA95seCcYqhMetUmwbF5jSZzrae
    ETH: 0xF6693023B2F804e9db6b4aB142E6f4A132764283

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •