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

get_players & get_user_team fix


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   Counter-Strike        Category:   Technical/Development       
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 09-11-2010 , 21:05   get_players & get_user_team fix
Reply With Quote #1

get_players & get_user_team fix




.: Description :.

When you change team, get_user_team() returns the previous team index untill you spawn. This plugin fixes that bug. Should be fixed by amxx dev though...
Also fixes get_players native that by default can return false result with flag "e" and dead players.


.: Modules/Requirements :.

Fakemeta
Attached Files
File Type: sma Get Plugin or Get Source (get_user_team_fix.sma - 4045 views - 1.5 KB)
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 09-13-2010 at 01:09.
ConnorMcLeod is offline
GXLZPGX
Veteran Member
Join Date: Sep 2009
Old 09-11-2010 , 21:07   Re: get_user_team fixer
Reply With Quote #2

Quote:
Originally Posted by ConnorMcLeod View Post
get_user_team() Fix




.: Description :.

When you change team, get_user_team() returns the previous team index untill you spawn. This plugin fixes that bug. Should be fixed by amxx dev though...


.: Modules/Requirements :.

Fakemeta
Very nice. Reviewing the code atm.

Edit: I don't see any problems, though I'm not one to listen to, I'm not retarded.
__________________
Currently accepting payment US DOLLARS ONLY for custom plugins, contact me through PM.
GXLZPGX is offline
fezh
Veteran Member
Join Date: Dec 2008
Location: BANNED
Old 09-11-2010 , 21:34   Re: get_user_team fixer
Reply With Quote #3

Quote:
Originally Posted by ConnorMcLeod View Post
Should be fixed by amxx dev though...
Indeed. For CS I stick with cs_get_user_team(), but this will be useful for other mods.
__________________
"There is no knowledge, that is not power"
fezh is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-11-2010 , 23:25   Re: get_user_team fixer
Reply With Quote #4

Quote:
Originally Posted by fezh View Post
Indeed. For CS I stick with cs_get_user_team(), but this will be useful for other mods.
Won't work in other mods. The pdata offset 114 is CS-specific.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 09-13-2010 , 01:10   Re: get_user_team fixer
Reply With Quote #5

Quote:
Originally Posted by fezh View Post
Indeed. For CS I stick with cs_get_user_team(), but this will be useful for other mods.
Forgot to write (hadn't tested when i posted the plugin) that get_players() native is fixed as well and is more usefull than get_user_team because there is not so efficient alternative.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-13-2010 , 20:43   Re: get_user_team fixer
Reply With Quote #6

Quote:
Originally Posted by Exolent[jNr] View Post
Won't work in other mods. The pdata offset 114 is CS-specific.
I suppose for that same reason you couldn't add a fix for 1.8.2?
__________________
fysiks is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 09-14-2010 , 01:40   Re: get_players & get_user_team fix
Reply With Quote #7

Not at all, get_user_team has 2 differents properties, independant one from other.

index (returned) based on ScoreInfo event, and Team Name (optional string param) that is based on TeamInfo event.
Team name is always correct, only index is wrong when you change team when you are dead.

Strangely, get_players and flag "e" (matching with team name) is base on the index ScoreInfo.

I'm not sure at all that i described all how team is handled and i'm not sure that the only problem is when you change your team while dead, but i think it's ok.

When you change team while alive, game first kill you, send a ScoreInfo event with your actual team, then change your team and send a TeamInfo event, that's why index from get_user_team is false at this moment untill a new ScoreInfo event is sent (at spawn).
If you were already dead at the moment you change team, no ScoreInfo event is sent at all.


If you can read amxx sources and see more than me, would be usefull to post a diff.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-14-2010 , 03:42   Re: get_players & get_user_team fix
Reply With Quote #8

Code:
static cell AMX_NATIVE_CALL get_players(AMX *amx, cell *params) /* 4 param */
{
    int iNum = 0;
    int ilen;
    char* sptemp = get_amxstring(amx, params[3], 0, ilen);
    int flags = UTIL_ReadFlags(sptemp);

    cell *aPlayers = get_amxaddr(amx, params[1]);
    cell *iMax = get_amxaddr(amx, params[2]);

    int team = 0;

    if (flags & 48)
    {
        sptemp = get_amxstring(amx, params[4], 0, ilen);

        if (flags & 16)
        {
            if (flags & 64)
                team = g_teamsIds.findTeamId(sptemp);
            else
                team = g_teamsIds.findTeamIdCase(sptemp);
        }
    }

    for (int i = 1; i <= gpGlobals->maxClients; ++i)
    {
        CPlayer* pPlayer = GET_PLAYER_POINTER_I(i);
        if (pPlayer->ingame)
        {
            if (pPlayer->IsAlive() ? (flags & 2) : (flags & 1))
                continue;
            if (pPlayer->IsBot() ? (flags & 4) : (flags & 8))
                continue;
            if ((flags & 16) && (pPlayer->teamId != team))
                continue;
            if ((flags & 128) && (pPlayer->pEdict->v.flags & FL_PROXY))
                continue;
            if (flags & 32)
            {
                if (flags & 64)
                {
                    if (stristr(pPlayer->name.c_str(), sptemp) == NULL)
                        continue;
                }
                else if (strstr(pPlayer->name.c_str(), sptemp) == NULL)
                    continue;
            }
            aPlayers[iNum++] = i;
        }
    }

    *iMax = iNum;
    
    return 1;
}
Should be:
Code:
static cell AMX_NATIVE_CALL get_players(AMX *amx, cell *params) /* 4 param */
{
    typedef int (*STRCOMPARE)(const char*, const char*);
    STRCOMPARE func;
    
    int iNum = 0;
    int ilen;
    char* sptemp = get_amxstring(amx, params[3], 0, ilen);
    int flags = UTIL_ReadFlags(sptemp);

    cell *aPlayers = get_amxaddr(amx, params[1]);
    cell *iMax = get_amxaddr(amx, params[2]);

    if (flags & 48)
    {
        sptemp = get_amxstring(amx, params[4], 0, ilen);
    }
    
    if (flags & 64)
        func = strcasecmp;
    else
        func = strcmp;

    for (int i = 1; i <= gpGlobals->maxClients; ++i)
    {
        CPlayer* pPlayer = GET_PLAYER_POINTER_I(i);
        if (pPlayer->ingame)
        {
            if (pPlayer->IsAlive() ? (flags & 2) : (flags & 1))
                continue;
            if (pPlayer->IsBot() ? (flags & 4) : (flags & 8))
                continue;
            if ((flags & 16) && (func)(pPlayer->team.c_str(), sptemp)
                continue;
            if ((flags & 128) && (pPlayer->pEdict->v.flags & FL_PROXY))
                continue;
            if ((flags & 32) && (func)(pPlayer->name.c_str(), sptemp))
                continue;
            aPlayers[iNum++] = i;
        }
    }

    *iMax = iNum;
    
    return 1;
}
Checks for team name rather than team id, also a bit case sensitivity correction copied from the find_player function's code.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 09-16-2010 , 05:54   Re: get_players & get_user_team fix
Reply With Quote #9

Nice for the get_players() flag fix =o
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...
Alucard^ is offline
Send a message via Skype™ to Alucard^
Fr33m@n
Veteran Member
Join Date: May 2008
Location: France Marne
Old 10-05-2010 , 07:19   Re: get_players & get_user_team fix
Reply With Quote #10

It would be nice if these modification is added in a new build. But when i see the low numbers of new build...
Fr33m@n 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 15:12.


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