AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get weaponbox name? (https://forums.alliedmods.net/showthread.php?t=273639)

OciXCrom 10-23-2015 15:38

Get weaponbox name?
 
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.

HamletEagle 10-23-2015 16:02

Re: Get weaponbox name?
 
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)
{
    



OciXCrom 10-23-2015 18:23

Re: Get weaponbox name?
 
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.

Bugsy 10-23-2015 20:58

Re: Get weaponbox name?
 
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



OciXCrom 10-24-2015 08:33

Re: Get weaponbox name?
 
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

Bugsy 10-24-2015 14:05

Re: Get weaponbox name?
 
See if this does what you want. Edit: see below

OciXCrom 10-24-2015 14:51

Re: Get weaponbox name?
 
No, this is worse. Now it drops the weapon on death + I'm still unable to pick up the C4 after dropping it.

Bugsy 10-24-2015 14:53

Re: Get weaponbox name?
 
Quote:

Originally Posted by OciXCrom (Post 2356247)
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 10-24-2015 14:55

Re: Get weaponbox name?
 
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



OciXCrom 10-24-2015 15:54

Re: Get weaponbox name?
 
Now they all drop upon death and dissapear when a player touches them. The C4 still can't be picked up. Here's a video of what's happening - https://youtu.be/6NU1paRlOgQ


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

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