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

[HELP] Adjust Code


Post New Thread Closed Thread   
 
Thread Tools Display Modes
Author Message
extream87
Senior Member
Join Date: Aug 2011
Old 03-03-2014 , 17:26   [HELP] Adjust Code
#1

Sometimes this plugin fails.
Example: The best player only kill 10 players and the colorchat says killed 11 or 12.

What is wrong? (The server have 32 slots)
Code:
#include <amxmodx>  #include <amxmisc>  #include <hamsandwich>  #include <cstrike> #include <colorchat>    #define PLUGIN    "Best Player Round"  #define AUTHOR    "extream87"  #define VERSION   "1.0"    new g_iKills[32], g_iDmg[32], zTAG   public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     RegisterHam(Ham_TakeDamage, "player", "hamTakeDamage")     register_event("DeathMsg", "EventDeathMsg", "a")      register_logevent("RoundEnd", 2, "1=Round_End")     zTAG = register_cvar("bp_prefix", "Prefix*") }    public client_disconnect(id)  {      g_iDmg[id] = 0;      g_iKills[id] = 0} public hamTakeDamage(victim, inflictor, attacker, Float:damage, DamageBits)  {      if( 1 <= attacker <= 32)      {          if(cs_get_user_team(victim) != cs_get_user_team(attacker))              g_iDmg[attacker] += floatround(damage)          else              g_iDmg[attacker] -= floatround(damage)      }  }    public EventDeathMsg()  {      new killer = read_data(1)      new victim = read_data(2)        if(killer != victim && killer && cs_get_user_team(killer) != cs_get_user_team(victim))      {          g_iKills[killer]++;      }      else          g_iKills[killer]--;  }    public RoundEnd()  {      new iBestPlayer = get_best_player()      new szName[32]      get_user_name(iBestPlayer, szName, charsmax(szName))          new szTAG[25];     get_pcvar_string(zTAG, szTAG, charsmax(szTAG));         if (g_iKills[iBestPlayer] <1 ){     ColorChat(0, GREEN, "[%s] ^x01Esta ronda nao contou.", szTAG);     }         else if (g_iKills[iBestPlayer] ==1 ){     ColorChat(0, GREEN, "[%s] ^x01Melhor jogador da ronda: ^x04%s ^x01matou ^x04%i ^x01jogador.", szTAG, szName, g_iKills[iBestPlayer]);     }         else if (g_iKills[iBestPlayer] >1 ){     ColorChat(0, GREEN, "[%s] ^x01Melhor jogador da ronda: ^x04%s ^x01matou ^x04%i ^x01jogadores.", szTAG, szName, g_iKills[iBestPlayer]);     }           for(new i; i < 31; i++)      {          g_iDmg[i] = 0;          g_iKills[i] = 0;      }  }    get_best_player()  {      new players[32], num;      get_players(players, num);      SortCustom1D(players, num, "sort_bestplayer")      return players[0]  }    public sort_bestplayer(id1, id2)  {      if(g_iKills[id1] > g_iKills[id2])          return -1;      else if(g_iKills[id1] < g_iKills[id2])          return 1;      else      {          if(g_iDmg[id1] > g_iDmg[id2])              return -1;          else if(g_iDmg[id1] < g_iDmg[id2])              return 1;          else              return 0;      }      return 0}

Last edited by extream87; 03-05-2014 at 09:14.
extream87 is offline
Old 03-10-2014, 06:43
extream87
This message has been deleted by YamiKaitou. Reason: wait 14 days before you bump
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 03-10-2014 , 09:42   Re: [HELP] Adjust Code
#2

Change from [32] to [33].
__________________
Kia is offline
extream87
Senior Member
Join Date: Aug 2011
Old 03-10-2014 , 09:45   Re: [HELP] Adjust Code
#3

That?
Code:
new g_iKills[33], g_iDmg[33] if( 1 <= attacker <= 33)

Last edited by extream87; 03-10-2014 at 09:45.
extream87 is offline
Neeeeeeeeeel.-
Some Guy Yellin'
Join Date: Jul 2010
Location: Argentina
Old 03-10-2014 , 11:07   Re: [HELP] Adjust Code
#4

Quote:
Originally Posted by extream87 View Post
That?
Code:
new g_iKills[33], g_iDmg[33] if( 1 <= attacker <= 33)
This should stay as it was.
PHP Code:
if( <= attacker <= 32
__________________
Neeeeeeeeeel.- is offline
Send a message via Skype™ to Neeeeeeeeeel.-
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 03-10-2014 , 11:24   Re: [HELP] Adjust Code
#5

Remember that when declaring an array, you specify how many "slots" it has. When referencing these slots later, the first slot is '0'. Second one is '1'. Etc.

So when declaring a new array of size 33, the first position in the array is 1-1 (0), and the last is 33-1 (32).
__________________

Last edited by ddhoward; 03-10-2014 at 11:25.
ddhoward is offline
extream87
Senior Member
Join Date: Aug 2011
Old 03-10-2014 , 11:40   Re: [HELP] Adjust Code
#6

So that is good?
Code:
#include <amxmodx>  #include <amxmisc>  #include <hamsandwich>  #include <cstrike> #include <colorchat>    #define PLUGIN    "Best Player Round"  #define AUTHOR    "extream87"  #define VERSION   "1.1"    new g_iKills[33], g_iDmg[33], zTAG   public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     RegisterHam(Ham_TakeDamage, "player", "hamTakeDamage")     register_event("DeathMsg", "EventDeathMsg", "a")      register_logevent("RoundEnd", 2, "1=Round_End")     zTAG = register_cvar("bp_prefix", "Prefix*") }    public client_disconnect(id)  {      g_iDmg[id] = 0;      g_iKills[id] = 0} public hamTakeDamage(victim, inflictor, attacker, Float:damage, DamageBits)  {      if( 1 <= attacker <= 32)      {          if(cs_get_user_team(victim) != cs_get_user_team(attacker))              g_iDmg[attacker] += floatround(damage)          else              g_iDmg[attacker] -= floatround(damage)      }  }    public EventDeathMsg()  {      new killer = read_data(1)      new victim = read_data(2)        if(killer != victim && killer && cs_get_user_team(killer) != cs_get_user_team(victim))      {          g_iKills[killer]++;      }      else          g_iKills[killer]--;  }    public RoundEnd()  {      new iBestPlayer = get_best_player()      new szName[33]      get_user_name(iBestPlayer, szName, charsmax(szName))          new szTAG[25];     get_pcvar_string(zTAG, szTAG, charsmax(szTAG));         if (g_iKills[iBestPlayer] <1 ){     ColorChat(0, GREEN, "[%s] ^x01Esta ronda nao foi jogada.", szTAG);     }         else if (g_iKills[iBestPlayer] ==1 ){     ColorChat(0, GREEN, "[%s] ^x01Melhor jogador da ronda: ^x04%s ^x01matou ^x04%i ^x01jogador.", szTAG, szName, g_iKills[iBestPlayer]);     }         else if (g_iKills[iBestPlayer] >1 ){     ColorChat(0, GREEN, "[%s] ^x01Melhor jogador da ronda: ^x04%s ^x01matou ^x04%i ^x01jogadores.", szTAG, szName, g_iKills[iBestPlayer]);     }           for(new i; i < 31; i++)      {          g_iDmg[i] = 0;          g_iKills[i] = 0;      }  }    get_best_player()  {      new players[32], num;     get_players(players, num);     SortCustom1D(players, num, "sort_bestplayer")     return players[0] }    public sort_bestplayer(id1, id2)  {      if(g_iKills[id1] > g_iKills[id2])          return -1;      else if(g_iKills[id1] < g_iKills[id2])          return 1;      else      {          if(g_iDmg[id1] > g_iDmg[id2])              return -1;          else if(g_iDmg[id1] < g_iDmg[id2])              return 1;          else              return 0;      }      return 0}

Last edited by extream87; 03-10-2014 at 11:41.
extream87 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-11-2014 , 02:11   Re: [HELP] Adjust Code
#7

Threads titles muts be descriptive.

Please read rules : https://forums.alliedmods.net/misc.php?do=showrules

Closed.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Closed Thread



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 04:57.


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