AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Reload bar (how to?) (https://forums.alliedmods.net/showthread.php?t=278867)

newb1e 02-09-2016 22:22

Reload bar (how to?)
 
https://forums.alliedmods.net/showthread.php?p=220167
can't understand the source of that plugin, but can anyone explaine how can i create an reload bar?
If i press and hold "E" (3 seconds/cvar) while aiming to player, the bar will appear and after that 3 seconds do some stuff. but if i stop pressing the bar will dissapear (cancel).

HamletEagle 02-10-2016 03:25

Re: Reload bar (how to?)
 
You have to send a BarTime message. To clear the message send another one with 0 as duration.

newb1e 02-10-2016 06:21

Re: Reload bar (how to?)
 
none of thiose functions is working

PHP Code:

#include < amxmodx >
//#include < hamsandwich >

new g_iBarTimeg_iBarTime2 

public plugin_init( )
{
    
//RegisterHam( Ham_Use, "func_button", "FwdUseButton" );
    
    
g_iBarTime get_user_msgid("BarTime"
    
g_iBarTime2 get_user_msgid("BarTime2")
    
    
register_clcmd("say /bar""Bar_Test")
}

public 
Bar_Test(id)
{
 if(
is_user_alive(id))
  {
    
Make_BarTime(id)
   }
   return 
PLUGIN_CONTINUE
  
}

Make_BarTime(idiSeconds

    
message_begin(MSG_ONE_UNRELIABLEg_iBarTime, .player=id
    
write_short(iSeconds
    
message_end() 


Make_BarTime2(idFloat:flSeconds

    new 
iRoundedSeconds floatround(flSecondsfloatround_ceil
    new 
iStartPercent floatround((1.0-(flSeconds iRoundedSeconds))*100
    
message_begin(MSG_ONE_UNRELIABLEg_iBarTime2, .player=id
    
write_short(iRoundedSeconds
    
write_short(iStartPercent
    
message_end() 
}

/*

public FwdUseButton( iEntity, iPlayer, iActivator, iUseType, Float:flValue )
{
    if( !is_user_alive( iPlayer )
    ||  iUseType != 2
    ||  flValue != 1.0 )
    {
        return HAM_IGNORED;
    }
    
    client_print( iPlayer, print_chat, "Button Entity: %i", iEntity );
    
    return HAM_IGNORED;
}
*/ 


siriusmd99 02-10-2016 07:18

Re: Reload bar (how to?)
 
Find lasermine plugin's setlaser function, it has the reload bar.

wickedd 02-10-2016 07:30

Re: Reload bar (how to?)
 
PHP Code:

#include <amxmodx>

new g_iBarTime

public plugin_init( )
{   
    
register_clcmd"say /bar""Make_BarTime" )
    
    
g_iBarTime get_user_msgid"BarTime" 


public 
Make_BarTimeid 

    
message_begin(MSG_ONE_UNRELIABLEg_iBarTime,_id 
    
write_short// This is the duration. 
    
message_end() 



newb1e 02-10-2016 12:14

Re: Reload bar (how to?)
 
Quote:

Originally Posted by wickedd (Post 2391696)
PHP Code:

#include <amxmodx>

new g_iBarTime

public plugin_init( )
{   
    
register_clcmd"say /bar""Make_BarTime" )
    
    
g_iBarTime get_user_msgid"BarTime" 


public 
Make_BarTimeid 

    
message_begin(MSG_ONE_UNRELIABLEg_iBarTime,_id 
    
write_short// This is the duration. 
    
message_end() 



Exatly! Thank you!
But what is the correct way to make this?:
pressing the +use key when aiming a player?
I want to press E and do some stuff

wickedd 02-10-2016 14:47

Re: Reload bar (how to?)
 
PHP Code:

#include <amxmodx>
#include <engine>
#include <fakemeta>

new g_iBarTime

public plugin_init( )
{   
    
register_forwardFM_PlayerPreThink"test" )
    
register_clcmd"say /bar""Make_BarTime" )
    
    
g_iBarTime get_user_msgid"BarTime" )


public 
testid )
{
    new 
newidbody
    get_user_aiming
idnewidbody )
    
    new 
zButton get_user_buttonid )
    
    if( 
is_user_connectednewid ) && ( zButton IN_USE )  )
    {
        
Make_BarTimeid )
    }
}

public 
Make_BarTimeid 

    
message_begin(MSG_ONE_UNRELIABLEg_iBarTime,_id 
    
write_short// This is the duration.
    
message_end() 


Here's a way, this will show the bar when you're aiming at a player and pressing the +use key.

P.S. Don't just copy and paste that into your plugin because it can be optimized.

HamletEagle 02-10-2016 14:56

Re: Reload bar (how to?)
 
You could get rid of PreThink, probably by using Ham_ObjectCaps.

newb1e 02-10-2016 15:54

Re: Reload bar (how to?)
 
So if i press the button E when aiming a player for 3 seconds i will steal his money, but what if player starts moving? How to cancel the event?

PHP Code:

#include <amxmodx>
#include <engine>
#include <fakemeta>

new g_iBarTime

public plugin_init( )
{   
    
register_forwardFM_PlayerPreThink"test" )
    
g_iBarTime get_user_msgid"BarTime" )


public 
testid )
{
    new 
newidbody
    get_user_aiming
idnewidbody )
    
    new 
zButton get_user_buttonid )
        new 
iKiller read_data(1)
        new 
iVictim read_data(2)
    
    if( 
is_user_connectednewid ) && ( zButton IN_USE )  )
    {
        
cs_set_user_money(iKillercs_get_user_money(iKiller) + cs_get_user_money(iVictim))
        
cs_set_user_money(iVictim0)
        
Make_BarTimeid )
    }
else
{
// ?
return PLUGIN_HANDLED
}
}

// this bar whil appear when  you press E aiming a player for 3 seconds
public Make_BarTimeid 

    
message_begin(MSG_ONE_UNRELIABLEg_iBarTime,_id 
    
write_short// This is the duration.
    
message_end() 



Depresie 02-10-2016 20:58

Re: Reload bar (how to?)
 
Oww hell no... prethink? seriously?

Just hook the T button instead of E so you will not need cmd start or prethink
Then use get_user_aiming(id, Target, Body, Distance)
Create a bool to tell if the action is in progress, and if it is in progress and you press again T remove the task and the bar aka cancel the action


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

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