AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Speed in duck (https://forums.alliedmods.net/showthread.php?t=277379)

wicho 01-08-2016 04:48

Speed in duck
 
Hi everybody, well I want to give more speed when the player is in duck, someone could give me an example of how I can do? ... thx in advance

safetymoose 01-08-2016 13:55

Re: Speed in duck
 
I'd like to know too. How can we change player's speed to a certain value while he's moving in duck mode, without affecting the normal speed values of walking, running, etc.. ?

Neeeeeeeeeel.- 01-08-2016 14:28

Re: Speed in duck
 
1 Attachment(s)
Not tested, but should work

safetymoose 01-08-2016 19:25

Re: Speed in duck
 
not quite, it seems like when you duck your maxspeed gets changed to the selected value, but your actual speed is lowered, probably the same thing that lowers your speed when you normally duck. I tested with the value 800.0, it sets maxspeed to 800, but when i try to duck the actual speed is lowered down to 160/170.

The way you made it changes the global value of the players speed(maxspeed, which is used for everything, running, walking, ducking). My knowledge about game values is very thin, but I think the walking and ducking values are values taken from the maxspeed value which are divided by a certain factor. I'm guessing that the +duck and +speed(command for walking) act as a dividing factor to the actual speed...

What i'm saying is it does change the speed when ducking, but not up to the desired value.

Any ideas?

siriusmd99 01-09-2016 08:22

Re: Speed in duck
 
register_forward(FM_CmdStart,"fwd_CmdStart")




public fwd_CmdStart(id, uc_handle, seed) {

if(!is_user_alive(id))
return FMRES_IGNORED;

new buttons = get_uc(uc_handle,UC_Buttons)

new oldbuttons = get_user_oldbutton(id);

if((buttons & IN_DUCK) && !(oldbuttons & IN_DUCK))
set_user_maxspeed(id,your_value)
}

safetymoose 01-09-2016 10:52

Re: Speed in duck
 
Quote:

Originally Posted by siriusmd99 (Post 2381546)
register_forward(FM_CmdStart,"fwd_CmdStart")




public fwd_CmdStart(id, uc_handle, seed) {

if(!is_user_alive(id))
return FMRES_IGNORED;

new buttons = get_uc(uc_handle,UC_Buttons)

new oldbuttons = get_user_oldbutton(id);

if((buttons & IN_DUCK) && !(oldbuttons & IN_DUCK))
set_user_maxspeed(id,your_value)
}

Same problem, you cant get the desired speed value because when you are in duck it lowers the speed.

set_user_maxspeed is not a good way to do this. Any other ideas?

siriusmd99 01-09-2016 11:22

Re: Speed in duck
 
Quote:

Originally Posted by safetymoose (Post 2381596)
Same problem, you cant get the desired speed value because when you are in duck it lowers the speed.

set_user_maxspeed is not a good way to do this. Any other ideas?

then try:

PHP Code:


public fwd_CmdStart(iduc_handleseed) {

if(!
is_user_alive(id))
return 
FMRES_IGNORED;

new 
buttons get_uc(uc_handle,UC_Buttons)

if(
buttons IN_DUCK)
set_user_maxspeed(id,your_value)



Bugsy 01-09-2016 12:55

Re: Speed in duck
 
1 Attachment(s)
Give this a try. I'm not sure if it is working perfectly, but it appears to from a client perspective. Hopefully someone with more orpheu experience will chime in.

Place the files in the attached archive in: amxmodx\configs\orpheu\functions
PHP Code:

#include <amxmodx>
#include <orpheu>
#include <orpheu_stocks>
#include <engine>

new const Version[] = "0.1";

new 
OrpheuStruct:g_ppmove

public plugin_init()
{       
    
register_plugin"Fast Duck" Version "bugsy" );
    
    
OrpheuRegisterHookOrpheuGetDLLFunction"pfnPM_Move" "PM_Move" ) , "PM_Move" );
    
OrpheuRegisterHookOrpheuGetFunction"PM_Duck" ) , "PM_Duck" );
}

public 
OrpheuHookReturn:PM_MoveOrpheuStruct:ppmove server )
{    
    
g_ppmove ppmove;
}

public 
OrpheuHookReturn:PM_Duck()
{
    
//If you need player id for anything
    //new id = OrpheuGetStructMember( g_ppmove , "player_index" ) + 1;
    
    
if ( OrpheuGetStructMemberg_ppmove "flags" ) & FL_DUCKING )
    {
        new 
iCmd OrpheuGetStructMemberg_ppmove "cmd" );
        
        
OrpheuSetStructMemberOrpheuStruct:iCmd "forwardmove" OrpheuGetStructMemberOrpheuStruct:iCmd "forwardmove" ) * 3.0 );
        
OrpheuSetStructMemberOrpheuStruct:iCmd "sidemove" OrpheuGetStructMemberOrpheuStruct:iCmd "sidemove" ) * 3.0 );
        
OrpheuSetStructMemberOrpheuStruct:iCmd "upmove" OrpheuGetStructMemberOrpheuStruct:iCmd "upmove" ) * 3.0 );
    }
    
    return 
OrpheuIgnored;



safetymoose 01-09-2016 16:28

Re: Speed in duck
 
Works like a charm, only we should note that the speed is still limited by the player's max speed.

It's a good idea to change the player's max speed when he goes into duck mode and then restore it back to normal after he stops ducking.

I like siriusmd99's idea about using fwd_CmdStart, so i combined the codes and ended up with something like this.

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <orpheu>
#include <orpheu_stocks>
#include <engine>

new const Version[] = "0.1";

new 
OrpheuStruct:g_ppmove

public plugin_init()
{       
    
register_plugin"Fast Duck" Version "bugsy" );
    
    
OrpheuRegisterHookOrpheuGetDLLFunction"pfnPM_Move" "PM_Move" ) , "PM_Move" );
    
OrpheuRegisterHookOrpheuGetFunction"PM_Duck" ) , "PM_Duck" );
    
    
register_forwardFM_CmdStart "fwd_CmdStart" );
}

public 
OrpheuHookReturn:PM_MoveOrpheuStruct:ppmove server )
{    
    
g_ppmove ppmove;
}

public 
fwd_CmdStartid uc_handle seed 
{
    if( !
is_user_alive(id) )
        return 
FMRES_IGNORED;
    
    new 
buttons get_ucuc_handle UC_Buttons )
    
    if( ( 
buttons IN_DUCK ) )
        
set_pevid pev_maxspeed 800.0 )
    else
        
set_pevid pev_maxspeed 250.0 )
    
    return 
FMRES_IGNORED;
}  

public 
OrpheuHookReturn:PM_Duck()
{
    
//If you need player id for anything
    //new id = OrpheuGetStructMember( g_ppmove , "player_index" ) + 1;
    
    
if ( OrpheuGetStructMemberg_ppmove "flags" ) & FL_DUCKING )
    {
    new 
iCmd OrpheuGetStructMemberg_ppmove "cmd" );
    
    
OrpheuSetStructMemberOrpheuStruct:iCmd "forwardmove" OrpheuGetStructMemberOrpheuStruct:iCmd "forwardmove" ) * 3.0 );
    
OrpheuSetStructMemberOrpheuStruct:iCmd "sidemove" OrpheuGetStructMemberOrpheuStruct:iCmd "sidemove" ) * 3.0 );
    
OrpheuSetStructMemberOrpheuStruct:iCmd "upmove" OrpheuGetStructMemberOrpheuStruct:iCmd "upmove" ) * 3.0 );
    }
    
    return 
OrpheuIgnored;


Thank you guys, this is just what i needed, and i'm sure this is what wicho was looking for too :)

Neeeeeeeeeel.- 01-11-2016 06:50

Re: Speed in duck
 
You are constantly setting the maxspeed value, it is not the best idea...
PHP Code:

if( ( buttons IN_DUCK ) )
    
set_pevid pev_maxspeed 800.0 )
else
    
set_pevid pev_maxspeed 250.0 



All times are GMT -4. The time now is 09:30.

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