Raised This Month: $ Target: $400
 0% 

Hey Need help with my plugin.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nakashimakun
Senior Member
Join Date: Feb 2010
Location: England
Old 08-23-2010 , 10:24   Hey Need help with my plugin.
Reply With Quote #1

been working on a plugin and im stuck at a hurdle where some people would like it off and some would like it on. I was wondering if there was a way I could do this by like say:

sm_killon - Turns plugin on for player
sm_killoff - Turns plugin off for player.

I don't want it unloading I just want it so for the player who types sm_killoff it just disables it for him until he types sm_killon to re enable it for him. If you need me to be a little more clear about what I want I could try.
nakashimakun is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 08-23-2010 , 10:34   Re: Hey Need help with my plugin.
Reply With Quote #2

The easiest way will likely be as you suggested, register two commands (or even one and just toggle) that store a boolean flag for the client (true if on, false if off, default to true on connect). Then check if the flag == true in any area of your code that might interact with the client. If you want the data to be saved for future reconnects, you'll need to look into using Cookies.
__________________
thetwistedpanda is offline
nakashimakun
Senior Member
Join Date: Feb 2010
Location: England
Old 08-23-2010 , 10:39   Re: Hey Need help with my plugin.
Reply With Quote #3

Quote:
Originally Posted by thetwistedpanda View Post
The easiest way will likely be as you suggested, register two commands (or even one and just toggle) that store a boolean flag for the client (true if on, false if off, default to true on connect). Then check if the flag == true in any area of your code that might interact with the client. If you want the data to be saved for future reconnects, you'll need to look into using Cookies.
Want to help me impliment it as you lost me at the start... New to all this had a friend helping me before now im on my own lol.
nakashimakun is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 08-23-2010 , 10:49   Re: Hey Need help with my plugin.
Reply With Quote #4

If you'd post the source several people would probably take a shot at it.
__________________
thetwistedpanda is offline
nakashimakun
Senior Member
Join Date: Feb 2010
Location: England
Old 08-23-2010 , 10:55   Re: Hey Need help with my plugin.
Reply With Quote #5

okay I learnt how to do it from somebody elses code but I put it together. anyways I just need somebody to help me put the little on off thing in. would be awesome.

PHP Code:
#include <sourcemod>
#pragma semicolon 1
#define VERSION "0.0.1"

public Plugin:myinfo = {
    
name "Kill Counter",
    
author "NakashimaKun",
    
description "Counts up your kills and headshots.",
    
version VERSION,
    
url "N/A"
}

new 
Handle:counter=INVALID_HANDLE;
new 
kill_counts[MAXPLAYERS+1][3];

public 
OnPluginStart() {
    
//create new cvars
    
counter CreateConVar("counters""1""0: Off. 1: On. 2: Headshots only.",FCVAR_REPLICATED|FCVAR_GAMEDLL|FCVAR_NOTIFY,true,0.0,true,2.0);
    
    
//hook events
    
HookEvent("player_death"Event_Player_DeathEventHookMode_Pre);
    
    
AutoExecConfig(true,"Kill Counter");
}

public 
Action:Event_Player_Death(Handle:event, const String:name[], bool:dontBroadcast) {
    new 
attacker_userid GetEventInt(event"attacker");
    new 
attacker =  GetClientOfUserId(attacker_userid);
    new 
bool:headshot GetEventBool(event"headshot");
    
    if (
attacker == || GetClientTeam(attacker) == 1)
    {
        return 
Plugin_Continue;
    }
    
    
printkillinfo(attackerheadshot);
    
    return 
Plugin_Continue;
}

printkillinfo(attackerbool:headshot)
{
    new 
intbroad=GetConVarInt(counter);
    new 
murder;
    
    if ((
intbroad >= 1) && headshot)
    {
        
murder kill_counts[attacker][0];
        
        if(
murder>1)
        {
            
PrintHintText(attacker"HEADSHOTS +%d"murder);
        }
        else
        {
            
PrintHintText(attacker"HEADSHOT!");
        }
        
        
kill_counts[attacker][0] = murder+1;
    }
    else if (
intbroad == 1)
    {
        
murder kill_counts[attacker][1];
        
        if(
murder>=1)
        {
            
PrintHintText(attacker"KILLS +%d"murder);
        }
        else
        {
            
PrintHintText(attacker"KILL!");
        }
        
        
kill_counts[attacker][1] = murder+1;
    }

nakashimakun is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 08-23-2010 , 11:30   Re: Hey Need help with my plugin.
Reply With Quote #6

Hehe we all have to start somewhere after all. Although your code is reset per client connect (or rather, should be), I went ahead and wrote up the code using cookies so that the setting is persistent, meaning clients won't have to use the command every time they join.

You can then expand upon this code and even start saving the client's kills/deaths using the basic cookie system should you wish, but you wouldn't be able to work it into any type of ranking system. I haven't tested the code, but it compiled fine. Let me know if you get any errors and I'll fix them up.

PHP Code:
#include <sourcemod>
#include <clientprefs>

#pragma semicolon 1
#define VERSION "0.0.1"

public Plugin:myinfo =
{
    
name "Kill Counter",
    
author "NakashimaKun",
    
description "Counts up your kills and headshots.",
    
version VERSION,
    
url "N/A"
}

//Create a handle for your cookie.
new Handle:g_displayStatus;
new 
g_canDisplay[MAXPLAYERS+1];

new 
Handle:counter=INVALID_HANDLE;
new 
kill_counts[MAXPLAYERS+1][2];

public 
OnPluginStart()
{
    
//Register the cookie for the client; this will appear when a user types !settings
    
g_displayStatus RegClientCookie("Kill_Counter""Display Kill Counter"CookieAccess_Protected);
    
SetCookieMenuItem(Menu_Status0"Display Kill Counter");
    
    
//create new cvars
    
counter CreateConVar("counters""1""0: Off. 1: On. 2: Headshots only.",FCVAR_REPLICATED|FCVAR_GAMEDLL|FCVAR_NOTIFY,true,0.0,true,2.0);
    
AutoExecConfig(true"Kill_Counter");
    
    
//hook events
    
HookEvent("player_death"Event_Player_DeathEventHookMode_Pre);
    
    
//create command
    
RegConsoleCmd("sm_counter"Command_Counter);
}

//If for whatever reason something wiggy happens later, default the setting to on for the client first.
public OnClientConnected(client)
{
    
g_canDisplay[client] = 1;
}

//Called after the player has been authorized and fully in-game
public OnClientPostAdminCheck(client)
{
    
//Check to ensure the clients are cached from the database before using them
    
if (AreClientCookiesCached(client))
    {
        
//Get the content of the cookie and store it into a string
        
decl String:cookie[3];
        
GetClientCookie(clientg_displayStatuscookiesizeof(cookie));
        
        
//Check to see if there is any data in the cookie, and if not, set the default value to on (1)
        
if (StrEqual(cookie""))
                {
            
SetClientCookie(clientg_displayStatus"1");
                        
cookie "1";
                }
        
        
//Throw their status into a cvar, so that the plug-in doesn't have to keep checking the client's cookie
        
g_canDisplay[client] = StringToInt(cookie);
    }
}

public 
Action:Event_Player_Death(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
attacker =  GetClientOfUserId(GetEventInt(event"attacker"));
    
    
//Only process if the player is a legal attacker (i.e., a player)
    
if(attacker <= MaxClients)
    {
        new 
bool:headshot GetEventBool(event"headshot");
        
printkillinfo(attackerheadshot);
    }

    return 
Plugin_Continue;
}

printkillinfo(attackerbool:headshot)
{
    new 
intbroad GetConVarInt(counter);
    new 
murder;
    
    if ((
intbroad >= 1) && headshot)
    {
        
murder kill_counts[attacker][0];
        
        
//Only display if they want it
        
if(g_canDisplay[attacker])
        {
            if(
murder>1)
                
PrintHintText(attacker"HEADSHOTS +%d"murder);
            else
                
PrintHintText(attacker"HEADSHOT!");
        }
        
        
kill_counts[attacker][0] = murder+1;
    }
    else if (
intbroad == 1)
    {
        
murder kill_counts[attacker][1];
        
        
//Only display if they want it
        
if(g_canDisplay[attacker])
        {
            if(
murder>=1)
                
PrintHintText(attacker"KILLS +%d"murder);
            else
                
PrintHintText(attacker"KILL!");
        }
        
        
kill_counts[attacker][1] = murder+1;
    }
}

//The code that is fired should a client type !counter or /counter in chat, or sm_counter in console
public Action:Command_Counter(clientargs)
{
    
//Since their status is already saved, use it to determine the change
    
if(g_canDisplay[client])
    {
        
//Display is on, they want off
        
SetClientCookie(clientg_displayStatus"0");
        
PrintToChat(client"Yo what up with you, you don't like my counter? Fine then, I'll hide it from you");
    }
    else
    {
        
//Display is off, turn on
        
SetClientCookie(clientg_displayStatus"1");
        
PrintToChat(client"You love my counter, don't you? Admit it! I shall show it to you then!");
    }
}

//Used for showing the client their counter status should they type !settings
public Menu_Status(clientCookieMenuAction:actionany:infoString:buffer[], maxlen
{
    if (
action == CookieMenuAction_DisplayOption)
        
Format(buffermaxlen"Display Counter Setting");
    else if (
action == CookieMenuAction_SelectOption)
        
CreateMenuStatus(client);
}

//Menu that appears when a user types !settings
stock CreateMenuStatus(client)
{
    new 
Handle:menu CreateMenu(Menu_StatusDisplay);
    
decl String:text[64];

    
//The title of the menu
    
Format(textsizeof(text), "Counter Setting");
    
SetMenuTitle(menutext);

    
//Since their status is already saved, use it to determine the change
    
if(g_canDisplay[client])
        
AddMenuItem(menu"Kill_Counter""Counter ~ Enabled!"ITEMDRAW_DISABLED);
    else
        
AddMenuItem(menu"Kill_Counter""Counter ~ Disabled!"ITEMDRAW_DISABLED);

    
//Give the menu a back button, and make it display on the client
    
SetMenuExitBackButton(menutrue);
    
SetMenuExitButton(menutrue);
    
DisplayMenu(menuclient15);
}

//Determines if the menu should be opened or closed (i.e. if the client types !settings twice)
public Menu_StatusDisplay(Handle:menuMenuAction:actionparam1param2)
{
    new 
client param1;
    switch (
action)
    {
        case 
MenuAction_Cancel
        {
            switch (
param2
            {
                case 
MenuCancel_ExitBack:
                {
                    
ShowCookieMenu(client);
                }
            }
        }
        case 
MenuAction_End
        {
            
CloseHandle(menu);
        }
    }

__________________

Last edited by thetwistedpanda; 08-23-2010 at 11:32.
thetwistedpanda is offline
nakashimakun
Senior Member
Join Date: Feb 2010
Location: England
Old 08-23-2010 , 11:32   Re: Hey Need help with my plugin.
Reply With Quote #7

okay I'll try it on my server now. Would you like to join me and see if it works how it should?
nakashimakun is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 08-23-2010 , 11:34   Re: Hey Need help with my plugin.
Reply With Quote #8

Sure if you want, not doing anything atm.
__________________
thetwistedpanda is offline
dYZER
Member
Join Date: Jan 2010
Location: Germany
Old 08-23-2010 , 11:37   Re: Hey Need help with my plugin.
Reply With Quote #9

PHP Code:
#include sourcemod
#include sdktools

#pragma semicolon 1
#define VERSION "0.0.1"

public Plugin:myinfo = {
    
name "Kill Counter",
    
author "NakashimaKun",
    
description "Counts up your kills and headshots.",
    
version VERSION,
    
url "N/A"
}

new 
Handle:counter=INVALID_HANDLE;
new 
kill_counts[MAXPLAYERS+1][3];

public 
OnPluginStart() {
    
//create new cvars
    
counter CreateConVar("counters""1""0: Off. 1: On. 2: Headshots only.",FCVAR_REPLICATED|FCVAR_GAMEDLL|FCVAR_NOTIFY,true,0.0,true,2.0);
    
    
//hook events
    
HookEvent("player_death"Event_Player_DeathEventHookMode_Pre);

    
RegConsoleCmd("say"Command_Say);
    
RegConsoleCmd("say_team"Command_Say);
    
//RegConsoleCmd("sm_killon",infon);
    //RegConsoleCmd("sm_killoff",infoff);
    
    
    
AutoExecConfig(true,"KillCounter");
}

public 
Action:Command_Say(clientargs)
{
    if(!
client) return Plugin_Continue;
    
decl String:text[192];
    if(!
GetCmdArgString(textsizeof(text))) return Plugin_Continue;
    new 
startidx 0;
    if(
text[strlen(text)-1] == '"')
    {
        
text[strlen(text)-1] = '\0';
        
startidx 1;
        }
    if(
strcmp(text[startidx], "!killon"false) == 0infon(clientargs);
    if(
strcmp(text[startidx], "!killoff"false) == 0infoff(clientargs);
    return 
Plugin_Continue;
}
public 
Action:infon(clientargs)
{
//[2] was unused
    
kill_counts[client][2] = 1;
}
public 
Action:infoff(clientargs)
{
    
kill_counts[client][2] = 0;
}
public 
OnClientPutInServer(client)
{
//set default on
    
if (client && !IsFakeClient(client)) { kill_counts[client][2] = 1; }
}

public 
Action:Event_Player_Death(Handle:event, const String:name[], bool:dontBroadcast) {
    new 
attacker_userid GetEventInt(event"attacker");
    new 
attacker =  GetClientOfUserId(attacker_userid);
    new 
bool:headshot GetEventBool(event"headshot");
    
    if (
attacker == || GetClientTeam(attacker) == 1)
    {
        return 
Plugin_Continue;
    }
    
    if (
kill_counts[attacker][2]==1) { printkillinfo(attackerheadshot); }

    
    return 
Plugin_Continue;
}

printkillinfo(attackerbool:headshot)
{
    new 
intbroad=GetConVarInt(counter);
    new 
murder;
    
    if ((
intbroad >= 1) && headshot)
    {
        
murder kill_counts[attacker][0];
        
        if(
murder>1)
        {
           
PrintHintText(attacker"HEADSHOTS +%d"murder); 
        }
        else
        {
            
PrintHintText(attacker"HEADSHOT!"); 
        }
        
        
kill_counts[attacker][0] = murder+1;
    }
    else if (
intbroad == 1)
    {
        
murder kill_counts[attacker][1];
        
        if(
murder>=1)
        {
            
PrintHintText(attacker"KILLS +%d"murder);
        }
        else
        {
           
PrintHintText(attacker"KILL!");
        }
        
        
kill_counts[attacker][1] = murder+1;
    }

ur on//off chat request hf
dYZER is offline
nakashimakun
Senior Member
Join Date: Feb 2010
Location: England
Old 08-23-2010 , 11:39   Re: Hey Need help with my plugin.
Reply With Quote #10

Quote:
Originally Posted by thetwistedpanda View Post
Sure if you want, not doing anything atm.
Cool my steamID is nakashimakun
nakashimakun 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 17:56.


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