AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Coins Plugin - Only Current Player Problem (https://forums.alliedmods.net/showthread.php?t=306921)

polimpo4 04-18-2018 23:53

Coins Plugin - Only Current Player Problem
 
I Create One Plugin To Give Coins To Players..

Like:

1 Normal Kill = 1 Coin
1 Knife Kill = 2 Coins
1 HeadShot = 3 Coins

The Problem:

When Another Player Kill Enemy Even From Other Team The Plugin Give Coins To All... I Need To Know How To Restric Only To The Current Player Give Himself Coins Not From Others...


The Code:

PHP Code:

/ * Plugin generated by AMXX-Studio * /

#include <amxmodx>
#include <amxmisc>
#include <cstrike>


#define PLUGIN "hudsync loop"
#define VERSION "3.2"
#define AUTHOR "_ | Polimpo4 | _"



// Variables
new Points 0;

public 
plugin_init () {
register_plugin (PLUGINVERSIONAUTHOR)

register_event ("DeathMsg""ev_DeathMsg""a");

set_task (0.5"Loop2"0""0"b");
}

public 
client_putinserver (id) {
set_task (0.5"Loop2"0""0"b");
}


public 
ev_DeathMsg () {
// new Live = is_user_alive (id)
new Attacker read_data (1)
new 
Vitima read_data (2)
new 
Headshot read_data (3)
new 
Arma get_user_weapon (Attacker// we can determine it by doing this
// new weapon [32]
// read_data (4, weapon, sizeof (weapon) -1) // but it is not important which method you will use.
new Virus_Name [32// this is just a variable, you can call whatever you want.
get_user_name (VictimVictimName31)
new 
Nickname [32]
get_user_name (AttackerAttackerName31)


if (
Gun == CSW_KNIFE) {
Points Points 2;
set_task (0.5"showpoints (Attacker)")
client_print (Attackerprint_chat"You killed% s with a knife"victim_name)
client_print (Victimprint_chat"You were killed by% s for a knife"Name_Actuating)
}

if (
Headshot) {

Points Points 3;
set_task (0.5"showpoints (Attacker)")
// Show to the attacker who killed.

client_print (Attackerprint_chat"You killed% s by HS"victim_name)

} else if (
Headshot) {

// Show to the victim who killed him:

client_print (Vitimaprint_chat"You were killed by the% s by HS"Name_Actuating)

}

else {
// this is the normal kill

Points Points 1;
set_task (0.5"showpoints (Attacker)")
// Show to the attacker who killed.

client_print (Attackerprint_chat"You killed% s"victim_name)

// Show to the victim who killed him:

client_print (victimprint_chat"was dead by% s"target_name)

}

if (
Attacker == Victim) {
client_print (Attackerprint_chat"You committed suicide!")
return 
PLUGIN_CONTINUE
}
****
if (
cs_get_user_team (Forward) == cs_get_user_team (Victim)) {
return 
PLUGIN_CONTINUE
}

if (
Attacker! = victim) {
// if he has killed 3 this round execute a function

}
****
return 
PLUGIN_CONTINUE
****
}

public 
mostrapontos (Forward) {
****
// your code here
****
****
client_print (Strikerprint_chat"One More Point!")
****
set_task (0.1"Loop2")
}


public 
Loop2 (id, & Points) {

set_hudmessage (2552552550.040.7000.02.00.00.2false)

show_hudmessage (id"Coins:% i"Points);



I Know I Have To Make CVARS But It Is Only In Dev Version.

Anyone Can Help Me?

raizo11 04-19-2018 01:45

Re: Coins Plugin - Only Current Player Problem
 
Sample

Code:

#include <amxmodx>
#include <hamsandwich>

#define PLUGIN ""
#define VERSION ""
#define AUTHOR ""

new g_coins[33];

new wid, hs;

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)

    RegisterHam(Ham_Killed, "player", "fw_PlayerKilled", 1)
}


public fw_PlayerKilled(victim, attacker) 
{
    if (victim == attacker || !is_user_alive(attacker) )
        return
   
    attacker = get_user_attacker(victim,wid,hs)

    if(get_user_weapon(attacker) == CSW_KNIFE)
    {
        g_coins[attacker]+= 1
    }
    else if(hs==HIT_HEAD)
    {
        g_coins[attacker]+= 2
    }

    g_coins[attacker]++
    client_print( attacker, print_center, "Coins %d", g_coins[attacker]);
}

Save coins

Code:

#include <amxmodx>
#include <hamsandwich>
#include <nvault>

#define PLUGIN ""
#define VERSION ""
#define AUTHOR ""

#define STATS_COINS 0 
#define UPDATETIME 5.0

new g_coins[33][1];

new vault, wid, hs;


public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)

    RegisterHam(Ham_Killed, "player", "fw_PlayerKilled", 1)

    set_task( UPDATETIME, "ShowCoinDetails", _, _, _, "b" );

    vault = nvault_open("SaveCoins")
}


public fw_PlayerKilled(victim, attacker) 
{
    if (victim == attacker || !is_user_alive(attacker) )
        return
   
    new A_name[32], V_name[32];

    get_user_name( attacker , A_name , charsmax( A_name ) );
    get_user_name( victim , V_name , charsmax( V_name ) );

    attacker = get_user_attacker(victim,wid,hs)

    if(get_user_weapon(attacker) == CSW_KNIFE)
    {
        g_coins[attacker][STATS_COINS]+=1
        //client_print (attacker, print_chat, "You killed %s with a knife", V_name)
        //client_print (victim, print_chat, "You were killed by %s with a knife", A_name)
    }
    else if(hs==HIT_HEAD)
    {
        g_coins[attacker][STATS_COINS]+=2 
        //client_print (victim, print_chat, "%s got you a headshoot", A_name)
    }

    g_coins[attacker][STATS_COINS]++
    client_print( attacker, print_center, "Coins %d", g_coins[attacker]);

}

public ShowCoinDetails()
{

    new Players[ 32 ];
    new playerCount, i, player;

    get_players(Players, playerCount, "ach");
    for (i=0; i<playerCount; i++)
    {
        player = Players[ i ];
               
        new name[ 50 ];
        get_user_name( player, name, 49 );

        new x_coins = g_coins[player][STATS_COINS]


        if(is_user_alive(player))
        {
            set_hudmessage( 0, 255, 255, 0.02, 0.17, 0, 6.0, UPDATETIME );
            show_hudmessage( player, "[Coins : %i]",x_coins);
        } 
    }

}

public client_putinserver(id)
{
    new name[32],data[512],raw[1][20] 
    get_user_name(id,name,31) 
   
    if(!nvault_get(vault,name,data,511))
        return PLUGIN_CONTINUE
   
    parse(data,raw[0],19)
    g_coins[id][STATS_COINS]=str_to_num(raw[0]) 
   
    return PLUGIN_CONTINUE
}

public client_disconnect(id)
{
    new name[32],data[512] 
    get_user_name(id,name,31) 
    formatex(data,511,"%d",g_coins[id][STATS_COINS]) 
    nvault_set(vault,name,data)

}


polimpo4 04-19-2018 17:06

Re: Coins Plugin - Only Current Player Problem
 
Quote:

Originally Posted by raizo11 (Post 2588418)
sample

Code:

#include <amxmodx>
#include <hamsandwich>

#define plugin ""
#define version ""
#define author ""

new g_coins[33];

new wid, hs;

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

    registerham(ham_killed, "player", "fw_playerkilled", 1)
}


public fw_playerkilled(victim, attacker) 
{
    if (victim == attacker || !is_user_alive(attacker) )
        return
   
    attacker = get_user_attacker(victim,wid,hs)

    if(get_user_weapon(attacker) == csw_knife)
    {
        g_coins[attacker]+= 1
    }
    else if(hs==hit_head)
    {
        g_coins[attacker]+= 2
    }

    g_coins[attacker]++
    client_print( attacker, print_center, "coins %d", g_coins[attacker]);
}

save coins

Code:

#include <amxmodx>
#include <hamsandwich>
#include <nvault>

#define plugin ""
#define version ""
#define author ""

#define stats_coins 0 
#define updatetime 5.0

new g_coins[33][1];

new vault, wid, hs;


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

    registerham(ham_killed, "player", "fw_playerkilled", 1)

    set_task( updatetime, "showcoindetails", _, _, _, "b" );

    vault = nvault_open("savecoins")
}


public fw_playerkilled(victim, attacker) 
{
    if (victim == attacker || !is_user_alive(attacker) )
        return
   
    new a_name[32], v_name[32];

    get_user_name( attacker , a_name , charsmax( a_name ) );
    get_user_name( victim , v_name , charsmax( v_name ) );

    attacker = get_user_attacker(victim,wid,hs)

    if(get_user_weapon(attacker) == csw_knife)
    {
        g_coins[attacker][stats_coins]+=1
        //client_print (attacker, print_chat, "you killed %s with a knife", v_name)
        //client_print (victim, print_chat, "you were killed by %s with a knife", a_name)
    }
    else if(hs==hit_head)
    {
        g_coins[attacker][stats_coins]+=2 
        //client_print (victim, print_chat, "%s got you a headshoot", a_name)
    }

    g_coins[attacker][stats_coins]++
    client_print( attacker, print_center, "coins %d", g_coins[attacker]);

}

public showcoindetails()
{

    new players[ 32 ];
    new playercount, i, player;

    get_players(players, playercount, "ach");
    for (i=0; i<playercount; i++)
    {
        player = players[ i ];
               
        new name[ 50 ];
        get_user_name( player, name, 49 );

        new x_coins = g_coins[player][stats_coins]


        if(is_user_alive(player))
        {
            set_hudmessage( 0, 255, 255, 0.02, 0.17, 0, 6.0, updatetime );
            show_hudmessage( player, "[coins : %i]",x_coins);
        } 
    }

}

public client_putinserver(id)
{
    new name[32],data[512],raw[1][20] 
    get_user_name(id,name,31) 
   
    if(!nvault_get(vault,name,data,511))
        return plugin_continue
   
    parse(data,raw[0],19)
    g_coins[id][stats_coins]=str_to_num(raw[0]) 
   
    return plugin_continue
}

public client_disconnect(id)
{
    new name[32],data[512] 
    get_user_name(id,name,31) 
    formatex(data,511,"%d",g_coins[id][stats_coins]) 
    nvault_set(vault,name,data)

}


you are the man... !!!! May i use your credits?! Like publish your nick?

polimpo4 04-19-2018 19:24

Re: Coins Plugin - Only Current Player Problem
 
I Add Some Functions As Give_Coins And Set_Coins... I Set Function "SaveCoins" to Save Into Vault To Be Easy To Save Coins Into Give_Coins And Set_Coins Functions And Create Chat Messages To All Players Know When Someone Give Them Coins Or Set...

raizo11 04-20-2018 03:24

Re: Coins Plugin - Only Current Player Problem
 
Code:

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <nvault>

#define PLUGIN ""
#define VERSION ""
#define AUTHOR ""

#define STATS_COINS 0 
#define UPDATETIME 5.0

new g_coins[33][1];

new vault, wid, hs;


public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)

    RegisterHam(Ham_Killed, "player", "fw_PlayerKilled", 1)

    register_clcmd( "amx_setcoins", "SetCoins", ADMIN_MENU );

    set_task( UPDATETIME, "ShowCoinDetails", _, _, _, "b" );

    vault = nvault_open("SaveCoins")
}


public fw_PlayerKilled(victim, attacker) 
{
    if (victim == attacker || !is_user_alive(attacker) )
        return
   
    new A_name[32], V_name[32];

    get_user_name( attacker , A_name , charsmax( A_name ) );
    get_user_name( victim , V_name , charsmax( V_name ) );

    attacker = get_user_attacker(victim,wid,hs)

    if(get_user_weapon(attacker) == CSW_KNIFE)
    {
        g_coins[attacker][STATS_COINS]+=1
        //client_print (attacker, print_chat, "You killed %s with a knife", V_name)
        //client_print (victim, print_chat, "You were killed by %s with a knife", A_name)
    }
    else if(hs==HIT_HEAD)
    {
        g_coins[attacker][STATS_COINS]+=2 
        //client_print (victim, print_chat, "%s got you a headshoot", A_name)
    }

    g_coins[attacker][STATS_COINS]++
    client_print( attacker, print_center, "Coins %d", g_coins[attacker]);

}

public SetCoins( id, level, cid )
{
        if (!cmd_access(id,level,cid,2))
                return PLUGIN_HANDLED ;

        new sxName[ 50 ], szName[ 32 ];
        get_user_name( id , szName , charsmax( szName ) );

        read_argv( 1, sxName, 49 );
        new valSz[ 50 ], val;
        read_argv( 2, valSz, 49 );
        val = str_to_num( valSz );
       
        new user = cmd_target( id, sxName, CMDTARGET_ALLOW_SELF );

        g_coins[user][STATS_COINS] = val * 1;

        client_print_color(0, "!t%s !greceive [%d] !tfrom the admin !g%s",sxName, g_coins[user][STATS_COINS], szName);
       
        return PLUGIN_HANDLED;
}

public ShowCoinDetails()
{

    new Players[ 32 ];
    new playerCount, i, player;

    get_players(Players, playerCount, "ach");
    for (i=0; i<playerCount; i++)
    {
        player = Players[ i ];
               
        new name[ 50 ];
        get_user_name( player, name, 49 );

        new x_coins = g_coins[player][STATS_COINS]


        if(is_user_alive(player))
        {
            set_hudmessage( 0, 255, 255, 0.02, 0.17, 0, 6.0, UPDATETIME );
            show_hudmessage( player, "[Coins : %i]",x_coins);
        } 
    }

}

public client_putinserver(id)
{
    new name[32],data[512],raw[1][20] 
    get_user_name(id,name,31) 
   
    if(!nvault_get(vault,name,data,511))
        return PLUGIN_CONTINUE
   
    parse(data,raw[0],19)
    g_coins[id][STATS_COINS]=str_to_num(raw[0]) 
   
    return PLUGIN_CONTINUE
}

public client_disconnect(id)
{
    new name[32],data[512] 
    get_user_name(id,name,31) 
    formatex(data,511,"%d",g_coins[id][STATS_COINS]) 
    nvault_set(vault,name,data)

}

stock client_print_color(const id, const input[], any:...) 

    new count = 1, players[32]; 
    static msg[191]; 
    vformat(msg, 190, input, 3);
    replace_all(msg, 190, "!g", "^x04"); // Green Color 
    replace_all(msg, 190, "!y", "^x01"); // Default Color 
    replace_all(msg, 190, "!t", "^x03"); // Team Color 
    if (id) players[0] = id; else get_players(players, count, "ch"); 
    { 
        for (new i = 0; i < count; i++) 
        { 
            if (is_user_connected(players[i])) 
            { 
                message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i]); 
                write_byte(players[i]); 
                write_string(msg); 
                message_end(); 

            } 
        } 
    } 
}



All times are GMT -4. The time now is 04:44.

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