Raised This Month: $ Target: $400
 0% 

Block Buy for Individual Player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Apollyon
SourceMod Donor
Join Date: Dec 2007
Location: California
Old 05-03-2011 , 06:59   Block Buy for Individual Player
Reply With Quote #1

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);
    }

__________________

Last edited by Apollyon; 05-03-2011 at 07:02.
Apollyon is offline
lis_16
Senior Member
Join Date: Feb 2008
Old 05-03-2011 , 07:02   Re: Block Buy for Individual Player
Reply With Quote #2

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.
lis_16 is offline
Apollyon
SourceMod Donor
Join Date: Dec 2007
Location: California
Old 05-03-2011 , 15:13   Re: Block Buy for Individual Player
Reply With Quote #3

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;  

__________________

Last edited by Apollyon; 05-03-2011 at 15:16.
Apollyon is offline
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 05-03-2011 , 16:10   Re: Block Buy for Individual Player
Reply With Quote #4

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)]

__________________


Last edited by SonicSonedit; 05-03-2011 at 16:13.
SonicSonedit is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 05-03-2011 , 17:01   Re: Block Buy for Individual Player
Reply With Quote #5

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.

Last edited by Doc-Holiday; 05-03-2011 at 17:10.
Doc-Holiday is offline
Apollyon
SourceMod Donor
Join Date: Dec 2007
Location: California
Old 05-03-2011 , 17:12   Re: Block Buy for Individual Player
Reply With Quote #6

Thanks guys! It's working great.
__________________
Apollyon is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-03-2011 , 20:48   Re: Block Buy for Individual Player
Reply With Quote #7

You only need to register the message once, so only use it in plugin_init().
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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