AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Rank plugin. (https://forums.alliedmods.net/showthread.php?t=49516)

aim4lex 01-05-2007 23:54

Rank plugin.
 
The plugin makes rank for everybody.
Player will have a small display ranking in his in-game screen (hud message) base on his stats.

Here's the list of rank that you can be.

100 - Private
200 - Private First Class
400 - Corporal
800 - Sergeant
1000 - Staff Sergeant
2000 - Gunnery Sergeant
4000 - Master Sergeant
8000 - Command Sergeant
10000 - Second Lieutenant
12000 - First Lieutenant
15000 - Colonel
20000 - Brigadier General
40000 -Major General
50000 - Lieutenant General
80000 - General
100000 -General of the Army

This plugin doesnt work, it always says that my rank is General. Doesnt matter how many kills do i have.

Here's the code. Please take a look at it and fix it if you can.


Code:
Code:

#include <amxmodx>
#include <amxmisc>
#include <csstats>

#define HUD_INTERVAL 1.0

#define RANK_NOTHING 0
#define RANK_PRIVATE 1
#define RANK_PRIVATE_FIRST_CLASS 2
#define RANK_CORPORAL 3
#define RANK_SERGEANT 4
#define RANK_STAFF_SERGEANT 5
#define RANK_GUNNERY_SERGEANT 6
#define RANK_MASTER_SERGEANT 7
#define RANK_COMMAND_SERGEANT 8
#define RANK_SECOND_LIEUTENANT 9
#define RANK_FIRST_LIEUTENANT 10
#define RANK_COLONEL 11
#define RANK_BRIGADIER_GENERAL 12
#define RANK_MAJOR_GENERAL 13
#define RANK_LIEUTENANT_GENERAL 14
#define RANK_GENERAL 15
#define RANK_GENERAL_OF_THE_ARMY 16

#define MAXRANKS 17

new PlayerRank[33]

new const RANKS[MAXRANKS][] =
{
        "None",
        "Private",
        "Private First Class",
        "Corporal",
        "Sergeant",
        "Staff Sergeant",
        "Gunnery Sergeant",
        "Master Sergeant",
        "Command Sergeant",
        "Second Lieutenant",
        "First Lieutenant",
        "Colonel",
        "Brigadier General",
        "Major General",
        "Lietenant General",
        "General",
        "General of the Army"
}

public plugin_init()
{
        register_plugin("Rank Display", "1.0", "Kensai")
}

public client_putinserver(id)
{       
        set_task(HUD_INTERVAL, "ShowHUD", id)
        return 0
}

public ShowHUD(id)   

        if(!is_user_connected(id))
                return 0
       
        new stats[8]
        new hits[8]
        get_user_stats(id, stats, hits)       
       
        new name[33]
        get_user_name(id, name, 32)
       
        if(stats[0] < 100)
        {
                PlayerRank[id] = RANK_NOTHING
        }
        if(stats[0] >= 100 || stats[0] <= 200)
        {
                PlayerRank[id] = RANK_PRIVATE
        }
        if(stats[0] >= 201 || stats[0] <= 400)
        {
                PlayerRank[id] = RANK_PRIVATE_FIRST_CLASS
        }
        if(stats[0] >= 401 || stats[0] <= 800)
        {
                PlayerRank[id] = RANK_CORPORAL
        }
        if(stats[0] >= 801 || stats[0] <= 1000)
        {
                PlayerRank[id] = RANK_SERGEANT
        }
        if(stats[0] >= 1001 || stats[0] <= 2000)
        {
                PlayerRank[id] = RANK_STAFF_SERGEANT
        }
        if(stats[0] >= 2001 || stats[0] <= 4000)
        {
                PlayerRank[id] = RANK_GUNNERY_SERGEANT
        }
        if(stats[0] >= 4001 || stats[0] <= 8000)
        {
                PlayerRank[id] = RANK_MASTER_SERGEANT
        }
        if(stats[0] >= 8001 || stats[0] <= 10000)
        {
                PlayerRank[id] = RANK_COMMAND_SERGEANT
        }
        if(stats[0] >= 10001 || stats[0] <= 12000)
        {
                PlayerRank[id] = RANK_SECOND_LIEUTENANT
        }
        if(stats[0] >= 12001 || stats[0] <= 15000)
        {
                PlayerRank[id] = RANK_FIRST_LIEUTENANT
        }
        if(stats[0] >= 15001 || stats[0] <= 20000)
        {
                PlayerRank[id] = RANK_COLONEL
        }
        if(stats[0] >= 20001 || stats[0] <= 40000)
        {
                PlayerRank[id] = RANK_BRIGADIER_GENERAL
        }
        if(stats[0] >= 40001 || stats[0] <= 50000)
        {
                PlayerRank[id] = RANK_MAJOR_GENERAL
        }
        if(stats[0] >= 50001 || stats[0] <= 80000)
        {
                PlayerRank[id] = RANK_LIEUTENANT_GENERAL
        }
        if(stats[0] >= 80001 || stats[0] <= 100000)
        {
                PlayerRank[id] = RANK_GENERAL
        }
        if(stats[0] >= 100001)
        {
                PlayerRank[id] = RANK_GENERAL_OF_THE_ARMY
        }

        set_hudmessage(237, 245, 9, 0.0, 0.6, 0, 6.0, 12.0)
        show_hudmessage(id, "[%s - %s] Kills: %i", name, RANKS[PlayerRank[id]], stats[0])
       
        set_task(HUD_INTERVAL, "ShowHUD", id)
       
        return 0
}


SweatyBanana 01-07-2007 23:36

Re: Rank plugin.
 
There is a two week bump minimum..

Salepate 01-08-2007 01:58

Re: Rank plugin.
 
If you only need to know his frags, you'd better use
Code:
get_user_frags(id)
It will free some memory instead of using arrays. you will be sure that it will contain kills.

SweatyBanana 01-08-2007 02:33

Re: Rank plugin.
 
Do not post here if you don't know what you are talking about.. He is getting the users rank stats.. Not just in game kills for that map/round/connection/whatever.

aim4lex 01-08-2007 05:09

Re: Rank plugin.
 
So, any ideas how to fix it?

dutchmeat 01-08-2007 05:43

Re: Rank plugin.
 
Aiml4x you should use [ small ] tags when posting a snippet


Quote:

Originally Posted by SweatyBanana (Post 424906)
Do not post here if you don't know what you are talking about.. He is getting the users rank stats.. Not just in game kills for that map/round/connection/whatever.

Actually he is, stats[0] are the kills, but the difference between user_frags and this stats thing is that the stats function gets the kills out a file.

Quote:

Syntax:

get_user_stats ( index, stats[8], bodyhits[8] )
Type:

Native
Notes:

Gets overall stats which are stored in file on server and updated on every respawn or user disconnect. Function returns the position in stats by differece in kills to deaths.
And you should also clean up your code.
here is a debug version:

Code:
#include <amxmodx> #include <amxmisc> #include <csstats> #define HUD_INTERVAL 1.0 #define RANK_NOTHING 0 #define RANK_PRIVATE 1 #define RANK_PRIVATE_FIRST_CLASS 2 #define RANK_CORPORAL 3 #define RANK_SERGEANT 4 #define RANK_STAFF_SERGEANT 5 #define RANK_GUNNERY_SERGEANT 6 #define RANK_MASTER_SERGEANT 7 #define RANK_COMMAND_SERGEANT 8 #define RANK_SECOND_LIEUTENANT 9 #define RANK_FIRST_LIEUTENANT 10 #define RANK_COLONEL 11 #define RANK_BRIGADIER_GENERAL 12 #define RANK_MAJOR_GENERAL 13 #define RANK_LIEUTENANT_GENERAL 14 #define RANK_GENERAL 15 #define RANK_GENERAL_OF_THE_ARMY 16 #define MAXRANKS 17 new PlayerRank[33] new const RANKS[MAXRANKS][] = {  "None",  "Private",  "Private First Class",  "Corporal",  "Sergeant",  "Staff Sergeant",  "Gunnery Sergeant",  "Master Sergeant",  "Command Sergeant",  "Second Lieutenant",  "First Lieutenant",  "Colonel",  "Brigadier General",  "Major General",  "Lietenant General",  "General",  "General of the Army" } public plugin_init() {  register_plugin("Rank Display", "1.0", "Dutchmeat") } public client_putinserver(id) {  set_task(HUD_INTERVAL, "ShowHUD", id)  return PLUGIN_HANDLED } public ShowHUD(id)     {    if(!is_user_connected(id))   return 0    new stats[8]  new hits[8]  get_user_stats(id, stats, hits)    new name[33]  get_user_name(id, name, 32)    if(stats[0] < 100)  {   PlayerRank[id] = RANK_NOTHING   console_print(id,"Debug 1")  }  else if(stats[0] >= 100 || stats[0] <= 200)  {   PlayerRank[id] = RANK_PRIVATE   console_print(id,"Debug 2")  }  else if(stats[0] >= 201 || stats[0] <= 400)  {   PlayerRank[id] = RANK_PRIVATE_FIRST_CLASS   console_print(id,"Debug 3")  }  else if(stats[0] >= 401 || stats[0] <= 800)  {   PlayerRank[id] = RANK_CORPORAL   console_print(id,"Debug 4")  }  else if(stats[0] >= 801 || stats[0] <= 1000)  {   PlayerRank[id] = RANK_SERGEANT   console_print(id,"Debug 5")  }  else if(stats[0] >= 1001 || stats[0] <= 2000)  {   PlayerRank[id] = RANK_STAFF_SERGEANT   console_print(id,"Debug 6")  }  else if(stats[0] >= 2001 || stats[0] <= 4000)  {   PlayerRank[id] = RANK_GUNNERY_SERGEANT   console_print(id,"Debug 7")  }  else if(stats[0] >= 4001 || stats[0] <= 8000)  {   PlayerRank[id] = RANK_MASTER_SERGEANT   console_print(id,"Debug 8")  }  else if(stats[0] >= 8001 || stats[0] <= 10000)  {   PlayerRank[id] = RANK_COMMAND_SERGEANT   console_print(id,"Debug 9")  }  else if(stats[0] >= 10001 || stats[0] <= 12000)  {   PlayerRank[id] = RANK_SECOND_LIEUTENANT   console_print(id,"Debug 10")  }  else if(stats[0] >= 12001 || stats[0] <= 15000)  {   PlayerRank[id] = RANK_FIRST_LIEUTENANT   console_print(id,"Debug 11")  }  else if(stats[0] >= 15001 || stats[0] <= 20000)  {   PlayerRank[id] = RANK_COLONEL   console_print(id,"Debug 12")  }  else if(stats[0] >= 20001 || stats[0] <= 40000)  {   PlayerRank[id] = RANK_BRIGADIER_GENERAL   console_print(id,"Debug 13")  }  else if(stats[0] >= 40001 || stats[0] <= 50000)  {   PlayerRank[id] = RANK_MAJOR_GENERAL   console_print(id,"Debug 14")  }  else if(stats[0] >= 50001 || stats[0] <= 80000)  {   PlayerRank[id] = RANK_LIEUTENANT_GENERAL   console_print(id,"Debug 15")  }  else if(stats[0] >= 80001 || stats[0] <= 100000)  {   PlayerRank[id] = RANK_GENERAL   console_print(id,"Debug 16")  }  else if(stats[0] >= 100001)  {   PlayerRank[id] = RANK_GENERAL_OF_THE_ARMY   console_print(id,"Debug 17")  }  console_print(id,"PlayerRank: %d",PlayerRank[id])  console_print(id,"Stats 0: %d",stats[0])  set_hudmessage(237, 245, 9, 0.0, 0.6, 0, 6.0, 12.0)  show_hudmessage(id, "[%s - %s] Kills: %i", name, RANKS[PlayerRank[id]], stats[0])    set_task(HUD_INTERVAL, "ShowHUD", id)    return PLUGIN_HANDLED }

aim4lex 01-08-2007 21:19

Re: Rank plugin.
 
Thanks man, i love you.

aim4lex 01-08-2007 23:44

Re: Rank plugin.
 
Max rank that you can get its Private you can not go upper then it.
Could you fix it plz?

SweatyBanana 01-09-2007 01:44

Re: Rank plugin.
 
Quote:

Originally Posted by SweatyBanana (Post 424906)
He is getting the users rank stats.. Not just in game kills for that map/round/connection/whatever.

Notice the underlined words?

I said that he is pulling the users stats..

MaximusBrood 01-09-2007 03:43

Re: Rank plugin.
 
Instead of those endless if branches, just loop.

Code:
#include <amxmodx> #include <amxmisc> #include <csstats> #define HUD_INTERVAL 1.0 #define RANK_NOTHING 0 #define RANK_PRIVATE 1 #define RANK_PRIVATE_FIRST_CLASS 2 #define RANK_CORPORAL 3 #define RANK_SERGEANT 4 #define RANK_STAFF_SERGEANT 5 #define RANK_GUNNERY_SERGEANT 6 #define RANK_MASTER_SERGEANT 7 #define RANK_COMMAND_SERGEANT 8 #define RANK_SECOND_LIEUTENANT 9 #define RANK_FIRST_LIEUTENANT 10 #define RANK_COLONEL 11 #define RANK_BRIGADIER_GENERAL 12 #define RANK_MAJOR_GENERAL 13 #define RANK_LIEUTENANT_GENERAL 14 #define RANK_GENERAL 15 #define RANK_GENERAL_OF_THE_ARMY 16 #define MAXRANKS 17 new PlayerRank[33] new const rankNames[MAXRANKS][] = {  "None",  "Private",  "Private First Class",  "Corporal",  "Sergeant",  "Staff Sergeant",  "Gunnery Sergeant",  "Master Sergeant",  "Command Sergeant",  "Second Lieutenant",  "First Lieutenant",  "Colonel",  "Brigadier General",  "Major General",  "Lietenant General",  "General",  "General of the Army" } new const rankXP[MAXRANKS] = {     0, 100, 200, 400, 800, 1000, 2000, 4000, 8000, 10000, 12000, 15000, 20000, 40000, 50000, 80000, 100000 } public plugin_init() {  register_plugin("Rank Display", "0.1", "gaben") } public client_putinserver(id) {     set_task(HUD_INTERVAL, "ShowHUD", id)     return PLUGIN_HANDLED } public ShowHUD(id)     {       if(!is_user_connected(id))         return 0       static stats[8], hits[8], name[33]     get_user_stats(id, stats, hits)     get_user_name(id, name, 32)       new currentPlayerRank = 0;     while(currentPlayerRank < (MAXRANKS - 1))     {         if(stats[0] >= rankXP[currentPlayerRank + 1])             ++currentPlayerRank;         else             break;     }         //I have no idea why you are storing the rank here, maybe you're planning to use it later     PlayerRank[id] = currentPlayerRank;         set_hudmessage(237, 245, 9, 0.0, 0.6, 0, 6.0, 12.0)     show_hudmessage(id, "[%s - %s] Kills: %i", name, rankNames[currentPlayerRank], stats[0])       set_task(HUD_INTERVAL, "ShowHUD", id)       return PLUGIN_HANDLED }


All times are GMT -4. The time now is 22:30.

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