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

Repair this script please


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
blodhblaka
Member
Join Date: Jan 2015
Old 01-31-2015 , 18:09   Repair this script please
Reply With Quote #1

Anyhow repair this script. (index error) and overall

PHP Code:
#include <sourcemod>
#include <cstrike>     
#include <sdktools>

#define PREFIX "\x06[Jail]\x04"

new I_ClientTime[26];

new 
bool:B_Info;

new 
bool:AllowCT true;

new 
bool:P_Info[32][2];

public 
Plugin:myinfo = {
    
name "No more nepoměr",
    
author "ffredyk and Blodhblaka",
    
description "Jailbreak Difference Balance - 1 CT to every 2 T",
    
version "1.1",
    
url "http://newera.fakaheda.eu"
};

public 
OnPluginStart()
{
    
HookEvent("round_prestart"RoundStart);
    
HookEvent("player_team"TeamChangeEventHookMode_Pre);
    
AddCommandListener(TeamJoin"jointeam");
}

public 
OnClientConnected(client)
{
    
I_ClientTime[client] = 0//Reset timestampu
}

public 
OnMapStart()
{
    for(new 
i=1;i<26;i++)
    {
        if(
IsClientConnected(i))
        {
            
I_ClientTime[i] = RoundToNearest(GetClientTime(i));
        }
    }
}                                                     

public 
Action:RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    {   
        {
            
CreateTimer(5.0Blodhblaka2);
        }
        
        
ResetInfo();
        
        
B_Info true;
        
ComputeDiff();
        for(new 
i=1;i<26;i++)
        {
            if(
IsClientInGame(i))
            {
                if(
P_Info[i][0]) 
                {
                    
PrintToChat(i,"%s Nemůžeš k CT, protože není dostatečný poměr!"PREFIX);
                    
P_Info[i][0] = false;
                }
                if(
P_Info[i][1]) 
                {
                    
PrintToChat(i,"%s Byl jsi přesunut k Terroristům, protože kazíš poměr!"PREFIX);   
                    
P_Info[i][1] = false;
                }
            }
        }
    }   
}
public 
Action:Blodhblaka2(Handle:timer)
{
    
ResetInfo();
    
B_Info true;
    
ComputeDiff();
    for(new 
i=1;i<33;i++)
    {
        if(
IsClientInGame(i))
        {
            if(
P_Info[i][0]) 
            {
                
PrintToChat(i,"%s Nemůžeš k CT, protože není dostatečný poměr!"PREFIX);
                
P_Info[i][0] = false;
            }
            if(
P_Info[i][1]) 
            {
                
PrintToChat(i,"%s Byl jsi přesunut k Terroristům, protože kazíš poměr!"PREFIX);   
                
P_Info[i][1] = false;
            }
        }
    }
}

public 
Action:TeamJoin(client, const String:command[], argc)
{
    
B_Info false;
    
ComputeDiff();
    if(
SwitchTest(client))
    {
        return 
Plugin_Continue;
    }
    else
    {
        return 
Plugin_Handled;
    }
}
public 
Action:TeamChange(Handle:event, const String:name[], bool:dontBroadcast)
{
    
B_Info false;
    
ComputeDiff();
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if(
SwitchTest(client)) 
    {
        return 
Plugin_Continue;
    }
    else
    {
        return 
Plugin_Handled;
    }
}

public 
SwitchTest(client)

    if(
AllowCT)
    {
        return 
true;
    }
    else
    {
        if(
GetUserAdmin(client)!= INVALID_ADMIN_ID)
        {
            return 
true;
        }
        else
        {
            
P_Info[client][0] = true;
            
PrintToChat(client,"%s Nemůžeš k CT, protože není dostatečný poměr!"PREFIX);
            return 
false;
        }
    }
}

public 
ComputeDiff()
{
    new 
TCount GetTeamClientCount(CS_TEAM_T);
    new 
CTCount GetTeamClientCount(CS_TEAM_CT);
    
TCount TCount - (TCount 2);
    new 
CTAllowed TCount 2;
    if(
CTCount CTAllowed && TCount && CTCount 0)
    {
        
ScrambleCT();
        
AllowCT false;
    }
    else 
    {
        
AllowCT true;  
        if(
B_InfoPrintToChatAll("%s Poměr je %.2f (optimum je 0.5)"PREFIXfloat(CTCount) / float(TCount));
        
B_Info false;
    }
}

public 
ScrambleCT()
{
    new 
targetTime 999999//Client time
    
new targetClient = -1//Result client
    
for(new i=1;i<33;i++)
    {
        if(
IsClientConnected(i) && GetClientTeam(i) == CS_TEAM_CT)
        {
            new 
time RoundToNearest(GetClientTime(i));
            if(
GetUserAdmin(i)!= INVALID_ADMIN_ID)
            {
                
targetClient = -99999;
            }
            else
            {
                if(
time targetTime)
                {
                    
targetTime time;
                    
targetClient i;
                }
            }
        }
    }
    if(
targetClient && IsClientInGame(targetClient))
    {
        
SetEntProp(targetClientProp_Send"m_lifeState"2);      
        
ChangeClientTeam(targetClient2);
        if(
GetClientHealth(targetClient) > 0)
        {
            
SetEntProp(targetClientProp_Send"m_lifeState"0);
        }
        
P_Info[targetClient][1] = true;
        
ComputeDiff();
    }
}

public 
ResetInfo()
{
    for(new 
i=0;i<26;i++)
    {
        
P_Info[i][0] = false;
        
P_Info[i][1] = false;
    }

blodhblaka is offline
Darkness_
Veteran Member
Join Date: Nov 2014
Old 01-31-2015 , 18:22   Re: Repair this script please
Reply With Quote #2

PHP Code:
//Don't do this when looping through clients
for(new i=1;i<26;i++) 
//Instead do this
for (new 1<= MaxClientsi++)
//and instead of IsClientConnected() use IsClientInGame() (atleast for what you are doing here) 
PHP Code:
#include <sourcemod> 
#include <cstrike>      
#include <sdktools> 

#define PREFIX "\x06[Jail]\x04" 

new I_ClientTime[26]; 

new 
bool:B_Info

new 
bool:AllowCT true

new 
bool:P_Info[32][2]; 

public 
Plugin:myinfo = { 
    
name "No more nepoměr"
    
author "ffredyk and Blodhblaka"
    
description "Jailbreak Difference Balance - 1 CT to every 2 T"
    
version "1.1"
    
url "http://newera.fakaheda.eu" 
}; 

public 
OnPluginStart() 

    
HookEvent("round_prestart"RoundStart); 
    
HookEvent("player_team"TeamChangeEventHookMode_Pre); 
    
AddCommandListener(TeamJoin"jointeam"); 


public 
OnClientConnected(client

    
I_ClientTime[client] = 0//Reset timestampu 


public 
OnMapStart() 

    for (new 
1<= MaxClientsi++)
    { 
        if(
IsClientInGame(i)) 
        { 
            
I_ClientTime[i] = RoundToNearest(GetClientTime(i)); 
        } 
    } 
}                                                      

public 
Action:RoundStart(Handle:event, const String:name[], bool:dontBroadcast

    {    
        { 
            
CreateTimer(5.0Blodhblaka2); 
        } 
         
        
ResetInfo(); 
         
        
B_Info true
        
ComputeDiff(); 
        for (new 
1<= MaxClientsi++)
        { 
            if(
IsClientInGame(i)) 
            { 
                if(
P_Info[i][0])  
                { 
                    
PrintToChat(i,"%s Nemůžeš k CT, protože není dostatečný poměr!"PREFIX); 
                    
P_Info[i][0] = false
                } 
                if(
P_Info[i][1])  
                { 
                    
PrintToChat(i,"%s Byl jsi přesunut k Terroristům, protože kazíš poměr!"PREFIX);    
                    
P_Info[i][1] = false
                } 
            } 
        } 
    }    

public 
Action:Blodhblaka2(Handle:timer

    
ResetInfo(); 
    
B_Info true
    
ComputeDiff(); 
    for (new 
1<= MaxClientsi++) 
    { 
        if(
IsClientInGame(i)) 
        { 
            if(
P_Info[i][0])  
            { 
                
PrintToChat(i,"%s Nemůžeš k CT, protože není dostatečný poměr!"PREFIX); 
                
P_Info[i][0] = false
            } 
            if(
P_Info[i][1])  
            { 
                
PrintToChat(i,"%s Byl jsi přesunut k Terroristům, protože kazíš poměr!"PREFIX);    
                
P_Info[i][1] = false
            } 
        } 
    } 


public 
Action:TeamJoin(client, const String:command[], argc

    
B_Info false
    
ComputeDiff(); 
    if(
SwitchTest(client)) 
    { 
        return 
Plugin_Continue
    } 
    else 
    { 
        return 
Plugin_Handled
    } 

public 
Action:TeamChange(Handle:event, const String:name[], bool:dontBroadcast

    
B_Info false
    
ComputeDiff(); 
    new 
client GetClientOfUserId(GetEventInt(event"userid")); 
    if(
SwitchTest(client))  
    { 
        return 
Plugin_Continue
    } 
    else 
    { 
        return 
Plugin_Handled
    } 


public 
SwitchTest(client
{  
    if(
AllowCT
    { 
        return 
true
    } 
    else 
    { 
        if(
GetUserAdmin(client)!= INVALID_ADMIN_ID
        { 
            return 
true
        } 
        else 
        { 
            
P_Info[client][0] = true
            
PrintToChat(client,"%s Nemůžeš k CT, protože není dostatečný poměr!"PREFIX); 
            return 
false
        } 
    } 


public 
ComputeDiff() 

    new 
TCount GetTeamClientCount(CS_TEAM_T); 
    new 
CTCount GetTeamClientCount(CS_TEAM_CT); 
    
TCount TCount - (TCount 2); 
    new 
CTAllowed TCount 2
    if(
CTCount CTAllowed && TCount && CTCount 0
    { 
        
ScrambleCT(); 
        
AllowCT false
    } 
    else  
    { 
        
AllowCT true;   
        if(
B_InfoPrintToChatAll("%s Poměr je %.2f (optimum je 0.5)"PREFIXfloat(CTCount) / float(TCount)); 
        
B_Info false
    } 


public 
ScrambleCT() 

    new 
targetTime 999999//Client time 
    
new targetClient = -1//Result client 
    
for (new 1<= MaxClientsi++) 
    { 
        if(
GetClientTeam(i) == CS_TEAM_CT
        { 
            new 
time RoundToNearest(GetClientTime(i)); 
            if(
GetUserAdmin(i)!= INVALID_ADMIN_ID
            { 
                
targetClient = -99999
            } 
            else 
            { 
                if(
time targetTime
                { 
                    
targetTime time
                    
targetClient i
                } 
            } 
        } 
    } 
    if(
targetClient && IsClientInGame(targetClient)) 
    { 
        
SetEntProp(targetClientProp_Send"m_lifeState"2);       
        
ChangeClientTeam(targetClient2); 
        if(
GetClientHealth(targetClient) > 0
        { 
            
SetEntProp(targetClientProp_Send"m_lifeState"0); 
        } 
        
P_Info[targetClient][1] = true
        
ComputeDiff(); 
    } 


public 
ResetInfo() 

    for (new 
1<= MaxClientsi++)
    { 
        
P_Info[i][0] = false
        
P_Info[i][1] = false
    } 


Last edited by Darkness_; 01-31-2015 at 20:33.
Darkness_ 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 12:56.


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