Raised This Month: $32 Target: $400
 8% 

Plugin doesnt work...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Javierko
AlliedModders Donor
Join Date: Sep 2017
Location: Czech republic
Old 03-14-2018 , 16:32   Plugin doesnt work...
Reply With Quote #1

Hi guys,

can you help me with solving this plugin? Its a ratio plugin, but it doesnt work and i dont know why. I tryed everything that i knew, but still doesnt work... T players can join to CT players every time, any block from plugin side... hastebin

PHP Code:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR "psst"
#define PLUGIN_VERSION "1.0.0"
#define PREFIX " [\x06Ratio\x01]"

#include <sourcemod>
#include <sdktools>
#include <cstrike>

bool B_Info;
bool AllowCT true;
bool P_Info[MAXPLAYERS+1][2];

public 
Plugin myinfo 
{
    
name "[CS:GO] Shit that doesnt work :)",
    
author PLUGIN_AUTHOR,
    
description "",
    
version PLUGIN_VERSION,
    
url ""
};

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

public 
Action Event_OnPreRoundStart(Handle event, const char[] namebool dontBroadcast)
{
    
ResetInfo();
    
B_Info true;
    
ComputeDiff();
    for (
int i=1;<= MaxClients;i++)
    {
        if(
IsClientInGame(i))
        {
            if(
P_Info[i][0])
            {
                
PrintToChat(i,"%s You cant join to CT, because there is bad ratio!"PREFIX);
                
P_Info[i][0] = false;
            }
            if(
P_Info[i][1])
            {
                
PrintToChat(i,"%s You have been moved to T side, because there is too many players in CT side."PREFIX);
                
P_Info[i][1] = false;
            }
        }
    }
}

public 
Action TeamJoin(int client, const char[] commandint args)
{
    
B_Info false;
    
ComputeDiff();
    if(
SwitchTest(client))
    {
        return 
Plugin_Continue;
    }
    else
    {
        return 
Plugin_Handled;
    }
}

public 
Action TeamChange(Handle event, const char[] namebool dontBroadcast)
{
    
B_Info false;
    
ComputeDiff();
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    if(
SwitchTest(client))
    {
        return 
Plugin_Continue;
    }
    else
    {
        return 
Plugin_Handled;
    }
}

public 
SwitchTest(int client)
{
    if(
AllowCT)
    {
        return 
true;
    }
    else
    {
        
P_Info[client][0] = true;
        
PrintToChat(client,"%s You cant go to Ct side, because there is bad ratio!"PREFIX);
        return 
false;
    }    
}

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

public 
void ScrambleCT()
{
    
int targetTime 9999999;
    
int targetClient = -1;
    
    for(
int i=1<= MaxClientsi++)
    {
        if(
IsClientConnected(i) && GetClientTeam(i) == CS_TEAM_CT)
        {
            
int time RoundToNearest(GetClientTime(i));
            if(
time targetTime)
            {
                
targetTime time;
                
targetClient i;
            }
        }
    }
    
    if(
targetClient && IsClientInGame(targetClient))
    {
        
SetEntProp(targetClientProp_Send"m_lifeState"2);
        
ChangeClientTeam(targetClientCS_TEAM_T);
        if(
GetClientHealth(targetClient) > 0)
        {
            
SetEntProp(targetClientProp_Send"m_lifeState"0);
        }
        
P_Info[targetClient][1] = true;
        
ComputeDiff();
    }
}

public 
void ResetInfo()
{
    for(
int i=1<= MaxClientsi++)
    {
        
P_Info[i][0] = false;
        
P_Info[i][1] = false;
    }    

__________________
My Github & Sourcemod work.
If you like my work and if you want to support me, you can through PayPal.

Official SourceMod CZ/SK Discord: https://discord.gg/Qvar55a
Javierko is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 03-14-2018 , 16:53   Re: Plugin doesnt work...
Reply With Quote #2

As i already told you yesterday on steam:

I recommend to add debug messages to all calculations and check their values.

Also in your line 103, the formula seem wierd.
Code:
TCount = TCount - (TCount % 2);
e.g TCount == 3
Code:
3 - (3 % 2) = 2
but on e.g TCount == 6
Code:
6 - (6 % 2) = 6
PS: I feel very fooled and flouted when I spend my spare time on steamchat to explain you your issue and give you help.
And on next day you ask the same question here without doing any of my recommendations.
not cool.
__________________
coding & free software

Last edited by shanapu; 03-14-2018 at 16:54.
shanapu is offline
Javierko
AlliedModders Donor
Join Date: Sep 2017
Location: Czech republic
Old 03-14-2018 , 18:30   Re: Plugin doesnt work...
Reply With Quote #3

I'm sure the problem will be elsewhere :/
__________________
My Github & Sourcemod work.
If you like my work and if you want to support me, you can through PayPal.

Official SourceMod CZ/SK Discord: https://discord.gg/Qvar55a
Javierko is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 03-14-2018 , 19:29   Re: Plugin doesnt work...
Reply With Quote #4

Quote:
Originally Posted by Javierko View Post
I'm sure the problem will be elsewhere :/
The solution to your issue is on here, on this link.

If you don't want to take the help you're getting, and simply being rude by wasting other people's time for nothing, you're all on your own with your issues.

People won't ever try to help you again, if you continue like that...
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline
Vaggelis
Senior Member
Join Date: May 2017
Old 03-14-2018 , 20:01   Re: Plugin doesnt work...
Reply With Quote #5

I dont know if this gonna help but this is what i use for 1 : 3 ratio: (((prisoners - 3) / guards) > 3)
This is how it works:
1 Guards | 7 Prisoners => 2 Guards | 6 Prisoners
2 Guards | 10 Prisoners => 3 Guards | 9 Prisoners
3 Guards | 13 Prisoners => 4 Guards | 12 Prisoners

Last edited by Vaggelis; 03-14-2018 at 20:01.
Vaggelis is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-15-2018 , 01:51   Re: Plugin doesnt work...
Reply With Quote #6

Quote:
Originally Posted by shanapu View Post
Also in your line 103, the formula seem wierd.
Code:
TCount = TCount - (TCount % 2);
e.g TCount == 3
Code:
3 - (3 % 2) = 2
but on e.g TCount == 6
Code:
6 - (6 % 2) = 6
Not really, it's code to round down to the next closest even number without converting the values to floats.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Javierko
AlliedModders Donor
Join Date: Sep 2017
Location: Czech republic
Old 03-15-2018 , 11:10   Re: Plugin doesnt work...
Reply With Quote #7

Quote:
Originally Posted by arne1288 View Post
The solution to your issue is on here, on this link.

If you don't want to take the help you're getting, and simply being rude by wasting other people's time for nothing, you're all on your own with your issues.

People won't ever try to help you again, if you continue like that...
I appreciate that shanapu helped me, but mistake in code must be elsewhere, not in "TCount = TCount - (TCount % 2);".
__________________
My Github & Sourcemod work.
If you like my work and if you want to support me, you can through PayPal.

Official SourceMod CZ/SK Discord: https://discord.gg/Qvar55a

Last edited by Javierko; 03-15-2018 at 12:16.
Javierko is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 03-15-2018 , 19:43   Re: Plugin doesnt work...
Reply With Quote #8

return Plugin_Handled;
on ALL team join event
and change client's team manually
__________________
8guawong is offline
Reply


Thread Tools
Display Modes

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 21:15.


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