AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Kills per second/ friendly mode (https://forums.alliedmods.net/showthread.php?t=279130)

PointlessFish 02-16-2016 06:47

Kills per second/ friendly mode
 
Hello!

I am trying to combine Dreamy's kBans plugin with the Friendly Mode plugin.
The source of the kBans plugin https://forums.alliedmods.net/showthread.php?t=180217 has this
PHP Code:

#pragma semicolon 1
#include <sourcemod>

#undef REQUIRE_PLUGIN
#include <sourcebans>

#define PLUGIN_VERSION            "1.4"
#define PLUGIN_DESCRIPTION        "Bans a player if he does [n] amount of kills in [n] seconds"

new bool:k_SBans;
new 
kCount[MAXPLAYERS+1];
new 
kFirstKill[MAXPLAYERS+1];

new    
Handle:kvar_Kills INVALID_HANDLE,
    
Handle:kvar_Time INVALID_HANDLE,
    
Handle:kvar_Ban INVALID_HANDLE,
    
Handle:kvar_Text INVALID_HANDLE,
    
Handle:kvar_Bots INVALID_HANDLE;

public 
Plugin:myinfo =
{
    
name         =    "kBans",
    
author        =    "Dreamy",
    
description    =    PLUGIN_DESCRIPTION,
    
version        =    PLUGIN_VERSION,
    
url            =    "http://SourceMod.net"
};

public 
OnPluginStart()
{
    
CreateConVar("kBans_version"PLUGIN_VERSION"kBans Version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
kvar_Kills CreateConVar("kBans_kills""12""Amount of kills players are not allowed to do in [n] seconds"FCVAR_PLUGINtrue1.0);
    
kvar_Time CreateConVar("kBans_interval""40""In which interval players are not allowed to do [n] kills"FCVAR_PLUGINtrue0.0);
    
kvar_Ban CreateConVar("kBans_bantime""0""0 = Permban, >0 = Time in minutes"FCVAR_PLUGINtrue0.0);
    
kvar_Text CreateConVar("kBans_reason""[kBans]: Suspicion of Cheating""If you are/are not using sourcebans = Log Reason in your database/ Kick Message showed to player"FCVAR_PLUGIN);
    
kvar_Bots CreateConVar("kBans_bots""0""1/0 = Bots are treated/not treated as human players"FCVAR_PLUGINtrue0.0true1.0);
    
AutoExecConfig();
    
    
HookEvent("player_death"Event_PlayerDeath);
}

public 
Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    
decl String:weapon[16];
    
GetEventString(event"weapon"weaponsizeof(weapon));
    new 
victim GetClientOfUserId(GetEventInt(event"userid"));
    new 
client GetClientOfUserId(GetEventInt(event"attacker"));
    if (!
client || (client == victim) || StrEqual(weapon"hegrenade") || IsFakeClient(client))
        return;
    
    if (!
GetConVarBool(kvar_Bots) && IsFakeClient(victim))
        return;
    
    new 
time GetTime();
    
    if ((
kFirstKill[client]+GetConVarInt(kvar_Time)) >= time)
    {
        if (++
kCount[client] == GetConVarInt(kvar_Kills))
        {        
            
decl String:auth[32];
            
GetClientAuthString(clientauthsizeof(auth));

            
decl String:reason[128];
            
GetConVarString(kvar_Textreasonsizeof(reason));
            
            if (
k_SBans)
                
SBBanPlayer(0clientGetConVarInt(kvar_Ban), reason);
            else
            {
                
LogMessage("The player %N (%s) was banned for suspicion of cheating."clientauth);
                
BanClient(clientGetConVarInt(kvar_Ban), BANFLAG_AUTHID"kBans"reason"kBan"client);
            }
        }
    }
    else
    {
        
kCount[client] = 1;
        
kFirstKill[client] = time;
    }
}

public 
OnLibraryAdded(const String:name[])
    if (
StrEqual(name"sourcebans"))
        
k_SBans true;

public 
OnAllPluginsLoaded()
    if (
LibraryExists("sourcebans"))
        
k_SBans true;
    
public 
OnLibraryRemoved(const String:name[])
    if (
StrEqual(name"sourcebans"))
        
k_SBans false;
    
public 
OnClientDisconnect(client)
{
    
kCount[client] = 0;
    
kFirstKill[client] = 0;


I am wondering how to, instead, make the player not banned but friendly for a certain amount of time. Does anyone know how to do this? Using the sm_friendly and sm_friendly_lock commands.

Thanks! :bee:

PointlessFish 02-16-2016 06:59

Re: Kills per second/ friendly mode
 
Also to remove the Sourcebans part.
Thanks :bee:

PointlessFish 02-16-2016 09:13

Re: Kills per second/ friendly mode
 
Otherwise I could maybe add a cooldown for weapons.

PointlessFish 02-16-2016 13:11

Re: Kills per second/ friendly mode
 
Not even sure if is possible

Edit: Seems to be "servercommand"

xines 02-16-2016 13:52

Re: Kills per second/ friendly mode
 
I'm not sure if this is what you're trying to do, but i recoded it fast so give it a try.

PHP Code:

#pragma semicolon 1
#include <sourcemod>

#undef REQUIRE_PLUGIN

#define PLUGIN_VERSION            "1.4"
#define PLUGIN_DESCRIPTION        "Friendly a player if he does [n] amount of kills in [n] seconds"

new bool:timer_friendly[MAXPLAYERS+1];
new 
kCount[MAXPLAYERS+1];
new 
kFirstKill[MAXPLAYERS+1];

new    
Handle:kvar_Kills INVALID_HANDLE,
    
Handle:kvar_Time INVALID_HANDLE,
    
Handle:kvar_ftime INVALID_HANDLE;

public 
Plugin:myinfo =
{
    
name        =    "kBans",
    
author        =    "Dreamy",
    
description    =    PLUGIN_DESCRIPTION,
    
version        =    PLUGIN_VERSION,
    
url            =    "http://SourceMod.net"
};

public 
OnPluginStart()
{
    
CreateConVar("kBans_version"PLUGIN_VERSION"kBans Version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
kvar_Kills CreateConVar("kBans_kills""2""Amount of kills players are not allowed to do in [n] seconds"FCVAR_PLUGINtrue1.0);
    
kvar_Time CreateConVar("kBans_interval""10""In which interval players are not allowed to do [n] kills"FCVAR_PLUGINtrue0.0);
    
kvar_ftime CreateConVar("kBans_friendlytime""5.0""0 = Permban, >0 = Time in minutes"FCVAR_PLUGINtrue0.0);
    
AutoExecConfig();
    
    
HookEvent("player_death"Event_PlayerDeath);
}

public 
Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
victim GetClientOfUserId(GetEventInt(event"userid"));    
    new 
client GetClientOfUserId(GetEventInt(event"attacker"));
    
decl String:weapon[16];
    
GetEventString(event"weapon"weaponsizeof(weapon));
    if (!
client || (client == victim) || StrEqual(weapon"hegrenade"))
    {
        return;
    }

    new 
time GetTime();

    if ((
kFirstKill[client]+GetConVarInt(kvar_Time)) >= time)
    {
        if (
kCount[client] == GetConVarInt(kvar_Kills))
        {
            
decl String:auth[32];
            
GetClientAuthId(clientAuthId_Engineauthsizeof(auth));
            if (
timer_friendly[client] == false)
            {
                
LogMessage("The player %N (%s) got friendly activated."clientauth);
                
PrintToChat(client"\x04[friendly] \x01Activated On %N"client);
                new 
userid GetEventInt(event"attacker");
                
ServerCommand("sm_friendly %d 1"userid);
                
timer_friendly[client] = true;
                new 
Float:ftime GetConVarFloat(kvar_ftime);
                
CreateTimer(ftimeFriendlytimerclient);
            }
        }
    }
    else
    {
        if (
timer_friendly[client] == false)
        {
            
kCount[client] += 1;
            
kFirstKill[client] = time;
        }
    }
}

public 
Action:Friendlytimer(Handle:timerany:client)
{
    
PrintToChat(client"\x04[friendly] \x01Stopped");
    for(new 
userid 1userid <= MaxClientsuserid++)
    {
        
ServerCommand("sm_friendly %d 0"userid);
    }
    
timer_friendly[client] = false;
    
kCount[client] = 0;
    
kFirstKill[client] = 0;
}

public 
OnClientPutInServer(client)
{
    
kCount[client] = 0;
    
kFirstKill[client] = 0;
    
timer_friendly[client] = false;
}

public 
OnClientDisconnect(client)
{
    
kCount[client] = 0;
    
kFirstKill[client] = 0;
    
timer_friendly[client] = false;



ddhoward 02-16-2016 14:04

Re: Kills per second/ friendly mode
 
Friendly Mode has an inc file with natives... There is no reason to be using ServerCommand.

xines 02-16-2016 14:32

Re: Kills per second/ friendly mode
 
Quote:

Originally Posted by ddhoward (Post 2393500)
Friendly Mode has an inc file with natives... There is no reason to be using ServerCommand.

Okay, but since i mainly code for CS:S i don't frequently use friendly mode but friendly fire, yet i don't see the big deal with using ServerCommand instead of a native that points the same direction, guess this is just a preference to have.

PointlessFish 02-16-2016 14:49

Re: Kills per second/ friendly mode
 
@xines

Thanks so much for the code! I am not sure whether you have included the bit about killing bots? It looks like you have removed that fuctionality.

Do you think you could like add it in if it isn't too much to ask?

Thanks

Unless that is already done.

Edit: Code does not seem to work after compiling.
It doesn't put anyone into friendly.

PointlessFish 02-16-2016 16:44

Re: Kills per second/ friendly mode
 
Found out the actual base kBans plugin doesn't work. Does anyone know how to limit the kills per second?


All times are GMT -4. The time now is 11:02.

Powered by vBulletin®
Copyright ©2000 - 2022, vBulletin Solutions, Inc.