#include <amxmodx>
#include <engine>
 
#define FALL_VELOCITY 350.0
#define MAX_FALL_HEIGHT 250 // player would get hurt if he falled over greater height
 
new g_start_falling_height[33]
new bool:g_height_reached[33];
 
public plugin_init() {
  register_plugin("No fall damage", "0.1", "v3x");
  if(!cvar_exists("mp_falldamage")) {
    register_cvar("mp_falldamage", "0");
  }
}
 
new bool:falling[33];
 
public client_PreThink(id) {
  if(get_cvar_num("mp_falldamage") == 0 && is_user_alive(id) && get_user_flags(id) & ADMIN_KICK) {
    if(entity_get_float(id, EV_FL_flFallVelocity) >= FALL_VELOCITY) {
      if(g_height_reached[id])
        return
      new origin[3]
      get_user_origin(id, origin)
      if(!falling[id]) {
        //server_print("DEBUG: [%d] Start falling at height [%d]", id, origin[2])
        falling[id] = true
        g_start_falling_height[id] = origin[2]
      }
      else if(g_start_falling_height[id] - origin[2] > MAX_FALL_HEIGHT) {
        /*
    server_print("DEBUG: [%d] MAX FALL HEIGHT is reached at height [%d]. Height difference [%d]",
    id, origin[2], g_start_falling_height[id] - origin[2])
        */
    falling[id] = false;
        g_height_reached[id] = true
      }
    } else {
      falling[id] = false;
      g_height_reached[id] = false
    }
  }
}
 
public client_PostThink(id) {
  if(get_cvar_num("mp_falldamage") == 0 && get_user_flags(id) & ADMIN_KICK) {
    if(falling[id]) {
      entity_set_int(id, EV_INT_watertype, -3);
    }
  }
}