AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [ HELP ] Invalid Player (-1) ? (https://forums.alliedmods.net/showthread.php?t=275064)

CrazY. 11-21-2015 08:32

[ HELP ] Invalid Player (-1) ?
 
I've got the following error:
Code:

L 11/21/2015 - 11:25:12: Start of error session.
L 11/21/2015 - 11:25:12: Info (map "cs_assault") (file "addons/amxmodx/logs/error_20151121.log")
L 11/21/2015 - 11:25:12: [ZP] Invalid Player (-1)
L 11/21/2015 - 11:25:12: [AMXX] Run time error 10 (plugin "zp_bot_addon_give_random_extras.amxx") (native "zp_force_buy_extra_item") - debug not enabled!
L 11/21/2015 - 11:25:12: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).

I do not know what the problem is, how to fix?
Code:
#include < amxmodx > #include < zombieplague > new const VERSION[] = "1.0"; new g_max_players , g_has_extra[33] , cvar_give_extras_delay; public plugin_init() {     register_plugin("[ZP] Bot Addon: Give Random Extras", VERSION, "CrazY");     cvar_give_extras_delay = register_cvar("zp_give_extras_delay", "20.0");     g_max_players = get_maxplayers() } public zp_round_started()     set_task(get_pcvar_float(cvar_give_extras_delay), "GiveRandomExtraBot", 053, .flags="b"); public zp_round_ended() {     if (task_exists(053)) remove_task(053);     g_has_extra[0] = false; } public GiveRandomExtraBot() {     static iBotName[33], iBotsNum; iBotsNum = fnGetBot();     new BotID = fnGetRandomBot(random_num(1, iBotsNum));     get_user_name(BotID, iBotName, 32);     set_hudmessage(random(255), random(255), random(255), -1.0, 0.7, 1, 6.0, 1.1, 0.5, 0.5);     show_hudmessage(0, "O bot %s ganhou uma  M249 Para Machinegun", iBotName);     zp_force_buy_extra_item(BotID, zp_get_extra_item_id("M249 Para Machinegun"), 1);     g_has_extra[BotID] = true; } stock fnGetBot() {     new iBot, id;     for (id = 1; id <= g_max_players; id++)     {         if (is_user_bot(id) && is_user_connected(id)) iBot++;     }     return iBot; } stock fnGetRandomBot(target_index) {     new iBot, id;     for (id = 1; id <= g_max_players; id++)     {         if (is_user_bot(id) && is_user_connected(id) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id) && !g_has_extra[id]) iBot++;         if (iBot == target_index)             return id;     }     return -1; }

Rirre 11-21-2015 08:35

Re: [ HELP ] Invalid Player (-1) ?
 
Code:
stock fnGetRandomBot(target_index) {     new iBot, id;     for (id = 1; id <= g_max_players; id++)     {         if (is_user_bot(id) && is_user_connected(id) && !zp_get_user_zombie(id) && !zp_get_user_survivor(id) && !g_has_extra[id]) iBot++;         if (iBot == target_index)             return id;     }     return -1; }

CrazY. 11-21-2015 08:59

Re: [ HELP ] Invalid Player (-1) ?
 
Other log error:
Code:

L 11/21/2015 - 11:57:45: Start of error session.
L 11/21/2015 - 11:57:45: Info (map "cs_assault") (file "addons/amxmodx/logs/error_20151121.log")
L 11/21/2015 - 11:57:45: [ZP] Invalid Player (-1)
L 11/21/2015 - 11:57:45: [AMXX] Displaying debug trace (plugin "zp_bot_addon_give_random_extras.amxx")
L 11/21/2015 - 11:57:45: [AMXX] Run time error 10: native error (native "zp_force_buy_extra_item")
L 11/21/2015 - 11:57:45: [AMXX]    [0] zp_bot_addon_give_random_extras.sma::GiveRandomExtraBot (line 50)

Code:
zp_force_buy_extra_item(BotID, zp_get_extra_item_id("M249 Para Machinegun"), 1); // Line 50

Code:
stock fnGetRandomBot(target_index) {     new iBot, id; iBot = 0;     for (id = 1; id <= g_max_players; id++)     {         if (is_user_bot(id) && is_user_connected(id) && !zp_get_user_zombie(id) && !zp_get_user_sniper(id) && !zp_get_user_survivor(id) && !g_has_extra[id]) iBot++;         if (iBot == target_index)             return id;     }     return-1; }

Chihuahuax 11-21-2015 09:15

Re: [ HELP ] Invalid Player (-1) ?
 
Replace is_user_connected(id) with is_user_alive(id) ?

CrazY. 11-21-2015 09:23

Re: [ HELP ] Invalid Player (-1) ?
 
Does not work, same mistake.

Bugsy 11-21-2015 10:29

Re: [ HELP ] Invalid Player (-1) ?
 
Untested
PHP Code:


#include < amxmodx >
#include < zombieplague >

#define MAX_PLAYERS 32

new const VERSION[] = "1.0";

new 
bool:g_bHasExtraMAX_PLAYERS ]; 

new 
cvar_give_extras_delay;

public 
plugin_init()
{
    
register_plugin("[ZP] Bot Addon: Give Random Extras"VERSION"CrazY");
    
cvar_give_extras_delay register_cvar("zp_give_extras_delay""20.0");
}

public 
zp_round_started()
    
set_task(get_pcvar_float(cvar_give_extras_delay), "GiveRandomExtraBot"053, .flags="b");

public 
zp_round_ended()
{
    
remove_task053 );
        
    
arraysetg_bHasExtra false sizeofg_bHasExtra ) );
    
//g_has_extra[0] = false;
}

public 
GiveRandomExtraBot()
{
    static 
iBotName[33];
    new 
BotID fnGetBot();
    
    if ( 
BotID 
    {
        
get_user_name(BotIDiBotName32);
        
set_hudmessage(random(255), random(255), random(255), -1.00.716.01.10.50.5);
        
show_hudmessage(0"O bot %s ganhou uma  M249 Para Machinegun"iBotName);
        
zp_force_buy_extra_item(BotIDzp_get_extra_item_id("M249 Para Machinegun"), 1);
        
g_bHasExtraBotID ] = true;
    }
}

stock fnGetBot()
{
    new 
iPlayers32 ] , iNum id iBot;
    
    
get_playersiPlayers iNum "dh" );
    
    for ( new 
iNum i++ )
    {
        
id iPlayers];
        
        if ( !
g_bHasExtraid ] )
        {
            
iBot id;
            break;
        }
    }
    
    return 
iBot;


get_players() flags
Code:

Optional list of filtering flags:
  "a" - do not include dead clients
  "b" - do not include alive clients
  "c" - do not include bots
  "d" - do not include human clients
  "e" - match with team
  "f" - match with part of name
  "g" - match case insensitive
  "h" - do not include HLTV proxies
  "i" - include connecting clients


CrazY. 11-21-2015 12:10

Re: [ HELP ] Invalid Player (-1) ?
 
It work, But how do I give extra item only to bots that did not receive an extra?

Bugsy 11-21-2015 12:18

Re: [ HELP ] Invalid Player (-1) ?
 
Quote:

Originally Posted by CrazY. (Post 2365091)
It work, But how do I give extra item only to bots that did not receive an extra?

I missed that requirement. Code is fixed.


All times are GMT -4. The time now is 18:14.

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