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

how to execute a function if player is in air?


Post New Thread Reply   
 
Thread Tools Display Modes
Grovliom
Member
Join Date: Mar 2020
Location: somewhere in Serbia
Old 05-31-2020 , 11:48   Re: how to execute a function if player is in air?
Reply With Quote #11

Quote:
Originally Posted by supertrio17 View Post
Jel ti treba ako Player skoci ili ako je bas u vazduhu?
kad je u vazduhu

Last edited by Grovliom; 05-31-2020 at 11:56.
Grovliom is offline
Old 05-31-2020, 13:19
thEsp
This message has been deleted by thEsp.
supertrio17
Senior Member
Join Date: May 2020
Location: Serbia
Old 05-31-2020 , 13:53   Re: how to execute a function if player is in air?
Reply With Quote #12

Quote:
Originally Posted by Grovliom View Post
kad je u vazduhu
PHP Code:
#include <amxmodx>
#include <engine>
#include <ColorChat>

new Air

public plugin_init()
{
    
register_plugin("Player in Air""3.2""Mr. Boopsy");
}

public 
client_authorized(id)
{
    
Air 1
}

public 
client_PreThink(id)
{
    
when_in_air(id);
    
when_on_ground(id);
}

public 
when_in_air(id)
{
    if(!(
get_entity_flags(id) & FL_ONGROUND))
    {
        if(
Air == 1)
        {
            
ColorChat(idGREEN"You are in air");
            
Air 0;
        }
    }


public 
when_on_ground(id)
{
    if(
get_entity_flags(id) & FL_ONGROUND)
    {
        
Air 1;
    }

My brain is officialy melted, its so simple solution, but it took me ages to figure this out.
supertrio17 is offline
supertrio17
Senior Member
Join Date: May 2020
Location: Serbia
Old 05-31-2020 , 13:56   Re: how to execute a function if player is in air?
Reply With Quote #13

Quote:
Originally Posted by Grovliom View Post
kad je u vazduhu
To make it a little bit simpler, here is more compact one

PHP Code:
#include <amxmodx>
#include <engine>
#include <ColorChat>

new Air

public plugin_init()
{
    
register_plugin("Player in Air""3.3""Mr. Boopsy");
}

public 
client_authorized(id)
{
    
Air 1
}

public 
client_PreThink(id)
{
    if(!(
get_entity_flags(id) & FL_ONGROUND))
    {
        if(
Air == 1)
        {
            
ColorChat(idGREEN"You are in air");
            
Air 0;
        }
    }
    else
    {
        
Air 1;
    }

Edit:

It's not only for jumping, but for falling too, so if you fall of a box or something similar it will execute your command, in my case "ColorChat(id, GREEN, "You are in air")".
Hope I helped

Last edited by supertrio17; 05-31-2020 at 14:01.
supertrio17 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 05-31-2020 , 19:58   Re: how to execute a function if player is in air?
Reply With Quote #14

btw english only and these examples are not efficient, tell us what are you trying to achieve!?
__________________
@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
supertrio17
Senior Member
Join Date: May 2020
Location: Serbia
Old 05-31-2020 , 20:06   Re: how to execute a function if player is in air?
Reply With Quote #15

Well, this is only way I could think of, I know that clientPreThink can be hard on CPU, but if anyone has a better solution, than post it, I can't forbid anyone from trying to help...
supertrio17 is offline
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: Astral planes
Old 05-31-2020 , 20:45   Re: how to execute a function if player is in air?
Reply With Quote #16

If they are not on the ground they might be in water which is not air. Does FL_FLY even work for this sort of thing effectively?
__________________
DJEarthQuake is offline
supertrio17
Senior Member
Join Date: May 2020
Location: Serbia
Old 05-31-2020 , 21:38   Re: how to execute a function if player is in air?
Reply With Quote #17

Quote:
Originally Posted by DJEarthQuake View Post
If they are not on the ground they might be in water which is not air. Does FL_FLY even work for this sort of thing effectively?
I just took a closer look at wiki, and you can detect pretty much any type of terrain, you could just add what to include or exclude from this code, I could try and finish this code tomorrow if needed.
supertrio17 is offline
supertrio17
Senior Member
Join Date: May 2020
Location: Serbia
Old 05-31-2020 , 22:53   Re: how to execute a function if player is in air?
Reply With Quote #18

Hey, so I experimented a bit, and it turns out there is no need for anything else, I mean it makes sense.

So I see it like this, every time you are in air, you will get function to work only once, so if you think a bit, before you go in water you will have function execute once, and than you need to get out of the water to reset it. Because it won't reset unless you step on the ground.

This can become a problem if player touches the bottom of a pool or something, but I will make sure to rewrite this code once again.
supertrio17 is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 06-01-2020 , 02:58   Re: how to execute a function if player is in air?
Reply With Quote #19

PHP Code:
new g_client_flying[33]

public 
client_PreThink(client)
{
  new 
client_flying is_client_flying(client)

  switch(
client_flying)
  {
    case 
0client_print(0print_chat"Client is on the ground #SPAM")
    case 
1client_print(0print_chat"Client is for the first time in the sky")
    case 
2client_print(0print_chat"Client is flying #SPAM")
  }
}

is_client_flying(client)
{
  static 
client_flags
  client_flags 
get_entity_flags(client)

  
// If client flying
  
if( !(client_flags FL_ONGROUND)
    && !(
client_flags FL_INWATER) )
  {
    
g_client_flying[client] = g_client_flying[client] ? 1
  
}
  else 
  {
    
g_client_flying[client] = 0
  
}
  return 
g_client_flying[client]

__________________
Retired.
Xalus is offline
supertrio17
Senior Member
Join Date: May 2020
Location: Serbia
Old 06-01-2020 , 11:37   Re: how to execute a function if player is in air?
Reply With Quote #20

PHP Code:
#include <amxmodx>
#include <engine>
#include <ColorChat>

new Air

public plugin_init()
{
    
register_plugin("Player in Air""3.7""Mr. Boopsy");
}

public 
client_PreThink(id)
{
    if(!(
get_entity_flags(id) & (FL_ONGROUND FL_PARTIALGROUND FL_INWATER FL_CONVEYOR FL_FLOAT FL_FLY)))
    {
        if(
Air == 1)
        {
            
ColorChat(idGREEN"You are in air");
            
Air 0;
        }
    }
    else
    {
        
Air 1;
    }

This is as far as I got, only issue in this code is that it detects ladders as air. I think that it could be excluded with "pev(id, pev_movetype)", but I can't do this right now.

I just now figured that client_authorized was not needed at all, sorry for that stupid mistake.

Hope I helped
supertrio17 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 19:31.


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