View Single Post
Pastout
Senior Member
Join Date: Dec 2010
Location: 1337 Street LeetTown
Old 04-04-2013 , 15:40   Re: Module: Parachute (not fake)
Reply With Quote #8

I was doing some testing cause some people have ask me about this and I found a way without hooking client_prethink. I am also using gravity cause its really smooth and acts more realistic. Would be nice to see this in a module coded like this.

PHP Code:
#include < amxmodx >
#include < fakemeta >
#include < hamsandwich >
#include < fun >
#include < orpheu >
#include < orpheu_stocks >
 
new OrpheuStruct:g_ppmove;
 
#define PLUGIN        "Parachute"
#define VERSION        "1.0"
#define AUTHOR        ""
 
#define PARACHUTE_MODEL "models/parachute.mdl"
 
#define MAX_PLAYERS    32
 
#define MarkUserHasParachute(%0)    g_bitHasParachute |= (1<<(%0&31))
#define ClearUserHasParachute(%0)    g_bitHasParachute &= ~(1<<(%0&31))
#define HasUserParachute(%0)        g_bitHasParachute & (1<<(%0&31))
 
#define MarkUserUsingParachute(%0)    g_bitUsingParachute |= (1<<(%0&31))
#define ClearUserUsingParachute(%0)    g_bitUsingParachute &= ~(1<<(%0&31))
#define HasUserUsingParachute(%0)    g_bitUsingParachute & (1<<(%0&31))
 
#define MarkUserAliveParachute(%0)    g_bitAlive |= (1<<(%0&31))
#define ClearUserAliveParachute(%0)    g_bitAlive &= ~(1<<(%0&31))
#define HasUserAliveParachute(%0)    g_bitAlive & (1<<(%0&31))
 
new g_bitAlive
new g_bitUsingParachute
new g_bitHasParachute 
 
new g_iUserParachute[MAX_PLAYERS+1]
new 
Float:g_flEntityFrame[MAX_PLAYERS+1]
 
new 
g_iModelIndex
new g_pCvarFallSpeed
 
new const PARACHUTE_CLASS[] = "parachute"
 
enum {
    
deploy,
    
idle,
    
detach
}
 
public 
plugin_init() {
    
register_plugin(_PLUGIN_VERSION_AUTHOR)
    
g_pCvarFallSpeed register_cvar("parachute_fallspeed""0.0001")
 
    
RegisterHam(Ham_Spawn"player""Ham_CBasePlayer_Spawn_Post"1)
    
RegisterHam(Ham_Killed"player""Ham_CBasePlayer_Killed_Post"1)
 
    
OrpheuRegisterHookOrpheuGetDLLFunction"pfnPM_Move""PM_Move" ), "PM_Move" );
    
OrpheuRegisterHookOrpheuGetFunction"PM_FlyMove" ), "PM_FlyMove" );
    
OrpheuRegisterHookOrpheuGetFunction"PM_PlayStepSound" ), "PM_PlayStepSound" );
}
 
public 
plugin_precache() {
    
g_iModelIndex precache_model(PARACHUTE_MODEL)
}
 
public 
client_putinserver(id) {
    if( 
HasUserParachute(id) ) {
        new 
iEnt g_iUserParachute[id]
        if( 
iEnt ) {
            
RemoveUserParachute(idiEnt)
        }
        
ClearUserHasParachute(id)
 
    }
    
ClearUserAliveParachute(id)
}
 
public 
client_disconnect(id) {
    if( 
HasUserParachute(id) ) {
        new 
iEnt g_iUserParachute[id]
        if( 
iEnt ) {
            
RemoveUserParachute(idiEnt)
        }
        
ClearUserHasParachute(id)
    }
    
ClearUserAliveParachute(id)
}
 
public 
Ham_CBasePlayer_Killed_Postid ) {
    if( 
HasUserParachute(id) ) {
        new 
iEnt g_iUserParachute[id]
        if( 
iEnt ) {
            
RemoveUserParachute(idiEnt)
        }
        
ClearUserHasParachute(id)
    }
    
ClearUserAliveParachute(id)
}
 
new 
Float:get_userGravity33 ]
new 
Float:get_cvar
 
public Ham_CBasePlayer_Spawn_Post(id) {
    if( 
is_user_alive(id) ) {
        
get_cvar get_pcvar_float(g_pCvarFallSpeed)
        
get_userGravityid ] = get_user_gravity(id)
        if( 
HasUserParachute(id) ) {
            new 
iEnt g_iUserParachute[id]
            if( 
iEnt ) {
                
RemoveUserParachute(idiEnt)
            }
        }
        
MarkUserHasParachute(id)
        
MarkUserAliveParachute(id)
    }
}
 
RemoveUserParachute(idiEnt) {
    
engfunc(EngFunc_RemoveEntityiEnt)
    
g_iUserParachute[id] = 0
    set_user_gravity
(idget_userGravityid ])
    
ClearUserUsingParachute(id)
}
 
CreateParachute(id) {
    static 
iszInfoTarget
    
if( !iszInfoTarget ) {
        
iszInfoTarget engfunc(EngFunc_AllocString"info_target")
    }
    new 
iEnt engfunc(EngFunc_CreateNamedEntityiszInfoTarget)
    if( 
iEnt 0) {
        static 
iszClass 0
        
if( !iszClass ) {
            
iszClass engfunc(EngFunc_AllocStringPARACHUTE_CLASS)
        }
        
set_pev_string(iEntpev_classnameiszClass)
        
set_pev(iEntpev_aimentid)
        
set_pev(iEntpev_ownerid)
        
set_pev(iEntpev_movetypeMOVETYPE_FOLLOW)
        static 
iszModel 0
        
if( !iszModel ) {
            
iszModel engfunc(EngFunc_AllocStringPARACHUTE_MODEL)
        }
        
set_pev_string(iEntpev_modeliszModel)
        
set_pev(iEntpev_modelindexg_iModelIndex)
        
set_pev(iEntpev_sequencedeploy)
        
set_pev(iEntpev_gaitsequence1)
        
set_pev(iEntpev_frame0.0)
 
        
set_pev(iEntpev_rendermodepev(idpev_rendermode));
        
set_pev(iEntpev_renderfxpev(idpev_renderfx));
        new 
Float:f_renderamt;
        
pev(idpev_renderamtf_renderamt);
        
set_pev(iEntpev_renderamtf_renderamt);
 
        
g_flEntityFrame[id] = 0.0
        g_iUserParachute
[id] = iEnt
        MarkUserHasParachute
(id)
        new 
Float:fVecOrigin[3]
        
pev(idpev_originfVecOrigin)
 
        return 
iEnt
    
}
    return 
0
}
 
public 
OrpheuHookReturn:PM_MoveOrpheuStruct:ppmoveserver )
{
    
g_ppmove ppmove;
 
    return 
OrpheuIgnored;
}
 
public 
OrpheuHookReturn:PM_PlayStepSound( )
{
    new 
id OrpheuGetStructMemberg_ppmove"player_index" ) + 1;
 
    if( ~
HasUserParachute(id) && ~HasUserAliveParachute(id)) {
        return 
OrpheuIgnored;
    }
    new 
iEnt g_iUserParachute[id]
    if(
iEnt && HasUserUsingParachute(id) ) {
 
        
RemoveUserParachute(idiEnt)
    }
 
    return 
OrpheuIgnored;
}
 
public 
OrpheuHookReturn:PM_FlyMove( )
{
    new 
id OrpheuGetStructMemberg_ppmove"player_index" ) + 1;
    new 
Float:flFrame
    
new iEnt g_iUserParachute[id]
    if( 
pev(idpev_button) & IN_USE ) {
        new 
Float:fVecVelocity[3], Float:fVelocity_z
        pev
(idpev_velocityfVecVelocity)
        
fVelocity_z fVecVelocity[2]
        if( 
fVelocity_z 0.0 ) {
            if(
iEnt <= 0) {
                
iEnt CreateParachute(id)
            }
            
//fVelocity_z = floatmin(fVelocity_z + 14.0, -get_pcvar_float(g_pCvarFallSpeed))
            //fVecVelocity[2] = fVelocity_z
            //set_pev(id, pev_velocity, fVecVelocity)
 
            
MarkUserUsingParachute(id)
            
set_user_gravity(id, (get_userGravityid ]/4)+get_cvar)
            if( 
pev(iEntpev_sequence) == deploy ) {
                
flFrame g_flEntityFrame[id]++
                if( 
flFrame 100.0 ) {
                    
set_pev(iEntpev_animtime0.0)
                    
set_pev(iEntpev_framerate0.4)
                    
set_pev(iEntpev_sequenceidle)
                    
set_pev(iEntpev_gaitsequence1)
                    
set_pev(iEntpev_frame0.0)
                    
g_flEntityFrame[id] = 0.0
                
}
                else {
                    
set_pev(iEntpev_frameflFrame)
                }
            }
        }
        else if(
iEnt 0) {
            
RemoveUserParachute(idiEnt)
        }
    }
    else if( 
iEnt && pev(idpev_oldbuttons) & IN_USE ) {
        
RemoveUserParachute(idiEnt)
    }
 
    return 
OrpheuIgnored;

Pastout is offline