AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Why didn't work ? (https://forums.alliedmods.net/showthread.php?t=188108)

Kiske 06-22-2012 10:37

Why didn't work ?
 
Why didn't work ?

PHP Code:

register_forward(FM_CmdStart"fw_CmdStart");

public 
fw_CmdStart(idhandle)
{
    if(!
is_user_alive(id))
        return 
FMRES_IGNORED;
    
    if(!
g_charm[id])
        return 
FMRES_IGNORED;
    
    static 
iButton;
    
iButton get_uc(handleUC_Buttons);
    
    if(
g_charm[id] && g_charm_nil[id])
    {
        if(
iButton IN_ATTACK)         iButton &= ~IN_ATTACK// this work
        
else if(iButton IN_ATTACK2)   iButton &= ~IN_ATTACK2// this work
        
else if(iButton IN_FORWARD)   iButton &= ~IN_FORWARD;
        else if(
iButton IN_BACK)      iButton &= ~IN_BACK;
        else if(
iButton IN_LEFT)      iButton &= ~IN_LEFT;
        else if(
iButton IN_RIGHT)     iButton &= ~IN_RIGHT;
        else if(
iButton IN_MOVELEFT)  iButton &= ~IN_MOVELEFT;
        else if(
iButton IN_MOVERIGHTiButton &= ~IN_MOVERIGHT;
        else if(
iButton IN_DUCK)      iButton &= ~IN_DUCK;
        else if(
iButton IN_JUMP)      iButton &= ~IN_JUMP;
        else if(
iButton IN_RUN)       iButton &= ~IN_RUN;
        
        
set_uc(handleUC_ButtonsiButton);
        
        return 
FMRES_SUPERCEDE;
    }
    
    return 
FMRES_IGNORED;



Napoleon_be 06-22-2012 12:20

Re: Why didn't work ?
 
What's the point of using else if statements all the time? Try using if statements only.

Exolent[jNr] 06-22-2012 13:29

Re: Why didn't work ?
 
PHP Code:

        if(iButton IN_ATTACK)         iButton &= ~IN_ATTACK// this work
        
else if(iButton IN_ATTACK2)   iButton &= ~IN_ATTACK2// this work
        
else if(iButton IN_FORWARD)   iButton &= ~IN_FORWARD;
        else if(
iButton IN_BACK)      iButton &= ~IN_BACK;
        else if(
iButton IN_LEFT)      iButton &= ~IN_LEFT;
        else if(
iButton IN_RIGHT)     iButton &= ~IN_RIGHT;
        else if(
iButton IN_MOVELEFT)  iButton &= ~IN_MOVELEFT;
        else if(
iButton IN_MOVERIGHTiButton &= ~IN_MOVERIGHT;
        else if(
iButton IN_DUCK)      iButton &= ~IN_DUCK;
        else if(
iButton IN_JUMP)      iButton &= ~IN_JUMP;
        else if(
iButton IN_RUN)       iButton &= ~IN_RUN

:arrow:
PHP Code:

        static const BUTTONS_REMOVE IN_ATTACK|IN_ATTACK2|IN_FORWARD|IN_BACK|IN_LEFT|IN_RIGHT|IN_MOVELEFT|IN_MOVERIGHT|IN_DUCK|IN_JUMP|IN_RUN;
        
        
iButton &= ~BUTTONS_REMOVE


Kiske 06-22-2012 14:56

Re: Why didn't work ?
 
Quote:

Originally Posted by Exolent[jNr] (Post 1733940)
PHP Code:

        if(iButton IN_ATTACK)         iButton &= ~IN_ATTACK// this work
        
else if(iButton IN_ATTACK2)   iButton &= ~IN_ATTACK2// this work
        
else if(iButton IN_FORWARD)   iButton &= ~IN_FORWARD;
        else if(
iButton IN_BACK)      iButton &= ~IN_BACK;
        else if(
iButton IN_LEFT)      iButton &= ~IN_LEFT;
        else if(
iButton IN_RIGHT)     iButton &= ~IN_RIGHT;
        else if(
iButton IN_MOVELEFT)  iButton &= ~IN_MOVELEFT;
        else if(
iButton IN_MOVERIGHTiButton &= ~IN_MOVERIGHT;
        else if(
iButton IN_DUCK)      iButton &= ~IN_DUCK;
        else if(
iButton IN_JUMP)      iButton &= ~IN_JUMP;
        else if(
iButton IN_RUN)       iButton &= ~IN_RUN

:arrow:
PHP Code:

        static const BUTTONS_REMOVE IN_ATTACK|IN_ATTACK2|IN_FORWARD|IN_BACK|IN_LEFT|IN_RIGHT|IN_MOVELEFT|IN_MOVERIGHT|IN_DUCK|IN_JUMP|IN_RUN;
        
        
iButton &= ~BUTTONS_REMOVE


Thanks for the optimization, but it didn't work. It only block IN_ATTACK and IN ATTACK2, on the others don't.

Aooka 06-22-2012 15:01

Re: Why didn't work ?
 
Exolent can you explain just this :
Code:
iButton &= ~BUTTONS_REMOVE; //The &= ?

Exolent[jNr] 06-22-2012 15:06

Re: Why didn't work ?
 
It's just a shortcut for the & operator, like += or *=.

Code:

a = b + c

If a is b, then you can see that
a = a + c

If that is the equation, then you can shortcut
a += c

So that line is really doing
Code:
iButtons = iButtons & ~BUTTONS_REMOVE;

& is a bitwise operator.
For more information on those, check out the Code Snippets/Tutorials section.

Aooka 06-22-2012 15:11

Re: Why didn't work ?
 
Oh okay. Thanks i go check the tutorials section :d

ConnorMcLeod 06-22-2012 18:58

Re: Why didn't work ?
 
A copy of user cmd is made before CmdStart is sent.
That copy is used to fill pmove->cmd, and that one is used to send PM_Move that is the base of game physics.

So, change cmd in CmdStart change the real cmd but is not taken in account for movements.

Kiske 06-22-2012 23:38

Re: Why didn't work ?
 
Only block IN_DUCK, but IN_JUMP didn't work.
PHP Code:

#include <orpheu>
#include <orpheu_stocks>

new OrpheuStruct:g_ppmove;

OrpheuRegisterHook(OrpheuGetDLLFunction("pfnPM_Move""PM_Move"), "PM_Move");
OrpheuRegisterHook(OrpheuGetFunction("PM_Jump"), "PM_Jump");
OrpheuRegisterHook(OrpheuGetFunction("PM_Duck"), "PM_Duck");

public 
PM_Move(OrpheuStruct:ppmoveserver)
    
g_ppmove ppmove;

public 
PM_Duck()
{
    new 
id OrpheuGetStructMember(g_ppmove"player_index") + 1;
    
    if(
is_user_alive(id) && g_charm[id] && g_charm_nil[id])
    {
        new 
OrpheuStruct:cmd OrpheuStruct:OrpheuGetStructMember(g_ppmove"cmd");
        
OrpheuSetStructMember(cmd"buttons"OrpheuGetStructMember(cmd"buttons" ) & ~IN_DUCK);
    }
}

public 
PM_Jump()
{
    new 
id OrpheuGetStructMember(g_ppmove"player_index") + 1;
    
    if(
is_user_alive(id) && g_charm[id] && g_charm_nil[id])
    {
        new 
OrpheuStruct:cmd OrpheuStruct:OrpheuGetStructMember(g_ppmove"cmd");
        
OrpheuSetStructMember(cmd"buttons"OrpheuGetStructMember(cmd"buttons" ) & ~IN_JUMP);
    }


How do i block the movements ?
+forward
+back
+moveleft
+moveright
+left
+right


Thanks in advanced!

Exolent[jNr] 06-23-2012 02:37

Re: Why didn't work ?
 
The CmdStart version should work fine, but this is the Orpheu for movement.

Code:
new OrpheuStruct:g_ppmove; public plugin_init( ) {     OrpheuRegisterHook( OrpheuGetDLLFunction( "pfnPM_Move", "PM_Move" ), "PM_Move" );     OrpheuRegisterHook( OrpheuGetFunction( "PM_PlayerMove" ), "PM_PlayerMove" );     OrpheuRegisterHook( OrpheuGetFunction( "PM_Duck" ), "PM_Duck" );     OrpheuRegisterHook( OrpheuGetFunction( "PM_Jump" ), "PM_Jump" ); } public OrpheuHookReturn:PM_Move( OrpheuStruct:ppmove, server ) {     g_ppmove = ppmove;         return OrpheuIgnored; } public OrpheuHookReturn:PM_PlayerMove( ) {     new iPlayer = OrpheuGetStructMember( g_ppmove, "player_index" ) + 1;         if( is_user_alive( iPlayer ) )     {         OrpheuSetStructMember( g_ppmove, "maxspeed", 0.0 );     }         return OrpheuIgnored; } public OrpheuHookReturn:PM_Jump( ) {     new iPlayer = OrpheuGetStructMember( g_ppmove, "player_index" ) + 1;         if( is_user_alive( iPlayer ) )     {         OrpheuSetStructMember( g_ppmove, "oldbuttons", OrpheuGetStructMember( g_ppmove, "oldbuttons" ) | IN_JUMP );     }         return OrpheuIgnored; } public OrpheuHookReturn:PM_Duck( ) {     new iPlayer = OrpheuGetStructMember( g_ppmove, "player_index" ) + 1;         if( is_user_alive( iPlayer ) )     {         new OrpheuStruct:cmd = OrpheuStruct:OrpheuGetStructMember( g_ppmove, "cmd" );         OrpheuSetStructMember( cmd, "buttons", OrpheuGetStructMember( cmd, "buttons" ) & ~IN_DUCK );     }         return OrpheuIgnored; }


All times are GMT -4. The time now is 06:19.

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