Raised This Month: $ Target: $400
 0% 

Activating powers when you press the reload key


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GXLZPGX
Veteran Member
Join Date: Sep 2009
Old 07-10-2010 , 18:02   Activating powers when you press the reload key
Reply With Quote #1

I have no idea why this wont work:

PHP Code:
public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_forward(FM_PlayerPreThink"Fw_PlayerPreThink")
}

public 
Fw_PlayerPreThinkid )
{
    if( 
pevidpev_button ) & IN_RELOAD )
    {
        if( 
IsHomer[id] == true )
        {
            
activateGravityid )
        }
        if( 
IsBart[id] == true )
        {
            
activateSpeedid )
        }
    }
}

public 
activateGravityid )
{
    if( 
is_user_aliveid ) && IsHomer[id] == true && UsedGravity[id] == false )
    {
        
UsedGravity[id] = true;
        
set_user_gravityid0.3 )
        
set_user_renderingidkRenderFxGlowShell050125kRenderNormal255 )
        
set_task15.0"removeGravity" )
        
client_print_coloridBlue"^4[^3FreezeTag^4] ^3Your gravity has been activated!" )
    } else {
        return 
PLUGIN_HANDLED;
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
removeGravityid )
{
    
set_user_gravityid1.0 )
    
set_user_renderingidkRenderFxNone000kRenderNormal255 )
    
client_print_coloridBlue"^4[^3FreezeTag^4] ^3Your gravity has expired!" )
}

public 
activateSpeedid )
{
    if( 
is_user_aliveid ) && IsBart[id] == true && UsedAccel[id] == false )
    {
        
UsedAccel[id] = true;
        
set_user_maxspeedid400.0 )
        
set_user_renderingidkRenderFxGlowShell050125kRenderNormal255 )
        
set_task15.0"removeSpeed" )
    } else {
        return 
PLUGIN_HANDLED;
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
removeSpeedid )
{
    
set_user_maxspeedid250.0 )
    
set_user_renderingidkRenderFxNone000kRenderNormal255 )
    
client_print_coloridBlue"^4[^3FreezeTag^4] ^3Your speed has expired!" )

__________________
Currently accepting payment US DOLLARS ONLY for custom plugins, contact me through PM.
GXLZPGX is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-10-2010 , 22:18   Re: Activating powers when you press the reload key
Reply With Quote #2

Tested using both Bart and Homer. Make sure you remove my client_connect() code that I used for testing.

PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <fun>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

const TASK_SPEED 515;
const 
TASK_GRAVITY 516;

new 
bool:IsHomer33 ];
new 
bool:IsBart33 ];
new 
bool:UsedGravity33 ];
new 
bool:UsedAccel33 ];

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_forwardFM_CmdStart "fw_FMCmdStart" )
}

public 
client_connectid )
{
    
IsBartid ] = true;
    
//IsHomer[ id ] = true;
}
    
public 
fw_FMCmdStartid uc_handle seed 
{
    if ( 
get_ucuc_handle UC_Buttons ) & IN_RELOAD )
    {
        if( 
IsHomer[id] && !task_existsTASK_GRAVITY id ) )
        {
            
activateGravityid )
        }
        if( 
IsBart[id] && !task_existsTASK_SPEED id ) )
        {
            
activateSpeedid )
        }
    }
}

public 
activateGravityid )
{
    if( 
is_user_aliveid ) && !UsedGravity[id] )
    {
        
UsedGravity[id] = true;
        
set_user_gravityid0.3 )
        
set_user_renderingidkRenderFxGlowShell050125kRenderNormal255 )
        
set_task15.0"removeGravity" TASK_GRAVITY id )
        
client_printidprint_chat "^4[^3FreezeTag^4] ^3Your gravity has been activated!" )
    } 
    
    return 
PLUGIN_CONTINUE;
}

public 
removeGravityid )
{
    
id -= TASK_GRAVITY;
    
    
set_user_gravityid1.0 )
    
set_user_renderingidkRenderFxNone000kRenderNormal255 )
    
client_printidprint_chat ,  "^4[^3FreezeTag^4] ^3Your gravity has expired!" )
}

public 
activateSpeedid )
{
    if( 
is_user_aliveid ) && !UsedAccel[id] )
    {
        
UsedAccel[id] = true;
        
set_user_maxspeedid400.0 )
        
set_user_renderingidkRenderFxGlowShell050125kRenderNormal255 )
        
set_task15.0"removeSpeed" TASK_SPEED id )
        
client_printidprint_chat "^4[^3FreezeTag^4] ^3Your speed has been activated!" )
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
removeSpeedid )
{
    
id -= TASK_SPEED;
    
    
set_user_maxspeedid250.0 )
    
set_user_renderingidkRenderFxNone000kRenderNormal255 )
    
client_printidprint_chat "^4[^3FreezeTag^4] ^3Your speed has expired!" )

__________________

Last edited by Bugsy; 07-10-2010 at 22:57.
Bugsy is offline
PattyBiena
BANNED
Join Date: Jul 2010
Location: Argentina
Old 07-11-2010 , 04:51   Re: Activating powers when you press the reload key
Reply With Quote #3

PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <fun>

new const PLUGIN_INFO[][] = { "New Plugin""1.0""Author" }
new 
g_class[33], Hability[33][2]

// Hability [0] is speed, [1] is gravity.

const TASK_SPEED 515;
const 
TASK_GRAVITY 516;

enum
{
    
IS_BART 0,
    
IS_HOMER
}

public 
plugin_init()
{
    
register_plugin(PLUGIN_INFO[0], PLUGIN_INFO[1], PLUGIN_INFO[2])
    
register_forwardFM_CmdStart "fw_FMCmdStart" )
}

public 
client_disconnect(id)
{
    
Hability[id][0] = false
    Hability
[id][1] = false
}

public 
fw_FMCmdStartid uc_handle seed 
{
    static class
    class = 
g_class[id]
    
    if ( 
get_ucuc_handle UC_Buttons ) & IN_RELOAD)
    {
        switch(class)
        {
            case 
IS_HOMER:if (!task_existsTASK_GRAVITY id)) activateGravity(id)
            case 
IS_BART: if (!task_existsTASK_SPEED   id)) activateSpeed(id)
        }
    }
}

activateGravityid )
{
    if( 
is_user_aliveid ) && !Hability[id][1] )
    {
        
Hability[id][1] = true
        set_user_gravity
id0.3 )
        
set_user_renderingidkRenderFxGlowShell050125kRenderNormal255 )
        
set_task15.0"removeGravity" id TASK_GRAVITY)
        
client_printidprint_chat "^4[^3FreezeTag^4] ^3Your gravity has been activated!" )
    } 
    
    return 
PLUGIN_CONTINUE;
}

public 
removeGravityid )
{
    
id -= TASK_GRAVITY;
    
    if (
is_user_alive(id))
    {
        
set_user_gravityid1.0 )
        
set_user_renderingidkRenderFxNone000kRenderNormal255 )
        
client_printidprint_chat ,  "^4[^3FreezeTag^4] ^3Your gravity has expired!" )
        
Hability[id][1] = false
    
}
}

activateSpeedid )
{
    if( 
is_user_aliveid ) && !Hability[id][0] )
    {
        
Hability[id][0] = true
        set_user_maxspeed
id400.0 )
        
set_user_renderingidkRenderFxGlowShell050125kRenderNormal255 )
        
set_task15.0"removeSpeed" id TASK_SPEED)
        
client_printidprint_chat "^4[^3FreezeTag^4] ^3Your speed has been activated!" )
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
removeSpeedid )
{
    
id -= TASK_SPEED;
    
    if (
is_user_alive(id))
    {
        
set_user_maxspeedid250.0 )
        
set_user_renderingidkRenderFxNone000kRenderNormal255 )
        
client_printidprint_chat "^4[^3FreezeTag^4] ^3Your speed has expired!" )
    }

Optimized(?) Xd
PattyBiena is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-11-2010 , 08:45   Re: Activating powers when you press the reload key
Reply With Quote #4

Quote:
Originally Posted by PattyBiena View Post
Optimized(?) Xd
All you really did is moved data storage from 1-dimension arrays to a 2-dimension array and created an enumerator for IS_BART and IS_HOMER; strangely you chose to use integers 0 and 1 to represent speed and gravity, why not be consistent and use an enumerator for that too? You also eliminated the UsedGravity and UsedSpeed boolean variables which the OP was using to only allow a player to have each power once. You added a Hability boolean variable which is true when a player has powers yet you still have a task_exists() check which is redundant in your code; the task_exist check will return true when a power is active for the player. I still wouldn't consider these revisions optimizations, it might even make it harder for the original poster to understand while giving no performance\functionality benefit.
__________________

Last edited by Bugsy; 07-11-2010 at 09:02.
Bugsy is offline
Old 07-11-2010, 12:21
wrecked_
This message has been deleted by wrecked_.
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 07:13.


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