AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to detach and attach shield entity to player? (https://forums.alliedmods.net/showthread.php?t=240168)

souvikdas95 05-10-2014 06:21

How to detach and attach shield entity to player?
 
I tried the following code but it crashed HLDS

PHP Code:

new shield_entity;
if ( 
cs_get_user_shield id ) )
{
    
engclient_cmd id"drop""weapon_shield" );
    
shield_entity find_ent_by_owner ( -1"weapon_shield"id );
}
client_print idprint_chat"SHIELD DETACHED" );
/*engclient_cmd ( id, "drop", "weapon_<pistol>" )*/
if ( is_valid_ent shield_entity ) && ExecuteHamB Ham_AddPlayerItemidshield_entity ) )
    
ExecuteHamB Ham_Item_AttachToPlayershield_entityid );
client_print idprint_chat"SHIELD ATTACHED" ); 

Also tried using fake_touch ( id, hasShield ), ExecuteHam ( Ham_Touch, id, hasShield ) - No Result.

Basically my main aim is to drop the pistol attached to the player rather than the shield on engclient_cmd ( id, "drop", "weapon_<pistol>" ). so i am using engclient_cmd ( id, "drop", "weapon_shield" ) and then engclient_cmd ( id, "drop", "weapon_<pistol>" ) to detach the pistol and then I wish to reattach the shield. I am able to get the entity index of the shield but I don't know how to attach it back.

souvikdas95 05-10-2014 06:25

Re: How to detach and attach shield entity to player?
 
Please don't suggest code snippets that work on the basis of entity model. Also I am trying to avoid using Fakemeta. Please don't ask why :P

Arkshine 05-10-2014 07:01

Re: How to detach and attach shield entity to player?
 
Quote:

Also I am trying to avoid using Fakemeta. Please don't ask why
There we go, long time we did read someone trying to not use a specific module, which is completely a non-sense. You probably no idea what you're doing.
Anyway, to set a shield, you will need to set offsets, oh, wait, offset.. fakemeta will be needed. That's too bad.
I have an idea, just make a whole module just to set a shield, you will avoid to use fakemeta. Ah well, but you will have to load another module.. Oh shit.
Oh, just another awesome idea, just request this to be integrated in cstrikle module since cs_set_user_shield doesn't seem to exist. Oh shit again, I bet you don't want to use cstrike.
Maybe you should actually not use AMXX because it's basically what you're trying to achieve.

/troll

NiHiLaNTh 05-10-2014 07:25

Re: How to detach and attach shield entity to player?
 
probably fakemeta simply dont run on his non-steam server thats why.

Arkshine 05-10-2014 08:23

Re: How to detach and attach shield entity to player?
 
Troll apart, here cs_set_user_shield() and cs_remove_user_shield().


PHP Code:

stock cs_remove_user_shield(user)
{
    return 
amxclient_cmd(user"drop""weapon_shield");


PHP Code:

stock bool:cs_set_user_shield(const user, const bool:retire true, const bool:gameCheck true, const bool:pickupSound true)
{
    const 
m_bHasPrimary      464;         // player
    
const m_bIsVIP           837;         // player
    
const m_bOwnsShield      2043;        // player
    
const m_pActiveItem      1492 4;    // player
    
const m_rgpPlayerItems   1468 4;    // player
    
const m_rgAmmo           1504 4     // player
    
const m_iPrimaryAmmoType 208  4;    // weapon
    
const m_iId              168  4;    // weapon
    
    // Sanity check.
    
if (gameCheck)
    {
        const 
slotSecondary 2;
    
        
// Not a player or has already a primary weapon
        
if( !is_user_alive(user) || get_pdata_bool(userm_bHasPrimary))
        {
            return 
false;
        }
        
        
// Don't give shield if player has already elite weapon.
        
new item get_pdata_cbase(userm_rgpPlayerItems slotSecondary);
        if (
item && get_pdata_int(itemm_iId4) == CSW_ELITE)
        {
            return 
false;
        }
        
        
// Weapon can't be holstered.
        
new activeItem get_pdata_cbase(userm_pActiveItem);
        if (
activeItem && !ExecuteHamB(Ham_Item_CanHolsteractiveItem))
        {
            return 
false;
        }
    
        
// Don't give shield to VIP.
        
if (get_pdata_bool(userm_bIsVIP))
        {
            return 
false;
        }
    }
    
    
set_pdata_bool(userm_bOwnsShieldtrue);
    
set_pdata_bool(userm_bHasPrimarytrue);

    new 
activeItem get_pdata_cbase(userm_pActiveItem);
    if (
activeItem)
    {
        if (
retire)
        {
            if (
get_pdata_cbase(userm_rgAmmo get_pdata_int(activeItemm_iPrimaryAmmoType4)) > 0)
            {
                
ExecuteHamB(Ham_Item_HolsteractiveItem0);       // No ammo, we holster.
            
}
            
            if (!
ExecuteHamB(Ham_Item_DeployactiveItem))
            {
                
ExecuteHamB(Ham_Weapon_RetireWeaponactiveItem);   // We can't deploy, so we retire weapon.
            
}
        }
    }
    
    if (
pickupSound)
    {
        
emit_sound(userCHAN_AUTO"items/gunpickup2.wav"VOL_NORMATTN_NORM0PITCH_NORM);
    }
    
    
set_pev(userpev_gamestate0);
    
    return 
true;



souvikdas95 05-10-2014 08:24

Re: How to detach and attach shield entity to player?
 
Never thought you were even taught sarcasm :P. So, that basically means, that I should constantly try to involve all modules... ok fine then... let's talk serious... I am making an upgrade to restmenu.sma - official amxmodx plugin under cstrike addon. What would you prefer? Less module interaction or more module interaction? I wanted to talk to you personally about it, but let it be public since you are so high today :D

btw, nice work there :) Thanks for it. Sadly would need to include fakemeta. But that's kind of inevitable in front of your sarcasm :)

Actually a similar thing was already coded by exolent ( https://forums.alliedmods.net/showthread.php?p=1521527 ).

Anyways, I wanted to know if we could use it just like what happens in engine, when we throw a weapon down and pick it up. Instead of removing the shield from world and then recreating, why not use existing drop and pickup function? Can you provide a code for that? eg. I drop the shield and I want it to be back to me without actually moving towards the shield and touching it in-game.

Backstabnoob 05-10-2014 08:26

Re: How to detach and attach shield entity to player?
 
It doesn't mean you should try to involve all modules, it means that trying to limit your plugin to engine/fakemeta is stupid and you should use whichever does what you want better.

Arkshine 05-10-2014 08:30

Re: How to detach and attach shield entity to player?
 
I think this would make sense to add these ones to cstrike module, as there is already cs_get_user_shield().

souvikdas95 05-10-2014 09:36

Re: How to detach and attach shield entity to player?
 
@Arkshine - It's giving me Invalid Entity error on Native : get_pdata_int under cs_set_user_shield ( ).

Arkshine 05-10-2014 09:51

Re: How to detach and attach shield entity to player?
 
It works fine for me, so you better explain exactly how you used the function and what get_pdata_int you're talking about.


All times are GMT -4. The time now is 09:48.

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