廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 3022 個閱讀者
 
發表文章 發表投票 回覆文章
  可列印版   加為IE收藏   收藏主題   上一主題 | 下一主題   
qma
數位造型
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x16 鮮花 x43
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片
推文 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()
    }
}
 



獻花 x0 回到頂端 [樓 主] From:上海 | Posted:2012-02-16 13:47 |
HiNess
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x11 鮮花 x51
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

都是用Ham_Killed判斷


獻花 x0 回到頂端 [1 樓] From:未知地址 | Posted:2012-02-16 17:31 |
qma
數位造型
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x16 鮮花 x43
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

沒人麽 我不要無意義回複
要完整的 謝了


獻花 x0 回到頂端 [2 樓] From:歐洲 | Posted:2012-02-17 19:08 |
husano896 手機
個人頭像
個人文章 個人相簿 個人日記 個人地圖
初露鋒芒
級別: 初露鋒芒 該用戶目前不上站
推文 x79 鮮花 x138
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

if (!g_hamnpc)     //記住!!g_hamnpc只能被放在function外面!!
{
    RegisterHamFromEntity(Ham_Killed, ent, "fw_Killed")
    g_hamnpc = 1
}
放在
    entity_set_string(ent,EV_SZ_classname,"info_present") 下面看看


這邊流動率真的挺低的'w' 但我是有在看的哦w
也許哪天被我亂入也說不定(!?

按這裡檢視影片,登入論壇可以直接觀看
*ZP*沒爆頭回合不結束

↓吃瀏覽數長大的龍:)
獻花 x0 回到頂端 [3 樓] From:臺灣中華電信股份有限公司 | Posted:2012-02-18 07:24 |
qma
數位造型
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x16 鮮花 x43
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

下面是引用 husano896 於 2012-02-18 07:24 發表的 : 到引言文
if (!g_hamnpc)     //記住!!g_hamnpc只能被放在function外面!!
{
    RegisterHamFromEntity(Ham_Killed, ent, "fw_Killed")
    g_hamnpc = 1
}
放在
    entity_set_string(ent,EV_SZ_classname,"info_present") 下面看看



试了不行
不知道为什么 NPC被破坏后什么也没发生(尽管我已经设定会加钱)


獻花 x0 回到頂端 [4 樓] From:未知地址 | Posted:2012-02-18 14:35 |
qma
數位造型
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x16 鮮花 x43
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

大大
我搞定了
我知道是什么原因了

pev(victim,pev_classname,31) 这句话不正确
正确是这样的
pev(victim, pev_classname, classname, charsmax(classname))
我照NST插件改的
也谢谢你了


[ 此文章被qma在2012-02-18 14:50重新編輯 ]


獻花 x0 回到頂端 [5 樓] From:未知地址 | Posted:2012-02-18 14:43 |

首頁  發表文章 發表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.024391 second(s),query:16 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言