View Single Post
1xAero
Member
Join Date: Feb 2018
Location: Sakha, Russia
Old 05-11-2023 , 00:13   Re: long jump plugin
Reply With Quote #2

PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <cromchat>

#define PLUGIN "Long Jump"
#define VERSION "1.0"
#define AUTHOR "Alex Winchester"
    
new bool:g_hasLongJump[33]
new 
Float:g_last_LongJump_time[33]
new 
g_LongJump_forceg_LongJump_heightg_LongJump_cooldown

public plugin_init()
{
   
register_plugin(PLUGINVERSIONAUTHOR)
   
   
RegisterHam(Ham_Spawn"player""Player_Spawn"1)
   
   
g_LongJump_force register_cvar("lj_longjump_force""550")
   
g_LongJump_height register_cvar("lj_longjump_height""255")
   
g_LongJump_cooldown register_cvar("lj_longjump_cooldown""5.0")
   
   
register_forward(FM_PlayerPreThink"fw_PlayerPreThink")
   
register_event("DeathMsg""death""a")
   
register_event("HLTV""event_round_start""a""1=0""2=0")
   
CC_SetPrefix("&x07[LJ]")
}

// Reset on disconnection
public client_disconnected(id)
{
   
g_hasLongJump[id] = false
}

// Reset on death
public death()
{
   
g_hasLongJump[read_data(2)] = false
}

// Reset at round start (for everyone)
public event_round_start()
{
   for (new 
1<= 32i++)
      
g_hasLongJump[i] = true
}

public 
Player_Spawn(id)
{
   if (
is_user_alive(id))
   {
      
g_hasLongJump[id] = true
      CC_SendMessage
(id"&x01You have recieved a Jump Pack. To use it, press duck and jump while moving forward.")
   }
}   
  
public 
fw_PlayerPreThink(id)
{
   if (!
is_user_alive(id))
      return 
FMRES_IGNORED
   
   
if (allow_LongJump(id))
   {
      static 
Float:velocity[3]
      
velocity_by_aim(idget_pcvar_num(g_LongJump_force), velocity)
      
      
velocity[2] = get_pcvar_float(g_LongJump_height)
      
      
set_pev(idpev_velocityvelocity)
      
      
g_last_LongJump_time[id] = get_gametime()
   }
   
   return 
FMRES_IGNORED
}

// Check if the player can longjump
public boolallow_LongJump(id)
{
   if (!
g_hasLongJump[id])
      return 
false;
   
   if (!(
pev(idpev_flags) & FL_ONGROUND) || fm_get_speed(id) < 80)
      return 
false;
   
   static 
buttons
   buttons 
pev(idpev_button)
   
   if (!
is_user_bot(id) && (!(buttons IN_JUMP) || !(buttons IN_DUCK)))
      return 
false;
      
   static 
Float:cooldown
   cooldown 
get_pcvar_float(g_LongJump_cooldown)
   
   if (
get_gametime() - g_last_LongJump_time[id] < cooldown)
   {
       
CC_SendMessage(id"&x01Please wait &x07%i &x01seconds to do &x07leap &x01again!")
       return 
false;
   }
    
   if(
g_last_LongJump_time[id] == cooldown)
   {
       
CC_SendMessage(id"&x01Now you can do &x07leap &x01again!")
   }
   
   return 
true;
}

// Get entity's speed (from fakemeta_util)
stock fm_get_speed(entity)
{
   static 
Float:velocity[3]
   
pev(entitypev_velocityvelocity)
   
   return 
floatround(vector_length(velocity));


Last edited by 1xAero; 05-11-2023 at 00:16. Reason: Wrong helping section
1xAero is offline