Raised This Month: $51 Target: $400
 12% 

Get all weapons entities carried by player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
rtxa
Senior Member
Join Date: Mar 2018
Location: Argentina
Old 03-23-2019 , 18:11   Get all weapons entities carried by player
Reply With Quote #1

Hi, I'm looking how to get all weapons entities carried by a player, I'm trying to make a freeze function for Half-Life and I need to set to those weapons m_flNextPrimaryAttack to some high value so the player can't shoot them while he is freeze, any ideas?

Last edited by rtxa; 03-23-2019 at 18:14.
rtxa is offline
baneado
Veteran Member
Join Date: Dec 2012
Location: amxmodx-es.com
Old 03-23-2019 , 19:01   Re: Get all weapons entities carried by player
Reply With Quote #2

Use m_flNextAttack and set to player instead of every weapon the player has
baneado is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-23-2019 , 20:10   Re: Get all weapons entities carried by player
Reply With Quote #3

I agree, makes no sense to do his entire inventory. Just set the attributes once the player holds the weapon.

Take a look at this: https://forums.alliedmods.net/showpo...9&postcount=47
__________________
Bugsy is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 03-23-2019 , 20:17   Re: Get all weapons entities carried by player
Reply With Quote #4

Loop over all slots (1..5):
Quote:
"m_rgpPlayerItems" // CBasePlayerItem*[6]
And over all items in every slot using:
Quote:
"m_pNext" // CBasePlayerItem*
__________________
My English is A0
E1_531G is offline
rtxa
Senior Member
Join Date: Mar 2018
Location: Argentina
Old 03-23-2019 , 22:53   Re: Get all weapons entities carried by player
Reply With Quote #5

I found the solution, maybe isn't the most efficient way, but it works, also I don't need it to hook anything, so I can keep it simple.
PHP Code:
BlockPlayerWeapons(Float:time) {
    new 
ident;
    for (new 
isizeof(WEAPONS_CLASSES); i++) {
        while ((
ent find_ent_by_class(entWEAPONS_CLASSES[i]))) {
            
id pev(entpev_owner);
            if (
IsPlayer(id)) {
                
set_ent_data_float(ent"CBasePlayerWeapon""m_flNextPrimaryAttack"time);
                
set_ent_data_float(ent"CBasePlayerWeapon""m_flNextSecondaryAttack"time);
            }
        }
    }


Quote:
Originally Posted by E1_531G View Post
Loop over all slots (1..5):

And over all items in every slot using:
That would make it more efficient, can you show me how to move over all items with m_pNext?

Quote:
Originally Posted by baneado View Post
Use m_flNextAttack and set to player instead of every weapon the player has
Thank you, but I have already test that and I found that sometimes player can do at least one shot (only client-side).

Quote:
Originally Posted by Bugsy View Post
I agree, makes no sense to do his entire inventory. Just set the attributes once the player holds the weapon.

Take a look at this: https://forums.alliedmods.net/showpo...9&postcount=47
Thanks but I would like to avoid hooks unless there is no other way, so I can keep it simple.

Last edited by rtxa; 03-23-2019 at 22:54.
rtxa is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-23-2019 , 23:52   Re: Get all weapons entities carried by player
Reply With Quote #6

Can you explain why you prefer to avoid hooks? Using hooks allows you to execute code exactly when needed, which is ideal IMO. The code written by ConnorMcLeod that I linked above works perfectly for this purpose.

If you prefer to use what you have above, shouldn't you add a condition to make it only impact a specific player? or do you intentionally have it to impact all?
__________________
Bugsy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-24-2019 , 05:56   Re: Get all weapons entities carried by player
Reply With Quote #7

https://forums.alliedmods.net/showpo...9&postcount=47 this is much better than what you have, as Bugsy said.
__________________
HamletEagle is offline
thEsp
BANNED
Join Date: Aug 2017
Old 03-24-2019 , 08:12   Re: Get all weapons entities carried by player
Reply With Quote #8

Simply freeze user, and make sure to block +attack checked by booleans
https://forums.alliedmods.net/showpo...20&postcount=2
thEsp is offline
rtxa
Senior Member
Join Date: Mar 2018
Location: Argentina
Old 03-24-2019 , 11:24   Re: Get all weapons entities carried by player
Reply With Quote #9

Quote:
Originally Posted by thEsp View Post
Simply freeze user, and make sure to block +attack checked by booleans
https://forums.alliedmods.net/showpo...20&postcount=2
I don't like FL_FROZEN, if you get freeze while in air, it cause some annoying jiterring on screen, so I prefer to block player move. Also, superceding those functions isn't enough, player can do at least one shot from client-side.

Quote:
Originally Posted by Bugsy View Post
Can you explain why you prefer to avoid hooks? Using hooks allows you to execute code exactly when needed, which is ideal IMO. The code written by ConnorMcLeod that I linked above works perfectly for this purpose.

If you prefer to use what you have above, shouldn't you add a condition to make it only impact a specific player? or do you intentionally have it to impact all?
Sorry, I'm too lazy to explain why I prefer to avoid hooks.

My intention is to freeze everyone, but now I made it for only one player, so the function can be more independent. Finally I found how to move over all items, so now is more efficient, thanks E1_531G.
PHP Code:
BlockPlayerWeapons(idFloat:time) {
    new 
weapon;
    for (new 
16i++) {
        if ((
weapon get_ent_data_entity(id"CBasePlayer""m_rgpPlayerItems"i)) != -1) {
            do {
                
set_ent_data_float(weapon"CBasePlayerWeapon""m_flNextPrimaryAttack"time);
                
set_ent_data_float(weapon"CBasePlayerWeapon""m_flNextSecondaryAttack"time);
            } while ((
weapon get_ent_data_entity(weapon"CBasePlayerItem""m_pNext")) != -1);
        }
    }


Last edited by rtxa; 03-24-2019 at 11:49.
rtxa is offline
thEsp
BANNED
Join Date: Aug 2017
Old 03-24-2019 , 13:50   Re: Get all weapons entities carried by player
Reply With Quote #10

If you just think, you can easily freeze players.
set_user_maxspeed
CurWeapon
thEsp 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 06:47.


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