Senior Member
|
04-08-2014
, 07:33
Bots Attack NPC
|
#1
|
Hi, as the title said I'd like to know how to make bots define that NPC is their enemy? This is my NPC code.
PHP Code:
new const ZOMBIE_CLASSNAME[] = "zombie_npc"; new const ZOMBIE_MODEL[] = "models/zombie_survival/zombie1.mdl";
public plugin_init() { register_plugin(PLUGIN, VERSION, AUTHOR); register_logevent("LogEvent_RoundStart", 2, "1=Round_Start"); register_think(ZOMBIE_CLASSNAME, "fwd_Think"); // Zombies attack players }
public LogEvent_RoundStart() { Load_Npc(); }
Load_Npc() { //Get the correct filepath and mapname new szConfigDir[256], szFile[256], szNpcDir[256]; get_configsdir(szConfigDir, charsmax(szConfigDir)); new szMapName[32]; get_mapname(szMapName, charsmax(szMapName)); formatex(szNpcDir, charsmax(szFile), "%s/zombie_survival", szConfigDir); formatex(szFile, charsmax(szFile), "%s/%s.cfg", szNpcDir, szMapName); //If the map config file does not exist we will make one if (!file_exists(szFile)) { //return PLUGIN_HANDLED_MAIN; //write_file(szFile, ""); } //Variables to store when reading our file new szFileOrigin[3][32]; new sOrigin[128], sAngle[128], Float:fOrigin[3], Float:fAngles[3]; new iLine, iLength, sBuffer[256]; //When we are reading our file... while (read_file(szFile, iLine++, sBuffer, charsmax(sBuffer), iLength)) { //Move to next line if the line is commented if((sBuffer[0]== ';') || !iLength) continue; //Split our line so we have origin and angle. The split is the vertical bar character strtok(sBuffer, sOrigin, charsmax(sOrigin), sAngle, charsmax(sAngle), '|', 0); //Store the X, Y and Z axis to our variables made earlier parse(sOrigin, szFileOrigin[0], charsmax(szFileOrigin[]), szFileOrigin[1], charsmax(szFileOrigin[]), szFileOrigin[2], charsmax(szFileOrigin[])); fOrigin[0] = str_to_float(szFileOrigin[0]); fOrigin[1] = str_to_float(szFileOrigin[1]); fOrigin[2] = str_to_float(szFileOrigin[2]); //Store the yawn angle fAngles[1] = str_to_float(sAngle[1]); //Keep reading the file until the end SpawnNpc(iLine, fOrigin, fAngles); } return PLUGIN_CONTINUE; }
SpawnNpc(iEnt, Float:flOrigin[3], Float:flAngle[3]) { iEnt = create_entity("info_target"); entity_set_string(iEnt, EV_SZ_classname, ZOMBIE_CLASSNAME); entity_set_model(iEnt, ZOMBIE_MODEL); entity_set_int(iEnt, EV_INT_solid, SOLID_SLIDEBOX); entity_set_int(iEnt, EV_INT_movetype, MOVETYPE_PUSHSTEP); entity_set_int(iEnt, EV_INT_flags, FL_MONSTER); entity_set_vector(iEnt, EV_VEC_angles, flAngle); entity_set_vector(iEnt, EV_VEC_origin, flOrigin); entity_set_byte(iEnt, EV_BYTE_controller1, 125); entity_set_byte(iEnt, EV_BYTE_controller2, 125); entity_set_byte(iEnt, EV_BYTE_controller3, 125); entity_set_byte(iEnt, EV_BYTE_controller4, 125); entity_set_float(iEnt, EV_FL_animtime, 2.0); entity_set_float(iEnt, EV_FL_framerate, 1.0); entity_set_float(iEnt, EV_FL_health, 200.0); entity_set_float(iEnt, EV_FL_takedamage, 1.0); entity_set_float(iEnt, EV_FL_dmg_take, DAMAGE_YES); entity_set_float(iEnt, EV_FL_gravity, 20.0); entity_set_vector(iEnt, EV_VEC_velocity, Float:{100.0, 100.0, 100.0}); new Float:maxs[3] = {16.0, 16.0, 36.0}; new Float:mins[3] = {-16.0, -16.0, -36.0}; entity_set_size(iEnt, mins, maxs); entity_set_int(iEnt, EV_INT_sequence, 0); entity_set_float(iEnt, EV_FL_nextthink, get_gametime() + 2.0); }
I ever tried by checking the distance between bots and npc if it is in bots' range, then set the bots' angles and execute Ham_Weapon_PrimaryAttack. It worked but it uses CPU usage and causes lag. Any solution to control bots?
__________________
What are you looking for here?
|
|