Raised This Month: $32 Target: $400
 8% 

Solved Shield entitiy detection doesn't work while player is using it?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GasmoN
Member
Join Date: Jul 2014
Old 05-23-2022 , 08:09   Shield entitiy detection doesn't work while player is using it?
Reply With Quote #1

Situation: Player is holding a shield, some some custom named entity touch that shield, and in FM_Touch forward doesn't recognize it. It registers that touch as if that custom named entity touched player, not a shield entity. How to fix this?

Last edited by GasmoN; 05-28-2022 at 08:40. Reason: Solved
GasmoN is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-23-2022 , 08:22   Re: Shield entitiy detection doesn't work while player is using it?
Reply With Quote #2

The shield is not an entity, just a model. If you need to detect shield touch you can likely use register_touch(custom entity, player) and check if the player currently has the shield deployed.
However, you may need to add more checks to filter cases when the entity touches the back of the player, depending on your needs.
__________________
HamletEagle is offline
GasmoN
Member
Join Date: Jul 2014
Old 05-23-2022 , 08:58   Re: Shield entitiy detection doesn't work while player is using it?
Reply With Quote #3

I know that, it really do works that way but I can't achive what I really need that way (or can I?).
So when custom entity touches player's shield, I need to check If player is actually using shield (sequence 98 ), if he is using it, I can call some function there.


Custom Entity touches player's shield > check if player is using that shield (sequence 98 ) > Call custom function

And by the method u mentioned, I am not really sure how to check if custom entity is touching player's shield. I do know to check if player is using shield tho.

PS: I don't need anyone to write me a code, I just need explanation how to actually achive this since I ran out of ideas.

Last edited by GasmoN; 05-24-2022 at 15:34.
GasmoN is offline
StanGilbertlandria
BANNED
Join Date: Mar 2022
Old 05-25-2022 , 07:07   Re: Shield entitiy detection doesn't work while player is using it?
Reply With Quote #4

I'm trying to detect if a player is holding up a shield, either in the main hand or offhand, for a stamina system. When they drop the shield, the stamina should start regenerating. Any suggestions?

I've tried using armour stands and villagers, but neither really work. With armour stands, I can't use the offhand. With villagers, it won't detect when I've stopped holding it up (also it means I can't interact with other blocks while the shield is in the offhand
StanGilbertlandria is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 05-25-2022 , 21:31   Re: Shield entitiy detection doesn't work while player is using it?
Reply With Quote #5

I had the same problem with detecting shield hits with my Realistic Bullet Physics plugin. The first realization was that there's no entity detection alone but another body part of the player, we can call it HIT_SHIELD, defined as 8 inside the amxconst.inc file.

This may help you, I guess.

Quote:
Originally Posted by StanGilbertlandria View Post
I'm trying to detect if a player is holding up a shield, either in the main hand or offhand, for a stamina system. When they drop the shield, the stamina should start regenerating. Any suggestions?

I've tried using armour stands and villagers, but neither really work. With armour stands, I can't use the offhand. With villagers, it won't detect when I've stopped holding it up (also it means I can't interact with other blocks while the shield is in the offhand
PHP Code:
#define OFFSET_HASSHIELD            2043

get_pdata_bool(iPlayerOFFSET_HASSHIELD
Not sure if this is what you asked, but detects whether the user has the shield.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 05-25-2022 at 21:34.
EFFx is offline
GasmoN
Member
Join Date: Jul 2014
Old 05-26-2022 , 10:41   Re: Shield entitiy detection doesn't work while player is using it?
Reply With Quote #6

Is there any solution for my issue tho?
GasmoN is offline
GasmoN
Member
Join Date: Jul 2014
Old 05-28-2022 , 08:37   Re: Shield entitiy detection doesn't work while player is using it?
Reply With Quote #7

SOLUTION:

It's maybe not the best solution out there, but it does works.
So, instead of detecting the shield, I thought about detecting if entity is touching player from behind, sides, or front. Since player is fully covered in front when using shield, this way of detecting is helping me achive what I wanted. (If entity is touching player in front, it means it's touching the shield too).

And that's where I remembered about this plugin that prevents players from back stabbing.
https://forums.alliedmods.net/showpo...66&postcount=4 So after some small changes I made it work.

The code I am using in FM_Touch forward after checking if entity is touching player and all other checks:
PHP Code:
        if(is_using_shield(id))
        {    
            static 
Float:fOrigin[3];
            
pev(idpev_originfOrigin);
            
            static 
Float:fViewAngles[3]
            static 
Float:fTViewAngles[3];
            
pev(bulletpev_v_anglefTViewAngles);
            
            static 
Float:fMinAngleFloat:fMaxAngle;
            
fMinAngle fViewAngles[1] - CHECK_ANGLE;
            
fMaxAngle fViewAngles[1] + CHECK_ANGLE;
            
            if(
fMinAngle <= fTViewAngles[1] <= fMaxAngle)
            {
                
// Entity is touching player's back
            
}
            else
            {
                
// Entity is touching player's front (shield)
            
}
        } 
Define and stock used
PHP Code:
#define CHECK_ANGLE 100.0

bool:is_using_shield(id)
{
    if(
entity_get_int(id EV_INT_sequence) == 98)
    return 
true;

    return 
false;

If there is a better way of doing this, I am always up for suggestions.

Last edited by GasmoN; 05-28-2022 at 08:48.
GasmoN is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 05-28-2022 , 11:54   Re: Shield entitiy detection doesn't work while player is using it?
Reply With Quote #8

You can give it a try with ( engfunc(EngFunc_TraceModel, const Float:start[3], const Float:end[3], hull, ent_to_hit, ptr) )

ent_to_hit is the victim player shield.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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 08:19.


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