Raised This Month: $ Target: $400
 0% 

[orpheu] Set airaccelerate


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-14-2011 , 19:27   Re: [orpheu] Set airaccelerate
Reply With Quote #11

Try that. I've tested with bots and so far it works fine.
The commands are the same as your plugin.

Note : you need Cvar Utilities and the provided signatures (plugin included too).

PHP Code:
#include <amxmodx>
#include <orpheu>
#include <orpheu_memory>
#include <orpheu_stocks>
#include <cvar_util>
#include <fakemeta>

/*
    │ PLUGIN
*/
    
new const PluginName    [] = "Custom Player Air Accelerate";
    new const 
PluginVersion [] = "1.3";
    new const 
PluginAuthor  [] = "Arkshine";

/*
    │ GENERAL
*/
    
const MaxSlots 32;

    
#define FBitSet(%1,%2)   ( %1 &   ( 1 << ( %2 & 31 ) ) )
    #define SetBits(%1,%2)   ( %1 |=  ( 1 << ( %2 & 31 ) ) )
    #define ClearBits(%1,%2) ( %1 &= ~( 1 << ( %2 & 31 ) ) )

    
new MaxClients;

/*
    │ CACHE HANDLING
*/
    
enum Movevars
    
{
        
Float:Gravity,
        
Float:StopSpeed,
        
Float:MaxSpeed,
        
Float:SpectatorMaxSpeed,
        
Float:Accelerate,
        
Float:AirAccelerate,
        
Float:WaterAccelerate,
        
Float:Friction,
        
Float:EdgeFriction,
        
Float:WaterFriction,
        
Float:EntGravity,
        
Float:Bounce,
        
Float:StepSize,
        
Float:MaxVelocity,
        
Float:ZMax,
        
Float:WaveHeigth,
        
bool:Footsteps,
        
Float:RollAngle,
        
Float:RollSpeed,
        
Float:SkyColorRed,
        
Float:SkyColorGreen,
        
Float:SkyColorBlue,
        
Float:SkyVecX,
        
Float:SkyVecY,
        
Float:SkyVecZ,
        
SkyName16 ],
    };

    new 
MoveVarsDataMovevars ];

/*
    │ AIR ACCELERATE HANDLING
*/
    
new OrpheuStruct:pmove;

    new 
OrpheuFunction:HandleFuncMove;
    new 
OrpheuFunction:HandleFuncAirAccelerate;
    new 
OrpheuFunction:HandleFuncAirMove;
    new 
OrpheuFunction:HandleFuncQueryMovevarsChanged;
    new 
OrpheuFunction:HandleFuncSetMoveVars;
    new 
OrpheuFunction:HandleFuncWriteMovevarsToClient;

    new 
bool:ChangeDetected;
    new 
HasCustomAirAccel;

    new 
Float:PlayerCustomAAValueMaxSlots ];


public 
plugin_init()
{
    
register_pluginPluginNamePluginVersionPluginAuthor );

    
handleCommand();
    
handleCache();
    
handleForward();
}

public 
plugin_cfg()
{
    
MaxClients get_maxplayers();
}

public 
client_disconnectclient )
{
    
ClientCommand_RemoveAAclient, .disconnected true );
}


/*
 │  ┌────────────────────────┐
 │  │     INIT FUNCTIONS     │
 │  └────────────────────────┘
 │       → handleCommand()
 │       → handleCache()
 │       → handleForward()
 */

handleCommand()
{
    
register_clcmd"say /setaa50" "ClientCommand_SetAA50"  );
    
register_clcmd"say /setaa100""ClientCommand_SetAA100" );
    
register_clcmd"say /rmaa"    "ClientCommand_RemoveAA" );
}

handleCache()
{
    
// Easily cache the value with Cvar Utilities. ;P
    
CvarCacheget_cvar_pointer"sv_gravity"           ), CvarType_Float MoveVarsDataGravity           ] );
    
CvarCacheget_cvar_pointer"sv_stopspeed"         ), CvarType_Float MoveVarsDataStopSpeed         ] );
    
CvarCacheget_cvar_pointer"sv_maxspeed"          ), CvarType_Float MoveVarsDataMaxSpeed          ] );
    
CvarCacheget_cvar_pointer"sv_spectatormaxspeed" ), CvarType_Float MoveVarsDataSpectatorMaxSpeed ] );
    
CvarCacheget_cvar_pointer"sv_accelerate"        ), CvarType_Float MoveVarsDataAccelerate        ] );
    
CvarCacheget_cvar_pointer"sv_airaccelerate"     ), CvarType_Float MoveVarsDataAirAccelerate     ] );
    
CvarCacheget_cvar_pointer"sv_wateraccelerate"   ), CvarType_Float MoveVarsDataWaterAccelerate   ] );
    
CvarCacheget_cvar_pointer"sv_friction"          ), CvarType_Float MoveVarsDataFriction          ] );
    
CvarCacheget_cvar_pointer"edgefriction"         ), CvarType_Float MoveVarsDataEdgeFriction      ] );
    
CvarCacheget_cvar_pointer"sv_waterfriction"     ), CvarType_Float MoveVarsDataWaterFriction     ] );
    
CvarCacheget_cvar_pointer"sv_bounce"            ), CvarType_Float MoveVarsDataBounce            ] );
    
CvarCacheget_cvar_pointer"sv_stepsize"          ), CvarType_Float MoveVarsDataStepSize          ] );
    
CvarCacheget_cvar_pointer"sv_maxvelocity"       ), CvarType_Float MoveVarsDataMaxVelocity       ] );
    
CvarCacheget_cvar_pointer"sv_zmax"              ), CvarType_Float MoveVarsDataZMax              ] );
    
CvarCacheget_cvar_pointer"sv_wateramp"          ), CvarType_Float MoveVarsDataWaveHeigth        ] );
    
CvarCacheget_cvar_pointer"mp_footsteps"         ), CvarType_Float MoveVarsDataFootsteps         ] );
    
CvarCacheget_cvar_pointer"sv_skycolor_r"        ), CvarType_Float MoveVarsDataSkyColorBlue      ] );
    
CvarCacheget_cvar_pointer"sv_skycolor_g"        ), CvarType_Float MoveVarsDataSkyColorGreen     ] );
    
CvarCacheget_cvar_pointer"sv_skycolor_b"        ), CvarType_Float MoveVarsDataSkyColorRed       ] );
    
CvarCacheget_cvar_pointer"sv_skyvec_x"          ), CvarType_Float MoveVarsDataSkyVecX           ] );
    
CvarCacheget_cvar_pointer"sv_skyvec_y"          ), CvarType_Float MoveVarsDataSkyVecY           ] );
    
CvarCacheget_cvar_pointer"sv_skyvec_z"          ), CvarType_Float MoveVarsDataSkyVecZ           ] );
    
CvarCacheget_cvar_pointer"sv_skyname"           ), CvarType_StringMoveVarsDataSkyName           ], charsmaxMoveVarsDataSkyName ] ) );

    
// No existing server cvars, hardcoded value.
    
MoveVarsDataEntGravity ] = _:1.0;
    
MoveVarsDataRollAngle  ] = _:0.0;
    
MoveVarsDataRollSpeed  ] = _:0.0;
}

handleForward()
{
    
register_forwardFM_ClientConnect"ClientConnect" );

    
// Mod.
    
HandleFuncMove OrpheuGetDLLFunction"pfnPM_Move""PM_Move" );

    if( 
is_linux_server() )
        
HandleFuncAirMove OrpheuGetFunction"PM_AirMove" );
    else
        
HandleFuncAirAccelerate OrpheuGetFunction"PM_AirAccelerate" );

    
// Engine - Main function.
    
HandleFuncQueryMovevarsChanged OrpheuGetFunction"SV_QueryMovevarsChanged" );
    {
        if( 
is_linux_server() )
        {
            
HandleFuncSetMoveVars           OrpheuGetFunction"SV_SetMoveVars" );
            
HandleFuncWriteMovevarsToClient OrpheuGetFunction"SV_WriteMovevarsToClient" );
        }
        else
        {
            
// Trick to avoid to make signatures.
            
new const startAddress OrpheuGetFunctionAddressHandleFuncQueryMovevarsChanged );
            new const 
numCallsToIgnore 1;

            
HandleFuncSetMoveVars           OrpheuCreateFunctionOrpheuGetNextCallAtAddressstartAddress, .number numCallsToIgnore ), "SV_SetMoveVars" );
            
HandleFuncWriteMovevarsToClient OrpheuCreateFunctionOrpheuGetNextCallAtAddressstartAddress, .number numCallsToIgnore ), "SV_WriteMovevarsToClient" );
        }
    }
}


/*
 │  ┌────────────────────┐
 │  │  FORWARD HANDLING  │
 │  └────────────────────┘
 │       → updateForward()
 */

updateForward()
{
    
// Mod.
    
static OrpheuHook:handleHookMove;
    static 
OrpheuHook:handleHookAirAccelerate;
    static 
OrpheuHook:handleHookAirMovePre;
    static 
OrpheuHook:handleHookAirMovePost;

    
// Engine.
    
static OrpheuHook:handleHookQueryMovevarsChanged;
    static 
OrpheuHook:handleHookSetMoveVars;
    static 
OrpheuHook:handleHookWriteMovevarsToClient;

    new 
foundUsers;
    static 
wasFoundUsers;

    
// Should the forwards be toggled ?
    
if( ( foundUsers = !!HasCustomAirAccel ) ^ wasFoundUsers )
    {
        
// There are at least one player and the forwards should be registered.
        
if( foundUsers )
        {
            
// Mod.
            
handleHookMove OrpheuRegisterHookHandleFuncMove"PM_Move" );

            if( 
is_linux_server() )
            {
                
// Damn. The content of PM_AirAccelerate is integrated in PM_AirMove.
                
handleHookAirMovePre  OrpheuRegisterHookHandleFuncAirMove"PM_AirMove_Pre" OrpheuHookPre );
                
handleHookAirMovePost OrpheuRegisterHookHandleFuncAirMove"PM_AirMove_Post"OrpheuHookPost );
            }
            else
            {
                
// I loves windows.
                
handleHookAirAccelerate OrpheuRegisterHookHandleFuncAirAccelerate"PM_AirAccelerate" );
            }

            
// Engine.
            
handleHookQueryMovevarsChanged  OrpheuRegisterHookHandleFuncQueryMovevarsChanged "SV_QueryMovevarsChanged_Post"OrpheuHookPost );
            
handleHookSetMoveVars           OrpheuRegisterHookHandleFuncSetMoveVars          "SV_SetMoveVars" );
            
handleHookWriteMovevarsToClient OrpheuRegisterHookHandleFuncWriteMovevarsToClient"SV_WriteMovevarsToClient" );
        }
        
// No more players are using the command, the forwards should be stopped now.
        
else
        {
            
// Mod.
            
OrpheuUnregisterHookhandleHookMove );

            if( 
is_linux_server() )
            {
                
OrpheuUnregisterHookhandleHookAirMovePre );
                
OrpheuUnregisterHookhandleHookAirMovePost );
            }
            else
            {
                
OrpheuUnregisterHookhandleHookAirAccelerate );
            }

            
// Engine.
            
OrpheuUnregisterHookhandleHookQueryMovevarsChanged );
            
OrpheuUnregisterHookhandleHookSetMoveVars );
            
OrpheuUnregisterHookhandleHookWriteMovevarsToClient );
        }
    }

    
wasFoundUsers foundUsers;
}


/*
 │  ┌────────────────────┐
 │  │  COMMAND HANDLING  │
 │  └────────────────────┘
 │       → ClientCommand_SetAA50()
 │            └ setAA()
 │       → ClientCommand_SetAA100()
 │            └ setAA()
 │       → ClientCommand_RemoveAA()
 */

public ClientCommand_SetAA50( const client )
{
    
setAAclient50.0 );
}

public 
ClientCommand_SetAA100( const client )
{
    
setAAclient100.0 );
}

public 
ClientCommand_RemoveAA( const client, const bool:disconnected )
{
    
// You stop using the custom air acceleration.
    
ClearBitsHasCustomAirAccelclient );

    
// Stops the forwards if no more users.
    
updateForward();

    
// Update the client right away with the original value.
    
if( !disconnected )
    {
        
WriteMovevarsToClientclient );
    }
}

setAA( const player, const Float:aa )
{
    
// Save the player's custom air accelerate value.
    
PlayerCustomAAValueplayer ] = aa;

    
// Allowed to use a custom air acceleration value.
    
SetBitsHasCustomAirAccelplayer );

    
// Register the forwards.
    
updateForward();

    
// Update the client with the new value, otherwise prediction will be off and resulting lag.
    
WriteMovevarsToClientplayer );
}


/*
 │  ┌───────────────────────────┐
 │  │  AIR ACCELERATE HANDLING  │
 │  └───────────────────────────┘
 │       → PM_Move()
 │       → PM_AirMove_Pre()
 │       → PM_AirMove_Post()
 │       → PM_AirAccelerate()
 │       → SV_SetMoveVars()
 │       → SV_WriteMovevarsToClient()
 │       → SV_QueryMovevarsChanged_Post()
 │            └ WriteMovevarsToClient()
 │                 ┌ checkConnectingClient()
 │                 └ sendNewMoveVars()
 */

public PM_MoveOrpheuStruct:ppmove, const server )
{
    
pmove ppmove;
}

public 
PM_AirMove_Pre()
{
    new 
player OrpheuGetStructMemberpmove"player_index" ) + 1;

    if( 
FBitSetHasCustomAirAccelplayer ) && is_user_aliveplayer ) )
    {
        
// Linux-specific.
        // We modify on-the-fly pmove->movevars->airaccelerate to our custom value.
        
OrpheuSetStructMemberOrpheuStruct:OrpheuGetStructMemberpmove"movevars" ), "airaccelerate"PlayerCustomAAValueplayer ] );
    }
}

public 
PM_AirMove_Post()
{
    new 
player OrpheuGetStructMemberpmove"player_index" ) + 1;

    if( 
FBitSetHasCustomAirAccelplayer ) && is_user_aliveplayer ) )
    {
        
// Linux-specific.
        // Then we set back the current sv_airaccelerate value to avoid to trigger change.
        
OrpheuSetStructMemberOrpheuStruct:OrpheuGetStructMemberpmove"movevars" ), "airaccelerate"MoveVarsDataAirAccelerate ] );
    }
}

public 
PM_AirAccelerate( const Float:wishdir[3], const Float:wishspeed, const Float:accel )
{
    new 
player OrpheuGetStructMemberpmove"player_index" ) + 1;

    if( 
FBitSetHasCustomAirAccelplayer ) && is_user_aliveplayer ) )
    {
        
// pmove->movevars->airaccelerate is passed as 'accel' param.
        // More simple to modify directly the function where the movevars is used.
        // Also, it would be called only when you are in the air.
        
OrpheuSetParam3PlayerCustomAAValueplayer ] );
    }
}

// Order of calls.
// SV_QueryMovevarsChanged -> SV_SetMoveVars -> SV_WriteMovevarsToClient

public SV_SetMoveVars()
{
    
// Called from SV_QueryMovevarsChanged
    // This function overwrites the server movevars values with the value of the cvars.
    // We use just this function to detect a change since the main function does not return a value.
    
ChangeDetected true;
}

public 
OrpheuHookReturn:SV_WriteMovevarsToClient()
{
    
// This function sends the message SVC_NEWMOVEVARS (internally) using the movevars values.
    // When a change is detected, this function is called for all players to update them.
    // Since the param passed is not the player's index and to have a full control,
    // We simply blocks the call all the time and sending manually a message when needed after.
    
return OrpheuSupercede;
}

public 
SV_QueryMovevarsChanged_Post()
{
    
// This function is called per frame to detect if there is at least one change between
    // the movevars values and the corresponding server cvars values.
    // When a change is detected, it calls SV_SetMoveVars to update all the server movevars,
    // then call SV_WriteMovevarsToClient to update each clients.
    // Here, we hook the function as post because since we block the update on the client, we
    // need to update manually the client. It allows us to put conditions and sending per player
    // and will handle the case where you use sv_ cvar in the console.

    
if( ChangeDetected )
    {
        
ChangeDetected false;
        
WriteMovevarsToClient( .client );
    }
}

public 
WriteMovevarsToClient( const client )
{
    
// Time to update the client.
    // Such message is originally sent one time  at player's connection,

    
new playerToUpdate client client checkConnectingClient();

    if( 
playerToUpdate )
    {
        
sendNewMoveVarsplayerToUpdate );
    }
    else
    {
        for( new 
1<= MaxClientsi++ )
        {
            if( 
is_user_connected) && !is_user_bot) )
            {
                
sendNewMoveVars);
            }
        }
    }
}

sendNewMoveVars( const client )
{
    
message_beginMSG_ONESVC_NEWMOVEVARS, .player client );
    {
        
write_long_:MoveVarsDataGravity         ] );
        
write_long_:MoveVarsDataStopSpeed       ] );
        
write_long_:MoveVarsDataMaxSpeed        ] );
        
write_long_:MoveVarsDataSpectatorMaxSpeed ] );
        
write_long_:MoveVarsDataAccelerate      ] );
        
write_long_:( FBitSetHasCustomAirAccelclient ) ? PlayerCustomAAValueclient ] : MoveVarsDataAirAccelerate ] ) );
        
write_long_:MoveVarsDataWaterAccelerate ] );
        
write_long_:MoveVarsDataFriction        ] );
        
write_long_:MoveVarsDataEdgeFriction    ] );
        
write_long_:MoveVarsDataWaterFriction   ] );
        
write_long_:MoveVarsDataEntGravity      ] );
        
write_long_:MoveVarsDataBounce          ] );
        
write_long_:MoveVarsDataStepSize        ] );
        
write_long_:MoveVarsDataMaxVelocity     ] );
        
write_long_:MoveVarsDataZMax            ] );
        
write_long_:MoveVarsDataWaveHeigth      ] );
        
write_byte( !!MoveVarsDataFootsteps       ] );
        
write_long_:MoveVarsDataRollAngle       ] );
        
write_long_:MoveVarsDataRollSpeed       ] );
        
write_long_:MoveVarsDataSkyColorBlue    ] );
        
write_long_:MoveVarsDataSkyColorGreen   ] );
        
write_long_:MoveVarsDataSkyColorRed     ] );
        
write_long_:MoveVarsDataSkyVecX         ] );
        
write_long_:MoveVarsDataSkyVecY         ] );
        
write_long_:MoveVarsDataSkyVecZ         ] );
        
write_stringMoveVarsDataSkyName         ] );
    }
    
message_end();
}

checkConnectingClient()
{
    for( new 
1<= MaxClientsi++ )
    {
        if( 
is_user_connecting) )
        {
            return 
i;
        }
    }

    return 
0;
}


/*
 │  ┌─────────────────┐
 │  │  USEFUL STOCKS  │
 │  └─────────────────┘
 │       → getEngineBuild()
 */

stock getEngineBuild()
{
    new 
version32 ];
    
get_pcvar_stringget_cvar_pointer"sv_version" ), versioncharsmaxversion ) );

    new 
length strlenversion );
    while( 
version[ --length ] != ',' ) {}

    return 
str_to_numversionlength ] );



Unzip and extract in your amxmodx/ directory.

Tell me If it works as expected.
Attached Files
File Type: zip [signatures]custom_air_accelerate.zip (6.5 KB, 237 views)
__________________

Last edited by Arkshine; 11-19-2011 at 04:57. Reason: Updated to 1.3
Arkshine is offline
 



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 15:27.


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