AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   SuperHero Ricochet plugin sometimes dont see trajectory (https://forums.alliedmods.net/showthread.php?t=308535)

gameplayonline 06-24-2018 11:45

SuperHero Ricochet plugin sometimes dont see trajectory
 
// RICOCHET!
I have this code of hero Ricochet:
Code:

/* CVARS - copy and paste to shconfig.cfg

//Ricochet
ricochet_level 0
ricochet_showrebound 1        //Show rebound sprites
ricochet_extradamage 5        //Additional damage (not a damage mult)

*/

/*
*    Based on Bouncing bullets 1.1 by marcellus.
*    (warcs_ricochet.sma)
*    Requested by fikstress.
*/

#include <superheromod>
#include <xs>

new gSpriteLaser
new g_normal_ptr[SH_MAXSLOTS+1]

new Float:g_last_attack_release_gametime[SH_MAXSLOTS+1]
static const g_czero_burnDecal[5] = {53, 54, 55, 56, 57}
static const g_cs_burnDecal[5] = {41, 42, 43, 44, 45}

#define MAX_BURST_FIRE_TIME 0.2

#define GUNS_BIT_SUM ((1<<CSW_P228) | (1<<CSW_SCOUT) | (1<<CSW_XM1014) | (1<<CSW_MAC10) | (1<<CSW_AUG) | (1<<CSW_ELITE) | (1<<CSW_FIVESEVEN) | (1<<CSW_UMP45) | (1<<CSW_SG550) | (1<<CSW_GALIL) | (1<<CSW_FAMAS) | (1<<CSW_USP) | (1<<CSW_GLOCK18) | (1<<CSW_AWP) | (1<<CSW_MP5NAVY) | (1<<CSW_M249) | (1<<CSW_M3) | (1<<CSW_M4A1) | (1<<CSW_TMP) | (1<<CSW_G3SG1) | (1<<CSW_DEAGLE) | (1<<CSW_SG552) | (1<<CSW_AK47) | (1<<CSW_P90))
#define BURSTGUNS_BIT_SUM ((1<<CSW_FAMAS) | (1<<CSW_GLOCK18))
#define SHOTGUNS_BIT_SUM ((1<<CSW_XM1014) | (1<<CSW_M3))

new bool:g_czero = false

// GLOBAL VARIABLES
new gHeroID
new const gHeroName[] = "Ricochet"
new bool:gHasRicochet[SH_MAXSLOTS+1]
new gPcvarExtraDmg
new gPcvarShowRebound
//----------------------------------------------------------------------------------------------
public plugin_init()
{
        // Plugin Info
        register_plugin("SUPERHERO Ricochet", "1.2", "Omus/Fr33m@n / marcellus")

        // DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
        new pcvarLevel = register_cvar("ricochet_level", "0")
        gPcvarShowRebound = register_cvar("ricochet_showrebound", "1")
        gPcvarExtraDmg = register_cvar("ricochet_extradamage", "5")

        // FIRE THE EVENTS TO CREATE THIS SUPERHERO!
        gHeroID = sh_create_hero(gHeroName, pcvarLevel)
        sh_set_hero_info(gHeroID, "Bouncing bullets", "Make every bullets bouncing upon walls, floor or objects. Also additional damage !")

        // REGISTER EVENTS THIS HERO WILL RESPOND TO! (AND SERVER COMMANDS)
        register_forward(FM_TraceLine, "fwTraceLine", 1)
        register_forward(FM_PlayerPreThink, "fwPlayerPreThink")

        new modname[7]; get_modname(modname, 6)
        g_czero = equal(modname,"czero") ? true : false
}
//----------------------------------------------------------------------------------------------
public plugin_precache()
{
        gSpriteLaser = precache_model("sprites/flare5.spr")
}
//----------------------------------------------------------------------------------------------
public sh_hero_init(id, heroID, mode)
{
        if ( gHeroID != heroID ) return

        gHasRicochet[id] = mode ? true : false

        sh_debug_message(id, 1, "%s %s", gHeroName, mode ? "ADDED" : "DROPPED")
}
//----------------------------------------------------------------------------------------------
// From VEN 's tutorial Detect fired particle creation/type/number/attack/obstacle/vector
public fwTraceLine(const Float:start[3], const Float:dest[3], ignore_monsters, id, ptr)
{
        if ( !sh_is_active() ) {
                return FMRES_IGNORED
        }

        if (ignore_monsters) {
                return FMRES_IGNORED
        }

        if (!is_user_alive(id) || !gHasRicochet[id]) {
                return FMRES_IGNORED
        }

        if (!g_normal_ptr[id]) {
                g_normal_ptr[id] = ptr

                return FMRES_IGNORED
        }

        if (ptr == g_normal_ptr[id]) {
                return FMRES_IGNORED
        }

        if (is_user_alive(get_tr2(ptr, TR_pHit))) {
                return FMRES_IGNORED
        }

        static clip, ammo, weapon_id

        // get the current weapon index
        weapon_id = get_user_weapon(id, clip, ammo)

        if (!(GUNS_BIT_SUM & (1<<weapon_id))) {
                return FMRES_IGNORED
        }

        static Float:gametime

        // get current game time
        gametime = get_gametime()

        new bool:is_hold_primary_attack = bool:(pev(id, pev_button) & IN_ATTACK)

        if (!(BURSTGUNS_BIT_SUM & (1<<weapon_id))) {
                // the current weapon isn't a burst gun
                if (!is_hold_primary_attack) {
                        return FMRES_IGNORED
                }
        }
        else {
                // the current weapon is a burst gun
                if (!is_hold_primary_attack) {
                        if (gametime - g_last_attack_release_gametime[id] > MAX_BURST_FIRE_TIME) {
                                return FMRES_IGNORED
                        }
                }
        }

        static Float:fired_particle_start_origin[3], Float:vector[3]

        // get the player's origin and view offset
        pev(id, pev_origin, fired_particle_start_origin)
        pev(id, pev_view_ofs, vector)

        // get the fired particle start origin
        xs_vec_add(fired_particle_start_origin, vector, fired_particle_start_origin)
        static bool:particle_is_fired ; particle_is_fired = xs_vec_equal(fired_particle_start_origin, start)

        if (particle_is_fired) {
                static Float: vnormal[3], Float:bulletshot[3], Float:v[3], Float:t[3], Float:t2[3], Float:n[3], Float:vdotvnormal, Float:r[3]
                static ptr2, Float:f, ent

                // get the end position of the current trace
                get_tr2(ptr, TR_vecEndPos, vector)
                xs_vec_copy(vector, bulletshot)

                xs_vec_sub(vector, fired_particle_start_origin, vector)

                get_tr2(ptr, TR_vecPlaneNormal, vnormal)

                if (get_pcvar_num(gPcvarShowRebound))
                {
                        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
                        write_byte(TE_BEAMPOINTS)        // 0
                        engfunc(EngFunc_WriteCoord,bulletshot[0]-vnormal[0]*200)
                        engfunc(EngFunc_WriteCoord,bulletshot[1]-vnormal[1]*200)
                        engfunc(EngFunc_WriteCoord,bulletshot[2]-vnormal[2]*200)
                        engfunc(EngFunc_WriteCoord,bulletshot[0]+vnormal[0]*200)
                        engfunc(EngFunc_WriteCoord,bulletshot[1]+vnormal[1]*200)
                        engfunc(EngFunc_WriteCoord,bulletshot[2]+vnormal[2]*200)
                        write_short(gSpriteLaser)
                        write_byte(1)                // framestart
                        write_byte(1)                // framerate
                        write_byte(99)                // life
                        write_byte(99)                // width
                        write_byte(0)                // noise
                        write_byte(random(255))                // r, g, b
                        write_byte(random(255))                // r, g, b
                        write_byte(random(255))                // r, g, b
                        write_byte(100)                // brightness
                        write_byte(0)                // speed
                        message_end()
                }

                // Calculate boucing bullet
                v[0] = (bulletshot[0] - fired_particle_start_origin[0]) * -1
                v[1] = (bulletshot[1] - fired_particle_start_origin[1]) * -1
                v[2] = (bulletshot[2] - fired_particle_start_origin[2]) * -1

                vdotvnormal = xs_vec_dot(v,vnormal) * 2.0
                xs_vec_mul_scalar(vnormal, vdotvnormal, t)
                xs_vec_sub(t, v, t2)
                xs_vec_normalize(t2,r)
                xs_vec_mul_scalar(r, 2048.0, r)
                xs_vec_add(bulletshot, r, n)

                ptr2 = create_tr2()
                engfunc(EngFunc_TraceLine,bulletshot, n, DONT_IGNORE_MONSTERS, id, ptr2)
                get_tr2(ptr2,TR_flFraction, f)

                if (f != 1.0)
                {
                        static hitgroup ; hitgroup = get_tr2(ptr2, TR_iHitgroup)
                        ent = get_tr2(ptr2, TR_pHit)

                        if (pev_valid(ent)) {
                                ExecuteHamB(Ham_TraceAttack, ent, id, 30.0, r, ptr2, hitgroup)
                        }
                        else {
                                static Float: vecend[3]
                                static decal_id

                                decal_id = (g_czero) ? g_czero_burnDecal[random_num(0,4)] : g_cs_burnDecal[random_num(0,4)]

                                get_tr2(ptr2, TR_vecEndPos, vecend)

                                engfunc(EngFunc_MessageBegin,MSG_PVS, SVC_TEMPENTITY, vecend, 0)
                                write_byte(TE_GUNSHOTDECAL)        // 109
                                engfunc(EngFunc_WriteCoord,vecend[0])
                                engfunc(EngFunc_WriteCoord,vecend[1])
                                engfunc(EngFunc_WriteCoord,vecend[2])
                                write_short(0)
                                write_byte(decal_id)
                                message_end()

                                engfunc(EngFunc_MessageBegin,MSG_PVS, SVC_TEMPENTITY, vecend, 0)
                                write_byte(TE_SPARKS)                // 9
                                engfunc(EngFunc_WriteCoord,vecend[0])
                                engfunc(EngFunc_WriteCoord,vecend[1])
                                engfunc(EngFunc_WriteCoord,vecend[2])
                                message_end()
                        }
                }
                free_tr2(ptr2)
                if (get_pcvar_num(gPcvarShowRebound))
                {
                        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
                        write_byte(TE_BEAMPOINTS)                // 0
                        engfunc(EngFunc_WriteCoord, fired_particle_start_origin[0])
                        engfunc(EngFunc_WriteCoord, fired_particle_start_origin[1])
                        engfunc(EngFunc_WriteCoord, fired_particle_start_origin[2])
                        engfunc(EngFunc_WriteCoord, bulletshot[0])
                        engfunc(EngFunc_WriteCoord, bulletshot[1])
                        engfunc(EngFunc_WriteCoord, bulletshot[2])
                        write_short(gSpriteLaser)
                        write_byte(1)                // framestart
                        write_byte(1)                // framerate
                        write_byte(99)                // life
                        write_byte(99)                // width
                        write_byte(0)                // noise
                        write_byte(random(255))                // r, g, b
                        write_byte(random(255))                // r, g, b
                        write_byte(random(255))                // r, g, b
                        write_byte(100)                // brightness
                        write_byte(0)                // speed
                        message_end()

                        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
                        write_byte(TE_BEAMPOINTS)                // 0
                        engfunc(EngFunc_WriteCoord, bulletshot[0])
                        engfunc(EngFunc_WriteCoord, bulletshot[1])
                        engfunc(EngFunc_WriteCoord, bulletshot[2])
                        engfunc(EngFunc_WriteCoord, n[0])
                        engfunc(EngFunc_WriteCoord, n[1])
                        engfunc(EngFunc_WriteCoord, n[2])
                        write_short(gSpriteLaser)
                        write_byte(1)                // framestart
                        write_byte(1)                // framerate
                        write_byte(99)                // life
                        write_byte(99)                // width
                        write_byte(0)                // noise
                        write_byte(random(255))                // r, g, b
                        write_byte(random(255))                // r, g, b
                        write_byte(random(255))                // r, g, b
                        write_byte(100)                // brightness
                        write_byte(0)                // speed
                        message_end()
                }
        }
        return FMRES_IGNORED
}
//----------------------------------------------------------------------------------------------
public client_damage(attacker, victim, damage, wpnindex, hitplace)
{
        if ( !sh_is_active() ) return
        if ( !is_user_alive(victim) || !is_user_connected(attacker) ) return

        if ( gHasRicochet[attacker] && CSW_P228 <= wpnindex <= CSW_P90 ) {
                new wpn[32]
                get_weaponname(wpnindex, wpn, charsmax(wpn))
                replace(wpn, charsmax(wpn), "weapon_", "")

                new headshot = hitplace == 1 ? 1 : 0

                // do extra damage
                new extraDamage = get_pcvar_num(gPcvarExtraDmg)
                if ( extraDamage > 0) sh_extra_damage(victim, attacker, extraDamage, wpn, headshot)
        }
}
//----------------------------------------------------------------------------------------------
public client_connect(id)
{
        gHasRicochet[id] = false
}
//----------------------------------------------------------------------------------------------
public client_disconnect(id)
{
        // clear variables on disconnect
        g_normal_ptr[id] = 0
        g_last_attack_release_gametime[id] = 0.0
}
//----------------------------------------------------------------------------------------------
public fwPlayerPreThink(id)
{
        if ((pev(id, pev_oldbuttons) & IN_ATTACK) && !(pev(id, pev_button) & IN_ATTACK)) {
                // the primary attack button is released
                // save the current gametime
                g_last_attack_release_gametime[id] = get_gametime()
        }
}
//----------------------------------------------------------------------------------------------

My problem is all is working good i see many different coolors(Red, Green, Blue) and after that for some time i cant see any trajectory. After ec. 10 seconds all trajcetories are shown again. Where is problem? I dont understand why is this doing. How can i rework it to see trajectory in colors all the time?

gameplayonline 06-24-2018 20:13

Re: SuperHero Ricochet plugin sometimes dont see trajectory
 
I think problem can be if function random dont choose on R,G,B in same time and this affect invisible trajectory. Am i right? Or is here problem in time calculation or can somebody explain please?

gameplayonline 07-01-2018 08:59

Re: SuperHero Ricochet plugin sometimes dont see trajectory
 
bump


All times are GMT -4. The time now is 12:24.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.