AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Block Buy for Individual Player (https://forums.alliedmods.net/showthread.php?t=156240)

Apollyon 05-03-2011 06:59

Block Buy for Individual Player
 
I have a plugin that will choose a random player from the TE team at player spawn. I would like to block that player from buying anything/anyway. The other players on that team could still buy. Can you show me an example of the code to use?

PHP Code:

public PlayerSpawn(id)
{
    new 
tPlayers[32], tPlayerNumname[32], id;
    
get_players(tPlayerstPlayerNum"e""TERRORIST");
    
    if(
tPlayerNum)
    {
        
id tPlayers[(tPlayerNum 1) ? random(tPlayerNum) : 0];
        
LeaderGlow(id);
        
get_user_name(idnamecharsmax(name));
        
ColorChat(0,RED"[%s] ^4%s ^1is Leader this round"PrefixNamename);
    }



lis_16 05-03-2011 07:02

Re: Block Buy for Individual Player
 
Search for plugins that block buying and just add if(id!=random_player) return plugin_continue where id is id of player called the block function and random_player is your player.

Apollyon 05-03-2011 15:13

Re: Block Buy for Individual Player
 
Can this be used on a single player? Can you show how to apply it to my random player from above post?

PHP Code:

#include <amxmodx> 
#include <fakemeta> 

public plugin_cfg()  
{  
    
register_message(get_user_msgid("StatusIcon"), "Message_StatusIcon"); 


public 
Message_StatusIcon(iMsgIdiMsgDestid)  
{  
    static 
szIcon[8];  
    
get_msg_arg_string(2szIconcharsmax(szIcon));  
    if( 
equal(szIcon"buyzone") ) 
    {  
        if( 
get_msg_arg_int(1) )  
        {  
            
set_pdata_int(id235get_pdata_int(id235) & ~(1<<0)); 
            return 
PLUGIN_HANDLED;  
        }  
    }  
      
    return 
PLUGIN_CONTINUE;  



SonicSonedit 05-03-2011 16:10

Re: Block Buy for Individual Player
 
PHP Code:

#include <amxmodx> 
#include <fakemeta> 

enum
{
    
CS_TEAM_UNASSIGNED=0,
    
CS_TEAM_T,
    
CS_TEAM_CT,
    
CS_TEAM_SPECTATOR
}

const 
OFFSET_LINUX=5
const OFFSET_CSTEAMS=114

new g_maxplayers

new some_random_ct
new some_random_t

public plugin_cfg()  
{  
    
register_message(get_user_msgid("StatusIcon"), "Message_StatusIcon")
    
    
register_event("HLTV""event_round_start""a""1=0""2=0")
    
    
g_maxplayers=get_maxplayers()


public 
Message_StatusIcon(iMsgIdiMsgDestid)  
{  
    static 
szIcon[8]
    
    if ((
id!=some_random_t)&&(id!=some_random_ct))
    return 
PLUGIN_CONTINUE;  
    
    
get_msg_arg_string(2szIconcharsmax(szIcon));  
    if( 
equal(szIcon"buyzone") ) 
    {  
        if( 
get_msg_arg_int(1) )  
        {  
            
set_pdata_int(id235get_pdata_int(id235) & ~(1<<0)); 
            return 
PLUGIN_HANDLED;  
        }  
    }  
    return 
PLUGIN_CONTINUE;  
}  

public 
event_round_start()
{
    
some_random_t=get_random_player(_CS_TEAM_T)
    
some_random_ct=get_random_player(_CS_TEAM_CT)
}

stock get_random_player(alive=2team=4)
{
    static 
idplayerscountplayers[32]
    
    
playerscount=0
    
    
for (id=1;id<=g_maxplayers;id++)
    {
        if (!
is_user_connected(id))
            continue
            
        if (
is_user_alive(id)!=alive&&alive!=2)
            continue
            
        if (
get_pdata_int(idOFFSET_CSTEAMSOFFSET_LINUX)!=team&&team!=4)
            continue

        
players[playerscount]=id
        playerscount
++
    }
    
    if (!
playerscount)
        return 
0
    
    
return players[random_num(0,playerscount-1)]



Doc-Holiday 05-03-2011 17:01

Re: Block Buy for Individual Player
 
Wouldn't you have to set the No buyzone in the round start since its a different random player each round?


PHP Code:

public plugin_init()

    
register_event("HLTV""NewRound""a""1=0""2=0");


PHP Code:

public NewRound()
{
    new 
tPlayers[32], tPlayerNumname[32];
    
get_players(tPlayerstPlayerNum"e""TERRORIST");
    
    if(
tPlayerNum)
    {
        
g_iLeaderid tPlayers[(tPlayerNum 1) ? random(tPlayerNum) : 0];
        
        
LeaderGlow(g_iLeaderid);
        
        
get_user_name(g_iLeaderidnamecharsmax(name));
        
ColorChat(0,RED"[%s] ^4%s ^1is Leader this round"PrefixNamename);
    }
    
register_message(get_user_msgid("StatusIcon"), "Message_StatusIcon");


PHP Code:

public Message_StatusIcon(iMsgIdiMsgDestid)  
{
    if(
id == g_iLeaderid)
    {
        static 
szIcon[8];  
        
get_msg_arg_string(2szIconcharsmax(szIcon));  
        if( 
equal(szIcon"buyzone") ) 
        {  
            if( 
get_msg_arg_int(1) )  
            {  
                
set_pdata_int(id235get_pdata_int(id235) & ~(1<<0)); 
                return 
PLUGIN_HANDLED;  
            }  
        }
    }
      
    return 
PLUGIN_CONTINUE;  


EDIT: Just tested works in both places however.. I think plugin_cfg is called less right? instead of every round so it would be more efficient to have it in cfg like you do.

Apollyon 05-03-2011 17:12

Re: Block Buy for Individual Player
 
Thanks guys! It's working great.

Exolent[jNr] 05-03-2011 20:48

Re: Block Buy for Individual Player
 
You only need to register the message once, so only use it in plugin_init().


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

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