AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   transfer plugin (https://forums.alliedmods.net/showthread.php?t=333035)

giumbalau 06-15-2021 14:46

transfer plugin
 
I was trying to limit the commands because the players are abusing of them but i am doing something wrong can anyone fix it ?

PHP Code:

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

new g_movelimit

public plugin_init()
{
       
register_plugin("Players transfer""1.9.0.5271""")

       
register_clcmd("say /spec","spec")
       
register_clcmd("say_team /spec","spec")
       
register_clcmd("say /ct","ct")
       
register_clcmd("say_team /ct","ct")
       
register_clcmd("say /t","t")
       
register_clcmd("say_team /t","t")

       
g_movelimit register_cvar("move_limit""3")
}
 
public 
spec(id)
{     
       if(
get_pcvar_num(g_movelimit))
       {
       
color_chat(id"^4%s^3 This command can be used only^4 3 times per map")
       return 
PLUGIN_HANDLED
       
}    
 
       
cs_set_user_team(id,CS_TEAM_SPECTATOR)

       if(
is_user_alive(id))
       
user_silentkill(id)

       return 
PLUGIN_HANDLED     
}

public 
ct(id)
{
       
cs_set_user_team(id,CS_TEAM_CT)
       
user_silentkill(id)

       return 
PLUGIN_HANDLED
}

public 
t(id)
{
       
cs_set_user_team(id,CS_TEAM_T)
       
user_silentkill(id)

       return 
PLUGIN_HANDLED
}

stock color_chat(const id, const input[], any:...)
{
    new 
count 1players[32];
    static 
msg[191];
    
vformat(msg190input3);
    
    
replace_all(msg190"!g""^4"); // Green Color
    
replace_all(msg190"!y""^1"); // Default Color
    
replace_all(msg190"!team""^3"); // Team Color
    
replace_all(msg190"!team2""^0"); // Team2 Color
        
    
if (idplayers[0] = id; else get_players(playerscount"ch");
    {
        for (new 
0counti++)
        {
            if (
is_user_connected(players[i]))
            {
                
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _players[i]);
                
write_byte(players[i]);
                
write_string(msg);
                
message_end();
            }
        }
    }



iceeedr 06-15-2021 14:53

Re: transfer plugin
 
In a very basic way you would do this, or you can save the amount of player team changes in a Trie that is cleared at every map change, good luck.

PHP Code:

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

new g_movelimit
new iTransferTimes[33]

public 
plugin_init()
{
       
register_plugin("Players transfer""1.9.0.5271""")

       
register_clcmd("say /spec","spec")
       
register_clcmd("say_team /spec","spec")
       
register_clcmd("say /ct","ct")
       
register_clcmd("say_team /ct","ct")
       
register_clcmd("say /t","t")
       
register_clcmd("say_team /t","t")

       
g_movelimit register_cvar("move_limit""3")
}

public 
client_connect(id)
{
        
iTransferTimes[id] = 0
}

public 
spec(id)
{     
        
iTransferTimes[id] += 1
       
if(iTransferTimes[id] >= get_pcvar_num(g_movelimit))
       {
        
color_chat(id"^4%s^3 This command can be used only^4 3 times per map")
        return 
PLUGIN_HANDLED
       
}    
 
       
cs_set_user_team(id,CS_TEAM_SPECTATOR)

       if(
is_user_alive(id))
       
user_silentkill(id)

       return 
PLUGIN_HANDLED     
}

public 
ct(id)
{
       
cs_set_user_team(id,CS_TEAM_CT)
       
user_silentkill(id)

       return 
PLUGIN_HANDLED
}

public 
t(id)
{
       
cs_set_user_team(id,CS_TEAM_T)
       
user_silentkill(id)

       return 
PLUGIN_HANDLED
}

stock color_chat(const id, const input[], any:...)
{
    new 
count 1players[32];
    static 
msg[191];
    
vformat(msg190input3);
    
    
replace_all(msg190"!g""^4"); // Green Color
    
replace_all(msg190"!y""^1"); // Default Color
    
replace_all(msg190"!team""^3"); // Team Color
    
replace_all(msg190"!team2""^0"); // Team2 Color
        
    
if (idplayers[0] = id; else get_players(playerscount"ch");
    {
        for (new 
0counti++)
        {
            if (
is_user_connected(players[i]))
            {
                
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _players[i]);
                
write_byte(players[i]);
                
write_string(msg);
                
message_end();
            }
        }
    }



giumbalau 06-15-2021 15:11

Re: transfer plugin
 
Quote:

Originally Posted by iceeedr (Post 2749806)
In a very basic way you would do this, or you can save the amount of player team changes in a Trie that is cleared at every map change, good luck.

PHP Code:

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

new g_movelimit
new iTransferTimes[33]

public 
plugin_init()
{
       
register_plugin("Players transfer""1.9.0.5271""")

       
register_clcmd("say /spec","spec")
       
register_clcmd("say_team /spec","spec")
       
register_clcmd("say /ct","ct")
       
register_clcmd("say_team /ct","ct")
       
register_clcmd("say /t","t")
       
register_clcmd("say_team /t","t")

       
g_movelimit register_cvar("move_limit""3")
}

public 
client_connect(id)
{
        
iTransferTimes[id] = 0
}

public 
spec(id)
{     
        
iTransferTimes[id] += 1
       
if(iTransferTimes[id] >= get_pcvar_num(g_movelimit))
       {
        
color_chat(id"^4%s^3 This command can be used only^4 3 times per map")
        return 
PLUGIN_HANDLED
       
}    
 
       
cs_set_user_team(id,CS_TEAM_SPECTATOR)

       if(
is_user_alive(id))
       
user_silentkill(id)

       return 
PLUGIN_HANDLED     
}

public 
ct(id)
{
       
cs_set_user_team(id,CS_TEAM_CT)
       
user_silentkill(id)

       return 
PLUGIN_HANDLED
}

public 
t(id)
{
       
cs_set_user_team(id,CS_TEAM_T)
       
user_silentkill(id)

       return 
PLUGIN_HANDLED
}

stock color_chat(const id, const input[], any:...)
{
    new 
count 1players[32];
    static 
msg[191];
    
vformat(msg190input3);
    
    
replace_all(msg190"!g""^4"); // Green Color
    
replace_all(msg190"!y""^1"); // Default Color
    
replace_all(msg190"!team""^3"); // Team Color
    
replace_all(msg190"!team2""^0"); // Team2 Color
        
    
if (idplayers[0] = id; else get_players(playerscount"ch");
    {
        for (new 
0counti++)
        {
            if (
is_user_connected(players[i]))
            {
                
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _players[i]);
                
write_byte(players[i]);
                
write_string(msg);
                
message_end();
            }
        }
    }



Thank you very much

fysiks 06-15-2021 22:20

Re: transfer plugin
 
Here is an example that shows both the method iceeedr posted but also a method for limiting the frequency of use by forcing players to wait a specific amount of time between subsequent uses:

PHP Code:

#include <amxmodx>

public plugin_init()
{
    
register_plugin("Limit Command Use Example""0.0""Author")
    
    
register_concmd("myTimeLimitedCommand""cmdLimitByTime")
    
register_concmd("myUseLimitCommandPerMap""cmdUseLimitPerMapCommand")
}


/*
*   Limit use by the time elapsed since last use
*/

new lastTimestamp[MAX_PLAYERS+1]

public 
cmdLimitByTime(id)
{
    new 
nowTimestamp get_systime()

    if( 
nowTimestamp lastTimestamp[id] > 60 )
    {
        
// 60 seconds has elapsed since last use
        
        /*
        *   Run Command Code Here
        */

        // Update the saved timestamp in lastTimestamp
        
lastTimestamp[id] = nowTimestamp
    
}
    else
    {
        
// 60 seconds has NOT yet elapsed since last use

        /*
        *   Notify user that they cannot use command until 60 seconds has elapsed since last use
        */
    
}
}


/*
*   Limit use by number of times command has been used on this map
*/

new useCount[MAX_PLAYERS+1]

public 
cmdUseLimitPerMapCommand(id)
{
    if( 
useCount[id] < )
    {
        
// Command has been used fewer than 3 times this map
        
        /*
        *   Run Command Code Here
        */
        
        // Increment the stored use count for this command
        
useCount[id]++
    }
    else
    {
        
// Command has already been used 3 times
        
        /*
        *   Notify user that they can no longer use this command on this map
        */
    
}




All times are GMT -4. The time now is 19:54.

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