Raised This Month: $51 Target: $400
 12% 

Solved [TF2] Repeat_Timer script help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ravrob
Junior Member
Join Date: Oct 2019
Location: The Ice
Old 11-16-2020 , 20:47   [TF2] Repeat_Timer script help
Reply With Quote #1

So, a brief explanation to this code. I want to make it so that the Bushwacka will grant cloak while you're holding attack2, but after you stop holding attack2 you will bleed for however many seconds you held for. Now I got all of it to work except I could only make it work with a global variable, which obviously causes problems if multiple people are using the weapons ability. I haven't gotten any alternatives I could think of to work so I'd really appreciate any help with this.

PHP Code:
bool g_wait[MAXPLAYERS 1];

float debt 1.0;

public 
Action OnPlayerRunCmd(int clientintbuttonsintimpulsefloat vel[3], float angles[3], intweapon
{
    
int iWeapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
    if(!
IsValidEntity(iWeapon))
    {
        return;
    }
        
    
int index GetEntProp(iWeaponProp_Send"m_iItemDefinitionIndex");
    if(
index == 232 && buttons IN_ATTACK2 && g_wait[client] == false)
    {
        
g_wait[client] = true;
        
CreateTimer(1.0yourDebtclientTIMER_REPEAT);
    }
}

public 
Action yourDebt(Handle timerint client)
{    
    if(
IsClientInGame(client) && IsPlayerAlive(client))
    {
        
int iWeapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
        if(!
IsValidEntity(iWeapon))
        {
            
g_wait[client] = false;
            return 
Plugin_Stop;
        }
        
int index GetEntProp(iWeaponProp_Send"m_iItemDefinitionIndex");
        
        
int buttons GetClientButtons(client);
        if(
index == 232 && buttons IN_ATTACK2 && debt != 15)
        {
            
TF2_AddCondition(clientTFCond_Stealthed1.3);
            if(
debt 10)
            {
                
SetHudTextParams(-1.00.751.0025500);
                
ShowHudText(client, -1"Blood debt: %i pints."RoundFloat(debt));
            }
            if(
debt >= 10 && debt != 14)
            {
                
SetHudTextParams(-1.00.751.025512800);
                
ShowHudText(client, -1"Blood debt: %i pints. The bushman is getting impatient."RoundFloat(debt));
            }
            if(
debt == 14)
            {
                
SetHudTextParams(-1.00.751.0255000);
                
ShowHudText(client, -1"Last chance mate!");
            }
            
debt debt 1.0;
            return 
Plugin_Continue;
        }
        else if (
debt >= 15)
        {
            
SDKHooks_TakeDamage(client00450.0);
            
g_wait[client] = false;
            
SetHudTextParams(-1.00.751.0255000);
            
ShowHudText(client, -1"G'day mate.");
            
debt 1.0;
            return 
Plugin_Stop;
        }
        else if (
debt 15)
        {
            
TF2_MakeBleed(clientclientdebt);
            
g_wait[client] = false;
            
debt 1.0;
            return 
Plugin_Stop;
        }
        else
        {
            
g_wait[client] = false;
            
debt 1.0;
            return 
Plugin_Stop;
        }
    }
    else
    {
        
g_wait[client] = false;
        
debt 1.0;
        return 
Plugin_Stop;
    }


Last edited by Ravrob; 11-17-2020 at 02:43.
Ravrob is offline
Balimbanana
Member
Join Date: Jan 2017
Old 11-17-2020 , 00:04   Re: [TF2] Repeat_Timer script help
Reply With Quote #2

You could potentially create the timer in each run, and set TIMER_FLAG_NO_MAPCHANGE
Code:
...
if(index == 232 && buttons & IN_ATTACK2 && g_wait[client] == false)
{
	g_wait[client] = true;
	CreateTimer(1.0, yourDebt, client, TIMER_FLAG_NO_MAPCHANGE);
}
...

...down at the end of:
public Action yourDebt(Handle timer, int client)
...
	CreateTimer(1.0, yourDebt, client, TIMER_FLAG_NO_MAPCHANGE);
}
Then you can keep all the original returns in there and the next timer won't be created unless it passes everything.
Balimbanana is offline
Ravrob
Junior Member
Join Date: Oct 2019
Location: The Ice
Old 11-17-2020 , 01:09   Re: [TF2] Repeat_Timer script help
Reply With Quote #3

I'm kinda confused as to how that would make a difference.. I'm pretty sure I'd still have the same problem with the 'debt' variable. I'm starting to think timers might not work with this concept.
Ravrob is offline
Balimbanana
Member
Join Date: Jan 2017
Old 11-17-2020 , 01:40   Re: [TF2] Repeat_Timer script help
Reply With Quote #4

Oh, I was thinking that somehow the client that was passed to the timer was not looping correctly.

To get the debt var to count for all players you could just make it indexed like the g_wait is.
Code:
float g_debt[ MAXPLAYERS + 1 ];
You would need to change all the other instances of debt = to g_debt[client] =
Then you should probably clear it when clients disconnect:
Code:
public void OnClientDisconnect(int client)
{
	g_debt[client] = 0.0;
	g_wait[client] = false;
}

Last edited by Balimbanana; 11-17-2020 at 01:50.
Balimbanana is offline
Ravrob
Junior Member
Join Date: Oct 2019
Location: The Ice
Old 11-17-2020 , 02:43   Re: [TF2] Repeat_Timer script help
Reply With Quote #5

Oh cool! I never would've thought of using an index. Thanks a ton!
Ravrob 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 10:48.


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