381828358 发表于 2011-8-18 11:22:24

终结者p90滚筒枪插件

本帖最后由 381828358 于 2011-8-18 14:12 编辑

我想搞这个插件 终结者p90但是不知道哪里出错了。不是编辑不了,就是带不了服。高手帮我看看

下面这个是我搞的源码

381828358 发表于 2011-8-18 11:25:45

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <cstrike>
#include <xs>

#define SUPPORT_CZBOT

#if defined SUPPORT_CZBOT
new cvar_botquota
new bool:BotHasDebug = false
#endif

#define TASK_RESET_WEAPON        12345

const OFFSET_FlNextPrimaryAttack = 46

const OFFSET_LINUX_WEAPONS = 4

const PRIMARY_WEAPONS_BIT_SUM = (1<<CSW_m249)
new const p_p90_V_Model[] = { "models/v_p90.mdl" }
new const p_p90_P_Model[] = { "models/p_p90.mdl" }
new const p_p90_W_Model[] = { "models/w_p90.mdl" }

new cvar_dmg_multiplier, cvar_knock_power, cvar_fire_rate, cvar_bullet_tracer
new g_beamSpr

new g_maxplayers
new bool:hasp_p90 = { false, ... }
new user_clip = { 0, ... }, user_bpammo = { 0, ... }
new user_drop = { -1, ... }, Float:drop_time = { 0.0, ... }
new bool:user_shoot = { false, ... }

public plugin_init()
{
        register_clcmd("say /buy_p_p90","p_p90")
        register_cvar("p_p90cost","5000")
        register_plugin("Make your own weapon", "4.0", "FOT")
       
        cvar_dmg_multiplier = register_cvar("cs_lahumshi_dmgmultiplier", "60")
        cvar_knock_power = register_cvar("cs_lahumshi_knockpower", "40")
        cvar_fire_rate = register_cvar("cs_lahumshi_firerate", "0.05")
       
        RegisterHam(Ham_TakeDamage, "player", "fw_Player_TakeDamage")
        RegisterHam(Ham_TraceAttack, "player", "fw_Player_TraceAttack")
        RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_m249", "fw_m249_PriAttack")
        RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_m249", "fw_m249_PriAttack_Post", 1)
       
        register_forward(FM_SetModel, "fw_SetModel")
        register_forward(FM_Touch, "fw_Touch")
       
        register_event("CurWeapon", "event_cur_weapon", "be", "1=1")
        register_event("HLTV", "event_round_start", "a", "1=0", "2=0")
       
        g_maxplayers = get_maxplayers()
       
        #if defined SUPPORT_CZBOT
        cvar_botquota = get_cvar_pointer("bot_quota")
        #endif
       
        new Float:maptime = get_cvar_float("mp_timelimit")
        if (maptime == 0.0)
                maptime = 15.0
        new Float:anntime = 60.0 * 5.0 // 5 minutes
        if (maptime < 5.0)
                anntime = maptime / 3.0
      set_task(anntime, "Announcement", 0, "", 0, "b")
}

public plugin_precache()
{
        precache_model(p_p90_V_Model)
        precache_model(p_p90_P_Model)
        precache_model(p_p90_W_Model)
       
        g_beamSpr = precache_model("sprites/zbeam4.spr")
}

public Announcement(id) {
        client_print(id, print_chat, "所有玩家可買p_p90 ")
}

public p_p90(id)
{
        new p_p90cost = get_cvar_num("p_p90cost")
      new money = cs_get_user_money(id)
       
        if(!is_user_alive(id))
        {
                client_print(id,print_chat,"活著才能買p_p90^n")
                return
        }
       
        if(hasp_p90)
        {
                client_print(id,print_chat,"你已經有p_p90了^n")
                cs_set_user_bpammo(id, CSW_M249, 90)
                return
        }
       
        if(money < p_p90cost)
        {
                client_print(id,print_chat,"現金不足^n")
                return
        }
       
        cs_set_user_money(id,money-p_p90cost)
        client_print(id,print_chat,"你買了p_p90^n")
        user_drop_m249(id)
        hasp_p90 = true
        fm_give_item(id, "weapon_m249")
        cs_set_user_bpammo(id, CSW_M249, 200)
        engclient_cmd(id, "weapon_m249")
}

user_drop_m249(id)
{
        if (user_has_weapon(id, CSW_M249))
        {
                engclient_cmd(id, "drop", "weapon_m249")
        }
}

public fw_Player_TakeDamage(victim, attacker, Float:damage, damage_type)
{
        static Float:damage_multiplier
        damage_multiplier = get_pcvar_float(cvar_dmg_multiplier)
        if (damage_multiplier <= 0.0)
                return HAM_IGNORED;
       
        if (victim == attacker || !is_user_connected(attacker))
                return HAM_IGNORED;
       
        if (!(damage_type & DMG_BULLET))
                return HAM_IGNORED;
       
        if (!hasp_p90 || (get_user_weapon(attacker) != CSW_M249))
                return HAM_IGNORED;
       
        SetHamParamFloat(4, damage * damage_multiplier)
       
        return HAM_IGNORED;
}

public fw_Player_TraceAttack(victim, attacker, Float:damage, Float:direction, tracehandle, damage_type)
{
        static Float:knockpower
        knockpower = get_pcvar_float(cvar_knock_power)
        if (knockpower <= 0.0)
                return HAM_IGNORED;
       
        if (victim == attacker || !is_user_connected(attacker))
                return HAM_IGNORED;
       
        if (!(damage_type & DMG_BULLET) || !get_cvar_num("cs_knockback"))
                return HAM_IGNORED;
       
        if (!hasp_p90 || (get_user_weapon(attacker) != CSW_M249))
                return HAM_IGNORED;
       
        static victimflags, Float:knockduck
        victimflags = pev(victim, pev_flags)
        knockduck = get_cvar_float("cs_knockback_ducking")
       
        if (knockduck == 0.0 && (victimflags & FL_DUCKING) && (victimflags & FL_ONGROUND))
                return HAM_IGNORED;
       
        static Float:origin1F, Float:origin2F
        pev(victim, pev_origin, origin1F)
        pev(attacker, pev_origin, origin2F)
       
        if (get_distance_f(origin1F, origin2F) > get_cvar_float("cs_knockback_distance"))
                return HAM_IGNORED;
       
        static Float:velocity
        pev(victim, pev_velocity, velocity)
       
        if (get_cvar_num("cs_knockback_damage"))
                xs_vec_mul_scalar(direction, damage, direction)
       
        if (knockpower > 0.0 && get_cvar_num("cs_knockback_power"))
                xs_vec_mul_scalar(direction, knockpower, direction)
       
        if ((victimflags & FL_DUCKING) && (victimflags & FL_ONGROUND))
                xs_vec_mul_scalar(direction, knockduck, direction)
       
        xs_vec_add(velocity, direction, direction)
       
        if (!get_cvar_num("cs_knockback_zvel"))
                direction = velocity
       
        set_pev(victim, pev_velocity, direction)
       
        SetHamParamVector(4, Float:{0.0, 0.0, 0.0})
       
        return HAM_IGNORED;
}

public fw_m249_PriAttack(weapon)
{
        if (!pev_valid(weapon))
                return HAM_IGNORED;
       
        static owner
        owner = pev(weapon, pev_owner)
       
        if (hasp_p90)
        {
                if (cs_get_weapon_ammo(weapon) > 0)
                {
                        user_shoot = true
                }
        }
       
        return HAM_IGNORED;
}

public fw_m249_PriAttack_Post(weapon)
{
        if (!pev_valid(weapon))
                return HAM_IGNORED;
       
        static owner
        owner = pev(weapon, pev_owner)
       
        if (hasp_p90)
        {
                if (user_shoot)
                {
                        static Float:fire_rate
                        fire_rate = get_pcvar_float(cvar_fire_rate)
                        if (fire_rate > 0.0)
                        {
                                static Float:next_pri_attack_time
                                next_pri_attack_time = get_weapon_next_pri_attack(weapon) * fire_rate
                                set_weapon_next_pri_attack(weapon, next_pri_attack_time)
                        }
                       
                        if (get_pcvar_num(cvar_bullet_tracer))
                        {
                                static Float:origin1, Float:origin2 //, iOrigin
                                fm_get_aim_vector(owner, 40, origin1, origin2)
                                origin1 += (pev(owner, pev_flags) & FL_DUCKING) ? 3.0 : -7.0
                                show_tracer_effect(origin1, origin2)
                        }
                       
                        user_shoot = false
                }
        }
       
        return HAM_IGNORED;
}

show_tracer_effect(const Float:start_point, const Float:end_point)
{
        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
        write_byte(TE_BEAMPOINTS) // TE id: 0
        engfunc(EngFunc_WriteCoord, start_point) // x
        engfunc(EngFunc_WriteCoord, start_point) // y
        engfunc(EngFunc_WriteCoord, start_point) // z
        engfunc(EngFunc_WriteCoord, end_point) // x
        engfunc(EngFunc_WriteCoord, end_point) // y
        engfunc(EngFunc_WriteCoord, end_point) // z
        write_short(g_beamSpr) // sprite index
        write_byte(0) // starting frame
        write_byte(1) // frame rate in 0.1's
        write_byte(1) // life in 0.1's
        write_byte(30) // line width in 0.1's
        write_byte(0) // noise amplitude in 0.01's
        write_byte(0) // red (R.G.B)
        write_byte(245) // green (R.G.B)
        write_byte(255) // blue (R.G.B)
        write_byte(255) // brightness
        write_byte(0) // scroll speed in 0.1's
        message_end()
}

381828358 发表于 2011-8-18 11:26:35

public fw_SetModel(entity, const model[])
{
        if (!pev_valid(entity))
                return FMRES_IGNORED;
       
        new owner
        owner = pev(entity, pev_owner)
       
        if (equal(model, "w_weaponbox.mdl"))
        {
                user_drop = entity;
                return FMRES_IGNORED;
        }
       
        if (user_drop == entity)
        {
                if (hasp_p90 && equal(model, "w_m249.mdl"))
                {
                        fm_kill_entity(entity)
                       
                        drop_p_p90(owner, 0, 1)
                       
                        drop_time = get_gametime()
                        hasp_p90 = false
                }
        }
       
        user_drop = -1
       
        return FMRES_IGNORED;
}

public fw_Touch(ptr, ptd)
{
        if (!pev_valid(ptr) || !pev_valid(ptd))
                return FMRES_IGNORED;
       
        new classname
        pev(ptr, pev_classname, classname, charsmax(classname))
       
        if (!equal(classname, "CS_p_p90"))
                return FMRES_IGNORED;
       
        if (has_custom_weapons(ptd, PRIMARY_WEAPONS_BIT_SUM))
                return FMRES_IGNORED;
       
        if (get_gametime() - drop_time < 0.5)
                return FMRES_IGNORED;
       
        hasp_p90 = true
        fm_give_item(ptd, "weapon_m249")
       
        static weap_clip, user_bpammo, weap_ent
        weap_clip = pev(ptr, pev_iuser3)
        user_bpammo = min(cs_get_user_bpammo(ptd, CSW_M249) + pev(ptr, pev_iuser4), 30)
        weap_ent = fm_find_ent_by_owner(-1, "weapon_m249", ptd)
       
        cs_set_weapon_ammo(weap_ent, weap_clip)
        cs_set_user_bpammo(ptd, CSW_M249, user_bpammo)
       
        engfunc(EngFunc_RemoveEntity, ptr)
       
        client_print(ptd, print_chat, "你撿到了一把p_p90.")
       
        return FMRES_IGNORED;
}

public event_cur_weapon(id)
{
        if (!hasp_p90)
                return;
       
        new weap_id, weap_clip, weap_bpammo
        weap_id = get_user_weapon(id, weap_clip, weap_bpammo)
       
        if (weap_id != CSW_M249)
                return;
       
        set_p_p90_model(id)
        user_clip = weap_clip
        user_bpammo = weap_bpammo
        user_shoot = false
}

public set_p_p90_model(id)
{
        set_pev(id, pev_viewmodel2, p_p90_V_Model)
        set_pev(id, pev_weaponmodel2, p_p90_P_Model)
}

public drop_p_p90(id, store_bpammo, drop_type)
{
        new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
       
        if (!pev_valid(ent))return 0;
       
        set_pev(ent, pev_classname, "CS_p_p90")
        set_pev(ent, pev_iuser1, 0) // hasn't bounced yet
        set_pev(ent, pev_solid, SOLID_TRIGGER)
        set_pev(ent, pev_movetype, MOVETYPE_TOSS)
       
        new Float:mins = { -16.0, -16.0, -16.0 }
        new Float:maxs = { 16.0, 16.0, 16.0 }
        engfunc(EngFunc_SetSize, ent, mins, maxs)
       
        set_pev(ent, pev_iuser3, user_clip)
       
        if (store_bpammo)
        {
                set_pev(ent, pev_iuser4, user_bpammo)
                cs_set_user_bpammo(id, CSW_M249, 0)
        }
        else
        {
                set_pev(ent, pev_iuser4, 0)
        }
       
        new Float:angles
        pev(id, pev_angles, angles)
        angles = angles = 0.0
        set_pev(ent, pev_angles, angles)
       
        engfunc(EngFunc_SetModel, ent, p_p90_W_Model)
       
        new Float:origin
        pev(id, pev_origin, origin)
       
        if (drop_type)
        {
                new Float:velocity
                velocity_by_aim(id, 15, velocity)
                origin += velocity
                origin += velocity
                origin += velocity
                set_pev(ent, pev_origin, origin)
                velocity_by_aim(id, 400, velocity)
                set_pev(ent, pev_velocity, velocity)
        }
        else
        {
                new Float:drop_angle = random_float(0.0, 360.0)
                origin += 15.0 * floatcos(drop_angle, degrees)
                origin += 15.0 * floatsin(drop_angle, degrees)
                set_pev(ent, pev_origin, origin)
        }
       
        return 1;
}

public client_connect(id)
{
        hasp_p90 = false
}

public client_disconnect(id)
{
        hasp_p90 = false
}

public reset_p_p90()
{
        for (new id = 1; id <= g_maxplayers; id++)
        {
                if (is_user_connected(id) && is_user_alive(id) && hasp_p90 && !user_has_weapon(id, CSW_M249))
                {
                        hasp_p90 = false
                }
        }
}

stock drop_primary_weapons(id)
{
        static weapons, num, i, weaponid
        num = 0 // reset passed weapons count (bugfix)
        get_user_weapons(id, weapons, num)
       
        for (i = 0; i < num; i++)
        {
                weaponid = weapons
               
                if ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM)
                {
                        static wname
                        get_weaponname(weaponid, wname, sizeof wname - 1)
                        engclient_cmd(id, "drop", wname)
                }
        }
}

stock fm_give_item(index, const item[])
{
        if (!equal(item, "weapon_", 7) && !equal(item, "ammo_", 5) && !equal(item, "item_", 5) && !equal(item, "tf_weapon_", 10))
                return 0
       
        new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, item))
        if (!pev_valid(ent))
                return 0
       
        new Float:origin
        pev(index, pev_origin, origin)
        set_pev(ent, pev_origin, origin)
        set_pev(ent, pev_spawnflags, pev(ent, pev_spawnflags) | SF_NORESPAWN)
        dllfunc(DLLFunc_Spawn, ent)
       
        new save = pev(ent, pev_solid)
        dllfunc(DLLFunc_Touch, ent, index)
        if (pev(ent, pev_solid) != save)
                return ent
       
        engfunc(EngFunc_RemoveEntity, ent)
       
        return -1
}

stock bool:has_custom_weapons(id, const bitsum)
{
        static weapons, num, i, weaponid
        num = 0 // reset passed weapons count (bugfix)
        get_user_weapons(id, weapons, num)
       
        for (i = 0; i < num; i++)
        {
                weaponid = weapons
               
                if ((1<<weaponid) & bitsum)
                        return true;
        }
       
        return false;
}

stock fm_find_ent_by_owner(entity, const classname[], owner)
{
        while ((entity = engfunc(EngFunc_FindEntityByString, entity, "classname", classname)) && (pev(entity, pev_owner) != owner)) {}
       
        return entity;
}

stock fm_find_ent_by_class(index, const classname[])
{
        return engfunc(EngFunc_FindEntityByString, index, "classname", classname)
}

stock fm_kill_entity(index)
{
        set_pev(index, pev_flags, pev(index, pev_flags) | FL_KILLME);
       
        return 1;
}

stock Float:get_weapon_next_pri_attack(entity)
{
        return get_pdata_float(entity, OFFSET_FlNextPrimaryAttack, OFFSET_LINUX_WEAPONS)
}

stock set_weapon_next_pri_attack(entity, Float:time)
{
        set_pdata_float(entity, OFFSET_FlNextPrimaryAttack, time, OFFSET_LINUX_WEAPONS)
}

stock fm_get_aim_vector(index, forward_distance, Float:forward_origin, Float:view_end_origin)
{
        new Float:start, Float:view_ofs
        pev(index, pev_origin, start);
        pev(index, pev_view_ofs, view_ofs);
        xs_vec_add(start, view_ofs, start);
       
        new Float:vector, Float:temp;
        pev(index, pev_v_angle, vector);
        engfunc(EngFunc_MakeVectors, vector);
        global_get(glb_v_forward, vector);
        xs_vec_mul_scalar(vector, float(forward_distance), temp);
        xs_vec_add(start, temp, forward_origin);
       
        new Float:dest
        xs_vec_mul_scalar(vector, 9999.0, temp);
        xs_vec_add(start, temp, dest);
        engfunc(EngFunc_TraceLine, start, dest, 0, index, 0);
        get_tr2(0, TR_vecEndPos, view_end_origin);
       
        return 1;
}

#if defined SUPPORT_CZBOT
// CZBot support
public client_putinserver(id)
{
        if (!cvar_botquota || !is_user_bot(id) || BotHasDebug)
                return;
       
        new classname
        pev(id, pev_classname, classname, 31)
       
        if (!equal(classname, "player"))
                set_task(0.1, "_Debug", id)
}
public _Debug(id)
{
        // Make sure it's a CZ bot and it's still connected
        if (!get_pcvar_num(cvar_botquota) || !is_user_connected(id))
                return;
       
        BotHasDebug = true
        RegisterHamFromEntity(Ham_TakeDamage, id, "fw_Player_TakeDamage")
        RegisterHamFromEntity(Ham_TraceAttack, id, "fw_Player_TraceAttack")
}

hackroad 发表于 2011-8-18 13:13:11

MDL文件有么

381828358 发表于 2011-8-18 14:13:19

已经发了

sanshi1978 发表于 2011-8-25 10:00:01

我有这个插件!联系qq71466322

chwafz 发表于 2011-9-1 09:41:35

我有这个插件!联系qq71466322
sanshi1978 发表于 2011-8-25 10:00 http://www.dt-club.net/forum/images/common/back.gif


有可以放上来啊 大家去下载多好
页: [1]
查看完整版本: 终结者p90滚筒枪插件