Raised This Month: $ Target: $400
 0% 

Why didn't work ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kiske
Veteran Member
Join Date: May 2009
Old 06-22-2012 , 10:37   Why didn't work ?
Reply With Quote #1

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;


Last edited by Kiske; 06-22-2012 at 10:38.
Kiske is offline
Send a message via Skype™ to Kiske
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 06-22-2012 , 12:20   Re: Why didn't work ?
Reply With Quote #2

What's the point of using else if statements all the time? Try using if statements only.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-22-2012 , 13:29   Re: Why didn't work ?
Reply With Quote #3

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

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
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Kiske
Veteran Member
Join Date: May 2009
Old 06-22-2012 , 14:56   Re: Why didn't work ?
Reply With Quote #4

Quote:
Originally Posted by Exolent[jNr] View Post
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

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.

Last edited by Kiske; 06-22-2012 at 14:58.
Kiske is offline
Send a message via Skype™ to Kiske
Aooka
Veteran Member
Join Date: Aug 2011
Location: Villeurbanne
Old 06-22-2012 , 15:01   Re: Why didn't work ?
Reply With Quote #5

Exolent can you explain just this :
Code:
iButton &= ~BUTTONS_REMOVE; //The &= ?
__________________
Pawn ? Useless

Last edited by Aooka; 06-22-2012 at 15:01.
Aooka is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-22-2012 , 15:06   Re: Why didn't work ?
Reply With Quote #6

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.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Aooka
Veteran Member
Join Date: Aug 2011
Location: Villeurbanne
Old 06-22-2012 , 15:11   Re: Why didn't work ?
Reply With Quote #7

Oh okay. Thanks i go check the tutorials section :d
__________________
Pawn ? Useless
Aooka is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-22-2012 , 18:58   Re: Why didn't work ?
Reply With Quote #8

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.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Kiske
Veteran Member
Join Date: May 2009
Old 06-22-2012 , 23:38   Re: Why didn't work ?
Reply With Quote #9

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!

Last edited by Kiske; 06-22-2012 at 23:38.
Kiske is offline
Send a message via Skype™ to Kiske
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-23-2012 , 02:37   Re: Why didn't work ?
Reply With Quote #10

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; }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 06-23-2012 at 02:38.
Exolent[jNr] 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 06:19.


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