AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved weaponbox/armoury_entity Touch (https://forums.alliedmods.net/showthread.php?t=304188)

edon1337 01-07-2018 08:43

weaponbox/armoury_entity Touch
 
Hello,

I'm trying to disable the player from getting a dropped weapon that he already has. They're custom created entities, but it's not working, the returned Weapon ID is always 0. I'm trying to create dropped weapons just like in fy_ maps, if anyone could give me any idea on fixing this bug or a better method of creating dropped entities, I'd be thankful! Have a nice day.

PHP Code:

new const g_szWeapons[ ][ ] =
{
    
"weapon_p228",
    
"weapon_scout",
    
"weapon_xm1014",
    
"weapon_mac10",
    
"weapon_aug",
    
"weapon_elite",
    
"weapon_fiveseven",
    
"weapon_ump45",
    
"weapon_sg550",
    
"weapon_galil",
    
"weapon_famas",
    
"weapon_usp",
    
"weapon_glock18",
    
"weapon_awp",
    
"weapon_mp5navy",
    
"weapon_m249",
    
"weapon_m3",
    
"weapon_m4a1",
    
"weapon_tmp",
    
"weapon_g3sg1",
    
"weapon_deagle",
    
"weapon_sg552",
    
"weapon_ak47",
    
"weapon_p90"
}

public 
plugin_init( )
{
    for( new 
isizeof g_szWeaponsi++ )
    
register_touchg_szWeapons], "player""OnTouchWeapon" );
}
    
public 
OnTouchWeaponiEntid )
{
    if( ! 
pev_validiEnt ) )
    return 
FMRES_IGNORED;
    
    if( 
user_has_weaponidcs_get_weapon_idiEnt ) ) ) // cs_get_weapon_id( iEnt ) always returns 0
    
return FMRES_SUPERCEDE;
    
    new 
szClassName32 ];
    
peviEntpev_classnameszClassNamecharsmaxszClassName ) );
    
    
give_item_newidszClassName );
    
engfuncEngFunc_RemoveEntityiEnt );
    
    return 
FMRES_IGNORED;
}

public 
OnNewRound( ) // the part where the custom entities are created
{
    new 
iArraySize ArraySizeg_aWeaponOrigins );
    new 
iEntity;

    for( new 
iiArraySizei++ )
    {
        
ArrayGetArrayg_aWeaponOriginsig_iWeapons );

        
iEntity engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"weaponbox"))
        
        
set_peviEntitypev_movetypeMOVETYPE_TOSS );
        
set_peviEntitypev_solidSOLID_TRIGGER );
        
set_peviEntitypev_sizeFloat:{ -16.0, -16.00.0}, Float:{ 16.016.02.0 } );
        
set_peviEntitypev_origing_iWeaponsWeapon_Origin ] );
        
set_peviEntitypev_classnameg_iWeaponsWeapon_ClassName ]    ); // weapon_*
        
engfuncEngFunc_DropToFlooriEntity );
        
        
engfunc(EngFunc_SetModeliEntityg_iWeaponsWeapon_Model ] );
    }



HamletEagle 01-07-2018 09:02

Re: FM Touch Entity
 
Use an armoury_entity, it will make things much easier for you. If you properly create it, the game will do everything for you, no need to hook touch or anything.

It returns 0 because you are not properly creating the weaponbox entity. To get cs_get_weapon_id to work you need to set m_iId offset when creating the weaponbox.

PRoSToTeM@ 01-07-2018 09:04

Re: FM Touch Entity
 
It is not fakemeta event, in engine you should use PLUGIN_[CONTINUE/HANDLED].

edon1337 01-07-2018 10:11

Re: FM Touch Entity
 
Quote:

Originally Posted by HamletEagle (Post 2570375)
Use an armoury_entity, it will make things much easier for you. If you properly create it, the game will do everything for you, no need to hook touch or anything.

So instead of creating a weaponbox entity, to create armoury_entity and to remove the Touch forward?

Quote:

Originally Posted by HamletEagle (Post 2570375)
It returns 0 because you are not properly creating the weaponbox entity. To get cs_get_weapon_id to work you need to set m_iId offset when creating the weaponbox.

Can you show me how to properly create a weaponbox in my case? Or should I just look at your tutorial? Set m_iId offset to what value?

Quote:

Originally Posted by PRoSToTeM@ (Post 2570376)
It is not fakemeta event, in engine you should use PLUGIN_[CONTINUE/HANDLED].

Oh, thanks.. I mixed register_touch with register_forward from FM.

Thanks both :)

HamletEagle 01-07-2018 11:22

Re: FM Touch Entity
 
In cs, the ground weapons you can find in different maps are armoury_entity. So if you want to create weapons on ground, do it with armoury_entity: https://forums.alliedmods.net/showthread.php?t=250922
Also it's easier than working with weaponbox entities. You just need to use CreateArmouryEntity( itemType, itemCount, Float: fOrigin[ ] ) stock, and it will do everything for you.

Tho if you properly create them, it does not matter if it's armoury_entity or weaponbox, touch will not be needed.

Quote:

Can you show me how to properly create a weaponbox in my case? Or should I just look at your tutorial? Set m_iId offset to what value?
You can read my tutorial, if you want to use orpheu. If you don't want, then be prepared to do a bit of work, you have to port CWeaponBox:: functions from c++ to pawn.
I strongly advise you to go with orpheu, much cleaner. You have everything you need in this tut: https://forums.alliedmods.net/showthread.php?t=261464

Quote:

Set m_iId offset to what value?
The CSW_ index of the weapon. You have to set that on the weapon entity that's going to be packed into the weaponbox(you will also need to create the weapon entities). Again, don't bother with this stuff, just go with armoury_entity.
What you did in your code is only creating an entity with weaponbox as classname, there's MUCH more to do.

edon1337 01-07-2018 13:24

Re: FM Touch Entity
 
Quote:

Originally Posted by HamletEagle (Post 2570408)
In cs, the ground weapons you can find in different maps are armoury_entity. So if you want to create weapons on ground, do it with armoury_entity: https://forums.alliedmods.net/showthread.php?t=250922
Also it's easier than working with weaponbox entities. You just need to use CreateArmouryEntity( itemType, itemCount, Float: fOrigin[ ] ) stock, and it will do everything for you.

Tho if you properly create them, it does not matter if it's armoury_entity or weaponbox, touch will not be needed.


You can read my tutorial, if you want to use orpheu. If you don't want, then be prepared to do a bit of work, you have to port CWeaponBox:: functions from c++ to pawn.
I strongly advise you to go with orpheu, much cleaner. You have everything you need in this tut: https://forums.alliedmods.net/showthread.php?t=261464


The CSW_ index of the weapon. You have to set that on the weapon entity that's going to be packed into the weaponbox(you will also need to create the weapon entities). Again, don't bother with this stuff, just go with armoury_entity.
What you did in your code is only creating an entity with weaponbox as classname, there's MUCH more to do.

I'll stick to your suggestion of armoury_entity, the only thing that bothers me is that I'm unable to create pistols, as they're needed.. But never mind.

Is this ok? Or I still have things to do?
PHP Code:

public OnNewRound( )
{
    new 
iArraySize ArraySizeg_aWeaponData );

    for( new 
iiArraySizei++ )
    {
        
ArrayGetArrayg_aWeaponDataig_iWeapons );
        
        
CreateArmouryEntityg_iWeaponsWeapon_ArmName ], 1g_iWeaponsWeapon_Origin ] );
    }


In my .ini file I put the ARM Name as a string, ex: "ARM_MP5" and when I read it I use str_to_num to make it an integer, is that correct?

PRoSToTeM@ 01-07-2018 13:53

Re: FM Touch Entity
 
Quote:

Originally Posted by edon1337 (Post 2570428)
In my .ini file I put the ARM Name as a string, ex: "ARM_MP5" and when I read it I use str_to_num to make it an integer, is that correct?

No, you need a string->int map (i.e. Trie) if you want to convert a enum string to integer.

edon1337 01-07-2018 14:03

Re: FM Touch Entity
 
Quote:

Originally Posted by PRoSToTeM@ (Post 2570432)
No, you need a string->int map (i.e. Trie) if you want to convert a enum string to integer.

If I use Tries, will I be able to store the weapon origin inside the .ini file too?

The format:
"ARM_MP5" "111.11 222.22 333.33"

Also my point is not to convert "ARM_MP5" (string) to an integer, I just need to make it compatible with the Enum (ARM_MP5).

HamletEagle 01-07-2018 14:24

Re: FM Touch Entity
 
Quote:

Originally Posted by edon1337 (Post 2570437)
If I use Tries, will I be able to store the weapon origin inside the .ini file too?

The format:
"ARM_MP5" "111.11 222.22 333.33"

Also my point is not to convert "ARM_MP5" (string) to an integer, I just need to make it compatible with the Enum (ARM_MP5).

Have an array with all the ARM_* strings(new const something[][]). Then in plugin_init use TrieSetCell with something[i] as key and the value of ARM_* constant as value.
Then when you read from file you need TrieGetCell.
What PRoSToTeM@ said basically.

Alternatively, you could do that without weaponbox/armoury_entity at all. Create some dummy entity(info_target) and set the weapon index that your entity will contain in a pev value like pev_iuser1. Hook touch, retrieve the CSW_* index from pev_iuser1, get it's name with get_weaponname and use give item, then remove the dummy entity.
That way you can put any weapon in there and you don't need to deal with complicated weaponbox code.

edon1337 01-07-2018 15:40

Re: FM Touch Entity
 
Quote:

Originally Posted by HamletEagle (Post 2570445)
Have an array with all the ARM_* strings(new const something[][]). Then in plugin_init use TrieSetCell with something[i] as key and the value of ARM_* constant as value.
Then when you read from file you need TrieGetCell.

I get the first part but when I read the file, if I use TrieSetArray it requires a key to save the data, what key to put?

PHP Code:

enum
{
    
ARM_MP5//0
    
ARM_TMP,
    
ARM_P90,
    
ARM_MAC10,
    
ARM_AK47,
    
ARM_SG552,
    
ARM_M4A1,
    
ARM_AUG,
    
ARM_SCOUT,
    
ARM_G3SG1,
    
ARM_AWP,
    
ARM_M3,
    
ARM_XM1014,
    
ARM_M249,
    
ARM_FLASHBANG,
    
ARM_HEGRENADE,
    
ARM_KEVLAR,
    
ARM_ASSAULT,
    
ARM_SMOKEGRENADE //18
}

new const 
g_szValues[ ][ ] =
{
    
"ARM_MP5",
    
"ARM_TMP",
    
"ARM_P90",
    
"ARM_MAC10",
    
"ARM_AK47",
    
"ARM_SG552",
    
"ARM_M4A1",
    
"ARM_AUG",
    
"ARM_SCOUT",
    
"ARM_G3SG1",
    
"ARM_AWP",
    
"ARM_M3",
    
"ARM_XM1014",
    
"ARM_M249",
    
"ARM_FLASHBANG",
    
"ARM_HEGRENADE",
    
"ARM_KEVLAR",
    
"ARM_ASSAULT",
    
"ARM_SMOKEGRENADE"
}

new 
Trie:g_tWeaponTrie;

public 
plugin_init( )
{
    
g_tWeaponTrie TrieCreate( );

    for( new 
isizeof g_szValuesi++ )
    {
        for( new 
iValue=ARM_MP5iValue <= ARM_SMOKEGRENADEiValue++ )
        {
            
TrieSetCellg_tWeaponTrieg_szValues], iValue );
        }
    }


Quote:

Originally Posted by HamletEagle (Post 2570445)
Alternatively, you could do that without weaponbox/armoury_entity at all. Create some dummy entity(info_target) and set the weapon index that your entity will contain in a pev value like pev_iuser1. Hook touch, retrieve the CSW_* index from pev_iuser1, get it's name with get_weaponname and use give item, then remove the dummy entity.
That way you can put any weapon in there and you don't need to deal with complicated weaponbox code.

Wouldn't that cause any glitches? As you're setting different values to pev_iuser1. Wouldn't it be better creating a variable that will hold the values instead of pev_iuser1 and then looping through all entities?


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

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