View Single Post
Mr. Zero
Veteran Member
Join Date: Jun 2009
Location: Denmark
Old 02-17-2011 , 18:02   [L4D1/2] Vocalize Fatigue 2
Reply With Quote #3

How to use filter config files:

Vocalize Fatigue supports two filter modes; blacklist or whitelist.

With blacklist, all vocalizations that are defined in the blacklist filter file, will be blocked from usage while all other vocalizations are allowed.
Whitelist of course works the other way around, all vocalizations defined in whitelist will be allowed while anything else will be blocked.

Using those files you can control exactly what vocalizations are allowed on your server.

How to use the filter files is quite simple. Each line in the file represents a vocalize string. So for example in the blacklist you would have this:

Code:
// Comments starts with two forward slashes
PlayerDeath
PlayerUseAdrenaline // Inlined comments are also allowed
That was players are no longer allowed to use those 2 vocalizations. And that is pretty much it.
Then you just change the filter mode cvar to choose which one you want active. I personally recommend the whitelist mode.

How to use fatigue config file:

Instead of the old Vocalize Fatigue where it would simply capture the vocalize command and block if the player called it too often, in this version we add fatigue to the player after using a vocalization.
In other words after a player have vocalized, he will suffer from fatigue from that vocalization.

For example, lets say the vocalization PlayerLaugh have a fatigue of 10 seconds. After a player have vocalize PlayerLaugh they would be unable to vocalize for another 10 seconds.
Each vocalization have it's own fatigue (if not default fatigue will be applied).

To add vocalize fatigue to a vocalization you simply type the vocalize string, add a semicolon and then how many seconds. As from the example above, here is how it would look in the fatigue config file:

Code:
PlayerLaugh:10.0
Now the player have to wait 10 seconds between each laugh.
You can use 1.0, 0.67 or 3842.399 seconds. It's really up to you how much fatigue you want to apply.
I have already included the fatigue config file and added fatigue for vocalizations as I deemed fitting, but don't be afraid of poke around and change them.

Natives and Forwards (as of version 2.1.0)

So with version 2.1.0 Vocalize Fatigue offers natives and forwards for other plugins to use.

The include file is both in the release and source package. However just for good manner here is the list.

Include file:
PHP Code:
/**
 * @brief Called on a client vocalizes.
 *
 * @param client        Client index doing the vocalization.
 * @param vocalize        Vocalize string, always lower case.
 * @param byPlugin        Whether it was initialized by a plugin.
 * @return                Plugin_Handled to stop vocalization, anything else to 
 *                        allow vocalization.
 */
forward Action:L4D_OnClientVocalize(client, const String:vocalize[], bool:byPlugin);

/**
 * @brief Called on post client vocalization.
 *
 * @param client        Client index that did the vocalization.
 * @param vocalize        Vocalize string, always lower case.
 * @param byPlugin        Whether it was initialized by a plugin.
 * @noreturn
 */
forward L4D_OnClientVocalize_Post(client, const String:vocalize[], bool:byPlugin);

/**
 * @brief Makes the client vocalize.
 * @remarks This will mark the vocalization as initialized by a plugin.
 *
 * @param client        Client index that will do the vocalization.
 * @param vocalize        Vocalize string, case insensitive.
 * @noreturn
 */
native L4D_MakeClientVocalize(client, const String:vocalize[]);

/**
 * @brief Makes the client vocalize.
 * @remarks This will not mark the vocalization as initialized by a plugin.
 *            Therefore it will be subject to normal filters.
 *
 * @param client        Client index that will do the vocalization.
 * @param vocalize        Vocalize string, case insensitive.
 * @noreturn
 */
native L4D_MakeClientVocalizeEx(client, const String:vocalize[]);

/**
 * @brief Forces a client to vocalize a certain scene.
 *
 * @param client        Client index that will do the vocalization.
 * @param scene            Scene name.
 * @noreturn
 */
native L4D_MakeClientVocalizeScene(client, const String:scene[]); 
Using the forwards and natives above you can control pretty much all vocalization that are initialized by players.

In this post I will show off 3 example scripts. Remember these are example, so don't use them for your server. They are for playing with, not for a real server environment.

Anyway.

Example Plugin 1: I feel funny...

This plugin makes the Survivor laugh for a bit after having eating pills. Seems those pills come with a side effect. You can't stop laughing for some reason.

PHP Code:
#include <sourcemod>
#include "vocalizefatigue"

static    const             MAX_FUNNY_TICKS 10;
static            
bool:    g_bFeelingFunny[MAXPLAYERS 1];
static            
Handle:    g_hTimer[MAXPLAYERS 1];
static                    
g_iTicks[MAXPLAYERS 1];

public 
Plugin:myinfo 
{
    
name "I feel funny...",
    
author "Mr. Zero",
    
description "... ha-ha funny",
    
version "1.0",
    
url "[email protected]"
}

public 
OnPluginStart()
{
    
HookEvent("pills_used"OnPillsUsed_Event);
}

public 
OnClientDisconnect(client)
{
    
g_bFeelingFunny[client] = false;
}

public 
OnPillsUsed_Event(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if (
client == || !IsClientInGame(client)) return;

    if (
g_bFeelingFunny[client])
    {
        
CloseHandle(g_hTimer[client]);
    }
    
g_bFeelingFunny[client] = true;
    
g_iTicks[client] = 0;
    
g_hTimer[client] = CreateTimer(2.0Drug_TimerclientTIMER_REPEAT);
}

public 
Action:Drug_Timer(Handle:timerany:client)
{
    if (!
IsClientInGame(client))
    {
        
g_bFeelingFunny[client] = false;
        return 
Plugin_Stop;
    }

    
g_iTicks[client]++;
    if (
g_iTicks[client] > MAX_FUNNY_TICKS)
    {
        
g_bFeelingFunny[client] = false;
        return 
Plugin_Stop;
    }

    new 
luck GetRandomInt(010);
    if (
luck 7)
    {
        return 
Plugin_Continue;
    }

    
L4D_MakeClientVocalize(client"playerlaugh");

    return 
Plugin_Continue;

This will cause a Survivor to laugh randomly after eating some pills for about 20 seconds.
Next time make sure to read the description before eat ALL of the pills in the bottle!

Example plugin 2: Death to deathscreamers!

I'm sure you hate death screaming as much as I do. So why not make the death scream a truly scream of death?

PHP Code:
#include <sourcemod>
#include <sdktools>
#include "vocalizefatigue"

public Plugin:myinfo 
{
    
name "Death to death screamers",
    
author "Mr. Zero",
    
description "Nope.",
    
version "1.0",
    
url "[email protected]"
}

public 
OnPluginStart()
{
    
/* */
}

public 
Action:L4D_OnClientVocalize(client, const String:vocalize[], bool:byPlugin)
{
    if (
byPlugin) return Plugin_Continue// We only punish the client if they called it them self

    
if (StrEqual(vocalize"playerdeath"))
    {
        
SetEntityHealth(client1);
        
decl Float:newVel[3];
        
newVel[0] = GetRandomFloat(50.0150.0);
        
newVel[1] = GetRandomFloat(50.0150.0);
        
newVel[2] = 700.0;
        
TeleportEntity(clientNULL_VECTORNULL_VECTORnewVel);

        
L4D_MakeClientVocalize(client"playerno");
        return 
Plugin_Handled;
    }

    return 
Plugin_Continue;

This will launch death screams into the air while setting their health to 1. That should learn them to not to death scream!

Enjoy your flight.

Example plugin 3: Vocalize chat triggers

This simply hooks chat and make the Survivors vocalize what the client typed in chat.

PHP Code:
#include <sourcemod>
#include "vocalizefatigue"

public Plugin:myinfo 
{
    
name "Vocalize Chat Triggers",
    
author "Mr. Zero",
    
description "Chat triggers for vocalization",
    
version "1.0",
    
url "[email protected]"
}

public 
OnPluginStart()
{
    
HookEvent("player_say"OnPlayerSay_Event);
}

public 
OnPlayerSay_Event(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if (
client == || !IsClientInGame(client)) return;

    
decl String:buffer[128];
    
GetEventString(event"text"buffersizeof(buffer));
    if (
StrContains(buffer"thanks"false) != -||
        
StrContains(buffer"thank you"false) != -||
        
StrContains(buffer"thx"false) != -1)
    {
        
L4D_MakeClientVocalize(client"playerthanks");
        return;
    }

    if (
StrContains(buffer"sorry"false) != -||
        
StrContains(buffer"sry"false) != -1)
    {
        
L4D_MakeClientVocalize(client"playersorry");
        return;
    }

    if (
StrContains(buffer"!buy"false) != -1)
    {
        
L4D_MakeClientVocalize(client"playertaunt");
        return;
    }

For example when the player says sorry in chat, the survivor will vocalize it too.

Feel free to suggest changes or other natives if you happen to need it ;3

Last edited by Mr. Zero; 03-03-2011 at 20:00.
Mr. Zero is offline