AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Isn't the killer/victim same (https://forums.alliedmods.net/showthread.php?t=168060)

reinert 09-23-2011 18:07

Isn't the killer/victim same
 
How to check isn't the victim same for 2nd or even 3rd time ?

Like If I've killed Player5 3times a row, I want message to be displayed, You have killed Player5 3 times in a row :)

hleV 09-23-2011 18:18

Re: Isn't the killer/victim same
 
PHP Code:

new Kills[33][33];
new 
MaxPlayers;

public 
plugin_init()
{
    
register_event("DeathMsg""OnDeathMsg""a""1>0");

    
MaxPlayers get_maxplayers();
}

public 
client_disconnect(client)
{
    
arrayset(Kills[client], 0sizeof Kills[]);

    for (new 
1<= MaxPlayersi++)
        
Kills[i][client] = 0;
}

public 
OnDeathMsg()
{
    new 
killer read_data(1);
    new 
victim read_data(2);

    if (
killer == victim)
        return;

    if (++
Kills[killer][victim] == 3)
    {
        
// killer killed victim 3 times in a row
    
}

    
Kills[victim][killer] = 0;



Hunter-Digital 09-23-2011 18:19

Re: Isn't the killer/victim same
 
Killing the same player without killing anyone else in between or killing a player more than once without you beeing killed by him ?

Example with the 2nd, like the when you dominate someone in TF2:
Code:

new g_iKilled[33][33]
new g_iMaxPlayers

public plugin_init()
{
    register_event("DeathMsg", "player_killed", "a")

    g_iMaxPlayers = get_maxplayers()
}

public player_killed()
{
    new victim = read_data(2)
    new killer = read_data(1)

    if(id != killer && 1 <= killer <= g_iMaxPlayers)
    {
        g_iKilled[victim][killer] = 0

        if(++g_iKilled[killer][victim] == 3)
        {
            new szKiller[32]
            new szVictim[32]

            get_user_name(killer, szKiller, charsmax(szKiller))
            get_user_name(victim, szVictim, charsmax(szVictim))

            client_print(0, print_chat, "**** %s is dominating %s ****", szKiller, szVictim)
        }
    }
}

public client_putinserver(id)
{
    for(new i = 1; i <= g_iMaxPlayers; i++)
    {
        g_iKilled[id][i] = 0
        g_iKilled[i][id] = 0
    }
}

untested :}


EDIT: pff, I forgot this forum doesn't notify me if someone posted while I was writing xD

Bugsy 09-23-2011 18:19

Re: Isn't the killer/victim same
 
Make 2d array and count each time one id killed another

Say id 3 kills id 9

new iKills[ 33 ][ 33 ];
iKills[ 9 ][ 3 ]++;

Edit: lols @ 3 posts at the same time

reinert 09-23-2011 18:25

Re: Isn't the killer/victim same
 
Quote:

Originally Posted by Bugsy (Post 1561771)
Make 2d array and count each time one id killed another

Say id 3 kills id 9

new iKills[ 33 ][ 33 ];
iKills[ 9 ][ 3 ]++;

Edit: lols @ 3 posts at the same time

Just as hleV did, didn't he the same u just said ? :)

Hunter-Digital 09-23-2011 18:27

Re: Isn't the killer/victim same
 
Yes we all suggested the same method, so you have your answer :P

But I'm still curious about:
Quote:

Originally Posted by Hunter-Digital (Post 1561770)
Killing the same player without killing anyone else in between or killing a player more than once without you beeing killed by him ?


reinert 09-23-2011 18:29

Re: Isn't the killer/victim same
 
Killing the same player without killing someone else in between ;p

also if I'm returning in this:

PHP Code:

if(++Kills[attacker][victim] >= 3)
                return 
PLUGIN_HANDLED

Is it good to have this: Kills[victim][attacker] = 0; after it ?

like:
PHP Code:

if(++Kills[attacker][victim] >= 3)
                return 
PLUGIN_HANDLED;
            
            
Kills[victim][attacker] = 0


Bugsy 09-23-2011 18:33

Re: Isn't the killer/victim same
 
Edit: Eliminated g_iLastKilled[ 33 ] array, now using first cell of g_iKills[ iKiller ][] (since it does not get used anyway) to store the last person iKiller killed.

PHP Code:

#define LastKilled 0
new g_iKills33 ][ 33 ];

public 
KilliVictim iKiller )
{
    if ( 
g_iKillsiKiller ][ LastKilled ] == iVictim )
    {
        if ( ++
g_iKillsiKiller ][ iVictim ] == )
        {
            
//third time killing this person, no kills inbetween
        
}
    }
    else
    {
        
g_iKillsiKiller ][ g_iKillsiKiller ][ LastKilled ] ] = 0;

        
g_iKillsiKiller ][ iVictim ] = 1;
        
g_iKillsiKiller ][ LastKilled ] = iVictim;
    }



Hunter-Digital 09-23-2011 18:37

Re: Isn't the killer/victim same
 
In that case, you need adjustments to the codes provided by me or hlev:

Code:

new g_iTarget[33]
new g_iKilled[33]

//....

public player_killed()
{
  //... get victim, killer, check if player, etc

  if(g_iTarget[victim] == killer) // reset victim's kills against killer
  {
      g_iTarget[victim] = 0
      g_iKilled[victim] = 0
  }

  if(g_iTarget[killer] != victim) // reset count because he killed someone else
  {
      g_iTarget[killer] = victim
      g_iKilled[killer] = 1
  }
  else if(++g_iKilled[killer] == 3)
  {
      // killed the same player 3 times without killing anyone else in between or beeing killed by him
  }
}

EDIT: seriously too much traffic on this thread =)



Quote:

Originally Posted by reinert (Post 1561779)
also if I'm returning in this:

PHP Code:

if(++Kills[attacker][victim] >= 3)
                return 
PLUGIN_HANDLED

Is it good to have this: Kills[victim][attacker] = 0; after it ?

like:
PHP Code:

if(++Kills[attacker][victim] >= 3)
                return 
PLUGIN_HANDLED;
            
            
Kills[victim][attacker] = 0


Well, think about it... the kills on the victim against attacker will be reset when the attacker kills the victim the first 2 times.

reinert 09-23-2011 18:41

Re: Isn't the killer/victim same
 
Isn't the bugsy's code good ? It looks more simply :)


All times are GMT -4. The time now is 19:32.

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