AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   [CS 1.6] How to detect if a player is crouched? (https://forums.alliedmods.net/showthread.php?t=302065)

sekac 10-15-2017 05:37

[CS 1.6] How to detect if a player is crouched?
 
The title says it all, how do i detect if a player is crouched (with and without holding the duck button, player will stay ducked if he is in a small area).

Relaxing 10-15-2017 07:49

Re: [CS 1.6] How to detect if a player is crouched?
 
https://forums.alliedmods.net/showthread.php?t=97083

sekac 10-15-2017 15:29

Re: [CS 1.6] How to detect if a player is crouched?
 
I don`t know how to use that

GrimmReaper 10-15-2017 21:20

Re: [CS 1.6] How to detect if a player is crouched?
 
Quote:

Originally Posted by sekac (Post 2554730)
I don`t know how to use that

Its quite easy actually.
First you have to include hamsandwich to use it like this
PHP Code:

#include <hamsandwich> 

Then in plugin_init() forward put this
PHP Code:

RegisterHam(Ham_Player_Duck"player""player_duck"0); 

Now to explain this
Ham_Player_Duck - This is a event which triggers the ham to execute
"player" - Its the entity or in simple words object to which the above event is hooked to.
"player_duck" - Its basically the name of function you create to execute the code before or while or after the the event you specified. You can change this one to anything as long as the function you are creating has the same name.
The last parameter is for the pre/post
2 - before the event
0 - while the event is active or in your case while the player is crouching
1 - after the event
Lastly you have to make a function to execute the code like this
PHP Code:

public player_duck(id)
{
//Some code here



Natsheh 10-16-2017 03:00

Re: [CS 1.6] How to detect if a player is crouched?
 
Quote:

Originally Posted by GrimmReaper (Post 2554782)
Its quite easy actually.
First you have to include hamsandwich to use it like this
PHP Code:

#include <hamsandwich> 

Then in plugin_init() forward put this
PHP Code:

RegisterHam(Ham_Player_Duck"player""player_duck"0); 

Now to explain this
Ham_Player_Duck - This is a event which triggers the ham to execute
"player" - Its the entity or in simple words object to which the above event is hooked to.
"player_duck" - Its basically the name of function you create to execute the code before or while or after the the event you specified. You can change this one to anything as long as the function you are creating has the same name.
The last parameter is for the pre/post
-1 - before the event
0 - while the event is active or in your case while the player is crouching
1 - after the event
Lastly you have to make a function to execute the code like this
PHP Code:

public player_duck(id)
{
//Some code here



The 4th param in registerham is only has 2 values 0 & 1

GrimmReaper 10-16-2017 07:08

Re: [CS 1.6] How to detect if a player is crouched?
 
Quote:

Originally Posted by Natsheh (Post 2554801)
The 4th param in registerham is only has 2 values 0 & 1

Sorry my bad.

sekac 10-16-2017 10:10

Re: [CS 1.6] How to detect if a player is crouched?
 
PHP Code:

register_clcmd("say /test""Test");

RegisterHam(Ham_Player_Duck"player""player_duck"0);  
new 
boolIsCrouched[32];

public 
player_duck(id

IsCrouched[id] = true;
}

public 
Test(id) {

if(
IsCrouched[id])
//some code here


Is this how i use it? I need to run a command somewhere else in the code, if the player is crouched. And if so, when do i set IsCrouched to false?

DjSoftero 10-16-2017 10:47

Re: [CS 1.6] How to detect if a player is crouched?
 
First of all, you should tell us what you`re trying to achieve

sekac 10-16-2017 10:53

Re: [CS 1.6] How to detect if a player is crouched?
 
Just trying to give an item to player if he is crouching, if he isn`t return a message. It`s simple.

DjSoftero 10-16-2017 11:41

Re: [CS 1.6] How to detect if a player is crouched?
 
i guess you can do it with orpheu
PHP Code:

new Is_Ducking OrpheuGetParamStructMember(1,"usehull")
if(
Is_Ducking == 1) {
    
//it means you`re ducking and you do smth
}
else
    
//not ducking 

I don`t really know if this will work and can`t test it atm, but you should give it a try.

source: https://forums.alliedmods.net/showth...7217?p=1387217


All times are GMT -4. The time now is 00:31.

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