AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Function to Forbid Primary Weapons (https://forums.alliedmods.net/showthread.php?t=85632)

Mlk27 02-13-2009 22:54

Function to Forbid Primary Weapons
 
can anyone write me a *function* to strip and drop any primary weapons when they are used and block them from being picked up from ground..

Bugsy 02-13-2009 23:06

Re: Forbid Primary Weapons
 
Quote:

Originally Posted by Mlk27 (Post 761226)
can anyone write me a function to strip and drop any primary weapons on weapon pickup and FM_Touch?

See this link, hlev's method works great for not picking up weapons. You will need to figure out on your own a way to specify which weapons get ignored. If you can't figure it out send me a PM and I will help you.

http://forums.alliedmods.net/showthread.php?t=78113

ConnorMcLeod 02-14-2009 02:31

Re: Forbid Primary Weapons
 
Would be more efficient to use hamsandwich.

PHP Code:

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

#define PLUGIN "Don't PickUp Primaries"
#define AUTHOR "ConnorMcLeod"
#define VERSION "0.0.1"

#define    m_rgpPlayerItems_Slot1    35

new g_iMaxPlayers

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
RegisterHam(Ham_Touch"weaponbox""WeaponBox_Touch")

    
g_iMaxPlayers get_maxplayers()
}

public 
WeaponBox_Touch(iEntid)
{
    if( 
id || id g_iMaxPlayers || !(pev(iEntpev_flags) & FL_ONGROUND) || !is_user_alive(id) )
    {
        return 
HAM_IGNORED
    
}

    static 
iWeapon
    iWeapon 
get_pdata_cbase(iEntm_rgpPlayerItems_Slot14)
    if( 
pev_valid(iWeapon) )
    {
        return 
HAM_SUPERCEDE
    
}

    return 
HAM_IGNORED



Mlk27 02-14-2009 03:15

Re: Forbid Primary Weapons
 
connor thanks man but that seems to ony block weapon picked up but it doesnt drop or strip bought primary weapons

ConnorMcLeod 02-14-2009 03:58

Re: Forbid Primary Weapons
 
You haven't ask this clearly.
Needs more code, will do it later if nobody else has tried something, and if i can do it :mrgreen:


-edit-
Seems that restrict plugin in default amxx package would be the best.

Bugsy 02-14-2009 13:16

Re: Function to Forbid Primary Weapons
 
Here is working code; I originally had it coded it with FM_Touch but used ConnorMcLeods Ham forward instead for efficiency. The Ham_AddPlayerItem code is by danielkza. I'm sure there is an optimization that can be done.

PHP Code:

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

#define PLUGIN "No Primary Weapons"
#define AUTHOR "bugsy\ConnorMcLeod\danielkza"
#define VERSION "0.1"

#define    m_rgpPlayerItems_Slot1    35

new g_iMaxPlayers;

new const 
g_PrimaryWeapons[33][] = 
{
    
"",
    
"",
    
"",
    
"weapon_scout",   
    
"",
    
"weapon_xm1014",
    
"",
    
"weapon_mac10",
    
"weapon_aug",
    
"",
    
"",
    
"",
    
"weapon_ump45",
    
"weapon_sg550",
    
"weapon_galil",
    
"weapon_famas",
    
"",
    
"",
    
"weapon_awp",
    
"weapon_mp5navy",
    
"weapon_m249",
    
"weapon_m3",
    
"weapon_m4a1",
    
"weapon_tmp",
    
"weapon_g3sg1",
    
"",
    
"",
    
"weapon_sg552",
    
"weapon_ak47",
    
"",
    
"weapon_p90",
    
"",
    
""
};

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
                               
    
RegisterHam(Ham_Touch"weaponbox""fw_Touch");
    
RegisterHam(Ham_AddPlayerItem,"player""fw_AddPlayerItem");

    
g_iMaxPlayers get_maxplayers();
}

public 
fw_AddPlayerItem(player,item)
{
    static 
szClassname[32];
    
    
pev(item,pev_classname,szClassname,charsmax(szClassname));
    
    if( 
IsPrimaryszClassname ) )
    {
        
//Use HAM_SUPERCEDE to make the weapon never get picked up and get removed from map when purchased
        
return HAM_SUPERCEDE;
        
        
//Use the below to let the player pickup the weapon but get instantly dropped. The weapon will remain
        //available for players to pickup. Must comment return HAM_SUPERCEDE above if using this method.
        //client_cmd(player , "drop %s" , szClassname);
    
}
    
    return 
HAM_IGNORED;
}


public 
fw_Touch(iEntid)
{
    if( !(
id g_iMaxPlayers) || !(pev(iEntpev_flags) & FL_ONGROUND) || !is_user_alive(id) )
        return 
HAM_IGNORED;
    
    static 
iWeapon;
    
iWeapon get_pdata_cbase(iEntm_rgpPlayerItems_Slot14);
    
    if( 
pev_valid(iWeapon) )
        return 
HAM_SUPERCEDE;
    
    return 
HAM_IGNORED;
}  

IsPrimary(szWeapon[])
{
    static 
i;
    for( 
33i++ )
        if( 
equalszWeapon g_PrimaryWeapons[i]) )
            return 
i;
    
    return 
0;



ConnorMcLeod 02-14-2009 13:53

Re: Function to Forbid Primary Weapons
 
With this method, player's money is still taken.
And you don't need to hook Touch.

PHP Code:

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

#define PLUGIN "no primaries"
#define AUTHOR "ConnorMcLeod"
#define VERSION "0.0.1"

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
RegisterHam(Ham_AddPlayerItem"player""Player_AddPlayerItem")
}

public 
Player_AddPlayerItem(idiWeapon)
{
    if( 
ExecuteHam(Ham_Item_ItemSlotiWeapon) == )
    {
        
SetHamReturnInteger(0)
        return 
HAM_SUPERCEDE
    
}
    return 
HAM_IGNORED



Mlk27 02-15-2009 20:02

Re: Function to Forbid Primary Weapons
 
@bugsy

thanks..i uncommented the line to drop weapon instead cause with 'return HAM_SUPERCEDE' make players pick weapons and that leave no weapons on ground..

your code works but its not like i want..when i tested it, i still got to picked up weapons on ground at first then they got dropped..when i tried to pick the dropped weapons again, the code blocked it..ummm thats great but i don't understand why weapons are initially still pickup able when ham_touch already take care of that?

can you make it so the weapons lying on ground ara not pickupable at all..and if players buy or are given with primary weapons, drop those weapons and block them from being picked up..

Bugsy 02-15-2009 20:33

Re: Function to Forbid Primary Weapons
 
Quote:

Originally Posted by Mlk27 (Post 762310)
@bugsy

thanks..i uncommented the line to drop weapon instead cause with 'return HAM_SUPERCEDE' make players pick weapons and that leave no weapons on ground..

your code works but its not like i want..when i tested it, i still got to picked up weapons on ground at first then they got dropped..when i tried to pick the dropped weapons again, the code blocked it..ummm thats great but i don't understand why weapons are initially still pickup able when ham_touch already take care of that?

can you make it so the weapons lying on ground ara not pickupable at all..and if players buy or are given with primary weapons, drop those weapons and block them from being picked up..

My code should drop the weapon when purchased and then not be picked up if you walk over the weapon. Did you comment out HAM_SUPERCEDE?

Mlk27 02-15-2009 20:57

Re: Function to Forbid Primary Weapons
 
yeh. i commented out ham_supercede because i dont want weapons to be taken away from ground when players step on those weapons.

Just completely block weapons on ground from being pick up and drop weapons when players buy them


All times are GMT -4. The time now is 17:01.

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