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

[L4D2] Help to Users Enable/Disable Plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
diorfo
Member
Join Date: Dec 2013
Old 05-21-2017 , 13:37   [L4D2] Help to Users Enable/Disable Plugin
Reply With Quote #1

Hello,

I just developed the plugin below to show in chat to players who they killed in game also from who they got killed.

I just like to let it in a way that players can enable and disable these chat messages (kind of !kd chat command).

Can someone please help me with this?

I know it's simple but i don't know how to do.

PHP Code:
#include <sourcemod>
#include <clients>
#include <colors>

// plugin information

public Plugin:myinfo 
{
    
name "kill-death chat actions",
    
author "diorfo",
    
description "kill-death chat actions",
    
version "1.0",
    
url ""
};


public 
OnPluginStart() 
{
    
    
HookEvent("player_death"Event_L4DPlayerDeath);

}

public 
Event_L4DPlayerDeath(Handleevent, const Stringname[], bool:dontBroadcast)
{    
    new 
victim   GetClientOfUserId(GetEventInt(event"userid"));
    
decl String:nickv[64];
    
GetClientName(victimnickvsizeof(nickv))
    new 
attacker GetClientOfUserId(GetEventInt(event"attacker"));
    
decl String:nicka[64];    
    
GetClientName(attackernickasizeof(nicka))
    
    if (
GetClientTeam(victim) == GetClientTeam(attacker))
    {
        
PrintToChat(attacker"\x05[Custom Maps 4fun] \x01Você matou com TK \x04%s"nickv);            
        
PrintToChat(victim"\x05[Custom Maps 4fun] \x01Você morreu por TK de \x04%s"nicka);            
        return 
Plugin_Stop;
    }
    
    if ((
victim 0) && (attacker 0) && (attacker != victim)) 
    {        
        new 
headshot GetEventBool(event"headshot");
        if (
headshot == 1
        {        
            
PrintToChat(attacker"\x05[Custom Maps 4fun] \x01Você matou no headshot \x04%s"nickv);            
            
PrintToChat(victim"\x05[Custom Maps 4fun] \x01Você morreu para \x04%s"nicka);            
            return 
Plugin_Stop;
        }    
        
        
PrintToChat(attacker"\x05[Custom Maps 4fun] \x01Você matou \x04%s"nickv);    
        
PrintToChat(victim"\x05[Custom Maps 4fun] \x01Você morreu para \x04%s"nicka);    
        return 
Plugin_Stop;
    }
    

diorfo is offline
africanspacejesus
Senior Member
Join Date: Nov 2016
Location: Bay Area, CA
Old 05-21-2017 , 16:33   Re: [L4D2] Help to Users Enable/Disable Plugin
Reply With Quote #2

I would use a cookie for every player to keep track of this and keep the settings. Try setting a value for the cookie when a player uses that command and then check that when the player kills someone, lemme know if you need actual code
__________________
Taking paid plugin requests
africanspacejesus is offline
diorfo
Member
Join Date: Dec 2013
Old 05-21-2017 , 18:23   Re: [L4D2] Help to Users Enable/Disable Plugin
Reply With Quote #3

Quote:
Originally Posted by africanspacejesus View Post
I would use a cookie for every player to keep track of this and keep the settings. Try setting a value for the cookie when a player uses that command and then check that when the player kills someone, lemme know if you need actual code
I don't know how to do that.

I apreciate if you could give me an example.
diorfo is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 05-21-2017 , 19:19   Re: [L4D2] Help to Users Enable/Disable Plugin
Reply With Quote #4

Use a simple global variable to keep track of the toggle.

PHP Code:
bool g_bCanUse[MAXPLAYERS 1];

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_toggle"Command_Toggle"Toggle");
}

public 
void OnClientPutInServer(int client)
{
    
g_bCanUse[client] = false;
}

public 
Action Command_Toggle(int clientint args)
{
    
g_bCanUse[client] = !g_bCanUse[client];
    
ReplyToCommand(client"You have %s this command!"g_bCanUse[client] ? "enabled" "disabled");
}

//some random function
public void myfunction()
{
    if (
g_bCanUse)
    {
        
//The toggle is enabled
    
}

__________________
Chaosxk is offline
diorfo
Member
Join Date: Dec 2013
Old 05-21-2017 , 20:12   Re: [L4D2] Help to Users Enable/Disable Plugin
Reply With Quote #5

i tried to make work with my above code but it's more dificult than i thought

i don't know how to link the command of players with event player_death

Last edited by diorfo; 05-21-2017 at 21:31.
diorfo is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 05-21-2017 , 21:50   Re: [L4D2] Help to Users Enable/Disable Plugin
Reply With Quote #6

Something like this:

PHP Code:
public Event_L4DPlayerDeath(Handleevent, const Stringname[], bool:dontBroadcast
{     
    new 
attacker GetClientOfUserId(GetEventInt(event"attacker"));
    
    if (!
g_bCanUse[attacker])
        return 
Plugin_Continue;
        
    new 
victim GetClientOfUserId(GetEventInt(event"userid")); 
    
    
decl String:nickv[64]; 
    
GetClientName(victimnickvsizeof(nickv))     
    
decl String:nicka[64];     
    
GetClientName(attackernickasizeof(nicka))
    
    
//Rest of your other code down here
    
    
    
    
return Plugin_Continue;

__________________
Chaosxk is offline
diorfo
Member
Join Date: Dec 2013
Old 05-21-2017 , 23:53   Re: [L4D2] Help to Users Enable/Disable Plugin
Reply With Quote #7

Quote:
Originally Posted by Chaosxk View Post
Something like this:

PHP Code:
public Event_L4DPlayerDeath(Handleevent, const Stringname[], bool:dontBroadcast
{     
    new 
attacker GetClientOfUserId(GetEventInt(event"attacker"));
    
    if (!
g_bCanUse[attacker])
        return 
Plugin_Continue;
        
    new 
victim GetClientOfUserId(GetEventInt(event"userid")); 
    
    
decl String:nickv[64]; 
    
GetClientName(victimnickvsizeof(nickv))     
    
decl String:nicka[64];     
    
GetClientName(attackernickasizeof(nicka))
    
    
//Rest of your other code down here
    
    
    
    
return Plugin_Continue;

thank you for supporting.

I tried like above and only works enable/disable when you are attacker.

When you are a victim only enable/disable function works if you change the code to if (!g_bCanUse[victim]) but by effect doesn't work when you are attacker.

I tried to use the operator OR if (!g_bCanUse[victim] || !g_bCanUse[attacker]) but doesn't work either.

Any idea to works for both attacker and victim?
diorfo is offline
diorfo
Member
Join Date: Dec 2013
Old 05-22-2017 , 19:03   Re: [L4D2] Help to Users Enable/Disable Plugin
Reply With Quote #8

With little modification below on code the plugin it's now working properly.

Thanks for supporting.

PHP Code:
#include <sourcemod>
#include <clients>
#include <colors>

// plugin information

public Plugin:myinfo 
{
    
name "kill-death chat actions",
    
author "diorfo",
    
description "kill-death chat actions",
    
version "1.0",
    
url ""
};

bool g_bCanUse[MAXPLAYERS 1];

public 
void OnPluginStart()
{    
    
HookEvent("player_death"Event_L4DPlayerDeath);
    
RegConsoleCmd("sm_kdc"Command_kd"Show Hide Kills and Deaths on chat");    
}

public 
void OnClientPutInServer(int client)
{
    
PrintToChat(client"\x04Digite \x01!kdc \x04para desabilitar ou habilitar as mensagens no chat de suas kills e mortes");
}

public 
Action Command_kd(int clientint args)
{
    
g_bCanUse[client] = !g_bCanUse[client];
    
ReplyToCommand(client"Você %s o aviso no chat de suas kills e mortes"g_bCanUse[client] ? "habilitou" "desabilitou");
}

public 
Event_L4DPlayerDeath(Handleevent, const Stringname[], bool:dontBroadcast)
{            
    new 
victim GetClientOfUserId(GetEventInt(event"userid"));
    
decl String:nickv[64]; 
    
GetClientName(victimnickvsizeof(nickv))
    
    new 
attacker GetClientOfUserId(GetEventInt(event"attacker"));
    
decl String:nicka[64];     
    
GetClientName(attackernickasizeof(nicka))
    
    if (
g_bCanUse[victim])
    {
        if (
GetClientTeam(victim) == GetClientTeam(attacker))
        {
        
        }
    
        if ((
victim 0) && (attacker 0) && (attacker != victim)) 
        {        
        new 
headshot GetEventBool(event"headshot");
        if (
headshot == 1
            {                            
            
PrintToChat(victim"\x05[Custom Maps 4fun] \x01Você morreu para \x04%s"nicka);            
            return 
Plugin_Stop;
            }    
        
        
PrintToChat(victim"\x05[Custom Maps 4fun] \x01Você morreu para \x04%s"nicka);    
        return 
Plugin_Stop;
        }    
    }
    
    if (
g_bCanUse[attacker])
    {
        if (
GetClientTeam(victim) == GetClientTeam(attacker))
        {
        
        }
    
        if ((
victim 0) && (attacker 0) && (attacker != victim)) 
        {        
        new 
headshot GetEventBool(event"headshot");
        if (
headshot == 1
            {                            
            
PrintToChat(attacker"\x05[Custom Maps 4fun] \x01Você matou no headshot \x04%s"nickv);            
            return 
Plugin_Stop;
            }    
        
        
PrintToChat(attacker"\x05[Custom Maps 4fun] \x01Você matou \x04%s"nickv);    
        return 
Plugin_Stop;
        }        
        
    }
return 
true;    

diorfo 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 10:25.


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