AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Crash when creating a bot (https://forums.alliedmods.net/showthread.php?t=308488)

marcelowzd 06-22-2018 00:49

Crash when creating a bot
 
Hello, i was trying to create a simple BOT with the following code.

PHP Code:

new g_iBotIndex;

public 
plugin_init( )
{
    
register_clcmd"CreateBot""BOT" );
}

public 
BOTid )
{
    
g_iBotIndex engfuncEngFunc_CreateFakeClient"Test Bot" );

    if( !
g_iBotIndex )
        return 
PLUGIN_HANDLED;

    
console_printid"Bot criado com id %i"g_iBotIndex );

    
engfuncEngFunc_FreeEntPrivateDatag_iBotIndex );

    static 
szBlock128 ];

    
//console_print( id, "Tentativa de conectar PRE" );

    
dllfuncDLLFunc_ClientConnectg_iBotIndex"[SV] Pro 1 BOT""127.0.0.1"szBlock );

    
console_printid"Tentativa de conectar POST" );

    if( !
is_user_connectedg_iBotIndex ) )
        return 
PLUGIN_HANDLED;

    
console_printid"Bot conectado" );

    
dllfuncDLLFunc_ClientPutInServerg_iBotIndex );

    
console_printid"Bot entrou no server" );

    
set_pevg_iBotIndexpev_spawnflagspevg_iBotIndexpev_spawnflags ) | FL_FAKECLIENT ); 
    
set_pevg_iBotIndexpev_flagspevg_iBotIndex,pev_flags ) | FL_FAKECLIENT );

    return 
PLUGIN_HANDLED;


Sometimes it works and sometimes it just crashes my CS. As you can see i already used some debug messages, but when the game crashes, it doesn't show anything at all. What could be the problem?

Some more info: Using AMXX 1.8.3 +dev5154, Metamod-P v1.21p37.

Natsheh 06-22-2018 03:57

Re: Crash when creating a bot
 
FL_FAKECLIENT this is not a spawn flag constants/values it doesnt go with pev_spawnflags, the ones that does go with it starts with prefix SF_

Try looking at some already existing plugins for how to correctly create a fake bot.

marcelowzd 06-22-2018 04:26

Re: Crash when creating a bot
 
What? This code is from Bugsy's Aimbot Detection Plugin (https://forums.alliedmods.net/showthread.php?p=689045)

He even had problems with this before, here ( https://forums.alliedmods.net/showthread.php?p=768468 )

Also, if i remove them the game still crashes.

Natsheh 06-22-2018 04:37

Re: Crash when creating a bot
 
Try swaping the bot into a team.

The code looks fine.

The crash might be not from that peice of code.

If you still believe the crash is from this use log to file. As debug

marcelowzd 06-22-2018 10:14

Re: Crash when creating a bot
 
Did as you requested with the same code, but changed everything to log_amx()

PHP Code:

public BOTid )
{
    
g_iBotIndex engfuncEngFunc_CreateFakeClient"Test Bot" );

    if( !
g_iBotIndex )
        return 
PLUGIN_HANDLED;

    
log_amx"Bot created with ID %i"g_iBotIndex );

    
log_amx"FREE ENT PRIVATE DATA PRE" );

    
engfuncEngFunc_FreeEntPrivateDatag_iBotIndex );

    
log_amx"FREE ENT PRIVATE DATA POST" );

    static 
szBlock128 ];

    
log_amx"BOT CONNECT PRE" );

    
dllfuncDLLFunc_ClientConnectg_iBotIndex"[SV] Pro 1 BOT""127.0.0.1"szBlock );

    
log_amx"BOT CONNECT POST" );

    if( !
is_user_connectedg_iBotIndex ) )
        return 
PLUGIN_HANDLED;

    
log_amx"BOT CONNECTED" );

    
log_amx"BOT PUTINSERVER PRE" );

    
dllfuncDLLFunc_ClientPutInServerg_iBotIndex );

    
log_amx"BOT PUTINSERVER POST" );

    
set_pevg_iBotIndexpev_spawnflagspevg_iBotIndexpev_spawnflags ) | FL_FAKECLIENT ); 
    
set_pevg_iBotIndexpev_flagspevg_iBotIndex,pev_flags ) | FL_FAKECLIENT );


The log shows nothing.

Code:

L 06/22/2018 - 01:36:38: -------- Mapchange to bhm_novice --------
L 06/22/2018 - 01:38:05: -------- Mapchange to bhop_celsbrick --------
L 06/22/2018 - 01:52:26: -------- Mapchange to bhm_novice --------
L 06/22/2018 - 11:10:16: -------- Mapchange to bhop_celsbrick --------

The game freezes and than crashes is a better description. Also, this is the only plugin running.

marcelowzd 06-22-2018 13:11

Re: Crash when creating a bot
 
After doing a clean install for the second time it started working, but now when i spawn the bot he is invisible.

PHP Code:

public BOTid )
{
    
g_iBotIndex engfuncEngFunc_CreateFakeClient"Test Bot" );

    if( !
g_iBotIndex )
        return 
PLUGIN_HANDLED;

    
engfuncEngFunc_FreeEntPrivateDatag_iBotIndex );

    static 
szBlock128 ];

    
dllfuncDLLFunc_ClientConnectg_iBotIndex"[SV] Pro 1 BOT""127.0.0.1"szBlock );

    if( !
is_user_connectedg_iBotIndex ) )
        return 
PLUGIN_HANDLED;

    
dllfuncDLLFunc_ClientPutInServerg_iBotIndex );

    
set_pevg_iBotIndexpev_spawnflagspevg_iBotIndexpev_spawnflags ) | FL_FAKECLIENT ); 
    
set_pevg_iBotIndexpev_flagspevg_iBotIndex,pev_flags ) | FL_FAKECLIENT );

    
cs_set_user_teamg_iBotIndexCS_TEAM_CTCS_CT_GSG9 );

    
ExecuteHamBHam_CS_RoundRespawng_iBotIndex ); // Tried

    //dllfunc( DLLFunc_Spawn, g_iBotIndex );  // Tried

    
if( !is_user_aliveg_iBotIndex ) )
        return 
PLUGIN_HANDLED;

    
//set_user_rendering( g_iBotIndex, kRenderFxNone, 255, 255, 255, kRenderNormal, 25 ); // Tried

    
fm_set_renderingg_iBotIndexkRenderNormal255255255kRenderNormal25 ); // Tried

    //fm_set_user_rendering( g_iBotIndex, kRenderFxGlowShell, 0, 0, 0, kRenderNormal, 25 ); //Tried

    //set_pev( g_iBotIndex, pev_origin, fOrigin );

    
return PLUGIN_HANDLED;


I can see his name, health and he can block me, but he is completely invisible.
Neither option listed above worked.

Kushfield 06-22-2018 13:58

Re: Crash when creating a bot
 
Try running this line twice in a row:
ExecuteHamB( Ham_CS_RoundRespawn, g_iBotIndex ); // Tried

I can't remember what exactly, but there's some issues when executing it just once, this might be one of them.

marcelowzd 06-22-2018 14:02

Re: Crash when creating a bot
 
Tested, same happens, and i'm pretty sure you're talking about fun's spawn() function, because it used to have problems when spawning players (i'm not sure if it still does, but everyone says you should use ExecuteHam to spawn a player)

Kushfield 06-22-2018 14:22

Re: Crash when creating a bot
 
I tried the exact code you last posted as the only plugin on my server and the bot is visible to me. Could the problem be somewhere else?

Natsheh 06-22-2018 15:11

Re: Crash when creating a bot
 
Try giving him amodel and set an animation.

Can i ask whats the point of this?


All times are GMT -4. The time now is 12:34.

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