| AzcariaX |
05-30-2010 14:05 |
Bot disappears some time after creation
Hello.
I'm trying to make a bot which spawns when you say /bot. The bot spawns without any problem. Then it starts to follow you as expected. After approximately 7 seconds it suddenly teleports to another location. It teleports between about 5 different locations and its not meant to teleport at all!
I have no idea what i've done wrong, here my code:
Most of this code comes from this plugin: http://forums.alliedmods.net/showthread.php?p=552563
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <cstrike>
#define PLUGIN "The bot"
#define VERSION "1.0"
#define AUTHOR "El Maco"
new is_bot[33]
new owner[33]
new MaxPlayers
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("say /bot", "bot_create")
register_forward(FM_StartFrame, "forward_startFrame", 1)
MaxPlayers=get_maxplayers()
}
public bot_create(id)
{
new bot = engfunc(EngFunc_CreateFakeClient, "BOT")
if (!bot)
{
server_print("Couldn't create a bot, server full?")
return PLUGIN_HANDLED
}
engfunc(EngFunc_FreeEntPrivateData, bot)
set_user_info(bot, "model", "gordon")
set_user_info(bot, "rate", "3500")
set_user_info(bot, "cl_updaterate", "30")
set_user_info(bot, "cl_lw", "0")
set_user_info(bot, "cl_lc", "0")
set_user_info(bot, "tracker", "0")
set_user_info(bot, "cl_dlmax", "128")
set_user_info(bot, "lefthand", "1")
set_user_info(bot, "friends", "0")
set_user_info(bot, "dm", "0")
set_user_info(bot, "ah", "1")
set_user_info(bot, "*bot", "1")
set_user_info(bot, "_cl_autowepswitch", "1")
set_user_info(bot, "_vgui_menu", "0")
set_user_info(bot, "_vgui_menus", "0")
new szRejectReason[128]
dllfunc(DLLFunc_ClientConnect, bot, "BOT", "127.0.0.1", szRejectReason)
if (!is_user_connected(bot))
{
server_print("Connection rejected: %s", szRejectReason)
return PLUGIN_HANDLED
}
dllfunc(DLLFunc_ClientPutInServer, bot);
set_pev(bot, pev_spawnflags, pev(bot, pev_spawnflags) | FL_FAKECLIENT)
set_pev(bot, pev_flags, pev(bot, pev_flags) | FL_FAKECLIENT)
set_user_flags(bot, ADMIN_IMMUNITY | ADMIN_USER)
set_cvar_num("mp_autokick", 0)
cs_set_user_team(bot, CS_TEAM_CT)
server_print("Bot successfully created! Id: %d, name: BOT", bot)
dllfunc(DLLFunc_Spawn, bot)
is_bot[bot]=1
owner[bot]=id
return PLUGIN_HANDLED
}
public forward_startFrame()
{
static Float:msecval, msec, id, Float:angles[3], buttons, Float:target_origin[3], Float:bot_origin[3], Float:bot_velocity[3]
global_get(glb_frametime, msecval), msec = floatround(msecval * 1000.0);
for (id = 1; id <= MaxPlayers; id++)
{
if (is_bot[id])
{
if (is_user_alive(id))
{
pev(owner[id], pev_origin, target_origin)
pev(id, pev_origin, bot_origin)
pev(id, pev_velocity, bot_velocity)
target_origin[0]-=bot_origin[0]
target_origin[1]-=bot_origin[1]
target_origin[2]-=bot_origin[2]
vector_to_angle(target_origin, angles)
buttons=0
target_origin[0]*-1
target_origin[1]*-1
target_origin[2]=bot_velocity[2]
set_pev(id, pev_velocity, target_origin)
set_pev(id, pev_v_angle, angles)
angles[0] /= -3.0;
set_pev(id, pev_angles, angles)
engfunc(EngFunc_RunPlayerMove, id, angles, vector_length(bot_velocity), 0.0, 0.0, buttons, 0, msec)
}
}
}
return FMRES_IGNORED
}
Please help me.
|