AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Solved] Player Duck (https://forums.alliedmods.net/showthread.php?t=219965)

Jhob94 07-05-2013 09:22

[Solved] Player Duck
 
Hi
What is the best way to know if player is ducking?

YamiKaitou 07-05-2013 09:23

Re: Player Duck
 
By seeing if their buttons contain IN_DUCK

Jhob94 07-05-2013 09:46

Re: Player Duck
 
Something like this?
PHP Code:

public plugin_init()
{  
    
register_forward(FM_CmdStart"fw_CmdStart")
}

public 
fw_CmdStart(iduc_handleseed)
{
    static 
CurrentButton
    CurrentButton 
get_uc(uc_handleUC_Buttons)
    
    if(
is_user_alive(id) && CurrentButton IN_DUCK)
    {
           
// Code
    
}


It seems good but on code i display one message and xD it display lot of messages :3

fysiks 07-05-2013 10:59

Re: Player Duck
 
If you print a message in that conditional statement it will print any time that it is true. It will be true the entire time that you are holding the button down (remember that it will execute really fast so what you may think is a single press is actually a long time relative to the computer).

If you only want the message to show when you first press the button then you need to save the previous value and compare it to the current value to detect the change of state.

If you search you can find all the information you need. Amazing how that works.

Jhob94 07-05-2013 11:11

Re: Player Duck
 
Hum i used bool and now works fine :3

fysiks 07-05-2013 11:19

Re: Player Duck
 
Quote:

Originally Posted by Jhob94 (Post 1983844)
Hum i used bool and now works fine :3

How so? How do you reset the boolean?

Bos93 07-05-2013 11:25

Re: Player Duck
 
Quote:

If you only want the message to show when you first press the button then you need to save the previous value and compare it to the current value to detect the change of state.
#define m_afButtonPressed 246
#define m_afButtonReleased 247

ConnorMcLeod 07-05-2013 11:39

Re: Player Duck
 
Player is ducking when size if lower than standup size, if you want to detect that, you can check flags & FL_DUCKING

Jhob94 07-05-2013 13:10

Re: Player Duck
 
Well its good how it is.
About bool i set Can_Duck false after ducks ;)

fysiks 07-05-2013 13:13

Re: Player Duck
 
Quote:

Originally Posted by Jhob94 (Post 1983947)
Well its good how it is.
About bool i set Can_Duck false after ducks ;)

So it only shows the message once per map?


All times are GMT -4. The time now is 06:26.

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