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

[orpheu] Set airaccelerate


Post New Thread Reply   
 
Thread Tools Display Modes
kostov
Member
Join Date: Jan 2010
Location: Bulgaria, Sofia
Old 09-13-2011 , 15:42   Re: [orpheu] Set airaccelerate
Reply With Quote #21

Quote:
Originally Posted by Arkshine View Post
Not sure if you have understood me..
I understand, but the idea was to feature every one to set airaccelerate self and not be one for all
kostov is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-13-2011 , 16:13   Re: [orpheu] Set airaccelerate
Reply With Quote #22

You can send a message per player.

EDIT: After some tests, I guess you would still need to use PM_Move and blocking the function which send the message. Will make a fix later.

EDIT2 : Or actually hooking simply PM_AirAccelerate(). Will do the code tomorrow.
__________________

Last edited by Arkshine; 09-13-2011 at 20:05.
Arkshine is offline
kostov
Member
Join Date: Jan 2010
Location: Bulgaria, Sofia
Old 09-14-2011 , 11:56   Re: [orpheu] Set airaccelerate
Reply With Quote #23

Quote:
Originally Posted by Arkshine View Post
You can send a message per player.

EDIT: After some tests, I guess you would still need to use PM_Move and blocking the function which send the message. Will make a fix later.

EDIT2 : Or actually hooking simply PM_AirAccelerate(). Will do the code tomorrow.
Thanks, I wait for answer
kostov is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-14-2011 , 19:27   Re: [orpheu] Set airaccelerate
Reply With Quote #24

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, 234 views)
__________________

Last edited by Arkshine; 11-19-2011 at 04:57. Reason: Updated to 1.3
Arkshine is offline
Pastout
Senior Member
Join Date: Dec 2010
Location: 1337 Street LeetTown
Old 09-14-2011 , 19:59   Re: [orpheu] Set airaccelerate
Reply With Quote #25

Wow. nice job Arkshine
Pastout is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 09-14-2011 , 20:01   Re: [orpheu] Set airaccelerate
Reply With Quote #26

I'm jealous of how nice and clean your code is
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Pastout
Senior Member
Join Date: Dec 2010
Location: 1337 Street LeetTown
Old 09-14-2011 , 20:30   Re: [orpheu] Set airaccelerate
Reply With Quote #27

Arkshine - When i run this plugin i seem to get this error

Parsing file "SV_QueryMovevarsChanged" started
Searching for signature "[0x55][0x8b][*][0x51][0xd9](...)" ... NOT FOUND
Parsing file "SV_QueryMovevarsChanged" ended
Parsing file "SV_SetMoveVars" started
Function is updated
Parsing file "SV_SetMoveVars" ended
Parsing file "SV_WriteMovevarsToClient" started
Argument type "int" validated
Searching for signature "[0xc3][0x90][*][*][*](...)" ... NOT FOUND
Parsing file "SV_WriteMovevarsToCli

Its not a big deal to me i just really wanted to test this...
Pastout is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-14-2011 , 20:41   Re: [orpheu] Set airaccelerate
Reply With Quote #28

I've tested the signature on a hlds server with the latest stable version (4553) and the latest hlbeta (5408) and it works fine. I don't have other binaries than that, so I can't help, sorry.
__________________

Last edited by Arkshine; 09-14-2011 at 20:46.
Arkshine is offline
Pastout
Senior Member
Join Date: Dec 2010
Location: 1337 Street LeetTown
Old 09-14-2011 , 20:45   Re: [orpheu] Set airaccelerate
Reply With Quote #29

Umm just wondering where can i get the version 4553 ? and does it matter if I am using a listen server to test this on?
Pastout is offline
Old 09-14-2011, 20:49
Arkshine
This message has been deleted by Arkshine. Reason: nvm
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-14-2011 , 20:53   Re: [orpheu] Set airaccelerate
Reply With Quote #30

Listen server... Not sure if it will work. (Joaquim says me Orpheu doesn't detect the library or something, will test tomorrow though)

Can't you test on a dedicated server ? Either using hldsupdateool or dedicated server through steam.
__________________

Last edited by Arkshine; 09-14-2011 at 20:58.
Arkshine 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 20:27.


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