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

Solved [CS:GO] give player X health every X seconds


Post New Thread Reply   
 
Thread Tools Display Modes
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 08-01-2018 , 15:50   Re: [CS:GO] give player X health every X seconds
Reply With Quote #11

Oh yeah. I forgot to add a check to kill the timer on every round start before creating a new one.

Also, wouldn't the player need to be alive to get the health?
__________________
Psyk0tik is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 08-01-2018 , 18:01   Re: [CS:GO] give player X health every X seconds
Reply With Quote #12

Quote:
Originally Posted by mug1wara View Post
He never told me to check if the client was valid :p
Translation: "He never told me the code must have no bugs and ERRORS".
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
LenHard
Senior Member
Join Date: Jan 2016
Old 08-01-2018 , 19:56   Re: [CS:GO] give player X health every X seconds
Reply With Quote #13

Quote:
Originally Posted by Crasher_3637 View Post
Also, wouldn't the player need to be alive to get the health?
Indeed, updated.
__________________
LenHard is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 08-02-2018 , 07:04   Re: [CS:GO] give player X health every X seconds
Reply With Quote #14

Quote:
Originally Posted by LenHard View Post
You should always check no matter what's the reason, it's really a bad practice to not check. It'll prevent you from making that mistake in the future and also prevent errors to those whom you're helping.



If I'm not wrong, that'd cause a timer to be set every round start causing duplicating timers. Add a integer of the round and stop the timer.

PHP Code:
int gI_Round;

public 
void eEventRoundStart(Event hEvent, const char[] sEventNamebool bDontBroadcast)
{
    ++
gI_Round;
    
CreateTimer(30.0Timer_HealgI_RoundTIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
}

public 
Action Timer_Heal(Handle hTimerany iRound)
{
    if (
gI_Round == iRound)
    {
        for (
int i 1<= MaxClientsi++) 
            if (
IsClientInGame(i) && IsPlayerAlive(i)) 
                
SetEntityHealth(iGetClientHealth(i) + 10); 
        return 
Plugin_Continue;
    }
    else return 
Plugin_Stop;

Why not use my code to simply put finish the timer instantly? I assume just having the timer run takes some data and bandwith. Finishing the timer is probably the most efficient choice unless the timer is 0.1 seconds or something.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
LenHard
Senior Member
Join Date: Jan 2016
Old 08-02-2018 , 07:48   Re: [CS:GO] give player X health every X seconds
Reply With Quote #15

Quote:
Originally Posted by eyal282 View Post
Why not use my code to simply put finish the timer instantly? I assume just having the timer run takes some data and bandwith. Finishing the timer is probably the most efficient choice unless the timer is 0.1 seconds or something.
I'm not following what you're saying. Elaborate please.
__________________
LenHard is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 08-02-2018 , 08:41   Re: [CS:GO] give player X health every X seconds
Reply With Quote #16

Quote:
Originally Posted by LenHard View Post
I'm not following what you're saying. Elaborate please.
My code shuts the timer in the beginning of a new round. Your code keeps it running until it gets executed again. Meaning that my code shuts the timer up to 30 seconds earlier than you, which might be a better option for CPU.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 08-02-2018 , 13:29   Re: [CS:GO] give player X health every X seconds
Reply With Quote #17

PHP Code:
public void OnPluginStart()
{
    
HookEvent("player_spawn"OnSpawn);
}

public 
Action OnSpawn(Handle pEvent, const char[] pNamebool bDontBroadcast)
{
    
int iClient GetClientOfUserId(GetEventInt(pEvent"userid"));
    
    
CreateTimer(30.0GiveHPiClientTIMER_REPEAT);
}

public 
Action GiveHP(Handle pTimerany iClient)
{
    if(
IsPlayerAlive(iClient))
    {
        
int iHP GetClientHealth(iClient);
        
int iBonusHP iHP 10;
        
SetEntityHealth(iClientiBonusHP);
        
PrintToChat(iClient"You got 10 HP!"// debug
    
}

or you can just use

PHP Code:
public void OnClientPutInServer(int iClient)
{
    
CreateTimer(30.0GiveHPiClientTIMER_REPEAT);

not tested, but should work
kratoss1812 is offline
micapat
Veteran Member
Join Date: Feb 2010
Location: Nyuu, nyuu (France).
Old 08-02-2018 , 14:58   Re: [CS:GO] give player X health every X seconds
Reply With Quote #18

Maybe it's time to stop posting things that don't work.
__________________
micapat is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 08-02-2018 , 16:56   Re: [CS:GO] give player X health every X seconds
Reply With Quote #19

Quote:
Originally Posted by kratoss1812 View Post
PHP Code:
public void OnPluginStart()
{
    
HookEvent("player_spawn"OnSpawn);
}

public 
Action OnSpawn(Handle pEvent, const char[] pNamebool bDontBroadcast)
{
    
int iClient GetClientOfUserId(GetEventInt(pEvent"userid"));
    
    
CreateTimer(30.0GiveHPiClientTIMER_REPEAT);
}

public 
Action GiveHP(Handle pTimerany iClient)
{
    if(
IsPlayerAlive(iClient))
    {
        
int iHP GetClientHealth(iClient);
        
int iBonusHP iHP 10;
        
SetEntityHealth(iClientiBonusHP);
        
PrintToChat(iClient"You got 10 HP!"// debug
    
}

or you can just use

PHP Code:
public void OnClientPutInServer(int iClient)
{
    
CreateTimer(30.0GiveHPiClientTIMER_REPEAT);

not tested, but should work
You dont send client indicies through timers. Especially 30 second timers. You send UserIds.
__________________
Neuro Toxin is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 08-02-2018 , 17:12   Re: [CS:GO] give player X health every X seconds
Reply With Quote #20

Quote:
Originally Posted by Neuro Toxin View Post
You dont send client indicies through timers. Especially 30 second timers. You send UserIds.
And ultimate especially repetitive timers.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 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:04.


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