qma
|
分享:
▼
x0
|
[1.6][插件] 关于NPC的问题
(版上的教学文看的不是很懂)
我要问的是 NPC怎么才能实现被杀死后有特殊效果 husa大大的方法我行不通
目前我已经有能力写出大型地图模式 我要用NPC实现障碍物的功能 用BOT当敌人 当障碍物破坏引发事件 转移BOT出生点
能帮我的话 谢谢了 我是用某老外的补给箱插件改的
#include <amxmodx> #include <amxmisc> #include <cstrike> #include <fakemeta> #include <engine> #include <fun> #include <hamsandwich> #define ADMIN_PRESENT_SPAWN ADMIN_RCON // access level for zp_ps_spawn command #define ADMIN_PRESENT_REMOVE ADMIN_RCON // access level for zp_ps_remove command #define ADMIN_PRESENT_STOP ADMIN_RCON // access level for zp_ps_stop command #define ADMIN_PRESENT_START ADMIN_RCON // access level for zp_ps_start command #define PRESENT_LIMIT 40 // maximum amount of presents new const present_model[] = "models/wall_n.mdl" // present model new file[78],total_presents, Float:present_data[PRESENT_LIMIT + 1][3], present_glow,present_light,present_light_radius,present_rot, spawn_time,min_presents,max_presents new g_hamnpc = 0 public plugin_precache() { precache_model(present_model) } public plugin_init() { register_plugin("[ZP] Addon: Present Spawner", "1.1", "Bill=Thailand=[UP] , <VeCo>") register_cvar("zp_addon_present_spawner_version","1.1",FCVAR_SERVER | FCVAR_SPONLY) register_logevent("round_end",2,"1=Round_End") register_logevent("round_start",2,"1=Round_Start") present_glow = register_cvar("zp_ps_present_glow","0") present_light = register_cvar("zp_ps_present_light","0") present_light_radius = register_cvar("zp_ps_present_light_radius","8") present_rot = register_cvar("zp_ps_present_rotate","0") spawn_time = register_cvar("zp_ps_spawn_presents_time","2.0") min_presents = register_cvar("zp_ps_min_spawn_presents","1") max_presents = register_cvar("zp_ps_max_spawn_presents","1") register_concmd("zp_ps_spawn","admin_present_spawn",ADMIN_PRESENT_SPAWN) register_concmd("zp_ps_remove","admin_present_remove",ADMIN_PRESENT_REMOVE) register_concmd("zp_ps_stop","admin_present_stop",ADMIN_PRESENT_STOP) register_concmd("zp_ps_start","admin_present_start",ADMIN_PRESENT_START) register_think("info_present","present_think") new mapname[32] get_mapname(mapname,31) format(file,77,"addons/amxmodx/configs/presents/%s.ini",mapname) load_presents() } public admin_present_spawn(id,level,cid) { if(!cmd_access(id,level,cid,1)) return PLUGIN_HANDLED if(total_presents == PRESENT_LIMIT) { console_print(id,"[ZP] Present limit exceeded! Maximum amount of presents is %i.",PRESENT_LIMIT) return PLUGIN_HANDLED } new Float:origin[3] entity_get_vector(id,EV_VEC_origin,origin) origin[2] -= 30.0 save_present(id,origin) return PLUGIN_HANDLED } public admin_present_remove(id,level,cid) { if(!cmd_access(id,level,cid,1)) return PLUGIN_HANDLED remove_all_presents() console_print(id,"[ZP] All presents were removed for this round.") return PLUGIN_HANDLED } public admin_present_stop(id,level,cid) { if(!cmd_access(id,level,cid,1)) return PLUGIN_HANDLED remove_all_presents() total_presents = 0 console_print(id,"[ZP] All presents were removed for this map.") return PLUGIN_HANDLED } public admin_present_start(id,level,cid) { if(!cmd_access(id,level,cid,1) || total_presents > 0) return PLUGIN_HANDLED remove_all_presents() load_presents() console_print(id,"[ZP] All presents were loaded for this map.") return PLUGIN_HANDLED } public round_end() { if(!total_presents) return remove_all_presents() } public round_start() { if(!total_presents) return remove_task(1337) set_task(get_pcvar_float(spawn_time),"spawn_random_presents",1337) } public spawn_random_presents() { new num = random_num(get_pcvar_num(min_presents),get_pcvar_num(max_presents)) if(num != 0) for(new ii=0;ii<num;ii++) spawn_present(present_data[random(total_presents)]) }
public present_think(ent) { if(get_pcvar_num(present_light)) { static Float:origin[3] entity_get_vector(ent,EV_VEC_origin,origin) engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0) write_byte(TE_DLIGHT) engfunc(EngFunc_WriteCoord, origin[0]) engfunc(EngFunc_WriteCoord, origin[1]) engfunc(EngFunc_WriteCoord, origin[2]) write_byte(get_pcvar_num(present_light_radius)) write_byte(entity_get_int(ent,EV_INT_iuser1)) write_byte(entity_get_int(ent,EV_INT_iuser2)) write_byte(entity_get_int(ent,EV_INT_iuser3)) write_byte(2) write_byte(0) message_end() } if(get_pcvar_num(present_rot)) { static Float:angles[3] entity_get_vector(ent,EV_VEC_angles,angles) angles[1]-- entity_set_vector(ent,EV_VEC_angles,angles) } entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01) } public remove_all_presents() remove_entity_name("info_present")
public load_presents() { total_presents = 0 new buffer[128], x[12],y[12],z[12] if(file_exists(file)) { new save = fopen(file,"rt") if(!save) return while(!feof(save)) { fgets(save,buffer,127) if(buffer[0] == ';' || !buffer[0]) continue parse(buffer, x,11, y,11, z,11) present_data[total_presents][0] = str_to_float(x) present_data[total_presents][1] = str_to_float(y) present_data[total_presents][2] = str_to_float(z) total_presents++ } fclose(save) } } public spawn_present(Float:origin[3]) { new ent = create_entity("info_target") if (!g_hamnpc) //記住!!g_hamnpc只能被放在function外面!! { RegisterHamFromEntity(Ham_Killed, ent, "fw_Killed") g_hamnpc = 1 } if(ent) { entity_set_string(ent,EV_SZ_classname,"info_present") entity_set_model(ent,present_model) entity_set_int(ent,EV_INT_solid,SOLID_BBOX) new Float:maxs[3] = {147.0,32.0,332.0} //這裡越大 NPC所佔的範圍越大 new Float:mins[3] = {-147.0,-32.0,-332.0} //這裡越小 NPC所佔的範圍越大 entity_set_size(ent,mins,maxs) //設定大小 entity_set_float(ent,EV_FL_health,500.0) //這裡是設定血量 entity_set_float(ent,EV_FL_takedamage,1.0) //這裡是讓它變成可被攻擊 entity_set_float(ent,EV_FL_gravity,1.0) if(get_pcvar_num(present_glow)) { entity_set_int(ent,EV_INT_iuser1,random(255)) entity_set_int(ent,EV_INT_iuser2,random(255)) entity_set_int(ent,EV_INT_iuser3,random(255)) set_rendering(ent,kRenderFxGlowShell,entity_get_int(ent,EV_INT_iuser1),entity_get_int(ent,EV_INT_iuser2),entity_get_int(ent,EV_INT_iuser3),kRenderNormal,60) } entity_set_origin(ent,origin) entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01) drop_to_floor(ent) } } public fw_Killed(victim, attacker) { //※跟上上方的說明一樣 非玩家指令不能用 除非你能確定你用的人是玩家 new classname[32] pev(victim,pev_classname,31) if (equal(classname,"info_present")) //這裡是檢查被打的人是不是NPC { if (is_user_connected(attacker)) //當攻擊者是玩家時 { give_item(attacker, "weapon_xm1014") } } return HAM_IGNORED }
public save_present(id,Float:origin[3]) { new save = fopen(file,"at") if(save) { fprintf(save,"%.2f %.2f %.2f^n",origin[0],origin[1],origin[2]) fclose(save) console_print(id,"[ZP] Present Spawn: successfully added at x:y:z(%.2f : %.2f : %.2f).",origin[0],origin[1],origin[2]) load_presents() } }
|