AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Total Kills of a team (https://forums.alliedmods.net/showthread.php?t=316824)

shadow728988 06-11-2019 23:33

Total Kills of a team
 
Is it possible to add up the kills of all the players in same team and display on hud?
I already have created the hud just cant get the kills to add up.
Thank you for your help.

<VeCo> 06-12-2019 11:24

Re: Total Kills of a team
 
Detect kill, check team of killer, add +1 to a global variable depending on the team, show that in the hud.

shadow728988 06-12-2019 23:13

Re: Total Kills of a team
 
Quote:

Originally Posted by <VeCo> (Post 2655335)
Detect kill, check team of killer, add +1 to a global variable depending on the team, show that in the hud.

I am new at this so i cant you know.
But we register a death event then what?
I mean how do you detect a kill
Like new attacker = get_user_id
New team = get_user_team(attacker) something like this?

HamletEagle 06-13-2019 04:20

Re: Total Kills of a team
 
Quote:

Originally Posted by shadow728988 (Post 2655381)
But we register a death event then what?
I mean how do you detect a kill

If you registered DeathMsg(the death event) then you already detected a kill. The event will be called when a player is killed.

Then get the attacker,(read_data(1) IIRC), team = get_user_team(attacker), globalVariable[team]++.

shadow728988 06-13-2019 08:24

Re: Total Kills of a team
 
Quote:

Originally Posted by HamletEagle (Post 2655394)
If you registered DeathMsg(the death event) then you already detected a kill. The event will be called when a player is killed.

Then get the attacker,(read_data(1) IIRC), team = get_user_team(attacker), globalVariable[team]++.

What if i want to show both the total kills of ts as well as cts?
Still just the one global variable?

shadow728988 06-13-2019 09:19

Re: Total Kills of a team
 
Quote:

Originally Posted by HamletEagle (Post 2655394)
If you registered DeathMsg(the death event) then you already detected a kill. The event will be called when a player is killed.

Then get the attacker,(read_data(1) IIRC), team = get_user_team(attacker), globalVariable[team]++.

Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>

new TKills
new CTKills
public plugin_init()
{
    register_plugin("hud", "", "rinf")
       
        register_event("DeathMsg", "Event_DeathMsg", "a", "1")
        hudmessage()
}


public Event_DeathMsg()
{
  new attacker = read_data(1)
  new Team = get_user_team(attacker)
  if(Team == 1)
  {
    TKills++;
  }
  else if(Team == 2)
  {
    CTKills++
  }
}
public hudmessage()
{
set_dhudmessage(0, 255, 0, -1.0, 0.0, 0, 6.0, 12.0)
show_dhudmessage(0, "〕Point〔^n〔%i〕      〔%i〕", TKills, CTKills);
}

correct me please thank you.

HamletEagle 06-13-2019 11:02

Re: Total Kills of a team
 
It's almost fine. You need to use a task to display the hud message(so it gets updated every time the variables change). So you should do something like set_task(1.0, "hudmessage", .flags = "b") in plugin_init. Also change the hudmessage hold time from 12.0 to something like 2.0(last param from set_dhudmessage).

shadow728988 06-13-2019 11:11

Re: Total Kills of a team
 
Quote:

Originally Posted by HamletEagle (Post 2655429)
It's almost fine. You need to use a task to display the hud message(so it gets updated every time the variables change). So you should do something like set_task(1.0, "hudmessage", .flags = "b") in plugin_init. Also change the hudmessage hold time from 12.0 to something like 2.0(last param from set_dhudmessage).

I was testing this and when i change team from ct to t it increments +1 to ct..what to do about this?

Add a victim condition too if so how?

thEsp 06-13-2019 11:17

Re: Total Kills of a team
 
Check if victim (Second param) is dead, or use Ham_Killed instead (And check if victim is not attacker).
https://forums.alliedmods.net/showthread.php?t=190333
Another method is to make a looping thread where you loop throughout all players and get their kills.

shadow728988 06-13-2019 11:32

Re: Total Kills of a team
 
Quote:

Originally Posted by HamletEagle (Post 2655429)
It's almost fine. You need to use a task to display the hud message(so it gets updated every time the variables change). So you should do something like set_task(1.0, "hudmessage", .flags = "b") in plugin_init. Also change the hudmessage hold time from 12.0 to something like 2.0(last param from set_dhudmessage).

Quote:

Originally Posted by thEsp (Post 2655432)
Check if victim (Second param) is dead, or use Ham_Killed instead.
https://forums.alliedmods.net/showthread.php?t=190333

Code:

if(Team ==1 && attacker != victim)
What will this do coz i didn't understand much about ham_killed


All times are GMT -4. The time now is 17:23.

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