Raised This Month: $ Target: $400
 0% 

How to detach and attach shield entity to player?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
souvikdas95
Senior Member
Join Date: Mar 2012
Old 05-10-2014 , 06:21   How to detach and attach shield entity to player?
Reply With Quote #1

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.

Last edited by souvikdas95; 05-10-2014 at 06:40.
souvikdas95 is offline
souvikdas95
Senior Member
Join Date: Mar 2012
Old 05-10-2014 , 06:25   Re: How to detach and attach shield entity to player?
Reply With Quote #2

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

Last edited by souvikdas95; 05-10-2014 at 06:36.
souvikdas95 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-10-2014 , 07:01   Re: How to detach and attach shield entity to player?
Reply With Quote #3

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
__________________

Last edited by Arkshine; 05-10-2014 at 07:02.
Arkshine is offline
Old 05-10-2014, 07:16
jok
This message has been deleted by YamiKaitou. Reason: comment not needed
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 05-10-2014 , 07:25   Re: How to detach and attach shield entity to player?
Reply With Quote #4

probably fakemeta simply dont run on his non-steam server thats why.
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-10-2014 , 08:23   Re: How to detach and attach shield entity to player?
Reply With Quote #5

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;

__________________

Last edited by Arkshine; 05-10-2014 at 08:38.
Arkshine is offline
souvikdas95
Senior Member
Join Date: Mar 2012
Old 05-10-2014 , 08:24   Re: How to detach and attach shield entity to player?
Reply With Quote #6

Never thought you were even taught sarcasm . 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

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.

Last edited by souvikdas95; 05-10-2014 at 08:34.
souvikdas95 is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 05-10-2014 , 08:26   Re: How to detach and attach shield entity to player?
Reply With Quote #7

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.
Backstabnoob is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-10-2014 , 08:30   Re: How to detach and attach shield entity to player?
Reply With Quote #8

I think this would make sense to add these ones to cstrike module, as there is already cs_get_user_shield().
__________________
Arkshine is offline
souvikdas95
Senior Member
Join Date: Mar 2012
Old 05-10-2014 , 09:36   Re: How to detach and attach shield entity to player?
Reply With Quote #9

@Arkshine - It's giving me Invalid Entity error on Native : get_pdata_int under cs_set_user_shield ( ).
souvikdas95 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-10-2014 , 09:51   Re: How to detach and attach shield entity to player?
Reply With Quote #10

It works fine for me, so you better explain exactly how you used the function and what get_pdata_int you're talking about.
__________________
Arkshine 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 09:48.


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