AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Stop players from buying but not from picking. (https://forums.alliedmods.net/showthread.php?t=170471)

Evaldas.Grigas 10-25-2011 10:19

Stop players from buying but not from picking.
 
I want to know what to do that this code would be only that players who don't have ADMIN_LEVEL_H coudn't buy awp, sg550, g3sg1. But they could pick it up if someone drop it.
PHP Code:

public event_CurSnipers(id)
    {    
    
get_mapnamemapnamecharsmax(mapname) );
    if ( 
equali(mapname"awp_india") || equali(mapname"awp_dust") || equali(mapname"cs_deagle5") )
        return 
PLUGIN_CONTINUE;
        
    if(
read_data(2) == CSW_G3SG1)
    {
        if(!(
get_user_flags(id) & ADMIN_LEVEL_H))
        {
        
client_print(idprint_center"Sniper's only for VIP's")
        
client_cmd(id"drop")
        }
    }
    if(
read_data(2) == CSW_SG550)
    {
        if(!(
get_user_flags(id) & ADMIN_LEVEL_H))
        {
            
client_print(idprint_center"Sniper's only for VIP's")
            
client_cmd(id"drop")
        }
    }
    if(
read_data(2) == CSW_AWP)
    {
        if(!(
get_user_flags(id) & ADMIN_LEVEL_H))
        {
        
client_print(idprint_center"Sniper's only for VIP's")
        
client_cmd(id"drop")
        }
    }
    return 
PLUGIN_HANDLED



Bugsy 10-25-2011 23:36

Re: Stop players from buying but not from picking.
 
I have a better/cleaner idea in mind, I'll redo it when I get a chance. The annoying thing with my current method is the player drops his current weapon when he attempts to buy a restricted weapon and the restricted weapon gets dropped/deleted and the player gets his money back. It would be cleaner if these things were not visible to they player.
PHP Code:


#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

new const Version[] = "0.1";

const 
OFFSET_CSMONEY 115;
const 
NO_BUY_WEAPONS = ( ( << CSW_AWP ) | ( << CSW_G3SG1 ) | ( << CSW_SG550 ) );
const 
ADMIN_FLAG ADMIN_LEVEL_H;

new 
g_iMoney33 ] , g_Weapons33 ] , HamHook:g_HamSpawn;

public 
plugin_init() 
{
    
register_plugin"Pickup-Only Weapons" Version "bugsy" );
    
    
register_messageget_user_msgid"Money" ) , "MessageMoney" );
    
RegisterHamHam_AddPlayerItem "player" "fw_HamAddPlayerItem" );
}

public 
MessageMoneymsgid dest id )
{
    if ( 
get_user_flagsid ) & ADMIN_FLAG )
        return;

    new 
iNewWeapon = ( pevid pev_weapons ) & ~g_Weaponsid ] ) & NO_BUY_WEAPONS;
    new 
iSpent g_iMoneyid ] - ( g_iMoneyid ] = get_msg_arg_int) );
    new 
iNewMoney g_iMoneyid ];
    
    if ( 
iNewWeapon )
    {
        
set_pdata_intid OFFSET_CSMONEY iNewMoney iSpent );
        
set_msg_arg_intARG_LONG iNewMoney iSpent );
        
g_iMoneyid ] += iSpent;
        
        new 
szWeapon20 ];
        
get_weaponnameGetBitiNewWeapon ) , szWeapon charsmaxszWeapon ) );
        
g_HamSpawn RegisterHamHam_Spawn "weaponbox" "fw_HamSpawn_Weaponbox" );
        
engclient_cmdid "drop" szWeapon );

        
ucfirstszWeapon] );
        
client_printid print_center "You Cannot Purchase The %s" szWeapon] );
    }
}

public 
fw_HamAddPlayerItemiPlayer )
{
    
g_WeaponsiPlayer ] = peviPlayer pev_weapons );
}

public 
fw_HamSpawn_WeaponboxiEntity )
{
    
set_peviEntity pev_flags FL_KILLME );
    
dllfuncDLLFunc_Think iEntity );
    
DisableHamForwardg_HamSpawn );
}

GetBitiValue )
{
    new 
iBit = -1;
    
    for ( new 
32 i++ )
    {
        if ( 
iValue & ( << ) )
        {
            
iBit i;
            break;
        }
    }
    
    return 
iBit;



ConnorMcLeod 10-26-2011 01:27

Re: Stop players from buying but not from picking.
 
When you remove a weaponbox at spawn it's too early so weapons are not removed as well.
I think this way is cleaner : http://forums.alliedmods.net/showthread.php?t=149380

And anyway, i think such plugins already exist.

Edit : Best way is "info_map_parameters" way !!!
Simple and efficient :
PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define VERSION "0.0.1"
#define PLUGIN "No Buy"

public plugin_init()
{
    
register_plugin(PLUGINVERSION"ConnorMcLeod")

    
register_clcmd("buy""ClientCommand_Buy")
    
register_clcmd("bUy""ClientCommand_Buy")
    
register_clcmd("buY""ClientCommand_Buy")
    
register_clcmd("bUY""ClientCommand_Buy")
    
register_clcmd("Buy""ClientCommand_Buy")
    
register_clcmd("BUy""ClientCommand_Buy")
    
register_clcmd("BuY""ClientCommand_Buy")
    
register_clcmd("BUY""ClientCommand_Buy")
}

public 
plugin_precache()
{
    
#define CMapInfo_Linux_XOff    5
    #define m_iBuyingStatus 34
    
new iEnt engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString,"info_map_parameters"))
    
set_pdata_int(iEntm_iBuyingStatus3CMapInfo_Linux_XOff)
    
dllfunc(DLLFunc_SpawniEnt)
    
engfunc(EngFunc_RemoveEntityiEnt)

    
server_cmd("sv_restartround 1")
}

public 
ClientCommand_Buy/* id */ )
{
    return 
PLUGIN_HANDLED_MAIN



Evaldas.Grigas 10-26-2011 01:41

Re: Stop players from buying but not from picking.
 
Ok. I don't understand your codes at all. Can you explaine me this?
PHP Code:

if(read_data(2) == CSW_AWP

Its reads if player tries to buy and if player has AWP?

drekes 10-26-2011 05:55

Re: Stop players from buying but not from picking.
 
Bacause client_buy is a forward.
It's used like this:
PHP Code:

public client_buy(idiItem)
{
    if(
iItem == CSW_G3SG1)
    {
        
// id attemps to buy g3sg1
    
}



Bugsy 10-26-2011 08:15

Re: Stop players from buying but not from picking.
 
Connor, this is the second time I forgot about your client_buy() forward and wasted time doing something another less desirable way. This is not the other method I had in mind, I was thinking what you did here which also worked cleanly but the method below is obviously much easier\appropriate.

The below plugin requires that you install ConnorMcLeods client_buy forward:
1. Download cl_buy.inc, put in include folder
2. Download and compile client_buy.sma. Place in plugins folder.
3. Add to plugins.ini client_buy.amxx

If you want it to display the weapon name when a buy attempt is made just let me know or you may be able to figure it out.
PHP Code:

#include <amxmodx>
#include <cl_buy>

new const Version[] = "0.2";

const 
NO_BUY_WEAPONS = ( ( << CSW_AWP ) | ( << CSW_G3SG1 ) | ( << CSW_SG550 ) );
const 
ADMIN_FLAG ADMIN_LEVEL_H;

public 
plugin_init() 
{
    
register_plugin"No-Buy Weapons" Version "bugsy" );
}

public 
client_buyid iItem )
{
    if ( ( ( 
<< iItem ) & NO_BUY_WEAPONS ) && !( get_user_flagsid ) & ADMIN_LEVEL_H ) && !user_has_weaponid iItem ) )
    {
        
client_printid print_center "You cannot buy that" );
        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_CONTINUE;



Evaldas.Grigas 10-26-2011 11:09

Re: Stop players from buying but not from picking.
 
Why this doesn't work? Still normal player can buy sg550. I want it to stop them from buying.
PHP Code:

public event_CurSnipers(idi Item)
{
    if(
iItem == CSW_SG550)
    {
        if(!(
get_user_flags(id) & ADMIN_LEVEL_H))
        {
            
client_print(idprint_center"Sniper's only for VIP's")
            
client_cmd(id"drop")
        }
    }



Bugsy 10-26-2011 11:17

Re: Stop players from buying but not from picking.
 
I wrote two plugins for you, why are you still trying to use your code which is wrong and doesn't work? Use the plugin in my above post.

Evaldas.Grigas 10-26-2011 11:20

Re: Stop players from buying but not from picking.
 
I'll test it.
EDIT: Doesn't work. Why do you need this? const ADMIN_FLAG = ADMIN_LEVEL_H;

Bugsy 10-26-2011 11:29

Re: Stop players from buying but not from picking.
 
If a player has that flag he can buy those rifles...like you asked for.


All times are GMT -4. The time now is 14:15.

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