Raised This Month: $51 Target: $400
 12% 

all the kills


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nhnkl159
Senior Member
Join Date: Jul 2012
Location: Israel 3>
Old 08-27-2015 , 14:50   all the kills
Reply With Quote #1

This is my code the idea of the code is to see all the death/kills on the round :

Code:
#pragma semicolon 1

#define DEBUG
#pragma tabsize 0

#include <sourcemod>
#include <sdktools>
#include <colors>
new String:attackersname[MAXPLAYERS+1][MAX_NAME_LENGTH];
new String:victimsname[MAXPLAYERS+1][MAX_NAME_LENGTH];
bool Dead = false;

public void OnPluginStart()
{
	RegAdminCmd("sm_viewkills", Cmd_ViewKills, ADMFLAG_BAN, "View Kills");
	HookEvent("player_death", Event_PlayerDeath);
	HookEvent("round_start", Event_RoundsStart);
}


public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast){

	GetClientName(GetClientOfUserId(GetEventInt(event, "attacker")), attackersname[GetClientOfUserId(GetEventInt(event, "userid"))], MAX_NAME_LENGTH);
	GetClientName(GetClientOfUserId(GetEventInt(event, "userid")), victimsname[GetClientOfUserId(GetEventInt(event, "userid"))], MAX_NAME_LENGTH);
	Dead = true;

}

public MenuViewkills(Handle:menu, MenuAction:action, param1, param2)
{
    if (action == MenuAction_Select) 
    {
        new String:info[32];
        
        GetMenuItem(menu, param2, info, sizeof(info));
        
    }
    else if (action == MenuAction_Cancel)
    {
        CloseHandle(menu);
    }
}

public Action:Cmd_ViewKills(client, args)
{
	if(Dead == true)
	{
	new String:Buffer[MAX_NAME_LENGTH];
	Menu menu = new Menu(MenuViewkills);
	menu.SetTitle("ViewKills Menu :");
  	Format(Buffer, sizeof(Buffer), "%s Was Killed By %s", victimsname[client], attackersname[client]);
    AddMenuItem(menu, "%s", Buffer); 
	menu.ExitButton = true;
	menu.Display(client, 20);
	} else {
		CPrintToChat(client, "[Viewkills] Non Player Was Dead.");
	}
	
	
}

public Action:Event_RoundsStart(Handle:event, const String:name[], bool:dontBroadcast)
{
	Dead = false;
}

i was try to change the userid to victim and try all but the same..

when i do userid its write :
"Name was killed by name" {same person}

and when i do victim :
"{nothing} was killed by {nothing}"

Can Someone chek the code ?
__________________
nhnkl159 is offline
Send a message via Skype™ to nhnkl159
Mehis
Senior Member
Join Date: Mar 2013
Location: basement
Old 08-27-2015 , 15:07   Re: all the kills
Reply With Quote #2

PHP Code:
public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    
// There is no reason to keep calling GetClientOfUserId().
    
int victim GetClientOfUserId(GetEventInt(event"userid"));
    
    
// You'll have to check if the players exist.
    
if (victim == 0)
    {
        return;
    }
    
    
    
int attacker GetClientOfUserId(GetEventInt(event"attacker"));
    
    if (
attacker != 0)
    {
        
// Attacker is a player.
        
GetClientName(attackerattackersname[victim], sizeof(attackersname[]));
    }
    else
    {
        
// Attacker not a player.
        
strcopy(attackersname[victim], sizeof(attackersname[]), "World");
    }

    
GetClientName(victimvictimsname[victim], sizeof(victimsname[]));

Not sure what you mean by this:
PHP Code:
bool Dead false
But it should probably be:
PHP Code:
bool Dead[MAXPLAYERS]; // FYI, booleans are by default false. 

Last edited by Mehis; 08-27-2015 at 15:26. Reason: ups
Mehis is offline
nhnkl159
Senior Member
Join Date: Jul 2012
Location: Israel 3>
Old 08-27-2015 , 15:39   Re: all the kills
Reply With Quote #3

Quote:
Originally Posted by Mehis View Post
PHP Code:
public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    
// There is no reason to keep calling GetClientOfUserId().
    
int victim GetClientOfUserId(GetEventInt(event"userid"));
    
    
// You'll have to check if the players exist.
    
if (victim == 0)
    {
        return;
    }
    
    
    
int attacker GetClientOfUserId(GetEventInt(event"attacker"));
    
    if (
attacker != 0)
    {
        
// Attacker is a player.
        
GetClientName(attackerattackersname[victim], sizeof(attackersname[]));
    }
    else
    {
        
// Attacker not a player.
        
strcopy(attackersname[victim], sizeof(attackersname[]), "World");
    }

    
GetClientName(victimvictimsname[victim], sizeof(victimsname[]));

Not sure what you mean by this:
PHP Code:
bool Dead false
But it should probably be:
PHP Code:
bool Dead[MAXPLAYERS]; // FYI, booleans are by default false. 
thx !

now the code is :

Code:
#pragma semicolon 1

#define DEBUG
#pragma tabsize 0

#include <sourcemod>
#include <sdktools>
#include <colors>
new String:attackersname[MAXPLAYERS+1][MAX_NAME_LENGTH];
new String:victimsname[MAXPLAYERS+1][MAX_NAME_LENGTH];


public void OnPluginStart()
{
	RegAdminCmd("sm_kills", Cmd_ViewKills, ADMFLAG_BAN, "View Kills");
	HookEvent("player_death", Event_PlayerDeath);
}


public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    // There is no reason to keep calling GetClientOfUserId().
    int victim = GetClientOfUserId(GetEventInt(event, "userid"));
    
    // You'll have to check if the players exist.
    if (victim == 0)
    {
        return;
    }
    
    
    int attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
    
    if (attacker != 0)
    {
        // Attacker is a player.
        GetClientName(attacker, attackersname[victim], sizeof(attackersname[]));
    }
    else
    {
        // Attacker not a player.
        strcopy(attackersname[victim], sizeof(attackersname[]), "World");
    }

    GetClientName(victim, victimsname[victim], sizeof(victimsname[]));
}  

public MenuViewkills(Handle:menu, MenuAction:action, param1, param2)
{
    if (action == MenuAction_Select) 
    {
        new String:info[32];
        
        GetMenuItem(menu, param2, info, sizeof(info));
        
    }
    else if (action == MenuAction_Cancel)
    {
        CloseHandle(menu);
    }
}

public Action:Cmd_ViewKills(client, args)
{

	new String:Buffer[MAX_NAME_LENGTH];
	Menu menu = new Menu(MenuViewkills);
	menu.SetTitle("ViewKills Menu :");
  	Format(Buffer, sizeof(Buffer), "%s Was Killed By %s", victimsname[client], attackersname[client]);
    AddMenuItem(menu, "%s", Buffer); 
	menu.ExitButton = true;
	menu.Display(client, 20);
	
	
}
and when i do !kills i see {nothing} was killed by {nothing}..
__________________
nhnkl159 is offline
Send a message via Skype™ to nhnkl159
nhnkl159
Senior Member
Join Date: Jul 2012
Location: Israel 3>
Old 08-28-2015 , 03:06   Re: all the kills
Reply With Quote #4

Still Need Help :/
__________________
nhnkl159 is offline
Send a message via Skype™ to nhnkl159
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 08-28-2015 , 05:28   Re: all the kills
Reply With Quote #5

You didn't save the names properly, your using client indexes which isn't right. You want to save it in an array that you can keep tabs on (e.g 0, 1, 2, 3 ... so on).

Try this one i whipped up quickly, it uses adt_arrays instead of regular arrays since its a bit easier to manage. Added some comments to it so hopefully you will understand.

Code:
#pragma semicolon 1

#define DEBUG
#pragma tabsize 0

#include <sourcemod>
#include <sdktools>
//#include <colors>

//Creates the array handles
new Handle:attacker_array = INVALID_HANDLE;
new Handle:victim_array = INVALID_HANDLE;


public void OnPluginStart()
{
	RegAdminCmd("sm_kills", Cmd_ViewKills, ADMFLAG_BAN, "View Kills");
	HookEvent("player_death", Event_PlayerDeath);
	
	//Creates the array for the handles
	attacker_array = CreateArray();
	victim_array = CreateArray();
}


public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    // There is no reason to keep calling GetClientOfUserId().
    int victim = GetClientOfUserId(GetEventInt(event, "userid"));
    
    // You'll have to check if the players exist.
    if (victim == 0)
    {
        return;
    }
    
    int attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
	
    //Maximum number of names to store, set to 10 will only save and show 10 names
    //This is to prevent the array from saving too much names and taking up memory
    new max_array_size = 10;
    if(GetArraySize(attacker_array) > max_array_size-1) 
    {
        RemoveFromArray(attacker_array, 0);
    }
	//does the same thing but with victims name
    if(GetArraySize(victim_array) > max_array_size-1) 
    {
    RemoveFromArray(victim_array, 0);
    }
	
    if (attacker != 0)
    {
        // Attacker is a player.
        decl String:attackersname[32];
        GetClientName(attacker, attackersname, sizeof(attackersname));
        //Pushes the attackers name into the attacker_array handle
        PushArrayString(attacker_array, attackersname);
    }
    else
    {
        // Attacker not a player.
        PushArrayString(attacker_array, "World");
    }
    decl String:victimsname[32];
    GetClientName(victim, victimsname, sizeof(victimsname));
    //Pushes the victim name into victim_array handle
    PushArrayString(victim_array, victimsname);
}  

public MenuViewkills(Handle:menu, MenuAction:action, param1, param2)
{
    if (action == MenuAction_Select) 
    {
        new String:info[32];
        
        GetMenuItem(menu, param2, info, sizeof(info));
        
    }
    else if (action == MenuAction_Cancel)
    {
        CloseHandle(menu);
    }
}

public Action:Cmd_ViewKills(client, args)
{
	new String:Buffer[MAX_NAME_LENGTH];
	decl String:attackersname[32], String:victimsname[32];
	Menu menu = new Menu(MenuViewkills);
	menu.SetTitle("ViewKills Menu :");
	//size of attacker_array and victim_array should always be the same
	//loops from 1st attackers/victims name to the last
	for(new i = 0; i < GetArraySize(attacker_array); i++) 
	{
        //Retrieve the names from the arrays
        GetArrayString(attacker_array, i, attackersname, sizeof(attackersname));
        GetArrayString(victim_array, i, victimsname, sizeof(victimsname));
        Format(Buffer, sizeof(Buffer), "%s Was Killed By %s", victimsname, attackersname);
        AddMenuItem(menu, "%s", Buffer);
		//PrintToServer("%s", Buffer);
	}
	menu.ExitButton = true;
	menu.Display(client, 20);
}
__________________

Last edited by Chaosxk; 08-28-2015 at 05:34.
Chaosxk is offline
nhnkl159
Senior Member
Join Date: Jul 2012
Location: Israel 3>
Old 08-29-2015 , 01:13   Re: all the kills
Reply With Quote #6

Quote:
Originally Posted by Chaosxk View Post
You didn't save the names properly, your using client indexes which isn't right. You want to save it in an array that you can keep tabs on (e.g 0, 1, 2, 3 ... so on).

Try this one i whipped up quickly, it uses adt_arrays instead of regular arrays since its a bit easier to manage. Added some comments to it so hopefully you will understand.

Code:
#pragma semicolon 1

#define DEBUG
#pragma tabsize 0

#include <sourcemod>
#include <sdktools>
//#include <colors>

//Creates the array handles
new Handle:attacker_array = INVALID_HANDLE;
new Handle:victim_array = INVALID_HANDLE;


public void OnPluginStart()
{
	RegAdminCmd("sm_kills", Cmd_ViewKills, ADMFLAG_BAN, "View Kills");
	HookEvent("player_death", Event_PlayerDeath);
	
	//Creates the array for the handles
	attacker_array = CreateArray();
	victim_array = CreateArray();
}


public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    // There is no reason to keep calling GetClientOfUserId().
    int victim = GetClientOfUserId(GetEventInt(event, "userid"));
    
    // You'll have to check if the players exist.
    if (victim == 0)
    {
        return;
    }
    
    int attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
	
    //Maximum number of names to store, set to 10 will only save and show 10 names
    //This is to prevent the array from saving too much names and taking up memory
    new max_array_size = 10;
    if(GetArraySize(attacker_array) > max_array_size-1) 
    {
        RemoveFromArray(attacker_array, 0);
    }
	//does the same thing but with victims name
    if(GetArraySize(victim_array) > max_array_size-1) 
    {
    RemoveFromArray(victim_array, 0);
    }
	
    if (attacker != 0)
    {
        // Attacker is a player.
        decl String:attackersname[32];
        GetClientName(attacker, attackersname, sizeof(attackersname));
        //Pushes the attackers name into the attacker_array handle
        PushArrayString(attacker_array, attackersname);
    }
    else
    {
        // Attacker not a player.
        PushArrayString(attacker_array, "World");
    }
    decl String:victimsname[32];
    GetClientName(victim, victimsname, sizeof(victimsname));
    //Pushes the victim name into victim_array handle
    PushArrayString(victim_array, victimsname);
}  

public MenuViewkills(Handle:menu, MenuAction:action, param1, param2)
{
    if (action == MenuAction_Select) 
    {
        new String:info[32];
        
        GetMenuItem(menu, param2, info, sizeof(info));
        
    }
    else if (action == MenuAction_Cancel)
    {
        CloseHandle(menu);
    }
}

public Action:Cmd_ViewKills(client, args)
{
	new String:Buffer[MAX_NAME_LENGTH];
	decl String:attackersname[32], String:victimsname[32];
	Menu menu = new Menu(MenuViewkills);
	menu.SetTitle("ViewKills Menu :");
	//size of attacker_array and victim_array should always be the same
	//loops from 1st attackers/victims name to the last
	for(new i = 0; i < GetArraySize(attacker_array); i++) 
	{
        //Retrieve the names from the arrays
        GetArrayString(attacker_array, i, attackersname, sizeof(attackersname));
        GetArrayString(victim_array, i, victimsname, sizeof(victimsname));
        Format(Buffer, sizeof(Buffer), "%s Was Killed By %s", victimsname, attackersname);
        AddMenuItem(menu, "%s", Buffer);
		//PrintToServer("%s", Buffer);
	}
	menu.ExitButton = true;
	menu.Display(client, 20);
}

thx Its Working

But I Want it Restart The Menu Every Round And I see half name.. i dont know why..
can you help me with that ?
__________________

Last edited by nhnkl159; 08-29-2015 at 01:24.
nhnkl159 is offline
Send a message via Skype™ to nhnkl159
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 08-29-2015 , 02:37   Re: all the kills
Reply With Quote #7

OnPluginStart, hook the event "teamplay_round_start". When the event starts add ClearArray(attacker_array) and ClearArray(victim_array). That should do it, and i'm not sure what you mean by seeing half name?
__________________
Chaosxk is offline
nhnkl159
Senior Member
Join Date: Jul 2012
Location: Israel 3>
Old 08-29-2015 , 02:59   Re: all the kills
Reply With Quote #8

Quote:
Originally Posted by Chaosxk View Post
OnPluginStart, hook the event "teamplay_round_start". When the event starts add ClearArray(attacker_array) and ClearArray(victim_array). That should do it, and i'm not sure what you mean by seeing half name?

I See In The Menu :

Pla Was Killed By Pla

I Mean Pla Is Player
__________________
nhnkl159 is offline
Send a message via Skype™ to nhnkl159
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 08-29-2015 , 03:57   Re: all the kills
Reply With Quote #9

Forgot to set the size, OnPluginStart change it to :

PHP Code:
attacker_array CreateArray(32);
victim_array CreateArray(32); 
__________________
Chaosxk is offline
nhnkl159
Senior Member
Join Date: Jul 2012
Location: Israel 3>
Old 08-29-2015 , 05:49   Re: all the kills
Reply With Quote #10

Quote:
Originally Posted by Chaosxk View Post
Forgot to set the size, OnPluginStart change it to :

PHP Code:
attacker_array CreateArray(32);
victim_array CreateArray(32); 

Thx Its Working !
Solved
__________________
nhnkl159 is offline
Send a message via Skype™ to nhnkl159
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 15:17.


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