This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

[Solved] Remove Dropped Weapons


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Whitez
Member
Join Date: Apr 2016
Location: London, UK
Old 05-13-2016 , 13:30   [Solved] Remove Dropped Weapons
Reply With Quote #1

I found different ways to remove dropped weapons, but i am looking for a way to add an exception to it

On my server i am using custom weapons on my server which i don't want to be removed on drop

Basically i want to remove all the default dropped weapons but not the extra ones

Here is what i user to set model and retrieve custom weapons

PHP Code:
// Added by Shidla
public fw_SetModel(entitymodel[])
{
    
// Entity is not valid
    
if(!is_valid_ent(entity))
        return 
FMRES_IGNORED;
        
    
// Entity model is not w_m249
    
if(!equal(model"models/w_m4a1.mdl")) 
        return 
FMRES_IGNORED;
        
    
// Get classname
    
static szClassName[33]
    
entity_get_string(entityEV_SZ_classnameszClassNamecharsmax(szClassName))
        
    
// Not a Weapon box
    
if(!equal(szClassName"weaponbox"))
        return 
FMRES_IGNORED
    
    
// Some vars
    
static iOwneriStoredGalilID
    
    
// Get owner
    
iOwner entity_get_edict(entityEV_ENT_owner)
    
    
// Get drop weapon index (galil) to use in fw_Galil_AddToPlayer forward
    
iStoredGalilID find_ent_by_owner(ENG_NULLENT"weapon_m4a1"entity)
    
    
// Entity classname is weaponbox, and galil has founded
    
if(g_haswep[iOwner] && is_valid_ent(iStoredGalilID))
    {
        
// Setting weapon options
        
entity_set_int(iStoredGalilIDEV_INT_WEAPONKEYWEP_WEAPONKEY)

        
// Reset user vars
        
g_haswep[iOwner] = false
        
        
// Set weaponbox new model
        
entity_set_model(entityMGUN_W_MODEL)
        
        return 
FMRES_SUPERCEDE
    
}

    return 
FMRES_IGNORED
}

// Added by Shidla
public fw_GMAC10AddToPlayer (GMAC10id)
{
    
// Make sure that this is M79
    
if( is_valid_ent(GMAC10) && is_user_connected(id) && entity_get_int(GMAC10EV_INT_WEAPONKEY) == WEP_WEAPONKEY)
    {
        
// Update
        
g_haswep[id] = true

        
// Reset weapon options
        
entity_set_int(GMAC10EV_INT_WEAPONKEY0)

        return 
HAM_HANDLED
    
}

    return 
HAM_IGNORED

Whitez is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-13-2016 , 13:54   Re: Remove Dropped Weapons
Reply With Quote #2

Hook Touch to know when the weapon is on ground, then check some properties to know if it's default weapon or your custom weapon(like getting all items from the box and checking classname(if you changed it) or some unused fields like pev_iuser) and call think on the entity. Calling think removes the box and the weapon(s) from it, assuming you don't create the weaponbox entity manually.
__________________

Last edited by HamletEagle; 05-13-2016 at 14:01.
HamletEagle is offline
Whitez
Member
Join Date: Apr 2016
Location: London, UK
Old 05-13-2016 , 18:08   Re: Remove Dropped Weapons
Reply With Quote #3

No, i don't want to create the weaponbox entity manually, i was thinking about that, but i have many custom weapons and i don't want to over complicate things

I cannot use g_hasweap bool too, because when the weapon will touch the ground it's owner will not have the bool set to true anymore

can you give me an example how to do it please?

I think it can be done using this too but i am not sure how

entity_set_int(iStoredGalilID, EV_INT_WEAPONKEY, WEP_WEAPONKEY)

Last edited by Whitez; 05-13-2016 at 18:08.
Whitez is offline
11922911
Senior Member
Join Date: Dec 2011
Location: Yuen Long Country
Old 05-13-2016 , 21:53   Re: Remove Dropped Weapons
Reply With Quote #4

Remove dropped weapon on SetModel() post, since your custom weapon has already blocked this function, so it won't remove that.

On SetModel() post check entity classname is "weaponbox" then set pev->nextthink to current game time

Example:
PHP Code:
    register_forward(FM_SetModel"OnSetModel_Post"1);
}

public 
OnSetModel_Post(entity, const model[])
{
    if (!
pev_valid(entity))
        return;
    
    new 
classname[32];
    
pev(entitypev_classnameclassnamecharsmax(classname));
    
    if (
equal(classname"weaponbox"))
        
set_pev(entitypev_nextthinkget_gametime());

__________________
youtube:
@holla16

Last edited by 11922911; 05-13-2016 at 22:05.
11922911 is offline
Whitez
Member
Join Date: Apr 2016
Location: London, UK
Old 05-14-2016 , 06:33   Re: Remove Dropped Weapons
Reply With Quote #5

I tried removing on set model post with the method posted by 1192 but it still removes the custom weapon

I tried changing the class name of the entity but the weapon is still removed

This is what i use to remove the weapons

PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
#include <engine>

new gMaxClients;
new 
pCvarTime;

public 
plugin_init ()
{
    
register_plugin"Remove Weaponbox""1.0.0""Arkshine" );

    
pCvarTime register_cvar"dw_time""5" );
    
RegisterHamHam_Touch"weaponbox""WeaponBox_Touch");
    
    
gMaxClients get_maxplayers();
}

public 
WeaponBox_Touch ( const WeaponBox, const Other )
{
    if ( !
Other || Other gMaxClients )
    {    
        
set_pevWeaponBoxpev_nextthinkget_gametime() + get_pcvar_floatpCvarTime ) );
    }


Last edited by Whitez; 05-14-2016 at 07:33.
Whitez is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-14-2016 , 09:21   Re: Remove Dropped Weapons
Reply With Quote #6

Let's try again. When you give the weapon to the player, set a custom value in pev_iuser1. On touch, loop all weappns from box and check for custom value. You are on scripting help, so don't expect to get a ready-made code.

How you give the custom weapon to player?
__________________

Last edited by HamletEagle; 05-14-2016 at 09:24.
HamletEagle is offline
Whitez
Member
Join Date: Apr 2016
Location: London, UK
Old 05-14-2016 , 09:34   Re: Remove Dropped Weapons
Reply With Quote #7

Something like this, using a bool

PHP Code:

new boolg_hasweapon_custom[MAXPLAYERS +1]

public 
give_weapon(id)
{
            
give_item(idweapon_ak47)
            
g_hasweapon_custom[id] = true
}
public 
Ham_Deploy CurWeapon (etc)
{
        if(
g_hasweapon_custom[id] && get_user_weapon(id) == weapon_ak47 )
        {  
                
set v model
                set p model
          
}

Then i use this to set world model and retrieve it from the ground

PHP Code:
#define is_valid_player(%1) (1 <= %1 <= 32)
#define ENG_NULLENT        -1    // Added by Shidla
#define EV_INT_WEAPONKEY    EV_INT_impulse    // Added by Shidla

// Added by Shidla
public fw_SetModel(entitymodel[])
{
    
// Entity is not valid
    
if(!is_valid_ent(entity))
        return 
FMRES_IGNORED;
        
    
// Entity model is not w_m249
    
if(!equal(model"models/w_ak47.mdl")) 
        return 
FMRES_IGNORED;
        
    
// Get classname
    
static szClassName[33]
    
entity_get_string(entityEV_SZ_classnameszClassNamecharsmax(szClassName))
        
    
// Not a Weapon box
    
if(!equal(szClassName"weaponbox"))
        return 
FMRES_IGNORED
    
    
// Some vars
    
static iOwneriStoredGalilID
    
    
// Get owner
    
iOwner entity_get_edict(entityEV_ENT_owner)
    
    
// Get drop weapon index (galil) to use in fw_Galil_AddToPlayer forward
    
iStoredGalilID find_ent_by_owner(ENG_NULLENT"weapon_m4a1"entity)
    
    
// Entity classname is weaponbox, and galil has founded
    
if(g_haswep[iOwner] && is_valid_ent(iStoredGalilID))
    {
        
// Setting weapon options
        
entity_set_int(iStoredGalilIDEV_INT_WEAPONKEYWEP_WEAPONKEY)

        
// Reset user vars
        
g_haswep[iOwner] = false
        
        
// Set weaponbox new model
        
entity_set_model(entityMGUN_W_MODEL)
        
        return 
FMRES_SUPERCEDE
    
}

    return 
FMRES_IGNORED
}

// Added by Shidla
public fw_GMAC10AddToPlayer (GMAC10id)
{
    
// Make sure that this is M79
    
if( is_valid_ent(GMAC10) && is_user_connected(id) && entity_get_int(GMAC10EV_INT_WEAPONKEY) == WEP_WEAPONKEY)
    {
        
// Update
        
g_haswep[id] = true

        
// Reset weapon options
        
entity_set_int(GMAC10EV_INT_WEAPONKEY0)

        return 
HAM_HANDLED
    
}

    return 
HAM_IGNORED


Last edited by Whitez; 05-14-2016 at 09:39.
Whitez is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-14-2016 , 10:09   Re: Remove Dropped Weapons
Reply With Quote #8

You need to also mark the weapon entity, not only the player, because the owner of weapon is set to weaponbox entity when dropped.
give_item returns the entity index, so you can do:
PHP Code:
new Entity give_item(idweapon_ak47)
if(
pev_valid(Entity))
{
    
set_pev(Entitypev_iuser1123456//instead 123456 you can use any value.

Then:
PHP Code:
#define MAX_ITEM_TYPES 6

new const m_rgpPlayerItems_CWeaponBox[MAX_ITEM_TYPES] = {3435, ...}

const 
m_pNext      42
const XoCWeaponBox 4

register_touch
("worldspawn""weaponbox""CWeaponBox_Touch")

public 
CWeaponBox_Touch(const Touched, const WeaponBoxEntity)
{
    if(
pev_valid(WeaponBoxEntity))
    {
        new 
WeaponEntity
        
for(new iMAX_ITEM_TYPES; ++i)
        {
            
WeaponEntity get_pdata_cbase(WeaponBoxEntitym_rgpPlayerItems_CWeaponBox[i], XoCWeaponBox)
            while(
pev_valid(WeaponEntity))
            {
                if(
pev(WeaponEntitypev_iuser1) != 123456)
                {
                    
call_think(WeaponBoxEntity)
                    break
                }

                
WeaponEntity get_pdata_cbase(WeaponEntitym_pNextXoCWeaponBox)
            }
        }
    }

__________________

Last edited by HamletEagle; 05-14-2016 at 10:10.
HamletEagle is offline
Whitez
Member
Join Date: Apr 2016
Location: London, UK
Old 05-14-2016 , 10:49   Re: Remove Dropped Weapons
Reply With Quote #9

I got few questions

PHP Code:
new Entity give_item(idweapon_ak47)
if(
pev_valid(Entity))
{
    
set_pev(Entitypev_iuser1123456//instead 123456 you can use any value.

Above, how do we know if the weapon recieved is a custom weapon and not a regular AK ?

PHP Code:
public CWeaponBox_Touch(const Touched, const WeaponBoxEntity)
{
    if(
pev_valid(WeaponBoxEntity))
    {
        new 
WeaponEntity
        
for(new iMAX_ITEM_TYPES; ++i)
        {
            
WeaponEntity get_pdata_cbase(WeaponBoxEntitym_rgpPlayerItems_CWeaponBox[i], XoCWeaponBox)
            while(
pev_valid(WeaponEntity))
            {
                if(
pev(WeaponEntitypev_iuser1) != 123456)
                {
                    
call_think(WeaponBoxEntity)
                    break
                }

                
WeaponEntity get_pdata_cbase(WeaponEntitym_pNextXoCWeaponBox)
            }
        }
    }

Why do we need to loop through all entities on touch? when we can check directly the WeaponBoxEntity for various parameters?

Also in this
Spoiler


Can't we just add some sort of flag to that entity when it's model is set ( which i presume happens before touching the ground ) and then check for that flag / parameter before removing the weaponbox on the floor?

PHP Code:
if(g_haswep[iOwner] && is_valid_ent(iStoredGalilID))
    {
        
// Setting weapon options
        
entity_set_int(iStoredGalilIDEV_INT_WEAPONKEYWEP_WEAPONKEY)

        
// Reset user vars
        
g_haswep[iOwner] = false
        
        
// Set weaponbox new model
        
entity_set_model(entityMGUN_W_MODEL)
      
// ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
      // Add some kind of flag or a parameter for which we can check and return on Ham_Touch before setting the task of removing the weaponbox
        
        
return FMRES_SUPERCEDE
    


Last edited by Whitez; 05-14-2016 at 10:49.
Whitez is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-14-2016 , 11:24   Re: Remove Dropped Weapons
Reply With Quote #10

Quote:
Above, how do we know if the weapon recieved is a custom weapon and not a regular AK ?
You put this where you give him the custom weapon, that's how you know. I assume you have some kind of command that is used to get this weapon. That's why I asked for source code.

Quote:
Why do we need to loop through all entities on touch? when we can check directly the WeaponBoxEntity for various parameters?
You don't loop through all entities, you only loop through weapons that are stored inside the box. weaponbox is just a box that contain weapons, you can't directly know what is inside it. You need to check slot by slot(6 slots). Also, if more than one weapon is inside the slot(like two primary weapons) they are linked with m_pNext offset, that's why you see the while loop.
for loop get all slots and the while loop all weapons from the slot.

slot 1 -> weapon1 -> weapon2
slot 2 -> anotherweapon
etc

Or at least in theory, because in cs you only have one weapon per weaponbox usually.
__________________
HamletEagle 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 20:27.


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