Raised This Month: $ Target: $400
 0% 

Get weaponbox name?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-23-2015 , 15:38   Get weaponbox name?
Reply With Quote #1

PHP Code:
RegisterHam(Ham_Spawn"weaponbox""weapon_ground"1)

public 
weapon_ground(iEnt)
{
    new 
szName[32]
    
entity_get_string(iEntEV_SZ_classnameszNamecharsmax(szName))
    
    if(
equal(szName"grenade"))
        return 
HAM_IGNORED
        
    set_pev
(iEntpev_flagsFL_KILLME)
    
dllfunc(DLLFunc_ThinkiEnt)
    return 
HAM_IGNORED

I'm using this to disallow weapon dropping, i.e. having weapons on the ground, but I wan't to allow only the C4 to be able to "spawn". I tried getting classname and modelname and check if it's equal to "grenade" or "weapon_c4", but it doesn't work.

Last edited by OciXCrom; 11-04-2015 at 06:25.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-23-2015 , 16:02   Re: Get weaponbox name?
Reply With Quote #2

If you want to block "drop" command then hook it and do your checks. Your way is just removing the box when it is spawned, while you could block it from being created.
Also, don't set FL_KILLME flags on a weaponbox, just make it to think.

Now, about your code:
The classname of an weaponbox entity is, guess what, "weaponbox". pev_classname will always give this in this case. To know if a weaponbox contain a specific weapon you could redo the CWeaponBox::HasWeapon function
(https://github.com/Arkshine/CSSDK/bl...pons.cpp#L1641). Or use this stock made by Connor(which is more or less the same thing):

PHP Code:
GetWeaponBoxWeaponTypeent 

    new 
weapon
    for(new 
1i<= 5i++) 
    { 
        
weapon get_pdata_cbase(entm_rgpPlayerItems_CWeaponBox[i], XO_CWEAPONBOX); 
        if( 
weapon 
        { 
            return 
cs_get_weapon_id(weapon); 
        } 
    } 

    return 
0

Then you can do:
PHP Code:
new WeaponId GetWeaponBoxWeaponType(WeaponBox)
if(
WeaponId == CSW_C4)
{
    

__________________

Last edited by HamletEagle; 10-23-2015 at 16:03.
HamletEagle is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-23-2015 , 18:23   Re: Get weaponbox name?
Reply With Quote #3

When a player dies the weapon will be dropped on the ground, so blocking the "drop" command won't help. I'll try the stock tomorrow.

Last edited by OciXCrom; 10-23-2015 at 18:24.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-23-2015 , 20:58   Re: Get weaponbox name?
Reply With Quote #4

Would you rather prevent the user from attempting a drop, or do you just want to not have weapons on the ground?

This will destroy the weaponbox once dropped, except for C4.
PHP Code:
#include <amxmodx>
#include <engine>
#include <hamsandwich>
#include <cstrike>

new const Version[] = "0.1";

public 
plugin_init()
{
    
register_plugin"No Weapon Drop" Version "ConnorMcLeod/bugsy" );

    new class[
32], ent;
    for(new 
iId CSW_P228iId <= CSW_P90iId++)
    {
        if( 
get_weaponname(iId, class, charsmax(class)) )
        {
            
ent create_entity(class);
            if( 
ent )
            {
                if( 
<= ExecuteHam(Ham_Item_ItemSlotent) <= )
                {
                    
RegisterHam(Ham_CS_Item_CanDrop, class, "PrimSec_CanDrop"false);
                }
                
remove_entity(ent);
            }
        }
    }
    
    
register_touch"weaponbox" "worldspawn" "WeaponboxPlayerTouch" );
}

public 
PrimSec_CanDropiEntity )
{
    
SetHamReturnIntegerfalse );
    return 
HAM_SUPERCEDE;
}

public 
WeaponboxPlayerTouchiWeaponbox iPlayer )
{
    if ( 
GetWeaponBoxWeaponTypeiWeaponbox ) != CSW_C4 )
    {
        
call_thinkiWeaponbox );
    }
}

GetWeaponBoxWeaponTypeent 

    new 
weapon
    new const 
m_rgpPlayerItems_CWeaponBox] = { 34 35 , ... };
    new const 
XO_CWEAPONBOX 4;
    
    for(new 
1i<= 5i++) 
    { 
        
weapon get_pdata_cbaseent m_rgpPlayerItems_CWeaponBox] , XO_CWEAPONBOX ); 
        
        if( 
weapon 
        { 
            return 
cs_get_weapon_idweapon ); 
        } 
    } 
    
    return 
0

__________________

Last edited by Bugsy; 10-24-2015 at 18:02.
Bugsy is offline
Old 10-24-2015, 08:30
OciXCrom
This message has been deleted by OciXCrom.
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-24-2015 , 08:33   Re: Get weaponbox name?
Reply With Quote #6

I'm going to block weapon drop + ground weapons. The first one because I don't want the players to drop their weapons accidentally and therefore play without a weapon until the next round, and the second one because I'm using custom models for the weapons and I don't have w_ models for all of them, so I don't want the default ones to lie on the ground.

The code sorta works. Only the C4 is able to be on the ground, but I'm unable to pick it up - http://i.imgur.com/0z67R0p.jpg
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-24-2015 , 14:05   Re: Get weaponbox name?
Reply With Quote #7

See if this does what you want. Edit: see below
__________________

Last edited by Bugsy; 10-24-2015 at 18:44.
Bugsy is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-24-2015 , 14:51   Re: Get weaponbox name?
Reply With Quote #8

No, this is worse. Now it drops the weapon on death + I'm still unable to pick up the C4 after dropping it.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-24-2015 , 14:53   Re: Get weaponbox name?
Reply With Quote #9

Quote:
Originally Posted by OciXCrom View Post
No, this is worse. Now it drops the weapon on death + I'm still unable to pick up the C4 after dropping it.
Ok, I can add the functionality from the above plugin which should resolve weapon dropping when a player dies. The C4 thing is not related to this plugin as I can pickup C4 without any problems.
__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-24-2015 , 14:55   Re: Get weaponbox name?
Reply With Quote #10

Try this:

Edited to kill weaponbox when it hits the ground instead of when it leaves the players hands.
PHP Code:
#include <amxmodx>
#include <engine>
#include <hamsandwich>
#include <cstrike>

new const Version[] = "0.1";

public 
plugin_init()
{
    
register_plugin"No Weapon Drop" Version "ConnorMcLeod/bugsy" );

    new class[
32], ent;
    for(new 
iId CSW_P228iId <= CSW_P90iId++)
    {
        if( 
get_weaponname(iId, class, charsmax(class)) )
        {
            
ent create_entity(class);
            if( 
ent )
            {
                if( 
<= ExecuteHam(Ham_Item_ItemSlotent) <= )
                {
                    
RegisterHam(Ham_CS_Item_CanDrop, class, "PrimSec_CanDrop"false);
                }
                
remove_entity(ent);
            }
        }
    }
    
    
register_touch"weaponbox" "worldspawn" "WeaponboxWorldTouch" );
}

public 
PrimSec_CanDropiEntity )
{
    
SetHamReturnIntegerfalse );
    return 
HAM_SUPERCEDE;
}

public 
WeaponboxWorldTouchiWeaponbox iWorld )
{
    if ( 
GetWeaponBoxWeaponTypeiWeaponbox ) != CSW_C4 )
    {
        
call_thinkiWeaponbox );
    }
}

GetWeaponBoxWeaponTypeent 

    new 
weapon
    new const 
m_rgpPlayerItems_CWeaponBox] = { 34 35 , ... };
    new const 
XO_CWEAPONBOX 4;
    
    for(new 
1i<= 5i++) 
    { 
        
weapon get_pdata_cbaseent m_rgpPlayerItems_CWeaponBox] , XO_CWEAPONBOX ); 
        
        if( 
weapon 
        { 
            return 
cs_get_weapon_idweapon ); 
        } 
    } 
    
    return 
0

__________________

Last edited by Bugsy; 10-24-2015 at 18:14.
Bugsy 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 22:17.


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