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

[Engine] entity_get_int(), NS v3.2b1 and AMXX 1.76b


  
 
 
Thread Tools Display Modes
Author Message
mrcoffee
Junior Member
Join Date: Jul 2006
Old 11-29-2006 , 18:01   [Engine] entity_get_int(), NS v3.2b1 and AMXX 1.76b
#1

Stumbled across a potential problem with using entity_get_int(playerid,EV_INT_team) to find a players team in Natural Selection v3.2b1 while rewriting the nscommands plugin to make it compatible with the latest version of NS. Instead of returning the values 1, 2 and 5 if a player is on marines, aliens or is spectating it is returning a value of 0 no matter what team the player is on. Testing the same code on a server running NS v3.1.3 and AMXX 1.75a resulted in entity_get_int(playerid,EV_INT_team) working perfectly and returning the correct value.

This is the nscommands code that I've rewritten, the command "amx_random" will print debug messages in global chat containing the values returned by entity_get_int(playerid,EV_INT_team) as a demo of above.

Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <ns>

#define PLUGIN "mrcoffee's NS commands"
#define VERSION "1.0"
#define AUTHOR "mrcoffee"

#define ACCESS_REQUIRED ADMIN_BAN

new team
new name_target[32]
new name[32]
new auth_target[35]
new auth[35]
new userid_target
new userid
new command_info[32]
new player_id

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    
    register_concmd("amx_alien","force_alien",ACCESS_REQUIRED,"<name or #userid>")
    register_concmd("amx_marine","force_marine",ACCESS_REQUIRED,"<name or #userid>")
    register_concmd("amx_uncomm","force_uncomm",ACCESS_REQUIRED," - force commander out of chair")
    register_concmd("amx_random","force_random",ACCESS_REQUIRED,"<name or #userid> - omit to do all in rr")
    register_concmd("amx_readyroom","force_readyroom",ACCESS_REQUIRED,"<name or #userid> - omit to do everybody")
}

public force_readyroom(id)
{
    if (!access(id,ACCESS_REQUIRED))
    {
        return PLUGIN_HANDLED
    }
    get_user_name(id,name,32)
    get_user_authid(id,auth,35)
    if (read_argc() > 1)
    {
        read_argv(1,command_info,32)
        player_id = cmd_target(id,command_info,1)
        if (!player_id)
        {
            client_print(id,print_chat,"[AMXX] That player is not on the server")
            return PLUGIN_HANDLED
        }
        get_user_name(player_id,name_target,32)
        get_user_authid(player_id,auth_target,35)
        
        switch (get_cvar_num("amx_show_activity"))
        {
            case 2: client_print(0,print_chat,"ADMIN %s: ready room %s",name,name_target)
            case 1: client_print(0,print_chat,"ADMIN: ready room %s",name_target)
        }
        log_amx("Cmd: ^"%s<%d><%s><>^" ready room ^"%s<%d><%s><>^"",name,get_user_userid(id),auth,name_target,get_user_userid(player_id),auth_target)
        
        engclient_cmd(player_id,"readyroom")
        engclient_cmd(player_id,"readyroom")
        return PLUGIN_HANDLED_MAIN
    }
        
    switch (get_cvar_num("amx_show_activity"))
    {
        case 2: client_print(0,print_chat,"ADMIN %s: ready room all",name)
        case 1: client_print(0,print_chat,"ADMIN: ready room all %s")
    }
    log_amx("Cmd: ^"%s<%d><%s><>^" ready room all",name,get_user_userid(id),auth)
    readyroom_loop()
    return PLUGIN_HANDLED_MAIN
}

public readyroom_loop()
{
    new numforced = 0
    for (new playerid; playerid <= get_maxplayers(); playerid++)
    {
        if (numforced > 4)
        {
            set_task(0.1,"readyroom_loop")
            break
        }
        if (!is_valid_ent(playerid))
        {
            continue
        }
        team = entity_get_int(playerid,EV_INT_team)
        if (team == 1 || team == 2)
        {
            engclient_cmd(playerid,"readyroom")
            engclient_cmd(playerid,"readyroom")
            numforced++
        }
    }
}

public force_random(id)
{    
    new numforced2 = 0
    if (!access(id,ACCESS_REQUIRED))
    {
        return PLUGIN_HANDLED
    }
    for (new playerid; playerid <= get_maxplayers(); playerid++)
    {
        if (numforced2 > 6)
        {
            set_task(0.1,"force_random")
            break
        }
        if (!is_valid_ent(playerid))
        {
            continue
        }
        team = entity_get_int(player_id,EV_INT_team)
        if (team != 1 && team != 2 && team != 5)
        {
            new name[32]
            get_user_name(playerid,name,32)
            client_print(0,print_chat,"%s on team %d and has playerid %d",name,team,playerid)
            engclient_cmd(playerid,"autoassign")
            numforced2++
        }
    }
    get_user_name(id,name,32)
    log_amx("Cmd: ^"%s<%d><%s><>^" random all",name,get_user_userid(id),auth)
    switch (get_cvar_num("amx_show_activity"))
    {
        case 2: client_print(0,print_chat,"ADMIN %s: random all",name)
        case 1: client_print(0,print_chat,"ADMIN: random all %s")
    }
    return PLUGIN_HANDLED_MAIN
}

public force_uncomm(id)
{
    if (!access(id,ACCESS_REQUIRED))
    {
        return PLUGIN_HANDLED
    }
    new is_comm = 0
    for (new playerid; playerid <= get_maxplayers(); playerid++)
    {
        if (!is_valid_ent(playerid))
        {
            continue
        }
        
        if (ns_get_class(playerid) == CLASS_COMMANDER)
        {
            get_user_authid(playerid,auth_target,35)
            get_user_name(playerid,name_target,32)
            userid_target = get_user_userid(playerid)
            engclient_cmd(playerid,"stopcommandermode")
            is_comm++
            break
        }
    }
    if (is_comm == 0)
    {
        client_print(id,print_chat,"[AMXX] There is no commander to eject")
        return PLUGIN_HANDLED
    }
    if (is_comm > 0)
    {
        get_user_name(id,name,32)
        get_user_authid(id,auth,35)
        userid = get_user_userid(id)
        switch (get_cvar_num("amx_show_activity"))
        {
            case 2: client_print(0,print_chat,"ADMIN %s: uncomm %s",name,name_target)
            case 1: client_print(0,print_chat,"ADMIN: uncomm %s",name_target)
        }
        log_amx("Cmd: ^"%s<d><%s><>^" uncomm ^"%s<d><%s><>^"",name,userid,auth,name_target,userid_target,auth_target)
    }
    return PLUGIN_HANDLED_MAIN
}

public force_marine(id)
{
    if (!access(id,ACCESS_REQUIRED))
    {
        return PLUGIN_HANDLED
    }
    if (read_argc() > 1)
    {
        read_argv(1,command_info,32)
        player_id = cmd_target(id,command_info,1)
        if (!player_id)
        {
            client_print(id,print_chat,"[AMXX] That player is not on the server")
            return PLUGIN_HANDLED
        }        
        team = entity_get_int(player_id,EV_INT_team)
        if (team == 1)
        {
            client_print(id,print_chat,"[AMXX] That player is already on marines")
            return PLUGIN_HANDLED
        }
        get_user_name(id,name,32)
        get_user_name(player_id,name_target,32)
        get_user_authid(id,auth,32)
        get_user_authid(player_id,auth_target,35)
        
        switch (get_cvar_num("amx_show_activity"))
        {
            case 2: client_print(0,print_chat,"ADMIN %s: marine %s",name,name_target)
            case 1: client_print(0,print_chat,"ADMIN: marine %s",name_target)
        }
        log_amx("Cmd: ^"%s<%d><%s><>^" alien ^"%s<%d><%s><>^"",name,get_user_userid(id),auth,name_target,get_user_userid(player_id),auth_target)
        
        engclient_cmd(player_id,"readyroom")
        engclient_cmd(player_id,"readyroom")
        engclient_cmd(player_id,"jointeamone")
        return PLUGIN_HANDLED_MAIN
    }
    return PLUGIN_CONTINUE
}

public force_alien(id)
{
    if (!access(id,ACCESS_REQUIRED))
    {
        return PLUGIN_HANDLED
    }
    if (read_argc() > 1)
    {
        read_argv(1,command_info,32)
        player_id = cmd_target(id,command_info,1)
        if (!player_id)
        {
            client_print(id,print_chat,"[AMXX] That player is not on the server")
            return PLUGIN_HANDLED
        }        
        team = entity_get_int(player_id,EV_INT_team)
        if (team == 2)
        {
            client_print(id,print_chat,"[AMXX] That player is already on aliens")
            return PLUGIN_HANDLED
        }
        get_user_name(id,name,32)
        get_user_name(player_id,name_target,32)
        get_user_authid(id,auth,32)
        get_user_authid(player_id,auth_target,35)
        
        switch (get_cvar_num("amx_show_activity"))
        {
            case 2: client_print(0,print_chat,"ADMIN %s: alien %s",name,name_target)
            case 1: client_print(0,print_chat,"ADMIN: alien %s",name_target)
        }
        log_amx("Cmd: ^"%s<%d><%s><>^" alien ^"%s<%d><%s><>^"",name,get_user_userid(id),auth,name_target,get_user_userid(player_id),auth_target)
        
        engclient_cmd(player_id,"readyroom")
        engclient_cmd(player_id,"readyroom")
        engclient_cmd(player_id,"jointeamtwo")
        return PLUGIN_HANDLED_MAIN
    }
    return PLUGIN_CONTINUE
}
mrcoffee is offline
BAILOPAN
Join Date: Jan 2004
Old 11-29-2006 , 19:47   Re: [Engine] entity_get_int(), NS v3.2b1 and AMXX 1.76b
#2

Unfortunately, this doesn't have anything to do with AMX Mod X. NS maintains those values privately and obviously something it did in between versions changed how you expected it to work.
__________________
egg
BAILOPAN is offline
toazron1
Senior Member
Join Date: Oct 2006
Old 11-30-2006 , 09:53   Re: [Engine] entity_get_int(), NS v3.2b1 and AMXX 1.76b
#3

make sure you have the latest nsamxx.dll file that we have patched for ns3.2
http://www.nsmod.org/forums/index.php?showtopic=6589
__________________
toazron1 is offline
Send a message via AIM to toazron1
karlos
Veteran Member
Join Date: Apr 2004
Location: Germany/Poland
Old 11-30-2006 , 10:56   Re: [Engine] entity_get_int(), NS v3.2b1 and AMXX 1.76b
#4

your code has bugs too
Code:
    for (new playerid; playerid <= get_maxplayers(); playerid++)   // here is the bug
    {
all your FOR loops
playerid starts with 0, but there is not player with id = 0
0 = server, so team is always 0
__________________
alias White Panther
karlos is offline
juKay
Member
Join Date: Mar 2004
Location: Sweden
Old 11-30-2006 , 11:29   Re: [Engine] entity_get_int(), NS v3.2b1 and AMXX 1.76b
#5

Quote:
Originally Posted by karlos View Post
your code has bugs too
Code:
    for (new playerid; playerid <= get_maxplayers(); playerid++)   // here is the bug
    {
all your FOR loops
playerid starts with 0, but there is not player with id = 0
0 = server, so team is always 0
Also a good thing to do is store the maxplayers count before the loop, else you just waste cpu cycles as get_maxplayers() get called for each loop the for-loop does.
juKay is offline
mrcoffee
Junior Member
Join Date: Jul 2006
Old 11-30-2006 , 14:04   Re: [Engine] entity_get_int(), NS v3.2b1 and AMXX 1.76b
#6

Found the problem, turns out the bug is actually a typo. The function should have been entity_get_int(playerid,EV_INT_team), not entity_get_int(player_id,EV_INT_team).
mrcoffee is offline
 



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 12:20.


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