Raised This Month: $ Target: $400
 0% 

How to detect last 2 killed players?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Tramp
Senior Member
Join Date: Aug 2005
Old 04-04-2008 , 19:37   How to detect last 2 killed players?
Reply With Quote #1

PHP Code:

#include <amxmodx>
#include <cstrike>



new killed[32];


public 
plugin_init()
{
    
register_event("DeathMsg","onDeath","a");
    
register_logevent("round_end"2"1=Round_End");

}


public 
onDeath()
{

    new 
i;
    new 
ctnum;
    new 
tnum;
    
    for (
1<= 32i++)
    {
        if (
is_user_connected(i))
        {
            if (
cs_get_user_team(i) == CS_TEAM_CT)
            {
                if (
is_user_alive(i))
                {
                    
ctnum++;
                }
            }
            else if (
cs_get_user_team(i) == CS_TEAM_T)
            {
                if (
is_user_alive(i))
                {
                    
tnum++;
                }
            }
        }
    }
    
    new 
x
    
new victim read_data(2);
    
    if (
tnum <= 2)
    {
        
killed[x] = victim;
    }
    
}

public 
round_end()
{

    new 
i;
    new 
x;
    new 
newcats;
    for (
1<= 32i++)
        if(
is_user_connected(i))
        {
            
            if (
cs_get_user_team(i) == CS_TEAM_T && newcats<2)
            {
                    
cs_set_user_team(killed[x], CS_TEAM_CTCS_CT_GIGN);
                    
newcats++;    
            }

            
        }
        
        
    new 
name[32];
    
    
get_user_name(killed[x], name17);
    
client_print(0print_chat"Last killed person is %s"name);

And it remember only last one, i want to remember two last killed players.
and at the end of round transfer them to other team (CT).

What is wrong? :/
__________________
STER-Gaming.pl - The Best Multigaming Club, CS 1.6, CS:S, ET, COD 2 more and more ! Check forum forum.ster-gaming.pl

amxmodx - Polish support about amxx.

Last edited by Tramp; 04-04-2008 at 20:10.
Tramp is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 04-04-2008 , 23:07   Re: How to detect last 2 killed players?
Reply With Quote #2

Code:
new g_lasttwo new g_lastone public death() {     new id = read_data(2)     if(is_user_connected(id) && cs_get_user_team(id) == CS_TEAM_T)     {          g_lasttwo = g_lastone          g_lastone = id     } }
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 04-04-2008 , 23:33   Re: How to detect last 2 killed players?
Reply With Quote #3

or
Code:
#include <amxmodx> public plugin_init() {   register_event("DeathMsg", "OnDeath", "a", "2!0"); } g_LastTwo[2]; g_Num; public OnDeath() {   new victim = read_data(2);   if(g_Num > 1)   {     g_Num = 0;   }   g_LastTwo[g_Num] = victim;   g_Num++; }
Should do the trick for getting the IDs of the last two victims. Modify it to your likings.
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-04-2008 , 23:53   Re: How to detect last 2 killed players?
Reply With Quote #4

I made this to be a little more dynamic:

Code:
#include <amxmodx> #include <cstrike> #define MAX_DEATH_COUNT 2 new g_iDeathCount; new g_LastKilled[MAX_DEATH_COUNT]; new bool:g_bCheckDeaths = false; public plugin_init() {     register_plugin("Last Dead", "0.1", "Exolent");     register_event("DeathMsg", "event_DeathMsg", "a");     register_logevent("logevent_Round_Start", 2, "1=Round_Start");     register_logevent("logevent_Round_End", 2, "1=Round_End"); } public event_DeathMsg() {     if(!g_bCheckDeaths)     {         return;     }         new id = read_data(2);     if(cs_get_user_team(id) != CS_TEAM_T)     {         return;     }         if(g_iDeathCount < MAX_DEATH_COUNT)     {         g_iDeathCount++;     }         for(new i = g_iDeathCount - 1; i > 0; i++)     {         g_LastKilled[i] = g_LastKilled[i - 1];     }     g_LastKilled[0] = id; } public logevent_Round_Start() {     g_bCheckDeaths = true; } public logevent_Round_End() {     g_bCheckDeaths = false;         new id;     for(new i = 0; i < MAX_DEATH_COUNT && i < g_iDeathCount; i++)     {         id = g_LastKilled[i];         if(is_user_connected(id))         {             cs_set_user_team(id, CS_TEAM_CT);         }     }         arrayset(g_LastKilled, 0, sizeof(g_LastKilled)); }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Tramp
Senior Member
Join Date: Aug 2005
Old 04-05-2008 , 06:57   Re: How to detect last 2 killed players?
Reply With Quote #5

Thanks, new stuff to learning ;)

: D
__________________
STER-Gaming.pl - The Best Multigaming Club, CS 1.6, CS:S, ET, COD 2 more and more ! Check forum forum.ster-gaming.pl

amxmodx - Polish support about amxx.
Tramp is offline
Tramp
Senior Member
Join Date: Aug 2005
Old 04-05-2008 , 13:11   Re: How to detect last 2 killed players?
Reply With Quote #6

I've checked it with HLTVs and it remember id only one time on second new round doesn't work and only one player is remembered also :/
It is setting team twice for the same ID.

Code:
#include <amxmodx> #include <cstrike> #define MAX_DEATH_COUNT 2 new g_iDeathCount; new g_LastKilled[MAX_DEATH_COUNT]; new bool:g_bCheckDeaths = false; public plugin_init() {     register_plugin("Last Dead", "0.1", "Exolent");     register_event("DeathMsg", "event_DeathMsg", "a");     register_logevent("logevent_Round_Start", 2, "1=Round_Start");     register_logevent("logevent_Round_End", 2, "1=Round_End"); } public event_DeathMsg() {     if(!g_bCheckDeaths)     {         return;     }         new id = read_data(2);     if(cs_get_user_team(id) != CS_TEAM_T)     {         return;     }         if(g_iDeathCount < MAX_DEATH_COUNT)     {         g_iDeathCount++;     }         for(new i = g_iDeathCount - 1; i > 0; i++)     {         g_LastKilled[i] = g_LastKilled[i - 1];     }     g_LastKilled[0] = id; } public logevent_Round_Start() {     g_bCheckDeaths = true; } public logevent_Round_End() {     g_bCheckDeaths = false;         new id;     for(new i = 0; i < MAX_DEATH_COUNT && i < g_iDeathCount; i++)     {         id = g_LastKilled[i];         if(is_user_connected(id))         {             cs_set_user_team(id, CS_TEAM_CT);             get_user_name(id, name, 17);             client_print(0, print_chat, "Last killed person is %s", name);         }     }         arrayset(g_LastKilled, 0, sizeof(g_LastKilled)); }
__________________
STER-Gaming.pl - The Best Multigaming Club, CS 1.6, CS:S, ET, COD 2 more and more ! Check forum forum.ster-gaming.pl

amxmodx - Polish support about amxx.
Tramp is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-05-2008 , 13:57   Re: How to detect last 2 killed players?
Reply With Quote #7

v3x way should be fine, you may just want to be able to retrieve the real last player who died.

PHP Code:
#include <amxmodx>

#define LAST_KILLED        0
#define PREVIOUS_KILLED    1

new g_iLastTwo[2]

public 
plugin_init()
{
    
register_event("DeathMsg""Event_DeathMsg""a")
    
register_event("HLTV""Event_NewRound""a""1=0""2=0")
}

public 
Event_DeathMsg()
{
    
g_iLastTwo[PREVIOUS_KILLED] = g_iLastTwo[LAST_KILLED]
    
g_iLastTwo[LAST_KILLED] = read_data(2)
}

public 
Event_NewRound()
{
    
g_iLastTwo[PREVIOUS_KILLED] = 0
    g_iLastTwo
[LAST_KILLED] = 0

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Tramp
Senior Member
Join Date: Aug 2005
Old 04-05-2008 , 14:05   Re: How to detect last 2 killed players?
Reply With Quote #8

This way is not universal
For 3th, 4th more code should be added.
__________________
STER-Gaming.pl - The Best Multigaming Club, CS 1.6, CS:S, ET, COD 2 more and more ! Check forum forum.ster-gaming.pl

amxmodx - Polish support about amxx.

Last edited by Tramp; 04-05-2008 at 14:08.
Tramp is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-05-2008 , 14:33   Re: How to detect last 2 killed players?
Reply With Quote #9

Quote:
Originally Posted by Tramp View Post
This way is not universal
For 3th, 4th more code should be added.
Sure, it just depends on what YOU need for your plugin.
If you only need the 2 last killed players, there's no point on make more code.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Tramp
Senior Member
Join Date: Aug 2005
Old 04-05-2008 , 15:19   Re: How to detect last 2 killed players?
Reply With Quote #10

Code:
public onDeath() {     new tnum;         for (new i = 1; i <= 32; i++)     {         if (is_user_connected(i))         {             if (cs_get_user_team(i) == CS_TEAM_T)             {                 if(is_user_alive(i))                 {                 tnum++;                 }             }         }     }         if (tnum == 1)     {         killed[1] = read_data(2);     }     else if (tnum < 1)     {         killed[2] = read_data(2);     } }

Okey, now i wrote in the very simple way :p
and it is working ;) but it looks like for noob ^^

But works, that is the main point
__________________
STER-Gaming.pl - The Best Multigaming Club, CS 1.6, CS:S, ET, COD 2 more and more ! Check forum forum.ster-gaming.pl

amxmodx - Polish support about amxx.
Tramp 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 21:08.


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