Raised This Month: $51 Target: $400
 12% 

Prevent weapon pickup... almost working but


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MaxK
New Member
Join Date: Sep 2010
Old 09-14-2010 , 18:34   Prevent weapon pickup... almost working but
Reply With Quote #1

Hello,

I'm just beginning sourcemod scripting. I have written my first plugin, but i have a problem.

The aim of this plugin is to limit the number of heavy weapon a team can have.

It almost works but when i pass over a heavy weapon, the weapon disappear

In fact, it's only the visibility of the weapon. If i change the con_var and the if a go where the weapon was, i actually pick it up

Can you help me ?
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
 
public Plugin:myinfo =
{
    
name "Heavy Weapon Drop",
    
author "MAX-k",
    
description "Limit the amount of heavy weapons a team can carry",
    
version "1.0.0.0",
    
url "http://www.sourcemod.net/"
};


new 
Handle:sm_hweapon_drop INVALID_HANDLE
new Handle:sm_hweapon_max_t INVALID_HANDLE
new Handle:sm_hweapon_max_ct INVALID_HANDLE
 
public OnPluginStart()
{
    
sm_hweapon_drop CreateConVar("sm_hweapon_drop""0""(Des)activate Heavy Weapon Drop Plugin"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFYtrue0.0true1.0)
    
sm_hweapon_max_t CreateConVar("sm_hweapon_max_t""-1""Amount of HW taht Ts can carry (-1 = unlimited)"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFYtrue, -1.0)
    
sm_hweapon_max_ct CreateConVar("sm_hweapon_max_ct""-1""Amount of HW taht CTs can carry (-1 = unlimited)"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFYtrue, -1.0)
    
AutoExecConfig(true"plugin_heavy_weapon_drop")
    
    
LoadTranslations ("hweapon_drop.phrases");

}

public 
Bool:IsHeavyWeapon(String:w_name[64])
{
    new 
String:hw_list[][32] = { "weapon_m3""weapon_xm1014""weapon_galil""weapon_ak47""weapon_scout""weapon_sg552""weapon_awp""weapon_g3sg1""weapon_famas""weapon_m4a1""weapon_aug""weapon_sg550""weapon_mac10""weapon_tmp""weapon_mp5navy""weapon_ump45""weapon_p90""weapon_m249" }
    new 
Bool:retVal false
    
for (new 018i++)
    {
        if(!
strcmp(hw_list[i], w_name))
        {
            
retVal true
            i 
18
        
}
    }
    
    return 
retVal
}

public 
OnClientPutInServer(client

    
SDKHook(clientSDKHook_WeaponEquipOnWeaponEquip

public 
OnClientDisconnect(client

    if ( 
IsClientInGame(client) ) 
    { 
        
SDKUnhook(clientSDKHook_WeaponEquipOnWeaponEquip
    } 

public 
Action:OnWeaponEquip(Cliweapon
{
    if(
GetConVarBool(sm_hweapon_drop))
    {    
        
        new 
String:Item[64]
        
GetEdictClassname(weaponItemsizeof(Item));
        
        if(
IsHeavyWeapon(Item))
        {        
            new 
Max 0
            
new TeamCli GetClientTeam(Cli)
            if(
TeamCli == 2)
            {
                
Max GetConVarInt(sm_hweapon_max_t)
            }
            else if(
TeamCli == 3)
            {
                
Max GetConVarInt(sm_hweapon_max_ct)
            }
            
            if (
Max != -1)
            {
                new 
nb 0
                
                
for(new 1<= GetMaxClients() && nb Maxi++)
                {
                    if(
!= Cli && IsClientInGame(i) && GetClientTeam(i) == TeamCli && GetPlayerWeaponSlot(i0) != -1)
                    {
                        
nb++
                    }
                }
                
                if(
nb >= Max)
                {
                    return 
Plugin_Handled;
                }
            }
        }
    }
    return 
Plugin_Continue;


Last edited by MaxK; 09-14-2010 at 19:05.
MaxK is offline
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 09-14-2010 , 19:49   Re: Prevent weapon pickup... almost working but
Reply With Quote #2

Weapon_Equip happens after the game 'vanished' the weapon from the ground. I'd say instead of just return Plugin_Handled you need to save Angles and AbsOrigin, remove the old gun, and spawn a new one in the same position.

That WILL spam if someone is sitting on said gun though.
AtomicStryker is offline
Death [GER]
Senior Member
Join Date: Mar 2010
Old 09-15-2010 , 02:53   Re: Prevent weapon pickup... almost working but
Reply With Quote #3

Something i had lying around.. dunno if it works as i dont have css atm
Attached Files
File Type: sp Get Plugin or Get Source (css_weaponrestriction.sp - 308 views - 2.3 KB)
__________________
Death [GER] is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 09-15-2010 , 06:22   Re: Prevent weapon pickup... almost working but
Reply With Quote #4

Have a look at the SDKHook_WeaponCanUse hook. That one is triggered before you pick up a weapon.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
spunkster21
Senior Member
Join Date: Aug 2008
Old 09-15-2010 , 07:28   Re: Prevent weapon pickup... almost working but
Reply With Quote #5

I had this problem as well. I got around it by using SDKHook_WeaponCanUse, which prevents the weapon from being used but doesn't remove it.

PHP Code:
SDKHook(clientSDKHook_WeaponCanUseOnWeaponCanUse);

public 
Action:OnWeaponCanUse(clientweapon)
{
    
/* Check if this client can use this weapon. */
    
if (!CanUseWeapon(client))
    {
        return 
Plugin_Handled;
    }
    
    return 
Plugin_Continue;

Edit: I had this in edit mode before rhelgeby posted his response and therefore didn't see it ;-)
spunkster21 is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 09-15-2010 , 07:57   Re: Prevent weapon pickup... almost working but
Reply With Quote #6

Off topic: The forum could have a update notifier when in edit mode (AJAX based or something).
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
NoS
Senior Member
Join Date: Nov 2006
Old 09-15-2010 , 09:26   Re: Prevent weapon pickup... almost working but
Reply With Quote #7

Just wanted to mention, if you decide to release the plugin, I would suggest you call it Anti-Primary Pick up, I got confused thinking it was like awps, saws, possibly m4s and aks blocking.
NoS 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 02:09.


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