Raised This Month: $ Target: $400
 0% 

Solved [nmrih]Exception reported: Client index 0 is invalid


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 06-07-2021 , 12:03   Re: [nmrih]Exception reported: Client index 0 is invalid
Reply With Quote #6

PHP Code:
#pragma semicolon 1
#pragma newdecls required

#define PL_VER "1.2.0 (rewritten by Grey83)"

Handle
    hTimer
[MAXPLAYERS+1];
int
    iMax
,
    
iAdd;
float
    fCD
;

public 
Plugin myinfo =
{
    
name        "Admin Regenerate",
    
version        PL_VER,
    
description    "Lets admins regenerate their health with a command",
    
author        "joac1144/Zyanthius"
}

public 
void OnPluginStart()
{
    
CreateConVar("adminregen_version"PL_VER"Plugin version. Do not change."FCVAR_DONTRECORD|FCVAR_NOTIFY|FCVAR_SPONLY);

    
ConVar cvar;
    
cvar CreateConVar("adminregen_maxhp""100""Maximum health you can have by regenerating (0 - plugin disabled)"_true);
    
cvar.AddChangeHook(CVarChange_Max);
    
iMax cvar.IntValue;

    
cvar CreateConVar("adminregen_health""2""Amount of health to regenerate"_true1.0);
    
cvar.AddChangeHook(CVarChange_Add);
    
iAdd cvar.IntValue;

    
cvar CreateConVar("adminregen_time""2.0""Amount of time (in seconds) between each health"_true0.1);
    
cvar.AddChangeHook(CVarChange_CD);
    
fCD cvar.FloatValue;

    
AutoExecConfig(true"plugin.adminregen");

    
RegAdminCmd("sm_adminregen"Cmd_RegenADMFLAG_SLAY"Activates regeneration.");
}

public 
void CVarChange_Max(ConVar cvar, const char[] oldValue, const char[] newValue)
{
    
iMax cvar.IntValue;
}

public 
void CVarChange_Add(ConVar cvar, const char[] oldValue, const char[] newValue)
{
    
iAdd cvar.IntValue;
}

public 
void CVarChange_CD(ConVar cvar, const char[] oldValue, const char[] newValue)
{
    
fCD cvar.FloatValue;
}

public 
void OnMapEnd()
{
    for(
int i 1<= MaxClientsi++) OnClientDisconnect(i);
}

public 
void OnClientDisconnect(int client)
{
    if(
hTimer[client]) delete hTimer;
}

public 
Action Cmd_Regen(int clientint args)
{
    if(!
client || IsFakeClient(client) || GetClientTeam(client) < || !IsPlayerAlive(client))
        return 
Plugin_Handled;

    if(
hTimer[client])
    {
        
ReplyToCommand(client"[SM] You have deactivated regeneration!");
        
PrintToServer("[SM] %N has deactivated regeneration!"client);
        
delete hTimer[client];
        return 
Plugin_Handled;
    }

    if(
GetClientHealth(client) >= iMax)
    {
        
ReplyToCommand(client"[SM] You already have maximum hp!");
        
PrintToServer("[SM] %N already has maximum hp!"client);
        return 
Plugin_Handled;
    }

    
hTimer[client] = CreateTimer(fCDRegenTimerGetClientUserId(client), TIMER_REPEAT);
    
ReplyToCommand(client"[SM] You have activated regeneration!");
    
PrintToServer("[SM] %N has activated regeneration!"client);

    return 
Plugin_Handled;
}

public 
Action RegenTimer(Handle timerint uid)
{
    
int client GetClientOfUserId(uid);
    if(!
client || GetClientTeam(client) < || !IsPlayerAlive(client))
        return 
StopTimer(client);

    
int hp GetClientHealth(client);
    if(
hp >= iMax)
        return 
StopTimer(client);

    if((
hp += iAdd) >= iMax)
    {
        
SetEntityHealth(clientiMax);
        return 
StopTimer(client);
    }

    
SetEntityHealth(clienthp);
    return 
Plugin_Continue;
}

stock Action StopTimer(int client)
{
    
hTimer[client] = null;
    return 
Plugin_Stop;

__________________
Grey83 is offline
 



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 03:28.


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